diff options
author | Jonathan Beck | 2009-10-16 22:26:13 +0200 |
---|---|---|
committer | Jonathan Beck | 2009-10-16 22:26:13 +0200 |
commit | 32be8ec384bfd78e189d3de6609e50cf4dd072a2 (patch) | |
tree | ac7edad0f19be2a31efaaaaa3acd477dd2f3c233 /src/Array.cpp | |
parent | 8aeef4dd2331445fea8a7a40466b19973e9d09c4 (diff) | |
download | libplist-32be8ec384bfd78e189d3de6609e50cf4dd072a2.tar.gz libplist-32be8ec384bfd78e189d3de6609e50cf4dd072a2.tar.bz2 |
Fix Node lifecycle and change argument as reference to const reference.
Diffstat (limited to 'src/Array.cpp')
-rw-r--r-- | src/Array.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/Array.cpp b/src/Array.cpp index 0505a27..b85a114 100644 --- a/src/Array.cpp +++ b/src/Array.cpp @@ -77,15 +77,9 @@ Array::Array(plist_t node) : Structure() } } -Array::Array(Array& a) +Array::Array(PList::Array& a) : Structure() { - plist_free(_node); - for (int it = 0; it < _array.size(); it++) - { - delete _array.at(it); - } _array.clear(); - _node = plist_copy(a.GetPlist()); uint32_t size = plist_array_get_size(_node); @@ -125,7 +119,7 @@ Array::Array(Array& a) } } -Array& Array::operator=(const Array& a) +Array& Array::operator=(PList::Array& a) { plist_free(_node); for (int it = 0; it < _array.size(); it++) @@ -175,12 +169,16 @@ Array& Array::operator=(const Array& a) Array::~Array() { - plist_free(_node); - for (int it = 0; it < _array.size(); it++) - { - delete _array.at(it); - } - _array.clear(); + for (int it = 0; it < _array.size(); it++) + { + delete (_array.at(it)); + } + _array.clear(); +} + +Node* Array::Clone() +{ + return new Array(*this); } Node* Array::operator[](unsigned int index) @@ -192,8 +190,9 @@ void Array::Append(Node* node) { if (node) { - plist_array_append_item(_node, node->GetPlist()); - _array.push_back(node); + Node* clone = node->Clone(); + plist_array_append_item(_node, clone->GetPlist()); + _array.push_back(clone); } } @@ -201,10 +200,11 @@ void Array::Insert(Node* node, unsigned int pos) { if (node) { - plist_array_insert_item(_node, node->GetPlist(), pos); + Node* clone = node->Clone(); + plist_array_insert_item(_node, clone->GetPlist(), pos); std::vector<Node*>::iterator it = _array.begin(); it += pos; - _array.insert(it, node); + _array.insert(it, clone); } } |