diff options
| author | 2013-12-13 00:44:17 +0100 | |
|---|---|---|
| committer | 2013-12-13 00:44:17 +0100 | |
| commit | a798afc8b5b00a43f4b121168e0419df2d398338 (patch) | |
| tree | c178d7a149028944254511d03f91266ca43cfcbd /swig/plist.i | |
| parent | 3b7647499474619b3e24bf01105b6b037887a0ed (diff) | |
| download | libplist-a798afc8b5b00a43f4b121168e0419df2d398338.tar.gz libplist-a798afc8b5b00a43f4b121168e0419df2d398338.tar.bz2 | |
change build system to autotools
Diffstat (limited to 'swig/plist.i')
| -rw-r--r-- | swig/plist.i | 284 |
1 files changed, 0 insertions, 284 deletions
diff --git a/swig/plist.i b/swig/plist.i deleted file mode 100644 index 3ae3d02..0000000 --- a/swig/plist.i +++ /dev/null | |||
| @@ -1,284 +0,0 @@ | |||
| 1 | /* swig.i */ | ||
| 2 | %module plist | ||
| 3 | %feature("autodoc", "1"); | ||
| 4 | %{ | ||
| 5 | /* Includes the header in the wrapper code */ | ||
| 6 | #include <plist/plist++.h> | ||
| 7 | #include <cstddef> | ||
| 8 | %} | ||
| 9 | |||
| 10 | %include "std_string.i" | ||
| 11 | %include "stdint.i" | ||
| 12 | |||
| 13 | %typemap(out) std::vector<char> { | ||
| 14 | $result = SWIG_FromCharPtrAndSize((const char*)&($1[0]),(size_t)($1.size())); | ||
| 15 | } | ||
| 16 | |||
| 17 | %typemap(in) (const std::vector<char>&) | ||
| 18 | { | ||
| 19 | char* buffer = NULL; | ||
| 20 | size_t length = 0; | ||
| 21 | SWIG_AsCharPtrAndSize($input, &buffer, &length, NULL); | ||
| 22 | $1 = new std::vector<char>(buffer, buffer + length - 1); | ||
| 23 | } | ||
| 24 | |||
| 25 | #if SWIGPYTHON | ||
| 26 | //for datetime in python | ||
| 27 | %{ | ||
| 28 | #include <ctime> | ||
| 29 | #include <datetime.h> | ||
| 30 | %} | ||
| 31 | |||
| 32 | %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) timeval { | ||
| 33 | PyDateTime_IMPORT; | ||
| 34 | $1 = PyDateTime_Check($input) ? 1 : 0; | ||
| 35 | } | ||
| 36 | |||
| 37 | %typemap(out) timeval { | ||
| 38 | struct tm* t = gmtime ( &$1.tv_sec ); | ||
| 39 | if (t) | ||
| 40 | { | ||
| 41 | PyDateTime_IMPORT; | ||
| 42 | $result = PyDateTime_FromDateAndTime(t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, $1.tv_usec); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | %typemap(in) (timeval t) | ||
| 47 | { | ||
| 48 | PyDateTime_IMPORT; | ||
| 49 | if (!PyDateTime_Check($input)) { | ||
| 50 | PyErr_SetString(PyExc_ValueError,"Expected a datetime"); | ||
| 51 | return NULL; | ||
| 52 | } | ||
| 53 | struct tm t = { | ||
| 54 | PyDateTime_DATE_GET_SECOND($input), | ||
| 55 | PyDateTime_DATE_GET_MINUTE($input), | ||
| 56 | PyDateTime_DATE_GET_HOUR($input), | ||
| 57 | PyDateTime_GET_DAY($input), | ||
| 58 | PyDateTime_GET_MONTH($input)-1, | ||
| 59 | PyDateTime_GET_YEAR($input)-1900, | ||
| 60 | 0,0,0 | ||
| 61 | }; | ||
| 62 | timeval ret = {(int)mktime(&t), PyDateTime_DATE_GET_MICROSECOND($input)}; | ||
| 63 | $1 = ret; | ||
| 64 | } | ||
| 65 | #endif | ||
| 66 | |||
| 67 | %apply SWIGTYPE *DYNAMIC { PList::Node* }; | ||
| 68 | %apply SWIGTYPE *DYNAMIC { PList::Structure* }; | ||
| 69 | |||
| 70 | %{ | ||
| 71 | static swig_type_info *Node_dynamic(void **ptr) | ||
| 72 | { | ||
| 73 | PList::Node* node = dynamic_cast<PList::Node *>((PList::Node *) *ptr); | ||
| 74 | if (node) | ||
| 75 | { | ||
| 76 | plist_type type = node->GetType(); | ||
| 77 | switch(type) | ||
| 78 | { | ||
| 79 | case PLIST_DICT: | ||
| 80 | *ptr = dynamic_cast<PList::Dictionary *>(node); | ||
| 81 | return SWIGTYPE_p_PList__Dictionary; | ||
| 82 | case PLIST_ARRAY: | ||
| 83 | *ptr = dynamic_cast<PList::Array *>(node); | ||
| 84 | return SWIGTYPE_p_PList__Array; | ||
| 85 | case PLIST_BOOLEAN: | ||
| 86 | *ptr = dynamic_cast<PList::Boolean *>(node); | ||
| 87 | return SWIGTYPE_p_PList__Boolean; | ||
| 88 | case PLIST_UINT: | ||
| 89 | *ptr = dynamic_cast<PList::Integer *>(node); | ||
| 90 | return SWIGTYPE_p_PList__Integer; | ||
| 91 | case PLIST_REAL: | ||
| 92 | *ptr = dynamic_cast<PList::Real *>(node); | ||
| 93 | return SWIGTYPE_p_PList__Real; | ||
| 94 | case PLIST_KEY: | ||
| 95 | *ptr = dynamic_cast<PList::Key *>(node); | ||
| 96 | return SWIGTYPE_p_PList__Key; | ||
| 97 | case PLIST_UID: | ||
| 98 | *ptr = dynamic_cast<PList::Uid *>(node); | ||
| 99 | return SWIGTYPE_p_PList__Uid; | ||
| 100 | case PLIST_STRING: | ||
| 101 | *ptr = dynamic_cast<PList::String *>(node); | ||
| 102 | return SWIGTYPE_p_PList__String; | ||
| 103 | case PLIST_DATE: | ||
| 104 | *ptr = dynamic_cast<PList::Date *>(node); | ||
| 105 | return SWIGTYPE_p_PList__Date; | ||
| 106 | case PLIST_DATA: | ||
| 107 | *ptr = dynamic_cast<PList::Data *>(node); | ||
| 108 | return SWIGTYPE_p_PList__Data; | ||
| 109 | default: | ||
| 110 | break; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | return 0; | ||
| 114 | } | ||
| 115 | %} | ||
| 116 | |||
| 117 | // Register the above casting function | ||
| 118 | DYNAMIC_CAST(SWIGTYPE_p_PList__Node, Node_dynamic); | ||
| 119 | DYNAMIC_CAST(SWIGTYPE_p_PList__Structure, Node_dynamic); | ||
| 120 | |||
| 121 | %include "std_map.i" | ||
| 122 | // Instantiate templates used by example | ||
| 123 | namespace std { | ||
| 124 | %template(PairStringNodePtr) std::pair<string, PList::Node*>; | ||
| 125 | %template(MapStringNodePtr) map<string,PList::Node*>; | ||
| 126 | } | ||
| 127 | |||
| 128 | #if SWIGPYTHON | ||
| 129 | %rename(__assign__) *::operator=; | ||
| 130 | %rename(__getitem__) *::operator[]; | ||
| 131 | %rename(__delitem__) *::Remove; | ||
| 132 | %rename(__setitem__) PList::Dictionary::Insert; | ||
| 133 | %rename(__deepcopy__) *::Clone; | ||
| 134 | %rename(__len__) *::GetSize; | ||
| 135 | %rename(get_type) *::GetType; | ||
| 136 | %rename(set_value) *::SetValue; | ||
| 137 | %rename(get_value) *::GetValue; | ||
| 138 | %rename(to_xml) *::ToXml; | ||
| 139 | %rename(to_bin) *::ToBin; | ||
| 140 | %rename(from_xml) *::FromXml; | ||
| 141 | %rename(from_bin) *::FromBin; | ||
| 142 | %rename(append) *::Append; | ||
| 143 | %rename(insert) PList::Array::Insert; | ||
| 144 | #endif | ||
| 145 | |||
| 146 | %ignore GetPlist(); | ||
| 147 | %ignore Boolean(plist_t); | ||
| 148 | %ignore Integer(plist_t); | ||
| 149 | %ignore Real(plist_t); | ||
| 150 | %ignore Key(plist_t); | ||
| 151 | %ignore Uid(plist_t); | ||
| 152 | %ignore String(plist_t); | ||
| 153 | %ignore Data(plist_t); | ||
| 154 | %ignore Date(plist_t); | ||
| 155 | %ignore Array(plist_t); | ||
| 156 | %ignore Dictionary(plist_t); | ||
| 157 | %ignore Begin(); | ||
| 158 | %ignore End(); | ||
| 159 | %ignore Find(); | ||
| 160 | |||
| 161 | %include <plist/Node.h> | ||
| 162 | %include <plist/Boolean.h> | ||
| 163 | %include <plist/Integer.h> | ||
| 164 | %include <plist/Real.h> | ||
| 165 | %include <plist/Key.h> | ||
| 166 | %include <plist/Uid.h> | ||
| 167 | %include <plist/String.h> | ||
| 168 | %include <plist/Data.h> | ||
| 169 | %include <plist/Date.h> | ||
| 170 | %include <plist/Structure.h> | ||
| 171 | %include <plist/Array.h> | ||
| 172 | %include <plist/Dictionary.h> | ||
| 173 | |||
| 174 | typedef enum { | ||
| 175 | PLIST_BOOLEAN, | ||
| 176 | PLIST_UINT, | ||
| 177 | PLIST_REAL, | ||
| 178 | PLIST_STRING, | ||
| 179 | PLIST_ARRAY, | ||
| 180 | PLIST_DICT, | ||
| 181 | PLIST_DATE, | ||
| 182 | PLIST_DATA, | ||
| 183 | PLIST_KEY, | ||
| 184 | PLIST_UID, | ||
| 185 | PLIST_NONE | ||
| 186 | } plist_type; | ||
| 187 | |||
| 188 | #if SWIGPYTHON | ||
| 189 | |||
| 190 | #if SWIG_VERSION <= 0x010336 | ||
| 191 | #define SwigPyIterator PySwigIterator | ||
| 192 | #endif | ||
| 193 | |||
| 194 | %extend PList::Dictionary { | ||
| 195 | |||
| 196 | %newobject key_iterator(PyObject **PYTHON_SELF); | ||
| 197 | swig::SwigPyIterator* key_iterator(PyObject **PYTHON_SELF) { | ||
| 198 | return swig::make_output_key_iterator(self->Begin(), self->Begin(), self->End(), *PYTHON_SELF); | ||
| 199 | } | ||
| 200 | |||
| 201 | %newobject value_iterator(PyObject **PYTHON_SELF); | ||
| 202 | swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) { | ||
| 203 | return swig::make_output_value_iterator(self->Begin(), self->Begin(), self->End(), *PYTHON_SELF); | ||
| 204 | } | ||
| 205 | |||
| 206 | iterator iteritems() | ||
| 207 | { | ||
| 208 | return self->Begin(); | ||
| 209 | } | ||
| 210 | |||
| 211 | bool has_key(const std::string& key) const { | ||
| 212 | PList::Dictionary* dict = const_cast<PList::Dictionary*>(self); | ||
| 213 | PList::Dictionary::iterator i = dict->Find(key); | ||
| 214 | return i != dict->End(); | ||
| 215 | } | ||
| 216 | |||
| 217 | PyObject* keys() { | ||
| 218 | uint32_t size = self->GetSize(); | ||
| 219 | int pysize = (size <= (uint32_t) INT_MAX) ? (int) size : -1; | ||
| 220 | if (pysize < 0) { | ||
| 221 | SWIG_PYTHON_THREAD_BEGIN_BLOCK; | ||
| 222 | PyErr_SetString(PyExc_OverflowError, | ||
| 223 | "map size not valid in python"); | ||
| 224 | SWIG_PYTHON_THREAD_END_BLOCK; | ||
| 225 | return NULL; | ||
| 226 | } | ||
| 227 | PyObject* keyList = PyList_New(pysize); | ||
| 228 | PList::Dictionary::iterator i = self->Begin(); | ||
| 229 | for (int j = 0; j < pysize; ++i, ++j) { | ||
| 230 | PyList_SET_ITEM(keyList, j, swig::from(i->first)); | ||
| 231 | } | ||
| 232 | return keyList; | ||
| 233 | } | ||
| 234 | |||
| 235 | PyObject* values() { | ||
| 236 | uint32_t size = self->GetSize(); | ||
| 237 | int pysize = (size <= (uint32_t) INT_MAX) ? (int) size : -1; | ||
| 238 | if (pysize < 0) { | ||
| 239 | SWIG_PYTHON_THREAD_BEGIN_BLOCK; | ||
| 240 | PyErr_SetString(PyExc_OverflowError, | ||
| 241 | "map size not valid in python"); | ||
| 242 | SWIG_PYTHON_THREAD_END_BLOCK; | ||
| 243 | return NULL; | ||
| 244 | } | ||
| 245 | PyObject* valList = PyList_New(pysize); | ||
| 246 | PList::Dictionary::iterator i = self->Begin(); | ||
| 247 | for (int j = 0; j < pysize; ++i, ++j) { | ||
| 248 | PList::Node *second = i->second; | ||
| 249 | PyObject *down = SWIG_NewPointerObj(SWIG_as_voidptr(second), SWIG_TypeDynamicCast(SWIGTYPE_p_PList__Node, SWIG_as_voidptrptr(&second)), 0 | 0 ); | ||
| 250 | PyList_SET_ITEM(valList, j, down); | ||
| 251 | } | ||
| 252 | return valList; | ||
| 253 | } | ||
| 254 | |||
| 255 | PyObject* items() { | ||
| 256 | uint32_t size = self->GetSize(); | ||
| 257 | int pysize = (size <= (uint32_t) INT_MAX) ? (int) size : -1; | ||
| 258 | if (pysize < 0) { | ||
| 259 | SWIG_PYTHON_THREAD_BEGIN_BLOCK; | ||
| 260 | PyErr_SetString(PyExc_OverflowError, | ||
| 261 | "map size not valid in python"); | ||
| 262 | SWIG_PYTHON_THREAD_END_BLOCK; | ||
| 263 | return NULL; | ||
| 264 | } | ||
| 265 | PyObject* itemList = PyList_New(pysize); | ||
| 266 | PList::Dictionary::iterator i = self->Begin(); | ||
| 267 | for (int j = 0; j < pysize; ++i, ++j) { | ||
| 268 | PyObject *item = PyTuple_New(2); | ||
| 269 | PList::Node *second = i->second; | ||
| 270 | PyObject *down = SWIG_NewPointerObj(SWIG_as_voidptr(second), SWIG_TypeDynamicCast(SWIGTYPE_p_PList__Node, SWIG_as_voidptrptr(&second)), 0 | 0 ); | ||
| 271 | PyTuple_SetItem(item, 0, swig::from(i->first)); | ||
| 272 | PyTuple_SetItem(item, 1, down); | ||
| 273 | PyList_SET_ITEM(itemList, j, item); | ||
| 274 | } | ||
| 275 | return itemList; | ||
| 276 | } | ||
| 277 | |||
| 278 | %pythoncode {def __iter__(self): return self.key_iterator()} | ||
| 279 | %pythoncode {def iterkeys(self): return self.key_iterator()} | ||
| 280 | %pythoncode {def itervalues(self): return self.value_iterator()} | ||
| 281 | } | ||
| 282 | |||
| 283 | #undef SwigPyIterator | ||
| 284 | #endif | ||
