summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-11-11 00:18:14 +0100
committerGravatar Jonathan Beck2009-11-11 00:18:14 +0100
commit8c6a809fafa6befff7e2b1adc3df2bdb47042dd1 (patch)
tree2336ae7ee66dbb639c8b8bd8c06171c1f6f6e334 /src
parent53a9f891f82e973440709593d259bd7c1f22dd1a (diff)
downloadlibplist-8c6a809fafa6befff7e2b1adc3df2bdb47042dd1.tar.gz
libplist-8c6a809fafa6befff7e2b1adc3df2bdb47042dd1.tar.bz2
Move some methods and drop Utils class in C++ binding.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Node.cpp49
-rw-r--r--src/Structure.cpp34
-rw-r--r--src/Utils.cpp109
4 files changed, 83 insertions, 110 deletions
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
24ADD_LIBRARY( plist SHARED ${libplist_SRC} ) 23ADD_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
25namespace PList 34namespace PList
26{ 35{
@@ -96,4 +105,44 @@ Node* Node::GetParent()
96 return _parent; 105 return _parent;
97} 106}
98 107
108Node* 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
88static 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
105Structure* 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
113Structure* 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
32namespace PList
33{
34
35Node* 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
75static 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
92Structure* 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
100Structure* 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};