Commit fed25735 authored by Jonathan Beck's avatar Jonathan Beck

Unlink previous node in SetParent().

parent 1bc33397
...@@ -39,6 +39,8 @@ class Structure : public Node ...@@ -39,6 +39,8 @@ class Structure : public Node
std::string ToXml(); std::string ToXml();
std::vector<char> ToBin(); std::vector<char> ToBin();
virtual void Remove(Node* node) = 0;
protected: protected:
Structure(Node* parent = NULL); Structure(Node* parent = NULL);
Structure(plist_type type, Node* parent = NULL); Structure(plist_type type, Node* parent = NULL);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <plist/Node.h> #include <plist/Node.h>
#include <plist/Structure.h>
namespace PList namespace PList
{ {
...@@ -96,6 +97,16 @@ Node* Node::GetParent() ...@@ -96,6 +97,16 @@ Node* Node::GetParent()
void Node::SetParent(Node* parent) 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; _parent = parent;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment