summaryrefslogtreecommitdiffstats
path: root/src/Utils.cpp
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-10-26 18:41:15 +0100
committerGravatar Jonathan Beck2009-10-26 18:41:15 +0100
commitc1363bea107b15bdc10ce80671747be891661889 (patch)
tree1a8ce452eb6c1110ea0cd88dec155e99bfe7b69b /src/Utils.cpp
parentbef50c0873aad5d8cd516428828e79fc05a43913 (diff)
downloadlibplist-c1363bea107b15bdc10ce80671747be891661889.tar.gz
libplist-c1363bea107b15bdc10ce80671747be891661889.tar.bz2
Add Set/Get Parent and a helper to create a Node from a plist_t.
Diffstat (limited to 'src/Utils.cpp')
-rw-r--r--src/Utils.cpp53
1 files changed, 44 insertions, 9 deletions
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);
}