]> icculus.org git repositories - mikachu/openbox.git/blob - wrap/otk_property.i
'final' cleanup for the new otk wrapper .i's
[mikachu/openbox.git] / wrap / otk_property.i
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 %module otk_property
4
5 %{
6 #include "config.h"
7 #include "property.hh"
8 %}
9
10 %include "otk_ustring.i"
11
12 %typemap(python,in) const otk::Property::StringVect & (otk::Property::StringVect temp) {
13   if (PyList_Check($input)) {
14     int s = PyList_Size($input);
15     temp = otk::Property::StringVect(s);
16     for (int i = 0; i < s; ++i) {
17       PyObject *o = PyList_GetItem($input, i);
18       if (PyString_Check(o)) {
19         temp[i] = PyString_AsString(o);
20       } else {
21         SWIG_exception(SWIG_TypeError, "list of strings expected");
22       }
23     }
24     $1 = &temp;
25   } else {
26     SWIG_exception(SWIG_TypeError, "list expected");
27   }
28 }
29
30 %typemap(python,in) unsigned long value[] (unsigned long *temp) {
31   if (PyList_Check($input)) {
32     int s = PyList_Size($input);
33     temp = new unsigned long[s];
34     for (int i = 0; i < s; ++i) {
35       PyObject *o = PyList_GetItem($input, i);
36       if (PyInt_Check(o)) {
37         temp[i] = PyInt_AsLong(o);
38       } else if (PyLong_Check(o)) {
39         temp[i] = PyLong_AsLong(o);
40       } else {
41         SWIG_exception(SWIG_TypeError, "list of numbers expected");
42       }
43     }
44     $1 = temp;
45   } else {
46     SWIG_exception(SWIG_TypeError, "list expected");
47   }
48 }
49
50 %typemap(python,freearg) unsigned long value[] {
51   delete [] $1;
52 }
53
54 %typemap(python,in,numinputs=0) otk::ustring *value (otk::ustring temp) {
55   $1 = &temp;
56 }
57
58 %typemap(python,argout) otk::ustring *value {
59   PyObject *tuple;
60   int s;
61   if (PyTuple_Check($result)) {
62     s = PyTuple_Size($result);
63     _PyTuple_Resize(&$result, s + 1);
64     tuple = $result;
65   } else {
66     tuple = PyTuple_New(2);
67     PyTuple_SET_ITEM(tuple, 0, $result);
68     Py_INCREF($result);
69     s = 1;
70   }
71
72   PyTuple_SET_ITEM(tuple, s, PyString_FromString($1->c_str()));
73   $result = tuple;
74 }
75
76 %typemap(python,in,numinputs=0) unsigned long *value (unsigned long temp) {
77   $1 = &temp;
78 }
79
80 %typemap(python,argout) unsigned long *value {
81   PyObject *s = PyLong_FromLong(*$1);
82   $result = s;
83 }
84
85 %typemap(python,in) unsigned long *nelements (unsigned long temp) {
86   temp = (unsigned)PyLong_AsLong($input);
87   $1 = &temp;
88 }
89
90 %typemap(python,in,numinputs=0) unsigned long **value (unsigned long *temp) {
91   $1 = &temp;
92 }
93
94 %typemap(python,argout) (unsigned long *nelements, unsigned long **value) {
95   PyObject *tuple;
96   int s;
97   if (PyTuple_Check($result)) {
98     s = PyTuple_Size($result);
99     _PyTuple_Resize(&$result, s + 2);
100     tuple = $result;
101   } else {
102     tuple = PyTuple_New(3);
103     PyTuple_SET_ITEM(tuple, 0, $result);
104     Py_INCREF($result);
105     s = 1;
106   }
107
108   int sz = *$1;
109
110   PyTuple_SET_ITEM(tuple, s++, PyLong_FromLong(sz));
111   
112   PyObject *r = PyList_New(sz);
113   for (int i = 0; i < sz; ++i) {
114     PyList_SET_ITEM(r, i, PyLong_FromLong((*$2)[i]));
115   }
116   PyTuple_SET_ITEM(tuple, s, r);
117   $result = tuple;
118 }
119
120 %typemap(python,in,numinputs=0) StringVect *strings (StringVect temp) {
121   $1 = &temp;
122 }
123
124 %typemap(python,argout) (unsigned long *nelements, StringVect *strings) {
125   PyObject *tuple;
126   int s;
127   if (PyTuple_Check($result)) {
128     s = PyTuple_Size($result);
129     _PyTuple_Resize(&$result, s + 2);
130     tuple = $result;
131   } else {
132     tuple = PyTuple_New(3);
133     PyTuple_SET_ITEM(tuple, 0, $result);
134     Py_INCREF($result);
135     s = 1;
136   }
137
138   int sz = *$1;
139
140   PyTuple_SET_ITEM(tuple, s++, PyLong_FromLong(sz));
141   
142   PyObject *r = PyList_New(sz);
143   for (int i = 0; i < sz; ++i) {
144     PyList_SET_ITEM(r, i, PyString_FromString((*$2)[i].c_str()));
145   }
146   PyTuple_SET_ITEM(tuple, s, r);
147   $result = tuple;
148 }
149
150 namespace otk {
151
152 %immutable otk::Property::atoms;
153
154 %ignore Property::NUM_STRING_TYPE;
155 %ignore Property::initialize();
156
157 %rename(getNum) Property::get(Window, Atom, Atom, unsigned long*);
158 %rename(getNums) Property::get(Window, Atom, Atom, unsigned long*,
159                                unsigned long**);
160 %rename(getString) Property::get(Window, Atom, StringType, ustring*);
161 %rename(getStrings) Property::get(Window, Atom, StringType, unsigned long*,
162                                   StringVect);
163
164 }
165
166 %include "property.hh"