summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-10-26 18:41:15 +0100
committerGravatar Jonathan Beck2009-10-26 18:41:15 +0100
commitc1363bea107b15bdc10ce80671747be891661889 (patch)
tree1a8ce452eb6c1110ea0cd88dec155e99bfe7b69b
parentbef50c0873aad5d8cd516428828e79fc05a43913 (diff)
downloadlibplist-c1363bea107b15bdc10ce80671747be891661889.tar.gz
libplist-c1363bea107b15bdc10ce80671747be891661889.tar.bz2
Add Set/Get Parent and a helper to create a Node from a plist_t.
-rw-r--r--include/plist/Array.h4
-rw-r--r--include/plist/Boolean.h4
-rw-r--r--include/plist/Data.h4
-rw-r--r--include/plist/Date.h4
-rw-r--r--include/plist/Dictionary.h4
-rw-r--r--include/plist/Integer.h4
-rw-r--r--include/plist/Node.h9
-rw-r--r--include/plist/Real.h4
-rw-r--r--include/plist/String.h4
-rw-r--r--include/plist/Structure.h4
-rw-r--r--include/plist/Utils.h1
-rw-r--r--src/Array.cpp107
-rw-r--r--src/Boolean.cpp4
-rw-r--r--src/Data.cpp4
-rw-r--r--src/Date.cpp4
-rw-r--r--src/Dictionary.cpp106
-rw-r--r--src/Integer.cpp4
-rw-r--r--src/Node.cpp18
-rw-r--r--src/Real.cpp4
-rw-r--r--src/String.cpp4
-rw-r--r--src/Structure.cpp4
-rw-r--r--src/Utils.cpp53
22 files changed, 113 insertions, 245 deletions
diff --git a/include/plist/Array.h b/include/plist/Array.h
index de4860e..8fd07cd 100644
--- a/include/plist/Array.h
+++ b/include/plist/Array.h
@@ -31,8 +31,8 @@ namespace PList
31class Array : public Structure 31class Array : public Structure
32{ 32{
33 public : 33 public :
34 Array(); 34 Array(Node* parent = NULL);
35 Array(plist_t node); 35 Array(plist_t node, Node* parent = NULL);
36 Array(Array& a); 36 Array(Array& a);
37 Array& operator=(Array& a); 37 Array& operator=(Array& a);
38 virtual ~Array(); 38 virtual ~Array();
diff --git a/include/plist/Boolean.h b/include/plist/Boolean.h
index b902171..149f8da 100644
--- a/include/plist/Boolean.h
+++ b/include/plist/Boolean.h
@@ -30,8 +30,8 @@ namespace PList
30class Boolean : public Node 30class Boolean : public Node
31{ 31{
32 public : 32 public :
33 Boolean(); 33 Boolean(Node* parent = NULL);
34 Boolean(plist_t node); 34 Boolean(plist_t node, Node* parent = NULL);
35 Boolean(Boolean& b); 35 Boolean(Boolean& b);
36 Boolean& operator=(Boolean& b); 36 Boolean& operator=(Boolean& b);
37 Boolean(bool b); 37 Boolean(bool b);
diff --git a/include/plist/Data.h b/include/plist/Data.h
index 3db98f7..59a0096 100644
--- a/include/plist/Data.h
+++ b/include/plist/Data.h
@@ -31,8 +31,8 @@ namespace PList
31class Data : public Node 31class Data : public Node
32{ 32{
33 public : 33 public :
34 Data(); 34 Data(Node* parent = NULL);
35 Data(plist_t node); 35 Data(plist_t node, Node* parent = NULL);
36 Data(Data& d); 36 Data(Data& d);
37 Data& operator=(Data& d); 37 Data& operator=(Data& d);
38 Data(const std::vector<char>& buff); 38 Data(const std::vector<char>& buff);
diff --git a/include/plist/Date.h b/include/plist/Date.h
index d3cd605..22565ef 100644
--- a/include/plist/Date.h
+++ b/include/plist/Date.h
@@ -31,8 +31,8 @@ namespace PList
31class Date : public Node 31class Date : public Node
32{ 32{
33 public : 33 public :
34 Date(); 34 Date(Node* parent = NULL);
35 Date(plist_t node); 35 Date(plist_t node, Node* parent = NULL);
36 Date(Date& d); 36 Date(Date& d);
37 Date& operator=(Date& d); 37 Date& operator=(Date& d);
38 Date(timeval t); 38 Date(timeval t);
diff --git a/include/plist/Dictionary.h b/include/plist/Dictionary.h
index dbb27d1..38604c8 100644
--- a/include/plist/Dictionary.h
+++ b/include/plist/Dictionary.h
@@ -32,8 +32,8 @@ namespace PList
32class Dictionary : public Structure 32class Dictionary : public Structure
33{ 33{
34 public : 34 public :
35 Dictionary(); 35 Dictionary(Node* parent = NULL);
36 Dictionary(plist_t node); 36 Dictionary(plist_t node, Node* parent = NULL);
37 Dictionary(Dictionary& d); 37 Dictionary(Dictionary& d);
38 Dictionary& operator=(Dictionary& d); 38 Dictionary& operator=(Dictionary& d);
39 virtual ~Dictionary(); 39 virtual ~Dictionary();
diff --git a/include/plist/Integer.h b/include/plist/Integer.h
index a86d0ca..fefcea1 100644
--- a/include/plist/Integer.h
+++ b/include/plist/Integer.h
@@ -30,8 +30,8 @@ namespace PList
30class Integer : public Node 30class Integer : public Node
31{ 31{
32 public : 32 public :
33 Integer(); 33 Integer(Node* parent = NULL);
34 Integer(plist_t node); 34 Integer(plist_t node, Node* parent = NULL);
35 Integer(Integer& i); 35 Integer(Integer& i);
36 Integer& operator=(Integer& i); 36 Integer& operator=(Integer& i);
37 Integer(uint64_t i); 37 Integer(uint64_t i);
diff --git a/include/plist/Node.h b/include/plist/Node.h
index 702d018..6e5411a 100644
--- a/include/plist/Node.h
+++ b/include/plist/Node.h
@@ -33,15 +33,18 @@ class Node
33 virtual ~Node(); 33 virtual ~Node();
34 34
35 virtual Node* Clone() = 0; 35 virtual Node* Clone() = 0;
36 Node * GetParent();
37 void SetParent(Node* parent);
36 38
37 plist_type GetType(); 39 plist_type GetType();
38 plist_t GetPlist(); 40 plist_t GetPlist();
39 41
40 protected: 42 protected:
41 Node(); 43 Node(Node* parent = NULL);
42 Node(plist_t node); 44 Node(plist_t node, Node* parent = NULL);
43 Node(plist_type type); 45 Node(plist_type type, Node* parent = NULL);
44 plist_t _node; 46 plist_t _node;
47 Node* _parent;
45}; 48};
46 49
47}; 50};
diff --git a/include/plist/Real.h b/include/plist/Real.h
index b011c7a..755842e 100644
--- a/include/plist/Real.h
+++ b/include/plist/Real.h
@@ -30,8 +30,8 @@ namespace PList
30class Real : public Node 30class Real : public Node
31{ 31{
32 public : 32 public :
33 Real(); 33 Real(Node* parent = NULL);
34 Real(plist_t node); 34 Real(plist_t node, Node* parent = NULL);
35 Real(Real& d); 35 Real(Real& d);
36 Real& operator=(Real& d); 36 Real& operator=(Real& d);
37 Real(double d); 37 Real(double d);
diff --git a/include/plist/String.h b/include/plist/String.h
index 64181f3..58b8619 100644
--- a/include/plist/String.h
+++ b/include/plist/String.h
@@ -31,8 +31,8 @@ namespace PList
31class String : public Node 31class String : public Node
32{ 32{
33 public : 33 public :
34 String(); 34 String(Node* parent = NULL);
35 String(plist_t node); 35 String(plist_t node, Node* parent = NULL);
36 String(String& s); 36 String(String& s);
37 String& operator=(String& s); 37 String& operator=(String& s);
38 String(const std::string& s); 38 String(const std::string& s);
diff --git a/include/plist/Structure.h b/include/plist/Structure.h
index 4910439..6f100cc 100644
--- a/include/plist/Structure.h
+++ b/include/plist/Structure.h
@@ -40,8 +40,8 @@ class Structure : public Node
40 std::vector<char> ToBin(); 40 std::vector<char> ToBin();
41 41
42 protected: 42 protected:
43 Structure(); 43 Structure(Node* parent = NULL);
44 Structure(plist_type type); 44 Structure(plist_type type, Node* parent = NULL);
45 45
46 private: 46 private:
47 Structure(Structure& s); 47 Structure(Structure& s);
diff --git a/include/plist/Utils.h b/include/plist/Utils.h
index 54baf02..65bec7e 100644
--- a/include/plist/Utils.h
+++ b/include/plist/Utils.h
@@ -30,6 +30,7 @@ namespace PList
30 class Utils 30 class Utils
31 { 31 {
32 public: 32 public:
33 static Node* FromPlist(plist_t node, Node* parent = NULL);
33 static Structure* FromXml(const std::string& in); 34 static Structure* FromXml(const std::string& in);
34 static Structure* FromBin(const std::vector<char>& in); 35 static Structure* FromBin(const std::vector<char>& in);
35 36
diff --git a/src/Array.cpp b/src/Array.cpp
index b85a114..7c8272c 100644
--- a/src/Array.cpp
+++ b/src/Array.cpp
@@ -20,23 +20,17 @@
20 20
21#include <stdlib.h> 21#include <stdlib.h>
22#include <plist/Array.h> 22#include <plist/Array.h>
23#include <plist/Dictionary.h> 23#include <plist/Utils.h>
24#include <plist/Boolean.h>
25#include <plist/Integer.h>
26#include <plist/Real.h>
27#include <plist/String.h>
28#include <plist/Date.h>
29#include <plist/Data.h>
30 24
31namespace PList 25namespace PList
32{ 26{
33 27
34Array::Array() : Structure(PLIST_ARRAY) 28Array::Array(Node* parent) : Structure(PLIST_ARRAY, parent)
35{ 29{
36 _array.clear(); 30 _array.clear();
37} 31}
38 32
39Array::Array(plist_t node) : Structure() 33Array::Array(plist_t node, Node* parent) : Structure(parent)
40{ 34{
41 _node = node; 35 _node = node;
42 uint32_t size = plist_array_get_size(_node); 36 uint32_t size = plist_array_get_size(_node);
@@ -44,36 +38,7 @@ Array::Array(plist_t node) : Structure()
44 for (uint32_t i = 0; i < size; i++) 38 for (uint32_t i = 0; i < size; i++)
45 { 39 {
46 plist_t subnode = plist_array_get_item(_node, i); 40 plist_t subnode = plist_array_get_item(_node, i);
47 plist_type subtype = plist_get_node_type(subnode); 41 _array.push_back( Utils::FromPlist(subnode, this) );
48 switch(subtype)
49 {
50 case PLIST_DICT:
51 _array.push_back( new Dictionary(subnode) );
52 break;
53 case PLIST_ARRAY:
54 _array.push_back( new Array(subnode) );
55 break;
56 case PLIST_BOOLEAN:
57 _array.push_back( new Boolean(subnode) );
58 break;
59 case PLIST_UINT:
60 _array.push_back( new Integer(subnode) );
61 break;
62 case PLIST_REAL:
63 _array.push_back( new Real(subnode) );
64 break;
65 case PLIST_STRING:
66 _array.push_back( new String(subnode) );
67 break;
68 case PLIST_DATE:
69 _array.push_back( new Date(subnode) );
70 break;
71 case PLIST_DATA:
72 _array.push_back( new Data(subnode) );
73 break;
74 default:
75 break;
76 }
77 } 42 }
78} 43}
79 44
@@ -86,36 +51,7 @@ Array::Array(PList::Array& a) : Structure()
86 for (uint32_t i = 0; i < size; i++) 51 for (uint32_t i = 0; i < size; i++)
87 { 52 {
88 plist_t subnode = plist_array_get_item(_node, i); 53 plist_t subnode = plist_array_get_item(_node, i);
89 plist_type subtype = plist_get_node_type(subnode); 54 _array.push_back( Utils::FromPlist(subnode, this) );
90 switch(subtype)
91 {
92 case PLIST_DICT:
93 _array.push_back( new Dictionary(subnode) );
94 break;
95 case PLIST_ARRAY:
96 _array.push_back( new Array(subnode) );
97 break;
98 case PLIST_BOOLEAN:
99 _array.push_back( new Boolean(subnode) );
100 break;
101 case PLIST_UINT:
102 _array.push_back( new Integer(subnode) );
103 break;
104 case PLIST_REAL:
105 _array.push_back( new Real(subnode) );
106 break;
107 case PLIST_STRING:
108 _array.push_back( new String(subnode) );
109 break;
110 case PLIST_DATE:
111 _array.push_back( new Date(subnode) );
112 break;
113 case PLIST_DATA:
114 _array.push_back( new Data(subnode) );
115 break;
116 default:
117 break;
118 }
119 } 55 }
120} 56}
121 57
@@ -134,36 +70,7 @@ Array& Array::operator=(PList::Array& a)
134 for (uint32_t i = 0; i < size; i++) 70 for (uint32_t i = 0; i < size; i++)
135 { 71 {
136 plist_t subnode = plist_array_get_item(_node, i); 72 plist_t subnode = plist_array_get_item(_node, i);
137 plist_type subtype = plist_get_node_type(subnode); 73 _array.push_back( Utils::FromPlist(subnode, this) );
138 switch(subtype)
139 {
140 case PLIST_DICT:
141 _array.push_back( new Dictionary(subnode) );
142 break;
143 case PLIST_ARRAY:
144 _array.push_back( new Array(subnode) );
145 break;
146 case PLIST_BOOLEAN:
147 _array.push_back( new Boolean(subnode) );
148 break;
149 case PLIST_UINT:
150 _array.push_back( new Integer(subnode) );
151 break;
152 case PLIST_REAL:
153 _array.push_back( new Real(subnode) );
154 break;
155 case PLIST_STRING:
156 _array.push_back( new String(subnode) );
157 break;
158 case PLIST_DATE:
159 _array.push_back( new Date(subnode) );
160 break;
161 case PLIST_DATA:
162 _array.push_back( new Data(subnode) );
163 break;
164 default:
165 break;
166 }
167 } 74 }
168} 75}
169 76
@@ -191,6 +98,7 @@ void Array::Append(Node* node)
191 if (node) 98 if (node)
192 { 99 {
193 Node* clone = node->Clone(); 100 Node* clone = node->Clone();
101 clone->SetParent(this);
194 plist_array_append_item(_node, clone->GetPlist()); 102 plist_array_append_item(_node, clone->GetPlist());
195 _array.push_back(clone); 103 _array.push_back(clone);
196 } 104 }
@@ -201,6 +109,7 @@ void Array::Insert(Node* node, unsigned int pos)
201 if (node) 109 if (node)
202 { 110 {
203 Node* clone = node->Clone(); 111 Node* clone = node->Clone();
112 clone->SetParent(this);
204 plist_array_insert_item(_node, clone->GetPlist(), pos); 113 plist_array_insert_item(_node, clone->GetPlist(), pos);
205 std::vector<Node*>::iterator it = _array.begin(); 114 std::vector<Node*>::iterator it = _array.begin();
206 it += pos; 115 it += pos;
diff --git a/src/Boolean.cpp b/src/Boolean.cpp
index 03d17c8..3b20f45 100644
--- a/src/Boolean.cpp
+++ b/src/Boolean.cpp
@@ -24,11 +24,11 @@
24namespace PList 24namespace PList
25{ 25{
26 26
27Boolean::Boolean() : Node(PLIST_BOOLEAN) 27Boolean::Boolean(Node* parent) : Node(PLIST_BOOLEAN, parent)
28{ 28{
29} 29}
30 30
31Boolean::Boolean(plist_t node) : Node(node) 31Boolean::Boolean(plist_t node, Node* parent) : Node(node, parent)
32{ 32{
33} 33}
34 34
diff --git a/src/Data.cpp b/src/Data.cpp
index 87a508a..a171c03 100644
--- a/src/Data.cpp
+++ b/src/Data.cpp
@@ -24,11 +24,11 @@
24namespace PList 24namespace PList
25{ 25{
26 26
27Data::Data() : Node(PLIST_DATA) 27Data::Data(Node* parent) : Node(PLIST_DATA, parent)
28{ 28{
29} 29}
30 30
31Data::Data(plist_t node) : Node(node) 31Data::Data(plist_t node, Node* parent) : Node(node, parent)
32{ 32{
33} 33}
34 34
diff --git a/src/Date.cpp b/src/Date.cpp
index 1aebfab..6321c84 100644
--- a/src/Date.cpp
+++ b/src/Date.cpp
@@ -24,11 +24,11 @@
24namespace PList 24namespace PList
25{ 25{
26 26
27Date::Date() : Node(PLIST_DATE) 27Date::Date(Node* parent) : Node(PLIST_DATE, parent)
28{ 28{
29} 29}
30 30
31Date::Date(plist_t node) : Node(node) 31Date::Date(plist_t node, Node* parent) : Node(node, parent)
32{ 32{
33} 33}
34 34
diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp
index a9f85ea..2c56c89 100644
--- a/src/Dictionary.cpp
+++ b/src/Dictionary.cpp
@@ -20,22 +20,16 @@
20 20
21#include <stdlib.h> 21#include <stdlib.h>
22#include <plist/Dictionary.h> 22#include <plist/Dictionary.h>
23#include <plist/Array.h> 23#include <plist/Utils.h>
24#include <plist/Boolean.h>
25#include <plist/Integer.h>
26#include <plist/Real.h>
27#include <plist/String.h>
28#include <plist/Date.h>
29#include <plist/Data.h>
30 24
31namespace PList 25namespace PList
32{ 26{
33 27
34Dictionary::Dictionary() : Structure(PLIST_DICT) 28Dictionary::Dictionary(Node* parent) : Structure(PLIST_DICT, parent)
35{ 29{
36} 30}
37 31
38Dictionary::Dictionary(plist_t node) : Structure() 32Dictionary::Dictionary(plist_t node, Node* parent) : Structure(parent)
39{ 33{
40 _node = node; 34 _node = node;
41 plist_dict_iter it = NULL; 35 plist_dict_iter it = NULL;
@@ -46,36 +40,7 @@ Dictionary::Dictionary(plist_t node) : Structure()
46 plist_dict_next_item(_node, it, &key, &subnode); 40 plist_dict_next_item(_node, it, &key, &subnode);
47 while (subnode) 41 while (subnode)
48 { 42 {
49 plist_type subtype = plist_get_node_type(subnode); 43 _map[std::string(key)] = Utils::FromPlist(subnode, this);
50 switch(subtype)
51 {
52 case PLIST_DICT:
53 _map[std::string(key)] = new Dictionary(subnode);
54 break;
55 case PLIST_ARRAY:
56 _map[std::string(key)] = new Array(subnode);
57 break;
58 case PLIST_BOOLEAN:
59 _map[std::string(key)] = new Boolean(subnode);
60 break;
61 case PLIST_UINT:
62 _map[std::string(key)] = new Integer(subnode);
63 break;
64 case PLIST_REAL:
65 _map[std::string(key)] = new Real(subnode);
66 break;
67 case PLIST_STRING:
68 _map[std::string(key)] = new String(subnode);
69 break;
70 case PLIST_DATE:
71 _map[std::string(key)] = new Date(subnode);
72 break;
73 case PLIST_DATA:
74 _map[std::string(key)] = new Data(subnode);
75 break;
76 default:
77 break;
78 }
79 44
80 subnode = NULL; 45 subnode = NULL;
81 free(key); 46 free(key);
@@ -103,36 +68,7 @@ Dictionary::Dictionary(PList::Dictionary& d) : Structure()
103 plist_dict_next_item(_node, it, &key, &subnode); 68 plist_dict_next_item(_node, it, &key, &subnode);
104 while (subnode) 69 while (subnode)
105 { 70 {
106 plist_type subtype = plist_get_node_type(subnode); 71 _map[std::string(key)] = Utils::FromPlist(subnode, this);
107 switch(subtype)
108 {
109 case PLIST_DICT:
110 _map[std::string(key)] = new Dictionary(subnode);
111 break;
112 case PLIST_ARRAY:
113 _map[std::string(key)] = new Array(subnode);
114 break;
115 case PLIST_BOOLEAN:
116 _map[std::string(key)] = new Boolean(subnode);
117 break;
118 case PLIST_UINT:
119 _map[std::string(key)] = new Integer(subnode);
120 break;
121 case PLIST_REAL:
122 _map[std::string(key)] = new Real(subnode);
123 break;
124 case PLIST_STRING:
125 _map[std::string(key)] = new String(subnode);
126 break;
127 case PLIST_DATE:
128 _map[std::string(key)] = new Date(subnode);
129 break;
130 case PLIST_DATA:
131 _map[std::string(key)] = new Data(subnode);
132 break;
133 default:
134 break;
135 }
136 72
137 subnode = NULL; 73 subnode = NULL;
138 free(key); 74 free(key);
@@ -160,36 +96,7 @@ Dictionary& Dictionary::operator=(PList::Dictionary& d)
160 plist_dict_next_item(_node, it, &key, &subnode); 96 plist_dict_next_item(_node, it, &key, &subnode);
161 while (subnode) 97 while (subnode)
162 { 98 {
163 plist_type subtype = plist_get_node_type(subnode); 99 _map[std::string(key)] = Utils::FromPlist(subnode, this);
164 switch(subtype)
165 {
166 case PLIST_DICT:
167 _map[std::string(key)] = new Dictionary(subnode);
168 break;
169 case PLIST_ARRAY:
170 _map[std::string(key)] = new Array(subnode);
171 break;
172 case PLIST_BOOLEAN:
173 _map[std::string(key)] = new Boolean(subnode);
174 break;
175 case PLIST_UINT:
176 _map[std::string(key)] = new Integer(subnode);
177 break;
178 case PLIST_REAL:
179 _map[std::string(key)] = new Real(subnode);
180 break;
181 case PLIST_STRING:
182 _map[std::string(key)] = new String(subnode);
183 break;
184 case PLIST_DATE:
185 _map[std::string(key)] = new Date(subnode);
186 break;
187 case PLIST_DATA:
188 _map[std::string(key)] = new Data(subnode);
189 break;
190 default:
191 break;
192 }
193 100
194 subnode = NULL; 101 subnode = NULL;
195 free(key); 102 free(key);
@@ -239,6 +146,7 @@ Dictionary::iterator Dictionary::Insert(const std::string& key, Node* node)
239 if (node) 146 if (node)
240 { 147 {
241 Node* clone = node->Clone(); 148 Node* clone = node->Clone();
149 clone->SetParent(this);
242 plist_dict_insert_item(_node, key.c_str(), clone->GetPlist()); 150 plist_dict_insert_item(_node, key.c_str(), clone->GetPlist());
243 delete _map[key]; 151 delete _map[key];
244 _map[key] = clone; 152 _map[key] = clone;
diff --git a/src/Integer.cpp b/src/Integer.cpp
index cf1ad33..9cf6619 100644
--- a/src/Integer.cpp
+++ b/src/Integer.cpp
@@ -24,11 +24,11 @@
24namespace PList 24namespace PList
25{ 25{
26 26
27Integer::Integer() : Node(PLIST_UINT) 27Integer::Integer(Node* parent) : Node(PLIST_UINT, parent)
28{ 28{
29} 29}
30 30
31Integer::Integer(plist_t node) : Node(node) 31Integer::Integer(plist_t node, Node* parent) : Node(node, parent)
32{ 32{
33} 33}
34 34
diff --git a/src/Node.cpp b/src/Node.cpp
index ace1990..4497bb1 100644
--- a/src/Node.cpp
+++ b/src/Node.cpp
@@ -24,15 +24,15 @@
24namespace PList 24namespace PList
25{ 25{
26 26
27Node::Node() 27Node::Node(Node* parent) : _parent(parent)
28{ 28{
29} 29}
30 30
31Node::Node(plist_t node) : _node(node) 31Node::Node(plist_t node, Node* parent) : _node(node), _parent(parent)
32{ 32{
33} 33}
34 34
35Node::Node(plist_type type) 35Node::Node(plist_type type, Node* parent) : _parent(parent)
36{ 36{
37 _node = NULL; 37 _node = NULL;
38 38
@@ -72,6 +72,7 @@ Node::~Node()
72{ 72{
73 plist_free(_node); 73 plist_free(_node);
74 _node = NULL; 74 _node = NULL;
75 _parent = NULL;
75} 76}
76 77
77plist_type Node::GetType() 78plist_type Node::GetType()
@@ -86,4 +87,15 @@ plist_t Node::GetPlist()
86{ 87{
87 return _node; 88 return _node;
88} 89}
90
91Node* Node::GetParent()
92{
93 return _parent;
94}
95
96void Node::SetParent(Node* parent)
97{
98 _parent = parent;
99}
100
89}; 101};
diff --git a/src/Real.cpp b/src/Real.cpp
index e527f6d..a877b40 100644
--- a/src/Real.cpp
+++ b/src/Real.cpp
@@ -24,11 +24,11 @@
24namespace PList 24namespace PList
25{ 25{
26 26
27Real::Real() : Node(PLIST_REAL) 27Real::Real(Node* parent) : Node(PLIST_REAL, parent)
28{ 28{
29} 29}
30 30
31Real::Real(plist_t node) : Node(node) 31Real::Real(plist_t node, Node* parent) : Node(node, parent)
32{ 32{
33} 33}
34 34
diff --git a/src/String.cpp b/src/String.cpp
index dbc81ac..e6cceaa 100644
--- a/src/String.cpp
+++ b/src/String.cpp
@@ -24,11 +24,11 @@
24namespace PList 24namespace PList
25{ 25{
26 26
27String::String() : Node(PLIST_STRING) 27String::String(Node* parent) : Node(PLIST_STRING, parent)
28{ 28{
29} 29}
30 30
31String::String(plist_t node) : Node(node) 31String::String(plist_t node, Node* parent) : Node(node, parent)
32{ 32{
33} 33}
34 34
diff --git a/src/Structure.cpp b/src/Structure.cpp
index 6fd9b3d..5c7dc9a 100644
--- a/src/Structure.cpp
+++ b/src/Structure.cpp
@@ -24,10 +24,10 @@
24namespace PList 24namespace PList
25{ 25{
26 26
27Structure::Structure() : Node() 27Structure::Structure(Node* parent) : Node(parent)
28{ 28{
29} 29}
30Structure::Structure(plist_type type) : Node(type) 30Structure::Structure(plist_type type, Node* parent) : Node(type, parent)
31{ 31{
32} 32}
33 33
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 4e47994..a88b2ba 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -22,44 +22,79 @@
22#include <plist/Utils.h> 22#include <plist/Utils.h>
23#include <plist/Dictionary.h> 23#include <plist/Dictionary.h>
24#include <plist/Array.h> 24#include <plist/Array.h>
25#include <plist/Boolean.h>
26#include <plist/Integer.h>
27#include <plist/Real.h>
28#include <plist/String.h>
29#include <plist/Data.h>
30#include <plist/Date.h>
25 31
26namespace PList 32namespace PList
27{ 33{
28 34
29static Structure* FromPlist(plist_t root) 35Node* Utils::FromPlist(plist_t node, Node* parent)
30{ 36{
31 Structure* ret = NULL; 37 Node* ret = NULL;
32 if (root) 38 if (node)
33 { 39 {
34 plist_type type = plist_get_node_type(root); 40 plist_type type = plist_get_node_type(node);
35 switch(type) 41 switch(type)
36 { 42 {
37 case PLIST_DICT: 43 case PLIST_DICT:
38 ret = new Dictionary(root); 44 ret = new Dictionary(node, parent);
39 break; 45 break;
40 case PLIST_ARRAY: 46 case PLIST_ARRAY:
41 ret = new Array(root); 47 ret = new Array(node, parent);
42 break; 48 break;
43 case PLIST_BOOLEAN: 49 case PLIST_BOOLEAN:
50 ret = new Boolean(node, parent);
51 break;
44 case PLIST_UINT: 52 case PLIST_UINT:
53 ret = new Integer(node, parent);
54 break;
45 case PLIST_REAL: 55 case PLIST_REAL:
56 ret = new Real(node, parent);
57 break;
46 case PLIST_STRING: 58 case PLIST_STRING:
59 ret = new String(node, parent);
60 break;
47 case PLIST_DATE: 61 case PLIST_DATE:
62 ret = new Date(node, parent);
63 break;
48 case PLIST_DATA: 64 case PLIST_DATA:
65 ret = new Data(node, parent);
66 break;
49 default: 67 default:
50 plist_free(root); 68 plist_free(node);
51 break; 69 break;
52 } 70 }
53 } 71 }
54 return ret; 72 return ret;
55} 73}
56 74
75static Structure* ImportStruct(plist_t root)
76{
77 Structure* ret = NULL;
78 plist_type type = plist_get_node_type(root);
79
80 if (PLIST_ARRAY == type || PLIST_DICT == type)
81 {
82 ret = static_cast<Structure*>(Utils::FromPlist(root));
83 }
84 else
85 {
86 plist_free(root);
87 }
88
89 return ret;
90}
91
57Structure* Utils::FromXml(const std::string& in) 92Structure* Utils::FromXml(const std::string& in)
58{ 93{
59 plist_t root = NULL; 94 plist_t root = NULL;
60 plist_from_xml(in.c_str(), in.size(), &root); 95 plist_from_xml(in.c_str(), in.size(), &root);
61 96
62 return FromPlist(root); 97 return ImportStruct(root);
63} 98}
64 99
65Structure* Utils::FromBin(const std::vector<char>& in) 100Structure* Utils::FromBin(const std::vector<char>& in)
@@ -67,7 +102,7 @@ Structure* Utils::FromBin(const std::vector<char>& in)
67 plist_t root = NULL; 102 plist_t root = NULL;
68 plist_from_bin(&in[0], in.size(), &root); 103 plist_from_bin(&in[0], in.size(), &root);
69 104
70 return FromPlist(root); 105 return ImportStruct(root);
71 106
72} 107}
73 108