comparison PyFeatureSet.cpp @ 37:27bab3a16c9a vampy2final

new branch Vampy2final
author fazekasgy
date Mon, 05 Oct 2009 11:28:00 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 37:27bab3a16c9a
1 /*
2
3 * Vampy : This plugin is a wrapper around the Vamp plugin API.
4 * It allows for writing Vamp plugins in Python.
5
6 * Centre for Digital Music, Queen Mary University of London.
7 * Copyright (C) 2008-2009 Gyorgy Fazekas, QMUL. (See Vamp sources
8 * for licence information.)
9
10 */
11
12 #include <Python.h>
13 #include "PyFeatureSet.h"
14 #include "vamp-sdk/Plugin.h"
15
16 using namespace std;
17
18 static int
19 FeatureSet_init(FeatureSetObject *self, PyObject *args, PyObject *kwds)
20 {
21 if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0)
22 return -1;
23 return 0;
24 }
25
26 static int
27 FeatureSetObject_ass_sub(FeatureSetObject *mp, PyObject *v, PyObject *w)
28 {
29 if (!PyInt_CheckExact(v)) {
30 PyErr_SetString(PyExc_ValueError,
31 "Output index must be positive integer.");
32 return 0;
33 }
34 if (w == NULL)
35 return PyDict_DelItem((PyObject *)mp, v);
36 else
37 return PyDict_SetItem((PyObject *)mp, v, w);
38 }
39
40 #define FeatureSet_alloc PyType_GenericAlloc
41 #define FeatureSet_free PyObject_Del
42 //#define FeatureSet_as_mapping PyDict_Type.tp_as_mapping
43
44 static PyMappingMethods FeatureSet_as_mapping = *(PyDict_Type.tp_as_mapping);
45
46 PyTypeObject FeatureSet_Type = PyDict_Type;
47
48 void
49 initFeatureSetType(void)
50 {
51 /*This type is derived from PyDict. We just override some slots here.*/
52 /*The typical use case is index based assignment as opposed to object memeber access.*/
53 FeatureSet_Type.ob_type = &PyType_Type;
54 FeatureSet_Type.tp_base = &PyDict_Type;
55 FeatureSet_Type.tp_bases = PyTuple_Pack(1, FeatureSet_Type.tp_base);
56 FeatureSet_Type.tp_name = "vampy.FeatureSet";
57 // FeatureSet_Type.tp_new = FeatureSet_new;
58 FeatureSet_Type.tp_init = (initproc)FeatureSet_init;
59 FeatureSet_Type.tp_basicsize = sizeof(FeatureSetObject);
60 FeatureSet_as_mapping.mp_ass_subscript = (objobjargproc)FeatureSetObject_ass_sub;
61 FeatureSet_Type.tp_as_mapping = &FeatureSet_as_mapping;
62 }
63