summaryrefslogtreecommitdiffstats
path: root/src/Array.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Array.cpp')
-rw-r--r--src/Array.cpp38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/Array.cpp b/src/Array.cpp
index 7c38a69..a511841 100644
--- a/src/Array.cpp
+++ b/src/Array.cpp
@@ -31,29 +31,30 @@ Array::Array(Node* parent) : Structure(PLIST_ARRAY, parent)
31 _array.clear(); 31 _array.clear();
32} 32}
33 33
34static void array_fill(Array *_this, std::vector<Node*> array, plist_t node)
35{
36 plist_array_iter iter = NULL;
37 plist_array_new_iter(node, &iter);
38 plist_t subnode;
39 do {
40 subnode = NULL;
41 plist_array_next_item(node, iter, &subnode);
42 array.push_back( Node::FromPlist(subnode, _this) );
43 } while (subnode);
44 free(iter);
45}
46
34Array::Array(plist_t node, Node* parent) : Structure(parent) 47Array::Array(plist_t node, Node* parent) : Structure(parent)
35{ 48{
36 _node = node; 49 _node = node;
37 uint32_t size = plist_array_get_size(_node); 50 array_fill(this, _array, _node);
38
39 for (uint32_t i = 0; i < size; i++)
40 {
41 plist_t subnode = plist_array_get_item(_node, i);
42 _array.push_back( Node::FromPlist(subnode, this) );
43 }
44} 51}
45 52
46Array::Array(const PList::Array& a) : Structure() 53Array::Array(const PList::Array& a) : Structure()
47{ 54{
48 _array.clear(); 55 _array.clear();
49 _node = plist_copy(a.GetPlist()); 56 _node = plist_copy(a.GetPlist());
50 uint32_t size = plist_array_get_size(_node); 57 array_fill(this, _array, _node);
51
52 for (uint32_t i = 0; i < size; i++)
53 {
54 plist_t subnode = plist_array_get_item(_node, i);
55 _array.push_back( Node::FromPlist(subnode, this) );
56 }
57} 58}
58 59
59Array& Array::operator=(PList::Array& a) 60Array& Array::operator=(PList::Array& a)
@@ -64,15 +65,8 @@ Array& Array::operator=(PList::Array& a)
64 delete _array.at(it); 65 delete _array.at(it);
65 } 66 }
66 _array.clear(); 67 _array.clear();
67
68 _node = plist_copy(a.GetPlist()); 68 _node = plist_copy(a.GetPlist());
69 uint32_t size = plist_array_get_size(_node); 69 array_fill(this, _array, _node);
70
71 for (uint32_t i = 0; i < size; i++)
72 {
73 plist_t subnode = plist_array_get_item(_node, i);
74 _array.push_back( Node::FromPlist(subnode, this) );
75 }
76 return *this; 70 return *this;
77} 71}
78 72