diff options
| author | 2009-10-26 18:41:15 +0100 | |
|---|---|---|
| committer | 2009-10-26 18:41:15 +0100 | |
| commit | c1363bea107b15bdc10ce80671747be891661889 (patch) | |
| tree | 1a8ce452eb6c1110ea0cd88dec155e99bfe7b69b /src/Utils.cpp | |
| parent | bef50c0873aad5d8cd516428828e79fc05a43913 (diff) | |
| download | libplist-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.cpp | 53 |
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 @@ | |||
| 22 | #include <plist/Utils.h> | 22 | #include <plist/Utils.h> |
| 23 | #include <plist/Dictionary.h> | 23 | #include <plist/Dictionary.h> |
| 24 | #include <plist/Array.h> | 24 | #include <plist/Array.h> |
| 25 | #include <plist/Boolean.h> | ||
| 26 | #include <plist/Integer.h> | ||
| 27 | #include <plist/Real.h> | ||
| 28 | #include <plist/String.h> | ||
| 29 | #include <plist/Data.h> | ||
| 30 | #include <plist/Date.h> | ||
| 25 | 31 | ||
| 26 | namespace PList | 32 | namespace PList |
| 27 | { | 33 | { |
| 28 | 34 | ||
| 29 | static Structure* FromPlist(plist_t root) | 35 | Node* Utils::FromPlist(plist_t node, Node* parent) |
| 30 | { | 36 | { |
| 31 | Structure* ret = NULL; | 37 | Node* ret = NULL; |
| 32 | if (root) | 38 | if (node) |
| 33 | { | 39 | { |
| 34 | plist_type type = plist_get_node_type(root); | 40 | plist_type type = plist_get_node_type(node); |
| 35 | switch(type) | 41 | switch(type) |
| 36 | { | 42 | { |
| 37 | case PLIST_DICT: | 43 | case PLIST_DICT: |
| 38 | ret = new Dictionary(root); | 44 | ret = new Dictionary(node, parent); |
| 39 | break; | 45 | break; |
| 40 | case PLIST_ARRAY: | 46 | case PLIST_ARRAY: |
| 41 | ret = new Array(root); | 47 | ret = new Array(node, parent); |
| 42 | break; | 48 | break; |
| 43 | case PLIST_BOOLEAN: | 49 | case PLIST_BOOLEAN: |
| 50 | ret = new Boolean(node, parent); | ||
| 51 | break; | ||
| 44 | case PLIST_UINT: | 52 | case PLIST_UINT: |
| 53 | ret = new Integer(node, parent); | ||
| 54 | break; | ||
| 45 | case PLIST_REAL: | 55 | case PLIST_REAL: |
| 56 | ret = new Real(node, parent); | ||
| 57 | break; | ||
| 46 | case PLIST_STRING: | 58 | case PLIST_STRING: |
| 59 | ret = new String(node, parent); | ||
| 60 | break; | ||
| 47 | case PLIST_DATE: | 61 | case PLIST_DATE: |
| 62 | ret = new Date(node, parent); | ||
| 63 | break; | ||
| 48 | case PLIST_DATA: | 64 | case PLIST_DATA: |
| 65 | ret = new Data(node, parent); | ||
| 66 | break; | ||
| 49 | default: | 67 | default: |
| 50 | plist_free(root); | 68 | plist_free(node); |
| 51 | break; | 69 | break; |
| 52 | } | 70 | } |
| 53 | } | 71 | } |
| 54 | return ret; | 72 | return ret; |
| 55 | } | 73 | } |
| 56 | 74 | ||
| 75 | static Structure* ImportStruct(plist_t root) | ||
| 76 | { | ||
| 77 | Structure* ret = NULL; | ||
| 78 | plist_type type = plist_get_node_type(root); | ||
| 79 | |||
| 80 | if (PLIST_ARRAY == type || PLIST_DICT == type) | ||
| 81 | { | ||
| 82 | ret = static_cast<Structure*>(Utils::FromPlist(root)); | ||
| 83 | } | ||
| 84 | else | ||
| 85 | { | ||
| 86 | plist_free(root); | ||
| 87 | } | ||
| 88 | |||
| 89 | return ret; | ||
| 90 | } | ||
| 91 | |||
| 57 | Structure* Utils::FromXml(const std::string& in) | 92 | Structure* Utils::FromXml(const std::string& in) |
| 58 | { | 93 | { |
| 59 | plist_t root = NULL; | 94 | plist_t root = NULL; |
| 60 | plist_from_xml(in.c_str(), in.size(), &root); | 95 | plist_from_xml(in.c_str(), in.size(), &root); |
| 61 | 96 | ||
| 62 | return FromPlist(root); | 97 | return ImportStruct(root); |
| 63 | } | 98 | } |
| 64 | 99 | ||
| 65 | Structure* Utils::FromBin(const std::vector<char>& in) | 100 | Structure* Utils::FromBin(const std::vector<char>& in) |
| @@ -67,7 +102,7 @@ Structure* Utils::FromBin(const std::vector<char>& in) | |||
| 67 | plist_t root = NULL; | 102 | plist_t root = NULL; |
| 68 | plist_from_bin(&in[0], in.size(), &root); | 103 | plist_from_bin(&in[0], in.size(), &root); |
| 69 | 104 | ||
| 70 | return FromPlist(root); | 105 | return ImportStruct(root); |
| 71 | 106 | ||
| 72 | } | 107 | } |
| 73 | 108 | ||
