summaryrefslogtreecommitdiffstats
path: root/swig/plist.i
diff options
context:
space:
mode:
Diffstat (limited to 'swig/plist.i')
-rw-r--r--swig/plist.i171
1 files changed, 171 insertions, 0 deletions
diff --git a/swig/plist.i b/swig/plist.i
new file mode 100644
index 0000000..78f102f
--- /dev/null
+++ b/swig/plist.i
@@ -0,0 +1,171 @@
1 /* swig.i */
2 %module PList
3 %{
4 /* Includes the header in the wrapper code */
5 #include <plist/plist.h>
6typedef struct {
7 plist_t node;
8} PListNode;
9 %}
10/* Parse the header file to generate wrappers */
11typedef enum {
12 PLIST_BOOLEAN,
13 PLIST_UINT,
14 PLIST_REAL,
15 PLIST_STRING,
16 PLIST_UNICODE,
17 PLIST_ARRAY,
18 PLIST_DICT,
19 PLIST_DATE,
20 PLIST_DATA,
21 PLIST_KEY,
22 PLIST_NONE
23} plist_type;
24
25typedef struct {
26 plist_t node;
27} PListNode;
28
29%extend PListNode { // Attach these functions to struct Vector
30 PListNode(plist_type t) {
31 PListNode* node = NULL;
32 switch (t) {
33 case PLIST_ARRAY :
34 node = (PListNode*) malloc(sizeof(PListNode));
35 node->node = plist_new_array();
36 break;
37 case PLIST_DICT :
38 node = (PListNode*) malloc(sizeof(PListNode));
39 node->node = plist_new_dict();
40 break;
41 default :
42 node = NULL;
43 break;
44 }
45 return node;
46 }
47
48 PListNode(char* xml) {
49 PListNode* plist = (PListNode*) malloc(sizeof(PListNode));
50 plist_from_xml(xml, strlen(xml), &plist->node);
51 return plist;
52 }
53
54 PListNode(char* bin, uint64_t len) {
55 PListNode* plist = (PListNode*) malloc(sizeof(PListNode));
56 plist_from_bin(bin, len, &plist->node);
57 return plist;
58 }
59
60 ~PListNode() {
61 plist_free($self->node);
62 free($self);
63 }
64
65 void AddSubNode(PListNode* subnode) {
66 plist_add_sub_node($self->node, subnode);
67 }
68
69 void AddSubKey(char* k) {
70 plist_add_sub_key_el($self->node, k);
71 }
72
73 void AddSubString(char* s) {
74 plist_add_sub_string_el($self->node, s);
75 }
76
77 void AddSubBool(char b) {
78 plist_add_sub_bool_el($self->node, b);
79 }
80
81 void AddSubUInt(uint64_t i) {
82 plist_add_sub_uint_el($self->node, i);
83 }
84
85 void AddSubReal(double d) {
86 plist_add_sub_real_el($self->node, d);
87 }
88
89 void AddSubData(char* v, uint64_t l) {
90 plist_add_sub_data_el($self->node, v, l);
91 }
92
93 PListNode* GetFirstChild() {
94 PListNode* plist = (PListNode*) malloc(sizeof(PListNode));
95 plist_get_first_child(&$self->node);
96 return plist;
97 }
98
99 PListNode* GetNextSibling() {
100 PListNode* plist = (PListNode*) malloc(sizeof(PListNode));
101 plist_get_next_sibling(&$self->node);
102 return plist;
103 }
104
105 PListNode* GetPrevSibling() {
106 PListNode* plist = (PListNode*) malloc(sizeof(PListNode));
107 plist_get_prev_sibling(&$self->node);
108 return plist;
109 }
110
111 char* AsKey() {
112 char* k = NULL;
113 plist_get_key_val($self->node, &k);
114 return k;
115 }
116
117 char* AsString() {
118 char* s = NULL;
119 plist_get_string_val($self->node, &s);
120 return s;
121 }
122
123 char AsBool() {
124 char b;
125 plist_get_bool_val($self->node, &b);
126 return b;
127 }
128
129 uint64_t AsUInt() {
130 uint64_t i = 0;
131 plist_get_uint_val($self->node, &i);
132 return i;
133 }
134
135 double AsReal() {
136 double d = 0;
137 plist_get_real_val($self->node, &d);
138 return d;
139 }
140
141 char* AsData() {
142 char* v;
143 uint64_t l;
144 plist_get_data_val($self->node, &v, &l);
145 return v;
146 }
147
148 plist_type GetType() {
149 return plist_get_node_type($self->node);
150 }
151
152 PListNode* FindSubNodeByString(char* s) {
153 PListNode* plist = (PListNode*) malloc(sizeof(PListNode));
154 plist = plist_find_node_by_string($self->node, s);
155 return plist;
156 }
157
158 char* ToXml () {
159 char* s = NULL;
160 uint32_t l;
161 plist_to_xml($self->node, &s, &l);
162 return s;
163 }
164
165 char* ToBin () {
166 char* s = NULL;
167 uint32_t l;
168 plist_to_bin($self->node, &s, &l);
169 return s;
170 }
171}; \ No newline at end of file