summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Array.cpp107
-rw-r--r--src/Boolean.cpp4
-rw-r--r--src/Data.cpp4
-rw-r--r--src/Date.cpp4
-rw-r--r--src/Dictionary.cpp106
-rw-r--r--src/Integer.cpp4
-rw-r--r--src/Node.cpp18
-rw-r--r--src/Real.cpp4
-rw-r--r--src/String.cpp4
-rw-r--r--src/Structure.cpp4
-rw-r--r--src/Utils.cpp53
11 files changed, 88 insertions, 224 deletions
diff --git a/src/Array.cpp b/src/Array.cpp
index b85a114..7c8272c 100644
--- a/src/Array.cpp
+++ b/src/Array.cpp
@@ -20,23 +20,17 @@
#include <stdlib.h>
#include <plist/Array.h>
-#include <plist/Dictionary.h>
-#include <plist/Boolean.h>
-#include <plist/Integer.h>
-#include <plist/Real.h>
-#include <plist/String.h>
-#include <plist/Date.h>
-#include <plist/Data.h>
+#include <plist/Utils.h>
namespace PList
{
-Array::Array() : Structure(PLIST_ARRAY)
+Array::Array(Node* parent) : Structure(PLIST_ARRAY, parent)
{
_array.clear();
}
-Array::Array(plist_t node) : Structure()
+Array::Array(plist_t node, Node* parent) : Structure(parent)
{
_node = node;
uint32_t size = plist_array_get_size(_node);
@@ -44,36 +38,7 @@ Array::Array(plist_t node) : Structure()
for (uint32_t i = 0; i < size; i++)
{
plist_t subnode = plist_array_get_item(_node, i);
- plist_type subtype = plist_get_node_type(subnode);
- switch(subtype)
- {
- case PLIST_DICT:
- _array.push_back( new Dictionary(subnode) );
- break;
- case PLIST_ARRAY:
- _array.push_back( new Array(subnode) );
- break;
- case PLIST_BOOLEAN:
- _array.push_back( new Boolean(subnode) );
- break;
- case PLIST_UINT:
- _array.push_back( new Integer(subnode) );
- break;
- case PLIST_REAL:
- _array.push_back( new Real(subnode) );
- break;
- case PLIST_STRING:
- _array.push_back( new String(subnode) );
- break;
- case PLIST_DATE:
- _array.push_back( new Date(subnode) );
- break;
- case PLIST_DATA:
- _array.push_back( new Data(subnode) );
- break;
- default:
- break;
- }
+ _array.push_back( Utils::FromPlist(subnode, this) );
}
}
@@ -86,36 +51,7 @@ Array::Array(PList::Array& a) : Structure()
for (uint32_t i = 0; i < size; i++)
{
plist_t subnode = plist_array_get_item(_node, i);
- plist_type subtype = plist_get_node_type(subnode);
- switch(subtype)
- {
- case PLIST_DICT:
- _array.push_back( new Dictionary(subnode) );
- break;
- case PLIST_ARRAY:
- _array.push_back( new Array(subnode) );
- break;
- case PLIST_BOOLEAN:
- _array.push_back( new Boolean(subnode) );
- break;
- case PLIST_UINT:
- _array.push_back( new Integer(subnode) );
- break;
- case PLIST_REAL:
- _array.push_back( new Real(subnode) );
- break;
- case PLIST_STRING:
- _array.push_back( new String(subnode) );
- break;
- case PLIST_DATE:
- _array.push_back( new Date(subnode) );
- break;
- case PLIST_DATA:
- _array.push_back( new Data(subnode) );
- break;
- default:
- break;
- }
+ _array.push_back( Utils::FromPlist(subnode, this) );
}
}
@@ -134,36 +70,7 @@ Array& Array::operator=(PList::Array& a)
for (uint32_t i = 0; i < size; i++)
{
plist_t subnode = plist_array_get_item(_node, i);
- plist_type subtype = plist_get_node_type(subnode);
- switch(subtype)
- {
- case PLIST_DICT:
- _array.push_back( new Dictionary(subnode) );
- break;
- case PLIST_ARRAY:
- _array.push_back( new Array(subnode) );
- break;
- case PLIST_BOOLEAN:
- _array.push_back( new Boolean(subnode) );
- break;
- case PLIST_UINT:
- _array.push_back( new Integer(subnode) );
- break;
- case PLIST_REAL:
- _array.push_back( new Real(subnode) );
- break;
- case PLIST_STRING:
- _array.push_back( new String(subnode) );
- break;
- case PLIST_DATE:
- _array.push_back( new Date(subnode) );
- break;
- case PLIST_DATA:
- _array.push_back( new Data(subnode) );
- break;
- default:
- break;
- }
+ _array.push_back( Utils::FromPlist(subnode, this) );
}
}
@@ -191,6 +98,7 @@ void Array::Append(Node* node)
if (node)
{
Node* clone = node->Clone();
+ clone->SetParent(this);
plist_array_append_item(_node, clone->GetPlist());
_array.push_back(clone);
}
@@ -201,6 +109,7 @@ void Array::Insert(Node* node, unsigned int pos)
if (node)
{
Node* clone = node->Clone();
+ clone->SetParent(this);
plist_array_insert_item(_node, clone->GetPlist(), pos);
std::vector<Node*>::iterator it = _array.begin();
it += pos;
diff --git a/src/Boolean.cpp b/src/Boolean.cpp
index 03d17c8..3b20f45 100644
--- a/src/Boolean.cpp
+++ b/src/Boolean.cpp
@@ -24,11 +24,11 @@
namespace PList
{
-Boolean::Boolean() : Node(PLIST_BOOLEAN)
+Boolean::Boolean(Node* parent) : Node(PLIST_BOOLEAN, parent)
{
}
-Boolean::Boolean(plist_t node) : Node(node)
+Boolean::Boolean(plist_t node, Node* parent) : Node(node, parent)
{
}
diff --git a/src/Data.cpp b/src/Data.cpp
index 87a508a..a171c03 100644
--- a/src/Data.cpp
+++ b/src/Data.cpp
@@ -24,11 +24,11 @@
namespace PList
{
-Data::Data() : Node(PLIST_DATA)
+Data::Data(Node* parent) : Node(PLIST_DATA, parent)
{
}
-Data::Data(plist_t node) : Node(node)
+Data::Data(plist_t node, Node* parent) : Node(node, parent)
{
}
diff --git a/src/Date.cpp b/src/Date.cpp
index 1aebfab..6321c84 100644
--- a/src/Date.cpp
+++ b/src/Date.cpp
@@ -24,11 +24,11 @@
namespace PList
{
-Date::Date() : Node(PLIST_DATE)
+Date::Date(Node* parent) : Node(PLIST_DATE, parent)
{
}
-Date::Date(plist_t node) : Node(node)
+Date::Date(plist_t node, Node* parent) : Node(node, parent)
{
}
diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp
index a9f85ea..2c56c89 100644
--- a/src/Dictionary.cpp
+++ b/src/Dictionary.cpp
@@ -20,22 +20,16 @@
#include <stdlib.h>
#include <plist/Dictionary.h>
-#include <plist/Array.h>
-#include <plist/Boolean.h>
-#include <plist/Integer.h>
-#include <plist/Real.h>
-#include <plist/String.h>
-#include <plist/Date.h>
-#include <plist/Data.h>
+#include <plist/Utils.h>
namespace PList
{
-Dictionary::Dictionary() : Structure(PLIST_DICT)
+Dictionary::Dictionary(Node* parent) : Structure(PLIST_DICT, parent)
{
}
-Dictionary::Dictionary(plist_t node) : Structure()
+Dictionary::Dictionary(plist_t node, Node* parent) : Structure(parent)
{
_node = node;
plist_dict_iter it = NULL;
@@ -46,36 +40,7 @@ Dictionary::Dictionary(plist_t node) : Structure()
plist_dict_next_item(_node, it, &key, &subnode);
while (subnode)
{
- plist_type subtype = plist_get_node_type(subnode);
- switch(subtype)
- {
- case PLIST_DICT:
- _map[std::string(key)] = new Dictionary(subnode);
- break;
- case PLIST_ARRAY:
- _map[std::string(key)] = new Array(subnode);
- break;
- case PLIST_BOOLEAN:
- _map[std::string(key)] = new Boolean(subnode);
- break;
- case PLIST_UINT:
- _map[std::string(key)] = new Integer(subnode);
- break;
- case PLIST_REAL:
- _map[std::string(key)] = new Real(subnode);
- break;
- case PLIST_STRING:
- _map[std::string(key)] = new String(subnode);
- break;
- case PLIST_DATE:
- _map[std::string(key)] = new Date(subnode);
- break;
- case PLIST_DATA:
- _map[std::string(key)] = new Data(subnode);
- break;
- default:
- break;
- }
+ _map[std::string(key)] = Utils::FromPlist(subnode, this);
subnode = NULL;
free(key);
@@ -103,36 +68,7 @@ Dictionary::Dictionary(PList::Dictionary& d) : Structure()
plist_dict_next_item(_node, it, &key, &subnode);
while (subnode)
{
- plist_type subtype = plist_get_node_type(subnode);
- switch(subtype)
- {
- case PLIST_DICT:
- _map[std::string(key)] = new Dictionary(subnode);
- break;
- case PLIST_ARRAY:
- _map[std::string(key)] = new Array(subnode);
- break;
- case PLIST_BOOLEAN:
- _map[std::string(key)] = new Boolean(subnode);
- break;
- case PLIST_UINT:
- _map[std::string(key)] = new Integer(subnode);
- break;
- case PLIST_REAL:
- _map[std::string(key)] = new Real(subnode);
- break;
- case PLIST_STRING:
- _map[std::string(key)] = new String(subnode);
- break;
- case PLIST_DATE:
- _map[std::string(key)] = new Date(subnode);
- break;
- case PLIST_DATA:
- _map[std::string(key)] = new Data(subnode);
- break;
- default:
- break;
- }
+ _map[std::string(key)] = Utils::FromPlist(subnode, this);
subnode = NULL;
free(key);
@@ -160,36 +96,7 @@ Dictionary& Dictionary::operator=(PList::Dictionary& d)
plist_dict_next_item(_node, it, &key, &subnode);
while (subnode)
{
- plist_type subtype = plist_get_node_type(subnode);
- switch(subtype)
- {
- case PLIST_DICT:
- _map[std::string(key)] = new Dictionary(subnode);
- break;
- case PLIST_ARRAY:
- _map[std::string(key)] = new Array(subnode);
- break;
- case PLIST_BOOLEAN:
- _map[std::string(key)] = new Boolean(subnode);
- break;
- case PLIST_UINT:
- _map[std::string(key)] = new Integer(subnode);
- break;
- case PLIST_REAL:
- _map[std::string(key)] = new Real(subnode);
- break;
- case PLIST_STRING:
- _map[std::string(key)] = new String(subnode);
- break;
- case PLIST_DATE:
- _map[std::string(key)] = new Date(subnode);
- break;
- case PLIST_DATA:
- _map[std::string(key)] = new Data(subnode);
- break;
- default:
- break;
- }
+ _map[std::string(key)] = Utils::FromPlist(subnode, this);
subnode = NULL;
free(key);
@@ -239,6 +146,7 @@ Dictionary::iterator Dictionary::Insert(const std::string& key, Node* node)
if (node)
{
Node* clone = node->Clone();
+ clone->SetParent(this);
plist_dict_insert_item(_node, key.c_str(), clone->GetPlist());
delete _map[key];
_map[key] = clone;
diff --git a/src/Integer.cpp b/src/Integer.cpp
index cf1ad33..9cf6619 100644
--- a/src/Integer.cpp
+++ b/src/Integer.cpp
@@ -24,11 +24,11 @@
namespace PList
{
-Integer::Integer() : Node(PLIST_UINT)
+Integer::Integer(Node* parent) : Node(PLIST_UINT, parent)
{
}
-Integer::Integer(plist_t node) : Node(node)
+Integer::Integer(plist_t node, Node* parent) : Node(node, parent)
{
}
diff --git a/src/Node.cpp b/src/Node.cpp
index ace1990..4497bb1 100644
--- a/src/Node.cpp
+++ b/src/Node.cpp
@@ -24,15 +24,15 @@
namespace PList
{
-Node::Node()
+Node::Node(Node* parent) : _parent(parent)
{
}
-Node::Node(plist_t node) : _node(node)
+Node::Node(plist_t node, Node* parent) : _node(node), _parent(parent)
{
}
-Node::Node(plist_type type)
+Node::Node(plist_type type, Node* parent) : _parent(parent)
{
_node = NULL;
@@ -72,6 +72,7 @@ Node::~Node()
{
plist_free(_node);
_node = NULL;
+ _parent = NULL;
}
plist_type Node::GetType()
@@ -86,4 +87,15 @@ plist_t Node::GetPlist()
{
return _node;
}
+
+Node* Node::GetParent()
+{
+ return _parent;
+}
+
+void Node::SetParent(Node* parent)
+{
+ _parent = parent;
+}
+
};
diff --git a/src/Real.cpp b/src/Real.cpp
index e527f6d..a877b40 100644
--- a/src/Real.cpp
+++ b/src/Real.cpp
@@ -24,11 +24,11 @@
namespace PList
{
-Real::Real() : Node(PLIST_REAL)
+Real::Real(Node* parent) : Node(PLIST_REAL, parent)
{
}
-Real::Real(plist_t node) : Node(node)
+Real::Real(plist_t node, Node* parent) : Node(node, parent)
{
}
diff --git a/src/String.cpp b/src/String.cpp
index dbc81ac..e6cceaa 100644
--- a/src/String.cpp
+++ b/src/String.cpp
@@ -24,11 +24,11 @@
namespace PList
{
-String::String() : Node(PLIST_STRING)
+String::String(Node* parent) : Node(PLIST_STRING, parent)
{
}
-String::String(plist_t node) : Node(node)
+String::String(plist_t node, Node* parent) : Node(node, parent)
{
}
diff --git a/src/Structure.cpp b/src/Structure.cpp
index 6fd9b3d..5c7dc9a 100644
--- a/src/Structure.cpp
+++ b/src/Structure.cpp
@@ -24,10 +24,10 @@
namespace PList
{
-Structure::Structure() : Node()
+Structure::Structure(Node* parent) : Node(parent)
{
}
-Structure::Structure(plist_type type) : Node(type)
+Structure::Structure(plist_type type, Node* parent) : Node(type, parent)
{
}
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 4e47994..a88b2ba 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -22,44 +22,79 @@
#include <plist/Utils.h>
#include <plist/Dictionary.h>
#include <plist/Array.h>
+#include <plist/Boolean.h>
+#include <plist/Integer.h>
+#include <plist/Real.h>
+#include <plist/String.h>
+#include <plist/Data.h>
+#include <plist/Date.h>
namespace PList
{
-static Structure* FromPlist(plist_t root)
+Node* Utils::FromPlist(plist_t node, Node* parent)
{
- Structure* ret = NULL;
- if (root)
+ Node* ret = NULL;
+ if (node)
{
- plist_type type = plist_get_node_type(root);
+ plist_type type = plist_get_node_type(node);
switch(type)
{
case PLIST_DICT:
- ret = new Dictionary(root);
+ ret = new Dictionary(node, parent);
break;
case PLIST_ARRAY:
- ret = new Array(root);
+ ret = new Array(node, parent);
break;
case PLIST_BOOLEAN:
+ ret = new Boolean(node, parent);
+ break;
case PLIST_UINT:
+ ret = new Integer(node, parent);
+ break;
case PLIST_REAL:
+ ret = new Real(node, parent);
+ break;
case PLIST_STRING:
+ ret = new String(node, parent);
+ break;
case PLIST_DATE:
+ ret = new Date(node, parent);
+ break;
case PLIST_DATA:
+ ret = new Data(node, parent);
+ break;
default:
- plist_free(root);
+ plist_free(node);
break;
}
}
return ret;
}
+static Structure* ImportStruct(plist_t root)
+{
+ Structure* ret = NULL;
+ plist_type type = plist_get_node_type(root);
+
+ if (PLIST_ARRAY == type || PLIST_DICT == type)
+ {
+ ret = static_cast<Structure*>(Utils::FromPlist(root));
+ }
+ else
+ {
+ plist_free(root);
+ }
+
+ return ret;
+}
+
Structure* Utils::FromXml(const std::string& in)
{
plist_t root = NULL;
plist_from_xml(in.c_str(), in.size(), &root);
- return FromPlist(root);
+ return ImportStruct(root);
}
Structure* Utils::FromBin(const std::vector<char>& in)
@@ -67,7 +102,7 @@ Structure* Utils::FromBin(const std::vector<char>& in)
plist_t root = NULL;
plist_from_bin(&in[0], in.size(), &root);
- return FromPlist(root);
+ return ImportStruct(root);
}