summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-10-13 20:04:06 +0200
committerGravatar Jonathan Beck2009-10-13 20:04:06 +0200
commita922b714c9b75fdc67735d674758d4eaedfd32f9 (patch)
tree509ec53c18c0be36a9e650eb0f760854cd8d4957 /src
parente492ef675c404cc6c0d1cfa26e47a1c16c850d5f (diff)
downloadlibplist-a922b714c9b75fdc67735d674758d4eaedfd32f9.tar.gz
libplist-a922b714c9b75fdc67735d674758d4eaedfd32f9.tar.bz2
Add C++ binding.
Diffstat (limited to 'src')
-rw-r--r--src/Array.cpp194
-rw-r--r--src/Boolean.cpp52
-rw-r--r--src/CMakeLists.txt17
-rw-r--r--src/Data.cpp57
-rw-r--r--src/Date.cpp52
-rw-r--r--src/Dictionary.cpp217
-rw-r--r--src/Integer.cpp52
-rw-r--r--src/Node.cpp105
-rw-r--r--src/Real.cpp52
-rw-r--r--src/String.cpp54
-rw-r--r--src/Structure.cpp74
-rw-r--r--src/Utils.cpp74
12 files changed, 1000 insertions, 0 deletions
diff --git a/src/Array.cpp b/src/Array.cpp
new file mode 100644
index 0000000..6f1d3f9
--- /dev/null
+++ b/src/Array.cpp
@@ -0,0 +1,194 @@
+/*
+ * Array.cpp
+ *
+ * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <plist/Array.h>
+#include <plist/Dictionary.h>
+
+namespace PList
+{
+
+Array::Array() : Structure(PLIST_ARRAY)
+{
+ _array.clear();
+}
+
+Array::Array(plist_t node) : Structure()
+{
+ _node = node;
+ uint32_t size = plist_array_get_size(_node);
+
+ 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:
+ case PLIST_UINT:
+ case PLIST_REAL:
+ case PLIST_STRING:
+ case PLIST_DATE:
+ case PLIST_DATA:
+ default:
+ _array.push_back( new Node(subnode) );
+ break;
+ }
+ }
+}
+
+Array::Array(Array& a)
+{
+ plist_free(_node);
+ for (int it = 0; it < _array.size(); it++)
+ {
+ delete _array.at(it);
+ }
+ _array.clear();
+
+ _node = plist_copy(a.GetPlist());
+ uint32_t size = plist_array_get_size(_node);
+
+ 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:
+ case PLIST_UINT:
+ case PLIST_REAL:
+ case PLIST_STRING:
+ case PLIST_DATE:
+ case PLIST_DATA:
+ default:
+ _array.push_back( new Node(subnode) );
+ break;
+ }
+ }
+}
+
+Array& Array::operator=(const Array& a)
+{
+ plist_free(_node);
+ for (int it = 0; it < _array.size(); it++)
+ {
+ delete _array.at(it);
+ }
+ _array.clear();
+
+ _node = plist_copy(a.GetPlist());
+ uint32_t size = plist_array_get_size(_node);
+
+ 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:
+ case PLIST_UINT:
+ case PLIST_REAL:
+ case PLIST_STRING:
+ case PLIST_DATE:
+ case PLIST_DATA:
+ default:
+ _array.push_back( new Node(subnode) );
+ break;
+ }
+ }
+}
+
+Array::~Array()
+{
+ plist_free(_node);
+ for (int it = 0; it < _array.size(); it++)
+ {
+ delete _array.at(it);
+ }
+ _array.clear();
+}
+
+Node* Array::operator[](unsigned int index)
+{
+ return _array.at(index);
+}
+
+void Array::Append(Node* node)
+{
+ if (node)
+ {
+ plist_array_append_item(_node, node->GetPlist());
+ _array.push_back(node);
+ }
+}
+
+void Array::Insert(Node* node, unsigned int pos)
+{
+ if (node)
+ {
+ plist_array_insert_item(_node, node->GetPlist(), pos);
+ std::vector<Node*>::iterator it = _array.begin();
+ it += pos;
+ _array.insert(it, node);
+ }
+}
+
+void Array::Remove(Node* node)
+{
+ if (node)
+ {
+ uint32_t pos = plist_array_get_item_index(node->GetPlist());
+ plist_array_remove_item(_node, pos);
+ std::vector<Node*>::iterator it = _array.begin();
+ it += pos;
+ _array.erase(it);
+ delete node;
+ }
+}
+
+void Array::Remove(unsigned int pos)
+{
+ plist_array_remove_item(_node, pos);
+ std::vector<Node*>::iterator it = _array.begin();
+ it += pos;
+ delete _array.at(pos);
+ _array.erase(it);
+}
+
+};
diff --git a/src/Boolean.cpp b/src/Boolean.cpp
new file mode 100644
index 0000000..5797d88
--- /dev/null
+++ b/src/Boolean.cpp
@@ -0,0 +1,52 @@
+/*
+ * Boolean.cpp
+ *
+ * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <plist/Boolean.h>
+
+namespace PList
+{
+
+Boolean::Boolean() : Node(PLIST_BOOLEAN)
+{
+}
+
+Boolean::Boolean(bool b) : Node(PLIST_BOOLEAN)
+{
+ plist_set_bool_val(_node, b);
+}
+
+Boolean::~Boolean()
+{
+}
+
+void Boolean::SetValue(bool b)
+{
+ plist_set_bool_val(_node, b);
+}
+
+bool Boolean::GetValue()
+{
+ uint8_t b = 0;
+ plist_get_bool_val(_node, &b);
+ return b;
+}
+
+};
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ab3f694..5e03748 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,11 +7,28 @@ SET(libplist_SRC
bplist.c
xplist.c )
+SET(libplist++_SRC
+ Node.cpp
+ Boolean.cpp
+ Integer.cpp
+ Real.cpp
+ String.cpp
+ Date.cpp
+ Data.cpp
+ Structure.cpp
+ Array.cpp
+ Dictionary.cpp
+ Utils.cpp
+ )
+
ADD_LIBRARY( plist SHARED ${libplist_SRC} )
TARGET_LINK_LIBRARIES( plist ${LIBXML2_LIBRARIES} ${GLIB2_LIBRARIES} )
SET_TARGET_PROPERTIES( plist PROPERTIES VERSION ${LIBPLIST_LIBVERSION} )
SET_TARGET_PROPERTIES( plist PROPERTIES SOVERSION ${LIBPLIST_SOVERSION} )
+ADD_LIBRARY( plist++ SHARED ${libplist++_SRC} )
+TARGET_LINK_LIBRARIES( plist++ plist )
+
INSTALL(TARGETS plist
RUNTIME DESTINATION bin COMPONENT lib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dev
diff --git a/src/Data.cpp b/src/Data.cpp
new file mode 100644
index 0000000..2ce610d
--- /dev/null
+++ b/src/Data.cpp
@@ -0,0 +1,57 @@
+/*
+ * Data.cpp
+ *
+ * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <plist/Data.h>
+
+namespace PList
+{
+
+Data::Data() : Node(PLIST_DATA)
+{
+}
+
+Data::Data(std::vector<char>& buff) : Node(PLIST_DATA)
+{
+ plist_set_data_val(_node, &buff[0], buff.size());
+}
+
+Data::~Data()
+{
+}
+
+void Data::SetValue(std::vector<char>& buff)
+{
+ plist_set_data_val(_node, &buff[0], buff.size());
+}
+
+std::vector<char> Data::GetValue()
+{
+ char* buff = NULL;
+ uint64_t length = 0;
+ plist_get_data_val(_node, &buff, &length);
+ std::vector<char> ret(buff, buff + length);
+ free(buff);
+ return ret;
+}
+
+
+
+};
diff --git a/src/Date.cpp b/src/Date.cpp
new file mode 100644
index 0000000..56e1e8e
--- /dev/null
+++ b/src/Date.cpp
@@ -0,0 +1,52 @@
+/*
+ * Date.cpp
+ *
+ * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <plist/Date.h>
+
+namespace PList
+{
+
+Date::Date() : Node(PLIST_DATE)
+{
+}
+
+Date::Date(uint64_t i) : Node(PLIST_DATE)
+{
+ plist_set_date_val(_node, i, 0);
+}
+
+Date::~Date()
+{
+}
+
+void Date::SetValue(uint64_t i)
+{
+ plist_set_date_val(_node, i, 0);
+}
+
+uint64_t Date::GetValue()
+{
+ int32_t i = 0;
+ plist_get_date_val(_node, &i, &i);
+ return i;
+}
+
+};
diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp
new file mode 100644
index 0000000..5bace76
--- /dev/null
+++ b/src/Dictionary.cpp
@@ -0,0 +1,217 @@
+/*
+ * Dictionary.cpp
+ *
+ * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <plist/Dictionary.h>
+#include <plist/Array.h>
+
+namespace PList
+{
+
+Dictionary::Dictionary() : Structure(PLIST_DICT)
+{
+}
+
+Dictionary::Dictionary(plist_t node) : Structure()
+{
+ _node = node;
+ plist_dict_iter it = NULL;
+
+ char* key = NULL;
+ plist_t subnode = NULL;
+ plist_dict_new_iter(_node, &it);
+ 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:
+ case PLIST_UINT:
+ case PLIST_REAL:
+ case PLIST_STRING:
+ case PLIST_DATE:
+ case PLIST_DATA:
+ default:
+ _map[std::string(key)] = new Node(subnode);
+ break;
+ }
+
+ subnode = NULL;
+ free(key);
+ key = NULL;
+ plist_dict_next_item(_node, it, NULL, &subnode);
+ }
+ free(it);
+}
+
+Dictionary::Dictionary(Dictionary& d)
+{
+ for (Dictionary::iterator it = _map.begin(); it != _map.end(); it++)
+ {
+ plist_free(it->second->GetPlist());
+ delete it->second;
+ }
+ _map.clear();
+
+ _node = plist_copy(d.GetPlist());
+ plist_dict_iter it = NULL;
+
+ char* key = NULL;
+ plist_t subnode = NULL;
+ plist_dict_new_iter(_node, &it);
+ 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:
+ case PLIST_UINT:
+ case PLIST_REAL:
+ case PLIST_STRING:
+ case PLIST_DATE:
+ case PLIST_DATA:
+ default:
+ _map[std::string(key)] = new Node(subnode);
+ break;
+ }
+
+ subnode = NULL;
+ free(key);
+ key = NULL;
+ plist_dict_next_item(_node, it, NULL, &subnode);
+ }
+ free(it);
+}
+
+Dictionary& Dictionary::operator=(const Dictionary& d)
+{
+ for (Dictionary::iterator it = _map.begin(); it != _map.end(); it++)
+ {
+ plist_free(it->second->GetPlist());
+ delete it->second;
+ }
+ _map.clear();
+
+ _node = plist_copy(d.GetPlist());
+ plist_dict_iter it = NULL;
+
+ char* key = NULL;
+ plist_t subnode = NULL;
+ plist_dict_new_iter(_node, &it);
+ 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:
+ case PLIST_UINT:
+ case PLIST_REAL:
+ case PLIST_STRING:
+ case PLIST_DATE:
+ case PLIST_DATA:
+ default:
+ _map[std::string(key)] = new Node(subnode);
+ break;
+ }
+
+ subnode = NULL;
+ free(key);
+ key = NULL;
+ plist_dict_next_item(_node, it, NULL, &subnode);
+ }
+ free(it);
+}
+
+Dictionary::~Dictionary()
+{
+ for (Dictionary::iterator it = _map.begin(); it != _map.end(); it++)
+ {
+ plist_free(it->second->GetPlist());
+ delete it->second;
+ }
+ _map.clear();
+}
+
+Node* Dictionary::operator[](std::string& key)
+{
+ return _map[key];
+}
+
+Dictionary::iterator Dictionary::Begin()
+{
+ return _map.begin();
+}
+
+Dictionary::iterator Dictionary::End()
+{
+ return _map.end();
+}
+
+void Dictionary::Insert(std::string& key, Node* node)
+{
+ if (node)
+ {
+ plist_dict_insert_item(_node, key.c_str(), node->GetPlist());
+ delete _map[key];
+ _map[key] = node;
+ }
+}
+
+void Dictionary::Remove(Node* node)
+{
+ if (node)
+ {
+ char* key = NULL;
+ plist_dict_get_item_key(node->GetPlist(), &key);
+ plist_dict_remove_item(_node, key);
+ std::string skey = key;
+ free(key);
+ delete node;
+ }
+}
+
+void Dictionary::Remove(std::string& key)
+{
+ plist_dict_remove_item(_node, key.c_str());
+ delete _map[key];
+}
+
+};
diff --git a/src/Integer.cpp b/src/Integer.cpp
new file mode 100644
index 0000000..d4a7645
--- /dev/null
+++ b/src/Integer.cpp
@@ -0,0 +1,52 @@
+/*
+ * Integer.cpp
+ *
+ * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <plist/Integer.h>
+
+namespace PList
+{
+
+Integer::Integer() : Node(PLIST_UINT)
+{
+}
+
+Integer::Integer(uint64_t i) : Node(PLIST_UINT)
+{
+ plist_set_uint_val(_node, i);
+}
+
+Integer::~Integer()
+{
+}
+
+void Integer::SetValue(uint64_t i)
+{
+ plist_set_uint_val(_node, i);
+}
+
+uint64_t Integer::GetValue()
+{
+ uint64_t i = 0;
+ plist_get_uint_val(_node, &i);
+ return i;
+}
+
+};
diff --git a/src/Node.cpp b/src/Node.cpp
new file mode 100644
index 0000000..dbcd6d6
--- /dev/null
+++ b/src/Node.cpp
@@ -0,0 +1,105 @@
+/*
+ * Node.cpp
+ *
+ * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <plist/Node.h>
+
+namespace PList
+{
+
+Node::Node()
+{
+}
+
+Node::Node(plist_t node) : _node(node)
+{
+}
+
+Node::Node(plist_type type)
+{
+ _node = NULL;
+
+ switch(type) {
+ case PLIST_BOOLEAN:
+ _node = plist_new_bool(0);
+ break;
+ case PLIST_UINT:
+ _node = plist_new_uint(0);
+ break;
+ case PLIST_REAL:
+ _node = plist_new_real(0.);
+ break;
+ case PLIST_STRING:
+ _node = plist_new_string("");
+ break;
+ case PLIST_DATA:
+ _node = plist_new_data(NULL,0);
+ break;
+ case PLIST_DATE:
+ _node = plist_new_date(0,0);
+ break;
+ case PLIST_ARRAY:
+ _node = plist_new_array();
+ break;
+ case PLIST_DICT:
+ _node = plist_new_dict();
+ break;
+ case PLIST_KEY:
+ case PLIST_NONE:
+ default:
+ break;
+ }
+}
+
+Node::~Node()
+{
+ plist_free(_node);
+ _node = NULL;
+}
+
+Node::Node(Node& node)
+{
+ plist_free(_node);
+ _node = NULL;
+
+ _node = plist_copy(_node);
+}
+
+Node& Node::operator=(const Node& node)
+{
+ plist_free(_node);
+ _node = NULL;
+
+ _node = plist_copy(_node);
+}
+
+plist_type Node::GetType()
+{
+ if (_node)
+ {
+ return plist_get_node_type(_node);
+ }
+}
+
+plist_t Node::GetPlist() const
+{
+ return _node;
+}
+};
diff --git a/src/Real.cpp b/src/Real.cpp
new file mode 100644
index 0000000..41c5d87
--- /dev/null
+++ b/src/Real.cpp
@@ -0,0 +1,52 @@
+/*
+ * Real.cpp
+ *
+ * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <plist/Real.h>
+
+namespace PList
+{
+
+Real::Real() : Node(PLIST_REAL)
+{
+}
+
+Real::Real(double d) : Node(PLIST_REAL)
+{
+ plist_set_real_val(_node, d);
+}
+
+Real::~Real()
+{
+}
+
+void Real::SetValue(double d)
+{
+ plist_set_real_val(_node, d);
+}
+
+double Real::GetValue()
+{
+ double d = 0.;
+ plist_get_real_val(_node, &d);
+ return d;
+}
+
+};
diff --git a/src/String.cpp b/src/String.cpp
new file mode 100644
index 0000000..24b4ce8
--- /dev/null
+++ b/src/String.cpp
@@ -0,0 +1,54 @@
+/*
+ * String.cpp
+ *
+ * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <plist/String.h>
+
+namespace PList
+{
+
+String::String() : Node(PLIST_STRING)
+{
+}
+
+String::String(std::string& s) : Node(PLIST_STRING)
+{
+ plist_set_string_val(_node, s.c_str());
+}
+
+String::~String()
+{
+}
+
+void String::SetValue(std::string& s)
+{
+ plist_set_string_val(_node, s.c_str());
+}
+
+std::string String::GetValue()
+{
+ char* s = NULL;
+ plist_get_string_val(_node, &s);
+ std::string ret = s;
+ free(s);
+ return ret;
+}
+
+};
diff --git a/src/Structure.cpp b/src/Structure.cpp
new file mode 100644
index 0000000..6fd9b3d
--- /dev/null
+++ b/src/Structure.cpp
@@ -0,0 +1,74 @@
+/*
+ * Structure.cpp
+ *
+ * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <plist/Structure.h>
+
+namespace PList
+{
+
+Structure::Structure() : Node()
+{
+}
+Structure::Structure(plist_type type) : Node(type)
+{
+}
+
+Structure::~Structure()
+{
+}
+
+uint32_t Structure::GetSize()
+{
+ uint32_t size = 0;
+ plist_type type = plist_get_node_type(_node);
+ if (type == PLIST_ARRAY)
+ {
+ size = plist_array_get_size(_node);
+ }
+ else if (type == PLIST_DICT)
+ {
+ size = plist_dict_get_size(_node);
+ }
+ return size;
+}
+
+std::string Structure::ToXml()
+{
+ char* xml = NULL;
+ uint32_t length = 0;
+ plist_to_xml(_node, &xml, &length);
+ std::string ret(xml, xml+length);
+ free(xml);
+ return ret;
+}
+
+std::vector<char> Structure::ToBin()
+{
+ char* bin = NULL;
+ uint32_t length = 0;
+ plist_to_bin(_node, &bin, &length);
+ std::vector<char> ret(bin, bin+length);
+ free(bin);
+ return ret;
+}
+
+};
+
diff --git a/src/Utils.cpp b/src/Utils.cpp
new file mode 100644
index 0000000..a9d2459
--- /dev/null
+++ b/src/Utils.cpp
@@ -0,0 +1,74 @@
+/*
+ * Utils.cpp
+ *
+ * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <plist/Utils.h>
+#include <plist/Dictionary.h>
+#include <plist/Array.h>
+
+namespace PList
+{
+
+static Structure* FromPlist(plist_t root)
+{
+ Structure* ret = NULL;
+ if (root)
+ {
+ plist_type type = plist_get_node_type(root);
+ switch(type)
+ {
+ case PLIST_DICT:
+ ret = new Dictionary(root);
+ break;
+ case PLIST_ARRAY:
+ ret = new Array(root);
+ break;
+ case PLIST_BOOLEAN:
+ case PLIST_UINT:
+ case PLIST_REAL:
+ case PLIST_STRING:
+ case PLIST_DATE:
+ case PLIST_DATA:
+ default:
+ plist_free(root);
+ break;
+ }
+ }
+ return ret;
+}
+
+Structure* Utils::FromXml(std::string& in)
+{
+ plist_t root = NULL;
+ plist_from_xml(in.c_str(), in.size(), &root);
+
+ return FromPlist(root);
+}
+
+Structure* Utils::FromBin(std::vector<char>& in)
+{
+ plist_t root = NULL;
+ plist_from_bin(&in[0], in.size(), &root);
+
+ return FromPlist(root);
+
+}
+
+};