summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Array.cpp38
-rw-r--r--src/plist.c38
2 files changed, 50 insertions, 26 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
diff --git a/src/plist.c b/src/plist.c
index 6b604d6..1b33ec3 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -2,9 +2,9 @@
2 * plist.c 2 * plist.c
3 * Builds plist XML structures 3 * Builds plist XML structures
4 * 4 *
5 * Copyright (c) 2009-2016 Nikias Bassen All Rights Reserved. 5 * Copyright (c) 2009-2019 Nikias Bassen, All Rights Reserved.
6 * Copyright (c) 2010-2015 Martin Szulecki All Rights Reserved. 6 * Copyright (c) 2010-2015 Martin Szulecki, All Rights Reserved.
7 * Copyright (c) 2008 Zach C. All Rights Reserved. 7 * Copyright (c) 2008 Zach C., All Rights Reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public 10 * modify it under the terms of the GNU Lesser General Public
@@ -457,6 +457,36 @@ PLIST_API void plist_array_remove_item(plist_t node, uint32_t n)
457 return; 457 return;
458} 458}
459 459
460PLIST_API void plist_array_new_iter(plist_t node, plist_array_iter *iter)
461{
462 if (iter)
463 {
464 *iter = malloc(sizeof(node_t*));
465 *((node_t**)(*iter)) = node_first_child(node);
466 }
467 return;
468}
469
470PLIST_API void plist_array_next_item(plist_t node, plist_array_iter iter, plist_t *item)
471{
472 node_t** iter_node = (node_t**)iter;
473
474 if (item)
475 {
476 *item = NULL;
477 }
478
479 if (node && PLIST_ARRAY == plist_get_node_type(node) && *iter_node)
480 {
481 if (item)
482 {
483 *item = (plist_t)(*iter_node);
484 }
485 *iter_node = node_next_sibling(*iter_node);
486 }
487 return;
488}
489
460PLIST_API uint32_t plist_dict_get_size(plist_t node) 490PLIST_API uint32_t plist_dict_get_size(plist_t node)
461{ 491{
462 uint32_t ret = 0; 492 uint32_t ret = 0;
@@ -469,7 +499,7 @@ PLIST_API uint32_t plist_dict_get_size(plist_t node)
469 499
470PLIST_API void plist_dict_new_iter(plist_t node, plist_dict_iter *iter) 500PLIST_API void plist_dict_new_iter(plist_t node, plist_dict_iter *iter)
471{ 501{
472 if (iter && *iter == NULL) 502 if (iter)
473 { 503 {
474 *iter = malloc(sizeof(node_t*)); 504 *iter = malloc(sizeof(node_t*));
475 *((node_t**)(*iter)) = node_first_child(node); 505 *((node_t**)(*iter)) = node_first_child(node);