comparison PyOutputDescriptor.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 "PyOutputDescriptor.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 /* OutputDescriptor Object's Methods */
12 //Feature objects have no callable methods
13
14 /* PyOutputDescriptor methods implementing protocols */
15 // these functions are called by the interpreter automatically
16
17 /* New OutputDescriptor object */
18 static PyObject *
19 OutputDescriptor_new(PyTypeObject *type, PyObject *args, PyObject *kw)
20 {
21
22 if (!PyArg_ParseTuple(args, ":OutputDescriptor")) {
23 PyErr_SetString(PyExc_TypeError,
24 "Error: OutputDescriptor initialised with arguments.");
25 return NULL;
26 }
27
28 OutputDescriptorObject *self =
29 (OutputDescriptorObject*)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 OutputDescriptorObject_dealloc(OutputDescriptorObject *self)
41 {
42 Py_XDECREF(self->dict);
43 PyObject_Del(self);
44 }
45
46
47 /* Set attributes */
48 static int
49 OutputDescriptor_setattr(OutputDescriptorObject *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 OutputDescriptor 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 OutputDescriptor_getattr(OutputDescriptorObject *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 OutputDescriptor_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 OutputDescriptor_alloc PyType_GenericAlloc
90 #define OutputDescriptor_free PyObject_Del
91
92
93 /* REAL-TIME TYPE OBJECT */
94
95 PyTypeObject OutputDescriptor_Type = {
96 PyObject_HEAD_INIT(NULL)
97 0, /*ob_size*/
98 "vampy.OutputDescriptor",/*tp_name*/
99 sizeof(OutputDescriptorObject), /*tp_basicsize*/
100 0, /*tp_itemsize*/
101 (destructor)OutputDescriptorObject_dealloc, /*tp_dealloc*/
102 0, /*tp_print*/
103 (getattrfunc)OutputDescriptor_getattr, /*tp_getattr*/
104 (setattrfunc)OutputDescriptor_setattr, /*tp_setattr*/
105 0, /*tp_compare*/
106 OutputDescriptor_repr, /*tp_repr*/
107 0, /*tp_as_number*/
108 0, /*tp_as_sequence*/
109 0, /*tp_as_mapping*/
110 0, /*tp_hash*/
111 0, /*tp_call*/
112 0, /*tp_str*/
113 0, /*tp_getattro*/
114 0, /*tp_setattro*/
115 0, /*tp_as_buffer*/
116 Py_TPFLAGS_DEFAULT, /*tp_flags*/
117 0, /*tp_doc*/
118 0, /*tp_traverse*/
119 0, /*tp_clear*/
120 0, /*tp_richcompare*/
121 0, /*tp_weaklistoffset*/
122 0, /*tp_iter*/
123 0, /*tp_iternext*/
124 0, /*tp_methods*/ //TypeObject Methods
125 0, /*tp_members*/
126 0, /*tp_getset*/
127 0, /*tp_base*/
128 0, /*tp_dict*/
129 0, /*tp_descr_get*/
130 0, /*tp_descr_set*/
131 0, /*tp_dictoffset*/
132 0, /*tp_init*/
133 OutputDescriptor_alloc, /*tp_alloc*/
134 OutputDescriptor_new, /*tp_new*/
135 OutputDescriptor_free, /*tp_free*/
136 0, /*tp_is_gc*/
137 };
138
139 /* PyOutputDescriptor C++ API */
140