summaryrefslogtreecommitdiff
path: root/src/unstable/json.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unstable/json.cpp81
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
129Bu::Json *Bu::Json::operator[]( const Bu::String &sKey ) const 129Bu::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
139Bu::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
140int Bu::Json::getSize() const 149int 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
193void Bu::Json::insert( const Bu::String &sKey, const Bu::String &sValue )
194{
195 uDat.pObject->insert( sKey, new Json( sValue ) );
196}
197
198void Bu::Json::insert( const Bu::String &sKey, const char *sValue )
199{
200 uDat.pObject->insert( sKey, new Json( sValue ) );
201}
202
203void Bu::Json::insert( const Bu::String &sKey, double dValue )
204{
205 uDat.pObject->insert( sKey, new Json( dValue ) );
206}
207
208void Bu::Json::insert( const Bu::String &sKey, bool bValue )
209{
210 uDat.pObject->insert( sKey, new Json( bValue ) );
211}
212
213Bu::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
220Bu::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
184void Bu::Json::append( Bu::Json *pObj ) 227void Bu::Json::append( Bu::Json *pObj )
185{ 228{
186 uDat.pArray->append( pObj ); 229 uDat.pArray->append( pObj );
187} 230}
188 231
232void Bu::Json::append( const Bu::String &sValue )
233{
234 uDat.pArray->append( new Json( sValue ) );
235}
236
237void Bu::Json::append( const char *sValue )
238{
239 uDat.pArray->append( new Json( sValue ) );
240}
241
242void Bu::Json::append( double dValue )
243{
244 uDat.pArray->append( new Json( dValue ) );
245}
246
247void Bu::Json::append( bool bValue )
248{
249 uDat.pArray->append( new Json( bValue ) );
250}
251
252Bu::Json &Bu::Json::appendObject()
253{
254 Json *pOb = new Json( Object );
255 uDat.pArray->append( pOb );
256 return *pOb;
257}
258
259Bu::Json &Bu::Json::appendArray()
260{
261 Json *pAr = new Json( Array );
262 uDat.pArray->append( pAr );
263 return *pAr;
264}
265
189void Bu::Json::parse( Bu::Stream &sInput ) 266void Bu::Json::parse( Bu::Stream &sInput )
190{ 267{
191 reset(); 268 reset();