diff options
Diffstat (limited to 'src/Dictionary.cpp')
| -rw-r--r-- | src/Dictionary.cpp | 106 |
1 files changed, 7 insertions, 99 deletions
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 @@ | |||
| 20 | 20 | ||
| 21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
| 22 | #include <plist/Dictionary.h> | 22 | #include <plist/Dictionary.h> |
| 23 | #include <plist/Array.h> | 23 | #include <plist/Utils.h> |
| 24 | #include <plist/Boolean.h> | ||
| 25 | #include <plist/Integer.h> | ||
| 26 | #include <plist/Real.h> | ||
| 27 | #include <plist/String.h> | ||
| 28 | #include <plist/Date.h> | ||
| 29 | #include <plist/Data.h> | ||
| 30 | 24 | ||
| 31 | namespace PList | 25 | namespace PList |
| 32 | { | 26 | { |
| 33 | 27 | ||
| 34 | Dictionary::Dictionary() : Structure(PLIST_DICT) | 28 | Dictionary::Dictionary(Node* parent) : Structure(PLIST_DICT, parent) |
| 35 | { | 29 | { |
| 36 | } | 30 | } |
| 37 | 31 | ||
| 38 | Dictionary::Dictionary(plist_t node) : Structure() | 32 | Dictionary::Dictionary(plist_t node, Node* parent) : Structure(parent) |
| 39 | { | 33 | { |
| 40 | _node = node; | 34 | _node = node; |
| 41 | plist_dict_iter it = NULL; | 35 | plist_dict_iter it = NULL; |
| @@ -46,36 +40,7 @@ Dictionary::Dictionary(plist_t node) : Structure() | |||
| 46 | plist_dict_next_item(_node, it, &key, &subnode); | 40 | plist_dict_next_item(_node, it, &key, &subnode); |
| 47 | while (subnode) | 41 | while (subnode) |
| 48 | { | 42 | { |
| 49 | plist_type subtype = plist_get_node_type(subnode); | 43 | _map[std::string(key)] = Utils::FromPlist(subnode, this); |
| 50 | switch(subtype) | ||
| 51 | { | ||
| 52 | case PLIST_DICT: | ||
| 53 | _map[std::string(key)] = new Dictionary(subnode); | ||
| 54 | break; | ||
| 55 | case PLIST_ARRAY: | ||
| 56 | _map[std::string(key)] = new Array(subnode); | ||
| 57 | break; | ||
| 58 | case PLIST_BOOLEAN: | ||
| 59 | _map[std::string(key)] = new Boolean(subnode); | ||
| 60 | break; | ||
| 61 | case PLIST_UINT: | ||
| 62 | _map[std::string(key)] = new Integer(subnode); | ||
| 63 | break; | ||
| 64 | case PLIST_REAL: | ||
| 65 | _map[std::string(key)] = new Real(subnode); | ||
| 66 | break; | ||
| 67 | case PLIST_STRING: | ||
| 68 | _map[std::string(key)] = new String(subnode); | ||
| 69 | break; | ||
| 70 | case PLIST_DATE: | ||
| 71 | _map[std::string(key)] = new Date(subnode); | ||
| 72 | break; | ||
| 73 | case PLIST_DATA: | ||
| 74 | _map[std::string(key)] = new Data(subnode); | ||
| 75 | break; | ||
| 76 | default: | ||
| 77 | break; | ||
| 78 | } | ||
| 79 | 44 | ||
| 80 | subnode = NULL; | 45 | subnode = NULL; |
| 81 | free(key); | 46 | free(key); |
| @@ -103,36 +68,7 @@ Dictionary::Dictionary(PList::Dictionary& d) : Structure() | |||
| 103 | plist_dict_next_item(_node, it, &key, &subnode); | 68 | plist_dict_next_item(_node, it, &key, &subnode); |
| 104 | while (subnode) | 69 | while (subnode) |
| 105 | { | 70 | { |
| 106 | plist_type subtype = plist_get_node_type(subnode); | 71 | _map[std::string(key)] = Utils::FromPlist(subnode, this); |
| 107 | switch(subtype) | ||
| 108 | { | ||
| 109 | case PLIST_DICT: | ||
| 110 | _map[std::string(key)] = new Dictionary(subnode); | ||
| 111 | break; | ||
| 112 | case PLIST_ARRAY: | ||
| 113 | _map[std::string(key)] = new Array(subnode); | ||
| 114 | break; | ||
| 115 | case PLIST_BOOLEAN: | ||
| 116 | _map[std::string(key)] = new Boolean(subnode); | ||
| 117 | break; | ||
| 118 | case PLIST_UINT: | ||
| 119 | _map[std::string(key)] = new Integer(subnode); | ||
| 120 | break; | ||
| 121 | case PLIST_REAL: | ||
| 122 | _map[std::string(key)] = new Real(subnode); | ||
| 123 | break; | ||
| 124 | case PLIST_STRING: | ||
| 125 | _map[std::string(key)] = new String(subnode); | ||
| 126 | break; | ||
| 127 | case PLIST_DATE: | ||
| 128 | _map[std::string(key)] = new Date(subnode); | ||
| 129 | break; | ||
| 130 | case PLIST_DATA: | ||
| 131 | _map[std::string(key)] = new Data(subnode); | ||
| 132 | break; | ||
| 133 | default: | ||
| 134 | break; | ||
| 135 | } | ||
| 136 | 72 | ||
| 137 | subnode = NULL; | 73 | subnode = NULL; |
| 138 | free(key); | 74 | free(key); |
| @@ -160,36 +96,7 @@ Dictionary& Dictionary::operator=(PList::Dictionary& d) | |||
| 160 | plist_dict_next_item(_node, it, &key, &subnode); | 96 | plist_dict_next_item(_node, it, &key, &subnode); |
| 161 | while (subnode) | 97 | while (subnode) |
| 162 | { | 98 | { |
| 163 | plist_type subtype = plist_get_node_type(subnode); | 99 | _map[std::string(key)] = Utils::FromPlist(subnode, this); |
| 164 | switch(subtype) | ||
| 165 | { | ||
| 166 | case PLIST_DICT: | ||
| 167 | _map[std::string(key)] = new Dictionary(subnode); | ||
| 168 | break; | ||
| 169 | case PLIST_ARRAY: | ||
| 170 | _map[std::string(key)] = new Array(subnode); | ||
| 171 | break; | ||
| 172 | case PLIST_BOOLEAN: | ||
| 173 | _map[std::string(key)] = new Boolean(subnode); | ||
| 174 | break; | ||
| 175 | case PLIST_UINT: | ||
| 176 | _map[std::string(key)] = new Integer(subnode); | ||
| 177 | break; | ||
| 178 | case PLIST_REAL: | ||
| 179 | _map[std::string(key)] = new Real(subnode); | ||
| 180 | break; | ||
| 181 | case PLIST_STRING: | ||
| 182 | _map[std::string(key)] = new String(subnode); | ||
| 183 | break; | ||
| 184 | case PLIST_DATE: | ||
| 185 | _map[std::string(key)] = new Date(subnode); | ||
| 186 | break; | ||
| 187 | case PLIST_DATA: | ||
| 188 | _map[std::string(key)] = new Data(subnode); | ||
| 189 | break; | ||
| 190 | default: | ||
| 191 | break; | ||
| 192 | } | ||
| 193 | 100 | ||
| 194 | subnode = NULL; | 101 | subnode = NULL; |
| 195 | free(key); | 102 | free(key); |
| @@ -239,6 +146,7 @@ Dictionary::iterator Dictionary::Insert(const std::string& key, Node* node) | |||
| 239 | if (node) | 146 | if (node) |
| 240 | { | 147 | { |
| 241 | Node* clone = node->Clone(); | 148 | Node* clone = node->Clone(); |
| 149 | clone->SetParent(this); | ||
| 242 | plist_dict_insert_item(_node, key.c_str(), clone->GetPlist()); | 150 | plist_dict_insert_item(_node, key.c_str(), clone->GetPlist()); |
| 243 | delete _map[key]; | 151 | delete _map[key]; |
| 244 | _map[key] = clone; | 152 | _map[key] = clone; |
