From 32be8ec384bfd78e189d3de6609e50cf4dd072a2 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Fri, 16 Oct 2009 22:26:13 +0200 Subject: Fix Node lifecycle and change argument as reference to const reference. --- src/Dictionary.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/Dictionary.cpp') diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp index 6879e33..15df0b4 100644 --- a/src/Dictionary.cpp +++ b/src/Dictionary.cpp @@ -85,7 +85,7 @@ Dictionary::Dictionary(plist_t node) : Structure() free(it); } -Dictionary::Dictionary(Dictionary& d) +Dictionary::Dictionary(PList::Dictionary& d) : Structure() { for (Dictionary::iterator it = _map.begin(); it != _map.end(); it++) { @@ -142,7 +142,7 @@ Dictionary::Dictionary(Dictionary& d) free(it); } -Dictionary& Dictionary::operator=(const Dictionary& d) +Dictionary& Dictionary::operator=(PList::Dictionary& d) { for (Dictionary::iterator it = _map.begin(); it != _map.end(); it++) { @@ -209,7 +209,12 @@ Dictionary::~Dictionary() _map.clear(); } -Node* Dictionary::operator[](std::string& key) +Node* Dictionary::Clone() +{ + return new Dictionary(*this); +} + +Node* Dictionary::operator[](const std::string& key) { return _map[key]; } @@ -224,13 +229,14 @@ Dictionary::iterator Dictionary::End() return _map.end(); } -void Dictionary::Insert(std::string& key, Node* node) +void Dictionary::Insert(const std::string& key, Node* node) { if (node) { - plist_dict_insert_item(_node, key.c_str(), node->GetPlist()); + Node* clone = node->Clone(); + plist_dict_insert_item(_node, key.c_str(), clone->GetPlist()); delete _map[key]; - _map[key] = node; + _map[key] = clone; } } @@ -247,7 +253,7 @@ void Dictionary::Remove(Node* node) } } -void Dictionary::Remove(std::string& key) +void Dictionary::Remove(const std::string& key) { plist_dict_remove_item(_node, key.c_str()); delete _map[key]; -- cgit v1.1-32-gdbae