diff options
| -rw-r--r-- | include/plist/Node.h | 6 | ||||
| -rw-r--r-- | include/plist/Structure.h | 1 | ||||
| -rw-r--r-- | src/Array.cpp | 4 | ||||
| -rw-r--r-- | src/Dictionary.cpp | 2 | ||||
| -rw-r--r-- | src/Node.cpp | 15 | ||||
| -rw-r--r-- | src/Structure.cpp | 15 |
6 files changed, 23 insertions, 20 deletions
diff --git a/include/plist/Node.h b/include/plist/Node.h index 7ea6ed9..2f9f5b6 100644 --- a/include/plist/Node.h +++ b/include/plist/Node.h | |||
| @@ -33,9 +33,8 @@ public : | |||
| 33 | virtual ~Node(); | 33 | virtual ~Node(); |
| 34 | 34 | ||
| 35 | virtual Node* Clone() = 0; | 35 | virtual Node* Clone() = 0; |
| 36 | Node * GetParent(); | ||
| 37 | void SetParent(Node* parent); | ||
| 38 | 36 | ||
| 37 | Node * GetParent(); | ||
| 39 | plist_type GetType(); | 38 | plist_type GetType(); |
| 40 | plist_t GetPlist(); | 39 | plist_t GetPlist(); |
| 41 | 40 | ||
| @@ -44,7 +43,10 @@ protected: | |||
| 44 | Node(plist_t node, Node* parent = NULL); | 43 | Node(plist_t node, Node* parent = NULL); |
| 45 | Node(plist_type type, Node* parent = NULL); | 44 | Node(plist_type type, Node* parent = NULL); |
| 46 | plist_t _node; | 45 | plist_t _node; |
| 46 | |||
| 47 | private: | ||
| 47 | Node* _parent; | 48 | Node* _parent; |
| 49 | friend class Structure; | ||
| 48 | }; | 50 | }; |
| 49 | 51 | ||
| 50 | }; | 52 | }; |
diff --git a/include/plist/Structure.h b/include/plist/Structure.h index 66d9293..f6e4495 100644 --- a/include/plist/Structure.h +++ b/include/plist/Structure.h | |||
| @@ -44,6 +44,7 @@ public : | |||
| 44 | protected: | 44 | protected: |
| 45 | Structure(Node* parent = NULL); | 45 | Structure(Node* parent = NULL); |
| 46 | Structure(plist_type type, Node* parent = NULL); | 46 | Structure(plist_type type, Node* parent = NULL); |
| 47 | void UpdateNodeParent(Node* node); | ||
| 47 | 48 | ||
| 48 | private: | 49 | private: |
| 49 | Structure(Structure& s); | 50 | Structure(Structure& s); |
diff --git a/src/Array.cpp b/src/Array.cpp index a847ae2..3069314 100644 --- a/src/Array.cpp +++ b/src/Array.cpp | |||
| @@ -101,7 +101,7 @@ void Array::Append(Node* node) | |||
| 101 | if (node) | 101 | if (node) |
| 102 | { | 102 | { |
| 103 | Node* clone = node->Clone(); | 103 | Node* clone = node->Clone(); |
| 104 | clone->SetParent(this); | 104 | UpdateNodeParent(clone); |
| 105 | plist_array_append_item(_node, clone->GetPlist()); | 105 | plist_array_append_item(_node, clone->GetPlist()); |
| 106 | _array.push_back(clone); | 106 | _array.push_back(clone); |
| 107 | } | 107 | } |
| @@ -112,7 +112,7 @@ void Array::Insert(Node* node, unsigned int pos) | |||
| 112 | if (node) | 112 | if (node) |
| 113 | { | 113 | { |
| 114 | Node* clone = node->Clone(); | 114 | Node* clone = node->Clone(); |
| 115 | clone->SetParent(this); | 115 | UpdateNodeParent(clone); |
| 116 | plist_array_insert_item(_node, clone->GetPlist(), pos); | 116 | plist_array_insert_item(_node, clone->GetPlist(), pos); |
| 117 | std::vector<Node*>::iterator it = _array.begin(); | 117 | std::vector<Node*>::iterator it = _array.begin(); |
| 118 | it += pos; | 118 | it += pos; |
diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp index 62ed433..8b5565f 100644 --- a/src/Dictionary.cpp +++ b/src/Dictionary.cpp | |||
| @@ -147,7 +147,7 @@ Dictionary::iterator Dictionary::Insert(const std::string& key, Node* node) | |||
| 147 | if (node) | 147 | if (node) |
| 148 | { | 148 | { |
| 149 | Node* clone = node->Clone(); | 149 | Node* clone = node->Clone(); |
| 150 | clone->SetParent(this); | 150 | UpdateNodeParent(clone); |
| 151 | plist_dict_insert_item(_node, key.c_str(), clone->GetPlist()); | 151 | plist_dict_insert_item(_node, key.c_str(), clone->GetPlist()); |
| 152 | delete _map[key]; | 152 | delete _map[key]; |
| 153 | _map[key] = clone; | 153 | _map[key] = clone; |
diff --git a/src/Node.cpp b/src/Node.cpp index 8ed3c6a..b0cc96a 100644 --- a/src/Node.cpp +++ b/src/Node.cpp | |||
| @@ -96,19 +96,4 @@ Node* Node::GetParent() | |||
| 96 | return _parent; | 96 | return _parent; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | void Node::SetParent(Node* parent) | ||
| 100 | { | ||
| 101 | //Unlink node first | ||
| 102 | if ( NULL != _parent ) | ||
| 103 | { | ||
| 104 | plist_type type = plist_get_node_type(_parent); | ||
| 105 | if (PLIST_ARRAY ==type || PLIST_DICT == type ) | ||
| 106 | { | ||
| 107 | Structure* s = static_cast<Structure*>(_parent); | ||
| 108 | s->Remove(this); | ||
| 109 | } | ||
| 110 | } | ||
| 111 | _parent = parent; | ||
| 112 | } | ||
| 113 | |||
| 114 | }; | 99 | }; |
diff --git a/src/Structure.cpp b/src/Structure.cpp index 872d396..cf7c611 100644 --- a/src/Structure.cpp +++ b/src/Structure.cpp | |||
| @@ -70,5 +70,20 @@ std::vector<char> Structure::ToBin() | |||
| 70 | return ret; | 70 | return ret; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | void Structure::UpdateNodeParent(Node* node) | ||
| 74 | { | ||
| 75 | //Unlink node first | ||
| 76 | if ( NULL != node->_parent ) | ||
| 77 | { | ||
| 78 | plist_type type = plist_get_node_type(node->_parent); | ||
| 79 | if (PLIST_ARRAY ==type || PLIST_DICT == type ) | ||
| 80 | { | ||
| 81 | Structure* s = static_cast<Structure*>(node->_parent); | ||
| 82 | s->Remove(node); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | node->_parent = this; | ||
| 86 | } | ||
| 87 | |||
| 73 | }; | 88 | }; |
| 74 | 89 | ||
