Mercurial > hg > vampy
comparison PyOutputDescriptor.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 "PyOutputDescriptor.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 /* OutputDescriptor Object's Methods */ | |
23 //these objects have no callable methods | |
24 | |
25 /* PyOutputDescriptor methods implementing protocols */ | |
26 // these functions are called by the interpreter automatically | |
27 | |
28 /* New OutputDescriptor object */ | |
29 static PyObject * | |
30 OutputDescriptor_new(PyTypeObject *type, PyObject *args, PyObject *kw) | |
31 { | |
32 OutputDescriptorObject *self = | |
33 (OutputDescriptorObject*)type->tp_alloc(type, 0); | |
34 | |
35 if (self == NULL) return NULL; | |
36 self->dict = PyDict_New(); | |
37 if (self->dict == NULL) return NULL; | |
38 | |
39 /// allow copying objects | |
40 if (args and PyTuple_Size(args) == 1) { | |
41 PyObject* arg = PyTuple_GET_ITEM(args,0); | |
42 if (PyOutputDescriptor_CheckExact(arg)) | |
43 PyDict_Merge(self->dict,PyOutputDescriptor_AS_DICT(arg),0); | |
44 else if (PyDict_CheckExact(arg)) | |
45 PyDict_Merge(self->dict,arg,0); | |
46 else { | |
47 PyErr_SetString(PyExc_TypeError, | |
48 "OutputDescriptor takes zero or one PyOutputDescriptor or dictionary arguments."); | |
49 return NULL; | |
50 } | |
51 } | |
52 return (PyObject *) self; | |
53 } | |
54 | |
55 | |
56 /* DESTRUCTOR: delete type object */ | |
57 static void | |
58 OutputDescriptorObject_dealloc(OutputDescriptorObject *self) | |
59 { | |
60 Py_XDECREF(self->dict); | |
61 PyObject_Del(self); | |
62 } | |
63 | |
64 | |
65 /* Set attributes */ | |
66 static int | |
67 OutputDescriptor_setattr(OutputDescriptorObject *self, char *name, PyObject *v) | |
68 { | |
69 if (v == NULL) { | |
70 int rv = PyDict_DelItemString(self->dict, name); | |
71 if (rv < 0) | |
72 PyErr_SetString(PyExc_AttributeError,"non-existing OutputDescriptor attribute"); | |
73 return rv; | |
74 } | |
75 else | |
76 return PyDict_SetItemString(self->dict, name, v); | |
77 } | |
78 | |
79 | |
80 /* Get attributes */ | |
81 static PyObject * | |
82 OutputDescriptor_getattr(OutputDescriptorObject *self, char *name) | |
83 { | |
84 if (self->dict != NULL) { | |
85 PyObject *v = PyDict_GetItemString(self->dict, name); | |
86 if (v != NULL) | |
87 { | |
88 Py_INCREF(v); | |
89 return v; | |
90 } | |
91 } | |
92 return NULL; | |
93 } | |
94 | |
95 | |
96 /* String representation */ | |
97 static PyObject * | |
98 OutputDescriptor_repr(PyObject *self) | |
99 { | |
100 OutputDescriptorObject* v = (OutputDescriptorObject*)self; | |
101 if (v->dict) return PyDict_Type.tp_repr((PyObject *)v->dict); | |
102 else return PyString_FromString("OutputDescriptor()"); | |
103 } | |
104 | |
105 #define OutputDescriptor_alloc PyType_GenericAlloc | |
106 #define OutputDescriptor_free PyObject_Del | |
107 | |
108 | |
109 /* REAL-TIME TYPE OBJECT */ | |
110 | |
111 PyTypeObject OutputDescriptor_Type = { | |
112 PyObject_HEAD_INIT(NULL) | |
113 0, /*ob_size*/ | |
114 "vampy.OutputDescriptor",/*tp_name*/ | |
115 sizeof(OutputDescriptorObject), /*tp_basicsize*/ | |
116 0, /*tp_itemsize*/ | |
117 (destructor)OutputDescriptorObject_dealloc, /*tp_dealloc*/ | |
118 0, /*tp_print*/ | |
119 (getattrfunc)OutputDescriptor_getattr, /*tp_getattr*/ | |
120 (setattrfunc)OutputDescriptor_setattr, /*tp_setattr*/ | |
121 0, /*tp_compare*/ | |
122 OutputDescriptor_repr, /*tp_repr*/ | |
123 0, /*tp_as_number*/ | |
124 0, /*tp_as_sequence*/ | |
125 0, /*tp_as_mapping*/ | |
126 0, /*tp_hash*/ | |
127 0, /*tp_call*/ | |
128 0, /*tp_str*/ | |
129 0, /*tp_getattro*/ | |
130 0, /*tp_setattro*/ | |
131 0, /*tp_as_buffer*/ | |
132 Py_TPFLAGS_DEFAULT, /*tp_flags*/ | |
133 0, /*tp_doc*/ | |
134 0, /*tp_traverse*/ | |
135 0, /*tp_clear*/ | |
136 0, /*tp_richcompare*/ | |
137 0, /*tp_weaklistoffset*/ | |
138 0, /*tp_iter*/ | |
139 0, /*tp_iternext*/ | |
140 0, /*tp_methods*/ //TypeObject Methods | |
141 0, /*tp_members*/ | |
142 0, /*tp_getset*/ | |
143 0, /*tp_base*/ | |
144 0, /*tp_dict*/ | |
145 0, /*tp_descr_get*/ | |
146 0, /*tp_descr_set*/ | |
147 0, /*tp_dictoffset*/ | |
148 0, /*tp_init*/ | |
149 OutputDescriptor_alloc, /*tp_alloc*/ | |
150 OutputDescriptor_new, /*tp_new*/ | |
151 OutputDescriptor_free, /*tp_free*/ | |
152 0, /*tp_is_gc*/ | |
153 }; | |
154 | |
155 /* PyOutputDescriptor C++ API */ | |
156 |