summaryrefslogtreecommitdiffstats
path: root/src/Node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Node.cpp')
-rw-r--r--src/Node.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/Node.cpp b/src/Node.cpp
index 9bf50ee..1043b31 100644
--- a/src/Node.cpp
+++ b/src/Node.cpp
@@ -18,7 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <stdlib.h>
+#include <cstdlib>
+#include "plist.h"
#include <plist/Node.h>
#include <plist/Structure.h>
#include <plist/Dictionary.h>
@@ -27,6 +28,8 @@
#include <plist/Integer.h>
#include <plist/Real.h>
#include <plist/String.h>
+#include <plist/Key.h>
+#include <plist/Uid.h>
#include <plist/Data.h>
#include <plist/Date.h>
@@ -50,7 +53,7 @@ Node::Node(plist_type type, Node* parent) : _parent(parent)
case PLIST_BOOLEAN:
_node = plist_new_bool(0);
break;
- case PLIST_UINT:
+ case PLIST_INT:
_node = plist_new_uint(0);
break;
case PLIST_REAL:
@@ -59,11 +62,18 @@ Node::Node(plist_type type, Node* parent) : _parent(parent)
case PLIST_STRING:
_node = plist_new_string("");
break;
+ case PLIST_KEY:
+ _node = plist_new_string("");
+ plist_set_key_val(_node, "");
+ break;
+ case PLIST_UID:
+ _node = plist_new_uid(0);
+ break;
case PLIST_DATA:
_node = plist_new_data(NULL,0);
break;
case PLIST_DATE:
- _node = plist_new_date(0,0);
+ _node = plist_new_unix_date(0);
break;
case PLIST_ARRAY:
_node = plist_new_array();
@@ -71,7 +81,6 @@ Node::Node(plist_type type, Node* parent) : _parent(parent)
case PLIST_DICT:
_node = plist_new_dict();
break;
- case PLIST_KEY:
case PLIST_NONE:
default:
break;
@@ -80,12 +89,17 @@ Node::Node(plist_type type, Node* parent) : _parent(parent)
Node::~Node()
{
- plist_free(_node);
+ /* If the Node is in a container, let _node be cleaned up by
+ * operations on the parent plist_t. Otherwise, duplicate frees
+ * occur when a Node is removed from or replaced in a Dictionary.
+ */
+ if (_parent == NULL)
+ plist_free(_node);
_node = NULL;
_parent = NULL;
}
-plist_type Node::GetType()
+plist_type Node::GetType() const
{
if (_node)
{
@@ -94,12 +108,12 @@ plist_type Node::GetType()
return PLIST_NONE;
}
-plist_t Node::GetPlist()
+plist_t Node::GetPlist() const
{
return _node;
}
-Node* Node::GetParent()
+Node* Node::GetParent() const
{
return _parent;
}
@@ -121,7 +135,7 @@ Node* Node::FromPlist(plist_t node, Node* parent)
case PLIST_BOOLEAN:
ret = new Boolean(node, parent);
break;
- case PLIST_UINT:
+ case PLIST_INT:
ret = new Integer(node, parent);
break;
case PLIST_REAL:
@@ -130,6 +144,12 @@ Node* Node::FromPlist(plist_t node, Node* parent)
case PLIST_STRING:
ret = new String(node, parent);
break;
+ case PLIST_KEY:
+ ret = new Key(node, parent);
+ break;
+ case PLIST_UID:
+ ret = new Uid(node, parent);
+ break;
case PLIST_DATE:
ret = new Date(node, parent);
break;
@@ -144,4 +164,4 @@ Node* Node::FromPlist(plist_t node, Node* parent)
return ret;
}
-};
+} // namespace PList