Mercurial > hg > vampy
comparison PyFeatureSet.cpp @ 31:4f1894c7591b vampy2
Created Vampy2 branch
author | fazekasgy |
---|---|
date | Sun, 20 Sep 2009 17:31:20 +0000 |
parents | |
children | a8231788216c |
comparison
equal
deleted
inserted
replaced
28:5139bf30f208 | 31:4f1894c7591b |
---|---|
1 #include <Python.h> | |
2 #include "PyFeatureSet.h" | |
3 #include "vamp-sdk/Plugin.h" | |
4 | |
5 using namespace std; | |
6 | |
7 static int | |
8 FeatureSet_init(FeatureSetObject *self, PyObject *args, PyObject *kwds) | |
9 { | |
10 if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0) | |
11 return -1; | |
12 self->state = 0; | |
13 cerr << "FeatureSet initialised" << endl; | |
14 return 0; | |
15 } | |
16 | |
17 static int | |
18 FeatureSetObject_ass_sub(FeatureSetObject *mp, PyObject *v, PyObject *w) | |
19 { | |
20 // cerr << "called FeatureSetObject_ass_sub" << endl; | |
21 if (!PyInt_CheckExact(v)) { | |
22 /// TODO: Set ValueError here. | |
23 cerr << "Output index must be positive integer" << endl; | |
24 return 0; | |
25 } | |
26 if (w == NULL) | |
27 return PyDict_DelItem((PyObject *)mp, v); | |
28 else | |
29 return PyDict_SetItem((PyObject *)mp, v, w); | |
30 } | |
31 | |
32 #define FeatureSet_alloc PyType_GenericAlloc | |
33 #define FeatureSet_free PyObject_Del | |
34 //#define FeatureSet_as_mapping PyDict_Type.tp_as_mapping | |
35 | |
36 static PyMappingMethods FeatureSet_as_mapping = *(PyDict_Type.tp_as_mapping); | |
37 | |
38 PyTypeObject FeatureSet_Type = PyDict_Type; | |
39 // PyTypeObject FeatureSet_Type = { | |
40 // PyObject_HEAD_INIT(NULL) | |
41 // 0, /*ob_size*/ | |
42 // "vampy.FeatureSet", /*tp_name*/ | |
43 // sizeof(FeatureSetObject), /*tp_basicsize*/ | |
44 // 0, /*tp_itemsize*/ | |
45 // (destructor)FeatureSetObject_dealloc, /*tp_dealloc*/ | |
46 // 0,//PyDict_Type.tp_print, /*tp_print*/ | |
47 // 0,//PyDict_Type.tp_getattr, /*tp_getattr*/ | |
48 // 0,//PyDict_Type.tp_setattr, /*tp_setattr*/ | |
49 // 0, /*tp_compare*/ | |
50 // 0,//PyDict_Type.tp_repr, /*tp_repr*/ | |
51 // 0, /*tp_as_number*/ | |
52 // 0, /*tp_as_sequence*/ | |
53 // FeatureSet_as_mapping, /*tp_as_mapping*/ | |
54 // 0, /*tp_hash*/ | |
55 // 0,//Feature_test, /*tp_call*/ // call on an instance | |
56 // 0, /*tp_str*/ | |
57 // PyDict_Type.tp_getattro,/*tp_getattro*/ | |
58 // 0,//PyDict_Type.tp_setattro,/*tp_setattro*/ | |
59 // 0, /*tp_as_buffer*/ | |
60 // Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ | |
61 // 0, /*tp_doc*/ | |
62 // PyDict_Type.tp_traverse, /*tp_traverse*/ | |
63 // PyDict_Type.tp_clear, /*tp_clear*/ | |
64 // 0, /*tp_richcompare*/ | |
65 // 0, /*tp_weaklistoffset*/ | |
66 // 0, /*tp_iter*/ | |
67 // 0, /*tp_iternext*/ | |
68 // PyDict_Type.tp_methods, /*tp_methods*/ //TypeObject Methods | |
69 // PyDict_Type.tp_members, /*tp_members*/ | |
70 // PyDict_Type.tp_getset, /*tp_getset*/ | |
71 // 0, /*tp_base*/ | |
72 // PyDict_Type.tp_dict, /*tp_dict*/ | |
73 // 0, /*tp_descr_get*/ | |
74 // 0, /*tp_descr_set*/ | |
75 // PyDict_Type.tp_dictoffset, /*tp_dictoffset*/ | |
76 // (initproc)FeatureSet_init, /*tp_init*/ | |
77 // FeatureSet_alloc, /*tp_alloc*/ | |
78 // FeatureSet_new, /*tp_new*/ | |
79 // FeatureSet_free, /*tp_free*/ | |
80 // 0, /*tp_is_gc*/ | |
81 // }; | |
82 | |
83 | |
84 void | |
85 initFeatureSetType(void) | |
86 { | |
87 /*This type is derived from PyDict. We just override some slots here.*/ | |
88 /*The typical use case is index based assignment as opposed to object memeber access.*/ | |
89 FeatureSet_Type.ob_type = &PyType_Type; | |
90 FeatureSet_Type.tp_base = &PyDict_Type; | |
91 FeatureSet_Type.tp_bases = PyTuple_Pack(1, FeatureSet_Type.tp_base); | |
92 FeatureSet_Type.tp_name = "vampy.FeatureSet"; | |
93 // FeatureSet_Type.tp_new = FeatureSet_new; | |
94 FeatureSet_Type.tp_init = (initproc)FeatureSet_init; | |
95 FeatureSet_Type.tp_basicsize = sizeof(FeatureSetObject); | |
96 FeatureSet_as_mapping.mp_ass_subscript = (objobjargproc)FeatureSetObject_ass_sub; | |
97 FeatureSet_Type.tp_as_mapping = &FeatureSet_as_mapping; | |
98 } | |
99 |