diff options
author | Mike Buland <mbuland@penny-arcade.com> | 2018-01-18 16:08:24 -0800 |
---|---|---|
committer | Mike Buland <mbuland@penny-arcade.com> | 2018-01-18 16:08:24 -0800 |
commit | 516fa9045af1e9c85ce524535d0ea5bc395e86cb (patch) | |
tree | 482ceb92494c3770d12b91a511f105c304025fa9 /src/unstable/json.cpp | |
parent | ea96e4decaa23fc8ddfb528d4851751ec9496490 (diff) | |
download | libbu++-516fa9045af1e9c85ce524535d0ea5bc395e86cb.tar.gz libbu++-516fa9045af1e9c85ce524535d0ea5bc395e86cb.tar.bz2 libbu++-516fa9045af1e9c85ce524535d0ea5bc395e86cb.tar.xz libbu++-516fa9045af1e9c85ce524535d0ea5bc395e86cb.zip |
Made json much more helpful. Fixed array iterators.
Diffstat (limited to '')
-rw-r--r-- | src/unstable/json.cpp | 81 |
1 files changed, 79 insertions, 2 deletions
diff --git a/src/unstable/json.cpp b/src/unstable/json.cpp index 6159ef3..3627214 100644 --- a/src/unstable/json.cpp +++ b/src/unstable/json.cpp | |||
@@ -126,15 +126,24 @@ bool Bu::Json::isNull() const | |||
126 | return eType == Null; | 126 | return eType == Null; |
127 | } | 127 | } |
128 | 128 | ||
129 | Bu::Json *Bu::Json::operator[]( const Bu::String &sKey ) const | 129 | Bu::Json &Bu::Json::operator[]( const Bu::String &sKey ) const |
130 | { | 130 | { |
131 | if( eType != Object ) | 131 | if( eType != Object ) |
132 | throw Bu::ExceptionBase( | 132 | throw Bu::ExceptionBase( |
133 | "Object entry requested from non-object json object." | 133 | "Object entry requested from non-object json object." |
134 | ); | 134 | ); |
135 | 135 | ||
136 | return uDat.pObject->get( sKey ); | 136 | return *uDat.pObject->get( sKey ); |
137 | } | ||
138 | |||
139 | Bu::Json &Bu::Json::operator[]( int iIndex ) const | ||
140 | { | ||
141 | if( eType != Array ) | ||
142 | throw Bu::ExceptionBase( | ||
143 | "Object entry requested from non-array json object." | ||
144 | ); | ||
137 | 145 | ||
146 | return *uDat.pArray->get( iIndex ); | ||
138 | } | 147 | } |
139 | 148 | ||
140 | int Bu::Json::getSize() const | 149 | int Bu::Json::getSize() const |
@@ -181,11 +190,79 @@ void Bu::Json::insert( const Bu::String &sKey, Bu::Json *pObj ) | |||
181 | uDat.pObject->insert( sKey, pObj ); | 190 | uDat.pObject->insert( sKey, pObj ); |
182 | } | 191 | } |
183 | 192 | ||
193 | void Bu::Json::insert( const Bu::String &sKey, const Bu::String &sValue ) | ||
194 | { | ||
195 | uDat.pObject->insert( sKey, new Json( sValue ) ); | ||
196 | } | ||
197 | |||
198 | void Bu::Json::insert( const Bu::String &sKey, const char *sValue ) | ||
199 | { | ||
200 | uDat.pObject->insert( sKey, new Json( sValue ) ); | ||
201 | } | ||
202 | |||
203 | void Bu::Json::insert( const Bu::String &sKey, double dValue ) | ||
204 | { | ||
205 | uDat.pObject->insert( sKey, new Json( dValue ) ); | ||
206 | } | ||
207 | |||
208 | void Bu::Json::insert( const Bu::String &sKey, bool bValue ) | ||
209 | { | ||
210 | uDat.pObject->insert( sKey, new Json( bValue ) ); | ||
211 | } | ||
212 | |||
213 | Bu::Json &Bu::Json::insertObject( const Bu::String &sKey ) | ||
214 | { | ||
215 | Json *pOb = new Json( Object ); | ||
216 | uDat.pObject->insert( sKey, pOb ); | ||
217 | return *pOb; | ||
218 | } | ||
219 | |||
220 | Bu::Json &Bu::Json::insertArray( const Bu::String &sKey ) | ||
221 | { | ||
222 | Json *pAr = new Json( Array ); | ||
223 | uDat.pObject->insert( sKey, pAr ); | ||
224 | return *pAr; | ||
225 | } | ||
226 | |||
184 | void Bu::Json::append( Bu::Json *pObj ) | 227 | void Bu::Json::append( Bu::Json *pObj ) |
185 | { | 228 | { |
186 | uDat.pArray->append( pObj ); | 229 | uDat.pArray->append( pObj ); |
187 | } | 230 | } |
188 | 231 | ||
232 | void Bu::Json::append( const Bu::String &sValue ) | ||
233 | { | ||
234 | uDat.pArray->append( new Json( sValue ) ); | ||
235 | } | ||
236 | |||
237 | void Bu::Json::append( const char *sValue ) | ||
238 | { | ||
239 | uDat.pArray->append( new Json( sValue ) ); | ||
240 | } | ||
241 | |||
242 | void Bu::Json::append( double dValue ) | ||
243 | { | ||
244 | uDat.pArray->append( new Json( dValue ) ); | ||
245 | } | ||
246 | |||
247 | void Bu::Json::append( bool bValue ) | ||
248 | { | ||
249 | uDat.pArray->append( new Json( bValue ) ); | ||
250 | } | ||
251 | |||
252 | Bu::Json &Bu::Json::appendObject() | ||
253 | { | ||
254 | Json *pOb = new Json( Object ); | ||
255 | uDat.pArray->append( pOb ); | ||
256 | return *pOb; | ||
257 | } | ||
258 | |||
259 | Bu::Json &Bu::Json::appendArray() | ||
260 | { | ||
261 | Json *pAr = new Json( Array ); | ||
262 | uDat.pArray->append( pAr ); | ||
263 | return *pAr; | ||
264 | } | ||
265 | |||
189 | void Bu::Json::parse( Bu::Stream &sInput ) | 266 | void Bu::Json::parse( Bu::Stream &sInput ) |
190 | { | 267 | { |
191 | reset(); | 268 | reset(); |