diff options
Diffstat (limited to '')
-rw-r--r-- | src/stable/array.h | 21 | ||||
-rw-r--r-- | src/unstable/json.cpp | 81 | ||||
-rw-r--r-- | src/unstable/json.h | 18 |
3 files changed, 115 insertions, 5 deletions
diff --git a/src/stable/array.h b/src/stable/array.h index a662705..8c17cc4 100644 --- a/src/stable/array.h +++ b/src/stable/array.h | |||
@@ -362,6 +362,18 @@ namespace Bu | |||
362 | long iPos; | 362 | long iPos; |
363 | 363 | ||
364 | public: | 364 | public: |
365 | iterator() : | ||
366 | src( NULL ), | ||
367 | iPos( -1 ) | ||
368 | { | ||
369 | } | ||
370 | |||
371 | iterator( const iterator &rSrc ) : | ||
372 | src( rSrc.src ), | ||
373 | iPos( rSrc.iPos ) | ||
374 | { | ||
375 | } | ||
376 | |||
365 | iterator operator++( int ) | 377 | iterator operator++( int ) |
366 | { | 378 | { |
367 | if( iPos < 0 ) | 379 | if( iPos < 0 ) |
@@ -480,11 +492,18 @@ namespace Bu | |||
480 | long iPos; | 492 | long iPos; |
481 | 493 | ||
482 | public: | 494 | public: |
483 | const_iterator( iterator &rSrc ) : | 495 | const_iterator( const iterator &rSrc ) : |
484 | src( rSrc.src ), | 496 | src( rSrc.src ), |
485 | iPos( rSrc.iPos ) | 497 | iPos( rSrc.iPos ) |
486 | { | 498 | { |
487 | } | 499 | } |
500 | |||
501 | const_iterator( const const_iterator &rSrc ) : | ||
502 | src( rSrc.src ), | ||
503 | iPos( rSrc.iPos ) | ||
504 | { | ||
505 | } | ||
506 | |||
488 | const_iterator operator++( int ) | 507 | const_iterator operator++( int ) |
489 | { | 508 | { |
490 | if( iPos < 0 ) | 509 | if( iPos < 0 ) |
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(); |
diff --git a/src/unstable/json.h b/src/unstable/json.h index 86074bc..217a69a 100644 --- a/src/unstable/json.h +++ b/src/unstable/json.h | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | #include "bu/hash.h" | 4 | #include "bu/hash.h" |
5 | #include "bu/list.h" | 5 | #include "bu/list.h" |
6 | #include "bu/array.h" | ||
6 | #include "bu/string.h" | 7 | #include "bu/string.h" |
7 | #include "bu/utfstring.h" | 8 | #include "bu/utfstring.h" |
8 | 9 | ||
@@ -15,7 +16,7 @@ namespace Bu | |||
15 | private: | 16 | private: |
16 | Json( char &c, Bu::Stream &sInput ); | 17 | Json( char &c, Bu::Stream &sInput ); |
17 | typedef Bu::Hash<Bu::String, Json *> JsonHash; | 18 | typedef Bu::Hash<Bu::String, Json *> JsonHash; |
18 | typedef Bu::List<Json *> JsonList; | 19 | typedef Bu::Array<Json *> JsonList; |
19 | 20 | ||
20 | public: | 21 | public: |
21 | typedef JsonList::iterator iterator; | 22 | typedef JsonList::iterator iterator; |
@@ -47,7 +48,8 @@ namespace Bu | |||
47 | double getNumber() const; | 48 | double getNumber() const; |
48 | bool getBoolean() const; | 49 | bool getBoolean() const; |
49 | bool isNull() const; | 50 | bool isNull() const; |
50 | Json *operator[]( const Bu::String &sKey ) const; | 51 | Json &operator[]( const Bu::String &sKey ) const; |
52 | Json &operator[]( int iIndex ) const; | ||
51 | int getSize() const; | 53 | int getSize() const; |
52 | iterator begin(); | 54 | iterator begin(); |
53 | const_iterator begin() const; | 55 | const_iterator begin() const; |
@@ -56,7 +58,19 @@ namespace Bu | |||
56 | 58 | ||
57 | bool has( const Bu::String &sKey ) const; | 59 | bool has( const Bu::String &sKey ) const; |
58 | void insert( const Bu::String &sKey, Bu::Json *pObj ); | 60 | void insert( const Bu::String &sKey, Bu::Json *pObj ); |
61 | void insert( const Bu::String &sKey, const Bu::String &sValue ); | ||
62 | void insert( const Bu::String &sKey, const char *sValue ); | ||
63 | void insert( const Bu::String &sKey, double dValue ); | ||
64 | void insert( const Bu::String &sKey, bool bValue ); | ||
65 | Json &insertObject( const Bu::String &sKey ); | ||
66 | Json &insertArray( const Bu::String &sKey ); | ||
59 | void append( Bu::Json *pObj ); | 67 | void append( Bu::Json *pObj ); |
68 | void append( const Bu::String &sValue ); | ||
69 | void append( const char *sValue ); | ||
70 | void append( double dValue ); | ||
71 | void append( bool bValue ); | ||
72 | Json &appendObject(); | ||
73 | Json &appendArray(); | ||
60 | 74 | ||
61 | void parse( Bu::Stream &sInput ); | 75 | void parse( Bu::Stream &sInput ); |
62 | void parse( const Bu::String &sInput ); | 76 | void parse( const Bu::String &sInput ); |