diff options
| author | 2009-10-13 20:04:06 +0200 | |
|---|---|---|
| committer | 2009-10-13 20:04:06 +0200 | |
| commit | a922b714c9b75fdc67735d674758d4eaedfd32f9 (patch) | |
| tree | 509ec53c18c0be36a9e650eb0f760854cd8d4957 /src/Utils.cpp | |
| parent | e492ef675c404cc6c0d1cfa26e47a1c16c850d5f (diff) | |
| download | libplist-a922b714c9b75fdc67735d674758d4eaedfd32f9.tar.gz libplist-a922b714c9b75fdc67735d674758d4eaedfd32f9.tar.bz2 | |
Add C++ binding.
Diffstat (limited to 'src/Utils.cpp')
| -rw-r--r-- | src/Utils.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp new file mode 100644 index 0000000..a9d2459 --- /dev/null +++ b/src/Utils.cpp | |||
| @@ -0,0 +1,74 @@ | |||
| 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 | |||
| 26 | namespace PList | ||
| 27 | { | ||
| 28 | |||
| 29 | static Structure* FromPlist(plist_t root) | ||
| 30 | { | ||
| 31 | Structure* ret = NULL; | ||
| 32 | if (root) | ||
| 33 | { | ||
| 34 | plist_type type = plist_get_node_type(root); | ||
| 35 | switch(type) | ||
| 36 | { | ||
| 37 | case PLIST_DICT: | ||
| 38 | ret = new Dictionary(root); | ||
| 39 | break; | ||
| 40 | case PLIST_ARRAY: | ||
| 41 | ret = new Array(root); | ||
| 42 | break; | ||
| 43 | case PLIST_BOOLEAN: | ||
| 44 | case PLIST_UINT: | ||
| 45 | case PLIST_REAL: | ||
| 46 | case PLIST_STRING: | ||
| 47 | case PLIST_DATE: | ||
| 48 | case PLIST_DATA: | ||
| 49 | default: | ||
| 50 | plist_free(root); | ||
| 51 | break; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | return ret; | ||
| 55 | } | ||
| 56 | |||
| 57 | Structure* Utils::FromXml(std::string& in) | ||
| 58 | { | ||
| 59 | plist_t root = NULL; | ||
| 60 | plist_from_xml(in.c_str(), in.size(), &root); | ||
| 61 | |||
| 62 | return FromPlist(root); | ||
| 63 | } | ||
| 64 | |||
| 65 | Structure* Utils::FromBin(std::vector<char>& in) | ||
| 66 | { | ||
| 67 | plist_t root = NULL; | ||
| 68 | plist_from_bin(&in[0], in.size(), &root); | ||
| 69 | |||
| 70 | return FromPlist(root); | ||
| 71 | |||
| 72 | } | ||
| 73 | |||
| 74 | }; | ||
