all repos — openbox @ 515f8d8760f614b127b4435dca7881a32b5b6207

openbox fork - make it a bit more like ryudo

wrap/otk_property.i (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-

%module otk_property

%{
#include "config.h"
#include "property.hh"
%}

%include "otk_ustring.i"

%typemap(python,in) const otk::Property::StringVect & (otk::Property::StringVect temp) {
  if (PyList_Check($input)) {
    int s = PyList_Size($input);
    temp = otk::Property::StringVect(s);
    for (int i = 0; i < s; ++i) {
      PyObject *o = PyList_GetItem($input, i);
      if (PyString_Check(o)) {
        temp[i] = PyString_AsString(o);
      } else {
        SWIG_exception(SWIG_TypeError, "list of strings expected");
      }
    }
    $1 = &temp;
  } else {
    SWIG_exception(SWIG_TypeError, "list expected");
  }
}

%typemap(python,in) unsigned long value[] (unsigned long *temp) {
  if (PyList_Check($input)) {
    int s = PyList_Size($input);
    temp = new unsigned long[s];
    for (int i = 0; i < s; ++i) {
      PyObject *o = PyList_GetItem($input, i);
      if (PyInt_Check(o)) {
        temp[i] = PyInt_AsLong(o);
      } else if (PyLong_Check(o)) {
        temp[i] = PyLong_AsLong(o);
      } else {
        SWIG_exception(SWIG_TypeError, "list of numbers expected");
      }
    }
    $1 = temp;
  } else {
    SWIG_exception(SWIG_TypeError, "list expected");
  }
}

%typemap(python,freearg) unsigned long value[] {
  delete [] $1;
}

%typemap(python,in,numinputs=0) otk::ustring *value (otk::ustring temp) {
  $1 = &temp;
}

%typemap(python,argout) otk::ustring *value {
  PyObject *tuple;
  int s;
  if (PyTuple_Check($result)) {
    s = PyTuple_Size($result);
    _PyTuple_Resize(&$result, s + 1);
    tuple = $result;
  } else {
    tuple = PyTuple_New(2);
    PyTuple_SET_ITEM(tuple, 0, $result);
    Py_INCREF($result);
    s = 1;
  }

  PyTuple_SET_ITEM(tuple, s, PyString_FromString($1->c_str()));
  $result = tuple;
}

%typemap(python,in,numinputs=0) unsigned long *value (unsigned long temp) {
  $1 = &temp;
}

%typemap(python,argout) unsigned long *value {
  PyObject *s = PyLong_FromLong(*$1);
  $result = s;
}

%typemap(python,in,numinputs=0) unsigned long *nelements (unsigned long temp) {
  $1 = &temp;
}

%typemap(python,in) unsigned long *nelements (unsigned long temp) {
  temp = (unsigned)PyLong_AsLong($input);
  $1 = &temp;
}

%typemap(python,in,numinputs=0) unsigned long **value (unsigned long *temp) {
  $1 = &temp;
}

%typemap(python,argout) (unsigned long *nelements, unsigned long **value) {
  PyObject *tuple;
  int s;
  if (PyTuple_Check($result)) {
    s = PyTuple_Size($result);
    _PyTuple_Resize(&$result, s + 2);
    tuple = $result;
  } else {
    tuple = PyTuple_New(3);
    PyTuple_SET_ITEM(tuple, 0, $result);
    Py_INCREF($result);
    s = 1;
  }

  int sz = *$1;

  PyTuple_SET_ITEM(tuple, s++, PyLong_FromLong(sz));
  
  PyObject *r = PyList_New(sz);
  for (int i = 0; i < sz; ++i) {
    PyList_SET_ITEM(r, i, PyLong_FromLong((*$2)[i]));
  }
  PyTuple_SET_ITEM(tuple, s, r);
  $result = tuple;
}

%typemap(python,in,numinputs=0) StringVect *strings (StringVect temp) {
  $1 = &temp;
}

%typemap(python,argout) (unsigned long *nelements, StringVect *strings) {
  PyObject *tuple;
  int s;
  if (PyTuple_Check($result)) {
    s = PyTuple_Size($result);
    _PyTuple_Resize(&$result, s + 2);
    tuple = $result;
  } else {
    tuple = PyTuple_New(3);
    PyTuple_SET_ITEM(tuple, 0, $result);
    Py_INCREF($result);
    s = 1;
  }

  int sz = *$1;

  PyTuple_SET_ITEM(tuple, s++, PyLong_FromLong(sz));
  
  PyObject *r = PyList_New(sz);
  for (int i = 0; i < sz; ++i) {
    PyList_SET_ITEM(r, i, PyString_FromString((*$2)[i].c_str()));
  }
  PyTuple_SET_ITEM(tuple, s, r);
  $result = tuple;
}

namespace otk {

%immutable otk::Property::atoms;

%ignore Property::NUM_STRING_TYPE;
%ignore Property::initialize();

%rename(getNum) Property::get(Window, Atom, Atom, unsigned long*);
%rename(getNums) Property::get(Window, Atom, Atom, unsigned long*,
                               unsigned long**);
%rename(getString) Property::get(Window, Atom, StringType, ustring*);
%rename(getStrings) Property::get(Window, Atom, StringType, unsigned long*,
                                  StringVect);

}

%include "property.hh"