diff options
| author | 2009-11-11 00:18:14 +0100 | |
|---|---|---|
| committer | 2009-11-11 00:18:14 +0100 | |
| commit | 8c6a809fafa6befff7e2b1adc3df2bdb47042dd1 (patch) | |
| tree | 2336ae7ee66dbb639c8b8bd8c06171c1f6f6e334 | |
| parent | 53a9f891f82e973440709593d259bd7c1f22dd1a (diff) | |
| download | libplist-8c6a809fafa6befff7e2b1adc3df2bdb47042dd1.tar.gz libplist-8c6a809fafa6befff7e2b1adc3df2bdb47042dd1.tar.bz2 | |
Move some methods and drop Utils class in C++ binding.
| -rw-r--r-- | include/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | include/plist/Node.h | 2 | ||||
| -rw-r--r-- | include/plist/Structure.h | 3 | ||||
| -rw-r--r-- | include/plist/Utils.h | 43 | ||||
| -rw-r--r-- | include/plist/plist++.h | 1 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/Node.cpp | 49 | ||||
| -rw-r--r-- | src/Structure.cpp | 34 | ||||
| -rw-r--r-- | src/Utils.cpp | 109 | ||||
| -rw-r--r-- | swig/plist.i | 1 |
10 files changed, 88 insertions, 156 deletions
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 00dbbda..ea77d45 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt | |||
| @@ -11,7 +11,6 @@ SET( libplist_HDR | |||
| 11 | ${CMAKE_CURRENT_SOURCE_DIR}/plist/Real.h | 11 | ${CMAKE_CURRENT_SOURCE_DIR}/plist/Real.h |
| 12 | ${CMAKE_CURRENT_SOURCE_DIR}/plist/String.h | 12 | ${CMAKE_CURRENT_SOURCE_DIR}/plist/String.h |
| 13 | ${CMAKE_CURRENT_SOURCE_DIR}/plist/Structure.h | 13 | ${CMAKE_CURRENT_SOURCE_DIR}/plist/Structure.h |
| 14 | ${CMAKE_CURRENT_SOURCE_DIR}/plist/Utils.h | ||
| 15 | ) | 14 | ) |
| 16 | 15 | ||
| 17 | INSTALL( FILES ${libplist_HDR} | 16 | INSTALL( FILES ${libplist_HDR} |
diff --git a/include/plist/Node.h b/include/plist/Node.h index 2f9f5b6..1da9ee1 100644 --- a/include/plist/Node.h +++ b/include/plist/Node.h | |||
| @@ -38,6 +38,8 @@ public : | |||
| 38 | plist_type GetType(); | 38 | plist_type GetType(); |
| 39 | plist_t GetPlist(); | 39 | plist_t GetPlist(); |
| 40 | 40 | ||
| 41 | static Node* FromPlist(plist_t node, Node* parent = NULL); | ||
| 42 | |||
| 41 | protected: | 43 | protected: |
| 42 | Node(Node* parent = NULL); | 44 | Node(Node* parent = NULL); |
| 43 | Node(plist_t node, Node* parent = NULL); | 45 | Node(plist_t node, Node* parent = NULL); |
diff --git a/include/plist/Structure.h b/include/plist/Structure.h index f6e4495..ace8b5c 100644 --- a/include/plist/Structure.h +++ b/include/plist/Structure.h | |||
| @@ -41,6 +41,9 @@ public : | |||
| 41 | 41 | ||
| 42 | virtual void Remove(Node* node) = 0; | 42 | virtual void Remove(Node* node) = 0; |
| 43 | 43 | ||
| 44 | static Structure* FromXml(const std::string& xml); | ||
| 45 | static Structure* FromBin(const std::vector<char>& bin); | ||
| 46 | |||
| 44 | protected: | 47 | protected: |
| 45 | Structure(Node* parent = NULL); | 48 | Structure(Node* parent = NULL); |
| 46 | Structure(plist_type type, Node* parent = NULL); | 49 | Structure(plist_type type, Node* parent = NULL); |
diff --git a/include/plist/Utils.h b/include/plist/Utils.h deleted file mode 100644 index 52503a0..0000000 --- a/include/plist/Utils.h +++ /dev/null | |||
| @@ -1,43 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Utils.h | ||
| 3 | * Import functions for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef PLIST__UTILS_H | ||
| 23 | #define PLIST__UTILS_H | ||
| 24 | |||
| 25 | #include <plist/Structure.h> | ||
| 26 | #include <string> | ||
| 27 | |||
| 28 | namespace PList | ||
| 29 | { | ||
| 30 | class Utils | ||
| 31 | { | ||
| 32 | public: | ||
| 33 | static Node* FromPlist(plist_t node, Node* parent = NULL); | ||
| 34 | static Structure* FromXml(const std::string& xml); | ||
| 35 | static Structure* FromBin(const std::vector<char>& bin); | ||
| 36 | |||
| 37 | private: | ||
| 38 | Utils(); | ||
| 39 | ~Utils(); | ||
| 40 | }; | ||
| 41 | }; | ||
| 42 | |||
| 43 | #endif // PLIST__UTILS_H | ||
diff --git a/include/plist/plist++.h b/include/plist/plist++.h index 79181c5..d5eb691 100644 --- a/include/plist/plist++.h +++ b/include/plist/plist++.h | |||
| @@ -33,6 +33,5 @@ | |||
| 33 | #include "Real.h" | 33 | #include "Real.h" |
| 34 | #include "String.h" | 34 | #include "String.h" |
| 35 | #include "Structure.h" | 35 | #include "Structure.h" |
| 36 | #include "Utils.h" | ||
| 37 | 36 | ||
| 38 | #endif | 37 | #endif |
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3c6ac09..afeb33b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt | |||
| @@ -18,7 +18,6 @@ SET(libplist++_SRC | |||
| 18 | Structure.cpp | 18 | Structure.cpp |
| 19 | Array.cpp | 19 | Array.cpp |
| 20 | Dictionary.cpp | 20 | Dictionary.cpp |
| 21 | Utils.cpp | ||
| 22 | ) | 21 | ) |
| 23 | 22 | ||
| 24 | ADD_LIBRARY( plist SHARED ${libplist_SRC} ) | 23 | ADD_LIBRARY( plist SHARED ${libplist_SRC} ) |
diff --git a/src/Node.cpp b/src/Node.cpp index b0cc96a..3122322 100644 --- a/src/Node.cpp +++ b/src/Node.cpp | |||
| @@ -21,6 +21,15 @@ | |||
| 21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
| 22 | #include <plist/Node.h> | 22 | #include <plist/Node.h> |
| 23 | #include <plist/Structure.h> | 23 | #include <plist/Structure.h> |
| 24 | #include <plist/Utils.h> | ||
| 25 | #include <plist/Dictionary.h> | ||
| 26 | #include <plist/Array.h> | ||
| 27 | #include <plist/Boolean.h> | ||
| 28 | #include <plist/Integer.h> | ||
| 29 | #include <plist/Real.h> | ||
| 30 | #include <plist/String.h> | ||
| 31 | #include <plist/Data.h> | ||
| 32 | #include <plist/Date.h> | ||
| 24 | 33 | ||
| 25 | namespace PList | 34 | namespace PList |
| 26 | { | 35 | { |
| @@ -96,4 +105,44 @@ Node* Node::GetParent() | |||
| 96 | return _parent; | 105 | return _parent; |
| 97 | } | 106 | } |
| 98 | 107 | ||
| 108 | Node* Node::FromPlist(plist_t node, Node* parent) | ||
| 109 | { | ||
| 110 | Node* ret = NULL; | ||
| 111 | if (node) | ||
| 112 | { | ||
| 113 | plist_type type = plist_get_node_type(node); | ||
| 114 | switch (type) | ||
| 115 | { | ||
| 116 | case PLIST_DICT: | ||
| 117 | ret = new Dictionary(node, parent); | ||
| 118 | break; | ||
| 119 | case PLIST_ARRAY: | ||
| 120 | ret = new Array(node, parent); | ||
| 121 | break; | ||
| 122 | case PLIST_BOOLEAN: | ||
| 123 | ret = new Boolean(node, parent); | ||
| 124 | break; | ||
| 125 | case PLIST_UINT: | ||
| 126 | ret = new Integer(node, parent); | ||
| 127 | break; | ||
| 128 | case PLIST_REAL: | ||
| 129 | ret = new Real(node, parent); | ||
| 130 | break; | ||
| 131 | case PLIST_STRING: | ||
| 132 | ret = new String(node, parent); | ||
| 133 | break; | ||
| 134 | case PLIST_DATE: | ||
| 135 | ret = new Date(node, parent); | ||
| 136 | break; | ||
| 137 | case PLIST_DATA: | ||
| 138 | ret = new Data(node, parent); | ||
| 139 | break; | ||
| 140 | default: | ||
| 141 | plist_free(node); | ||
| 142 | break; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | return ret; | ||
| 146 | } | ||
| 147 | |||
| 99 | }; | 148 | }; |
diff --git a/src/Structure.cpp b/src/Structure.cpp index cf7c611..18b19ef 100644 --- a/src/Structure.cpp +++ b/src/Structure.cpp | |||
| @@ -85,5 +85,39 @@ void Structure::UpdateNodeParent(Node* node) | |||
| 85 | node->_parent = this; | 85 | node->_parent = this; |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | static Structure* ImportStruct(plist_t root) | ||
| 89 | { | ||
| 90 | Structure* ret = NULL; | ||
| 91 | plist_type type = plist_get_node_type(root); | ||
| 92 | |||
| 93 | if (PLIST_ARRAY == type || PLIST_DICT == type) | ||
| 94 | { | ||
| 95 | ret = static_cast<Structure*>(Node::FromPlist(root)); | ||
| 96 | } | ||
| 97 | else | ||
| 98 | { | ||
| 99 | plist_free(root); | ||
| 100 | } | ||
| 101 | |||
| 102 | return ret; | ||
| 103 | } | ||
| 104 | |||
| 105 | Structure* Structure::FromXml(const std::string& xml) | ||
| 106 | { | ||
| 107 | plist_t root = NULL; | ||
| 108 | plist_from_xml(xml.c_str(), xml.size(), &root); | ||
| 109 | |||
| 110 | return ImportStruct(root); | ||
| 111 | } | ||
| 112 | |||
| 113 | Structure* Structure::FromBin(const std::vector<char>& bin) | ||
| 114 | { | ||
| 115 | plist_t root = NULL; | ||
| 116 | plist_from_bin(&bin[0], bin.size(), &root); | ||
| 117 | |||
| 118 | return ImportStruct(root); | ||
| 119 | |||
| 120 | } | ||
| 121 | |||
| 88 | }; | 122 | }; |
| 89 | 123 | ||
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 | }; | ||
diff --git a/swig/plist.i b/swig/plist.i index 5e3f75a..925752e 100644 --- a/swig/plist.i +++ b/swig/plist.i | |||
| @@ -159,7 +159,6 @@ namespace std { | |||
| 159 | %include <plist/Structure.h> | 159 | %include <plist/Structure.h> |
| 160 | %include <plist/Array.h> | 160 | %include <plist/Array.h> |
| 161 | %include <plist/Dictionary.h> | 161 | %include <plist/Dictionary.h> |
| 162 | %include <plist/Utils.h> | ||
| 163 | 162 | ||
| 164 | typedef enum { | 163 | typedef enum { |
| 165 | PLIST_BOOLEAN, | 164 | PLIST_BOOLEAN, |
