Mercurial > hg > vampy
comparison PyParameterDescriptor.cpp @ 37:27bab3a16c9a vampy2final
new branch Vampy2final
author | fazekasgy |
---|---|
date | Mon, 05 Oct 2009 11:28:00 +0000 |
parents | |
children | af9c4cee95a8 |
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 "PyParameterDescriptor.h" | |
14 #include "vamp-sdk/Plugin.h" | |
15 #include <string> | |
16 #include "PyTypeInterface.h" | |
17 | |
18 using namespace std; | |
19 using namespace Vamp; | |
20 using Vamp::Plugin; | |
21 | |
22 /* ParameterDescriptor Object's Methods */ | |
23 //these objects have no callable methods | |
24 | |
25 /* PyParameterDescriptor methods implementing protocols */ | |
26 // these functions are called by the interpreter automatically | |
27 | |
28 /* New ParameterDescriptor object */ | |
29 static PyObject * | |
30 ParameterDescriptor_new(PyTypeObject *type, PyObject *args, PyObject *kw) | |
31 { | |
32 | |
33 ParameterDescriptorObject *self = | |
34 (ParameterDescriptorObject*)type->tp_alloc(type, 0); | |
35 | |
36 if (self == NULL) return NULL; | |
37 self->dict = PyDict_New(); | |
38 if (self->dict == NULL) return NULL; | |
39 | |
40 /// allow copying objects | |
41 if (args and PyTuple_Size(args) == 1) { | |
42 PyObject* arg = PyTuple_GET_ITEM(args,0); | |
43 if (PyParameterDescriptor_CheckExact(arg)) | |
44 PyDict_Merge(self->dict,PyParameterDescriptor_AS_DICT(arg),0); | |
45 else if (PyDict_CheckExact(arg)) | |
46 PyDict_Merge(self->dict,arg,0); | |
47 else { | |
48 PyErr_SetString(PyExc_TypeError, | |
49 "Object takes zero or one ParameterDescriptor or dictionary arguments."); | |
50 return NULL; | |
51 } | |
52 } | |
53 return (PyObject *) self; | |
54 } | |
55 | |
56 | |
57 /* DESTRUCTOR: delete type object */ | |
58 static void | |
59 ParameterDescriptorObject_dealloc(ParameterDescriptorObject *self) | |
60 { | |
61 Py_XDECREF(self->dict); | |
62 PyObject_Del(self); | |
63 } | |
64 | |
65 | |
66 /* Set attributes */ | |
67 static int | |
68 ParameterDescriptor_setattr(ParameterDescriptorObject *self, char *name, PyObject *v) | |
69 { | |
70 if (v == NULL) { | |
71 int rv = PyDict_DelItemString(self->dict, name); | |
72 if (rv < 0) | |
73 PyErr_SetString(PyExc_AttributeError,"non-existing ParameterDescriptor attribute"); | |
74 return rv; | |
75 } | |
76 else | |
77 return PyDict_SetItemString(self->dict, name, v); | |
78 } | |
79 | |
80 | |
81 /* Get attributes */ | |
82 static PyObject * | |
83 ParameterDescriptor_getattr(ParameterDescriptorObject *self, char *name) | |
84 { | |
85 if (self->dict != NULL) { | |
86 PyObject *v = PyDict_GetItemString(self->dict, name); | |
87 if (v != NULL) | |
88 { | |
89 Py_INCREF(v); | |
90 return v; | |
91 } | |
92 } | |
93 return NULL; | |
94 } | |
95 | |
96 | |
97 /* String representation */ | |
98 static PyObject * | |
99 ParameterDescriptor_repr(PyObject *self) | |
100 { | |
101 ParameterDescriptorObject* v = (ParameterDescriptorObject*)self; | |
102 if (v->dict) return PyDict_Type.tp_repr((PyObject *)v->dict); | |
103 else return PyString_FromString("ParameterDescriptor()"); | |
104 } | |
105 | |
106 #define ParameterDescriptor_alloc PyType_GenericAlloc | |
107 #define ParameterDescriptor_free PyObject_Del | |
108 | |
109 PyTypeObject ParameterDescriptor_Type = { | |
110 PyObject_HEAD_INIT(NULL) | |
111 0, /*ob_size*/ | |
112 "vampy.ParameterDescriptor",/*tp_name*/ | |
113 sizeof(ParameterDescriptorObject), /*tp_basicsize*/ | |
114 0, /*tp_itemsize*/ | |
115 (destructor)ParameterDescriptorObject_dealloc, /*tp_dealloc*/ | |
116 0, /*tp_print*/ | |
117 (getattrfunc)ParameterDescriptor_getattr, /*tp_getattr*/ | |
118 (setattrfunc)ParameterDescriptor_setattr, /*tp_setattr*/ | |
119 0, /*tp_compare*/ | |
120 ParameterDescriptor_repr, /*tp_repr*/ | |
121 0, /*tp_as_number*/ | |
122 0, /*tp_as_sequence*/ | |
123 0, /*tp_as_mapping*/ | |
124 0, /*tp_hash*/ | |
125 0, /*tp_call*/ | |
126 0, /*tp_str*/ | |
127 0, /*tp_getattro*/ | |
128 0, /*tp_setattro*/ | |
129 0, /*tp_as_buffer*/ | |
130 Py_TPFLAGS_DEFAULT, /*tp_flags*/ | |
131 0, /*tp_doc*/ | |
132 0, /*tp_traverse*/ | |
133 0, /*tp_clear*/ | |
134 0, /*tp_richcompare*/ | |
135 0, /*tp_weaklistoffset*/ | |
136 0, /*tp_iter*/ | |
137 0, /*tp_iternext*/ | |
138 0, /*tp_methods*/ //TypeObject Methods | |
139 0, /*tp_members*/ | |
140 0, /*tp_getset*/ | |
141 0, /*tp_base*/ | |
142 0, /*tp_dict*/ | |
143 0, /*tp_descr_get*/ | |
144 0, /*tp_descr_set*/ | |
145 0, /*tp_dictoffset*/ | |
146 0, /*tp_init*/ | |
147 ParameterDescriptor_alloc,/*tp_alloc*/ | |
148 ParameterDescriptor_new,/*tp_new*/ | |
149 ParameterDescriptor_free,/*tp_free*/ | |
150 0, /*tp_is_gc*/ | |
151 }; | |
152 | |
153 /* PyParameterDescriptor C++ API */ | |
154 |