Mercurial > hg > vampy
comparison PyParameterDescriptor.cpp @ 31:4f1894c7591b vampy2
Created Vampy2 branch
author | fazekasgy |
---|---|
date | Sun, 20 Sep 2009 17:31:20 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
28:5139bf30f208 | 31:4f1894c7591b |
---|---|
1 #include <Python.h> | |
2 #include "PyParameterDescriptor.h" | |
3 #include "vamp-sdk/Plugin.h" | |
4 #include <string> | |
5 #include "PyTypeInterface.h" | |
6 | |
7 using namespace std; | |
8 using namespace Vamp; | |
9 using Vamp::Plugin; | |
10 | |
11 /* ParameterDescriptor Object's Methods */ | |
12 //Feature objects have no callable methods | |
13 | |
14 /* PyParameterDescriptor methods implementing protocols */ | |
15 // these functions are called by the interpreter automatically | |
16 | |
17 /* New ParameterDescriptor object */ | |
18 static PyObject * | |
19 ParameterDescriptor_new(PyTypeObject *type, PyObject *args, PyObject *kw) | |
20 { | |
21 | |
22 if (!PyArg_ParseTuple(args, ":ParameterDescriptor")) { | |
23 PyErr_SetString(PyExc_TypeError, | |
24 "Error: ParameterDescriptor initialised with arguments."); | |
25 return NULL; | |
26 } | |
27 | |
28 ParameterDescriptorObject *self = | |
29 (ParameterDescriptorObject*)type->tp_alloc(type, 0); | |
30 | |
31 if (self == NULL) return NULL; | |
32 self->dict = PyDict_New(); | |
33 if (self->dict == NULL) return NULL; | |
34 return (PyObject *) self; | |
35 } | |
36 | |
37 | |
38 /* DESTRUCTOR: delete type object */ | |
39 static void | |
40 ParameterDescriptorObject_dealloc(ParameterDescriptorObject *self) | |
41 { | |
42 Py_XDECREF(self->dict); | |
43 PyObject_Del(self); | |
44 } | |
45 | |
46 | |
47 /* Set attributes */ | |
48 static int | |
49 ParameterDescriptor_setattr(ParameterDescriptorObject *self, char *name, PyObject *v) | |
50 { | |
51 if (v == NULL) { | |
52 int rv = PyDict_DelItemString(self->dict, name); | |
53 if (rv < 0) | |
54 PyErr_SetString(PyExc_AttributeError,"non-existing ParameterDescriptor attribute"); | |
55 return rv; | |
56 } | |
57 else | |
58 return PyDict_SetItemString(self->dict, name, v); | |
59 } | |
60 | |
61 | |
62 /* Get attributes */ | |
63 static PyObject * | |
64 ParameterDescriptor_getattr(ParameterDescriptorObject *self, char *name) | |
65 { | |
66 if (self->dict != NULL) { | |
67 PyObject *v = PyDict_GetItemString(self->dict, name); | |
68 if (v != NULL) | |
69 { | |
70 Py_INCREF(v); | |
71 return v; | |
72 } | |
73 } | |
74 return NULL; | |
75 } | |
76 | |
77 | |
78 /* String representation */ | |
79 static PyObject * | |
80 ParameterDescriptor_repr(PyObject *self) | |
81 { | |
82 // if (PyFeature_CheckExact(self)) {} | |
83 // PyObject* intdict = self | |
84 return Py_BuildValue("s", | |
85 "not yet implemented"); | |
86 // ((RealTimeObject*)self)->rt->toString().c_str()); | |
87 } | |
88 | |
89 #define ParameterDescriptor_alloc PyType_GenericAlloc | |
90 #define ParameterDescriptor_free PyObject_Del | |
91 | |
92 PyTypeObject ParameterDescriptor_Type = { | |
93 PyObject_HEAD_INIT(NULL) | |
94 0, /*ob_size*/ | |
95 "vampy.ParameterDescriptor",/*tp_name*/ | |
96 sizeof(ParameterDescriptorObject), /*tp_basicsize*/ | |
97 0, /*tp_itemsize*/ | |
98 (destructor)ParameterDescriptorObject_dealloc, /*tp_dealloc*/ | |
99 0, /*tp_print*/ | |
100 (getattrfunc)ParameterDescriptor_getattr, /*tp_getattr*/ | |
101 (setattrfunc)ParameterDescriptor_setattr, /*tp_setattr*/ | |
102 0, /*tp_compare*/ | |
103 ParameterDescriptor_repr, /*tp_repr*/ | |
104 0, /*tp_as_number*/ | |
105 0, /*tp_as_sequence*/ | |
106 0, /*tp_as_mapping*/ | |
107 0, /*tp_hash*/ | |
108 0, /*tp_call*/ | |
109 0, /*tp_str*/ | |
110 0, /*tp_getattro*/ | |
111 0, /*tp_setattro*/ | |
112 0, /*tp_as_buffer*/ | |
113 Py_TPFLAGS_DEFAULT, /*tp_flags*/ | |
114 0, /*tp_doc*/ | |
115 0, /*tp_traverse*/ | |
116 0, /*tp_clear*/ | |
117 0, /*tp_richcompare*/ | |
118 0, /*tp_weaklistoffset*/ | |
119 0, /*tp_iter*/ | |
120 0, /*tp_iternext*/ | |
121 0, /*tp_methods*/ //TypeObject Methods | |
122 0, /*tp_members*/ | |
123 0, /*tp_getset*/ | |
124 0, /*tp_base*/ | |
125 0, /*tp_dict*/ | |
126 0, /*tp_descr_get*/ | |
127 0, /*tp_descr_set*/ | |
128 0, /*tp_dictoffset*/ | |
129 0, /*tp_init*/ | |
130 ParameterDescriptor_alloc,/*tp_alloc*/ | |
131 ParameterDescriptor_new,/*tp_new*/ | |
132 ParameterDescriptor_free,/*tp_free*/ | |
133 0, /*tp_is_gc*/ | |
134 }; | |
135 | |
136 /* PyParameterDescriptor C++ API */ | |
137 |