From c1363bea107b15bdc10ce80671747be891661889 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Mon, 26 Oct 2009 18:41:15 +0100 Subject: Add Set/Get Parent and a helper to create a Node from a plist_t. --- src/Dictionary.cpp | 106 ++++------------------------------------------------- 1 file changed, 7 insertions(+), 99 deletions(-) (limited to 'src/Dictionary.cpp') 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 #include -#include -#include -#include -#include -#include -#include -#include +#include 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; -- cgit v1.1-32-gdbae