diff options
Diffstat (limited to 'src/Utils.cpp')
| -rw-r--r-- | src/Utils.cpp | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp deleted file mode 100644 index cb6da5e..0000000 --- a/src/Utils.cpp +++ /dev/null | |||
| @@ -1,109 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Utils.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/Utils.h> | ||
| 23 | #include <plist/Dictionary.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> | ||
| 31 | |||
| 32 | namespace PList | ||
| 33 | { | ||
| 34 | |||
| 35 | Node* Utils::FromPlist(plist_t node, Node* parent) | ||
| 36 | { | ||
| 37 | Node* ret = NULL; | ||
| 38 | if (node) | ||
| 39 | { | ||
| 40 | plist_type type = plist_get_node_type(node); | ||
| 41 | switch (type) | ||
| 42 | { | ||
| 43 | case PLIST_DICT: | ||
| 44 | ret = new Dictionary(node, parent); | ||
| 45 | break; | ||
| 46 | case PLIST_ARRAY: | ||
| 47 | ret = new Array(node, parent); | ||
| 48 | break; | ||
| 49 | case PLIST_BOOLEAN: | ||
| 50 | ret = new Boolean(node, parent); | ||
| 51 | break; | ||
| 52 | case PLIST_UINT: | ||
| 53 | ret = new Integer(node, parent); | ||
| 54 | break; | ||
| 55 | case PLIST_REAL: | ||
| 56 | ret = new Real(node, parent); | ||
| 57 | break; | ||
| 58 | case PLIST_STRING: | ||
| 59 | ret = new String(node, parent); | ||
| 60 | break; | ||
| 61 | case PLIST_DATE: | ||
| 62 | ret = new Date(node, parent); | ||
| 63 | break; | ||
| 64 | case PLIST_DATA: | ||
| 65 | ret = new Data(node, parent); | ||
| 66 | break; | ||
| 67 | default: | ||
| 68 | plist_free(node); | ||
| 69 | break; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | return ret; | ||
| 73 | } | ||
| 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 | |||
| 92 | Structure* Utils::FromXml(const std::string& xml) | ||
| 93 | { | ||
| 94 | plist_t root = NULL; | ||
| 95 | plist_from_xml(xml.c_str(), xml.size(), &root); | ||
| 96 | |||
| 97 | return ImportStruct(root); | ||
| 98 | } | ||
| 99 | |||
| 100 | Structure* Utils::FromBin(const std::vector<char>& bin) | ||
| 101 | { | ||
| 102 | plist_t root = NULL; | ||
| 103 | plist_from_bin(&bin[0], bin.size(), &root); | ||
| 104 | |||
| 105 | return ImportStruct(root); | ||
| 106 | |||
| 107 | } | ||
| 108 | |||
| 109 | }; | ||
