diff options
author | Jonathan Beck | 2009-10-28 18:08:33 +0100 |
---|---|---|
committer | Jonathan Beck | 2009-10-28 18:08:33 +0100 |
commit | fed2573566c2da1c5489260069a99ae9d2abf255 (patch) | |
tree | e86071e7e6e6616676a290eff504a223efe13d1d | |
parent | 1bc333972bb5d5b45ba8908f1b12015300d88711 (diff) | |
download | libplist-fed2573566c2da1c5489260069a99ae9d2abf255.tar.gz libplist-fed2573566c2da1c5489260069a99ae9d2abf255.tar.bz2 |
Unlink previous node in SetParent().
-rw-r--r-- | include/plist/Structure.h | 2 | ||||
-rw-r--r-- | src/Node.cpp | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/include/plist/Structure.h b/include/plist/Structure.h index 6f100cc..239a8b8 100644 --- a/include/plist/Structure.h +++ b/include/plist/Structure.h @@ -38,6 +38,8 @@ class Structure : public Node std::string ToXml(); std::vector<char> ToBin(); + + virtual void Remove(Node* node) = 0; protected: Structure(Node* parent = NULL); diff --git a/src/Node.cpp b/src/Node.cpp index e513862..c6a5b51 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -20,6 +20,7 @@ #include <stdlib.h> #include <plist/Node.h> +#include <plist/Structure.h> namespace PList { @@ -96,6 +97,16 @@ Node* Node::GetParent() void Node::SetParent(Node* parent) { + //Unlink node first + if ( NULL != _parent ) + { + plist_type type = plist_get_node_type(_parent); + if (PLIST_ARRAY ==type || PLIST_DICT == type ) + { + Structure* s = static_cast<Structure*>(_parent); + s->Remove(this); + } + } _parent = parent; } |