From 516fa9045af1e9c85ce524535d0ea5bc395e86cb Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 18 Jan 2018 16:08:24 -0800 Subject: Made json much more helpful. Fixed array iterators. --- src/unstable/json.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 2 deletions(-) (limited to 'src/unstable/json.cpp') 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 return eType == Null; } -Bu::Json *Bu::Json::operator[]( const Bu::String &sKey ) const +Bu::Json &Bu::Json::operator[]( const Bu::String &sKey ) const { if( eType != Object ) throw Bu::ExceptionBase( "Object entry requested from non-object json object." ); - return uDat.pObject->get( sKey ); + return *uDat.pObject->get( sKey ); +} + +Bu::Json &Bu::Json::operator[]( int iIndex ) const +{ + if( eType != Array ) + throw Bu::ExceptionBase( + "Object entry requested from non-array json object." + ); + return *uDat.pArray->get( iIndex ); } int Bu::Json::getSize() const @@ -181,11 +190,79 @@ void Bu::Json::insert( const Bu::String &sKey, Bu::Json *pObj ) uDat.pObject->insert( sKey, pObj ); } +void Bu::Json::insert( const Bu::String &sKey, const Bu::String &sValue ) +{ + uDat.pObject->insert( sKey, new Json( sValue ) ); +} + +void Bu::Json::insert( const Bu::String &sKey, const char *sValue ) +{ + uDat.pObject->insert( sKey, new Json( sValue ) ); +} + +void Bu::Json::insert( const Bu::String &sKey, double dValue ) +{ + uDat.pObject->insert( sKey, new Json( dValue ) ); +} + +void Bu::Json::insert( const Bu::String &sKey, bool bValue ) +{ + uDat.pObject->insert( sKey, new Json( bValue ) ); +} + +Bu::Json &Bu::Json::insertObject( const Bu::String &sKey ) +{ + Json *pOb = new Json( Object ); + uDat.pObject->insert( sKey, pOb ); + return *pOb; +} + +Bu::Json &Bu::Json::insertArray( const Bu::String &sKey ) +{ + Json *pAr = new Json( Array ); + uDat.pObject->insert( sKey, pAr ); + return *pAr; +} + void Bu::Json::append( Bu::Json *pObj ) { uDat.pArray->append( pObj ); } +void Bu::Json::append( const Bu::String &sValue ) +{ + uDat.pArray->append( new Json( sValue ) ); +} + +void Bu::Json::append( const char *sValue ) +{ + uDat.pArray->append( new Json( sValue ) ); +} + +void Bu::Json::append( double dValue ) +{ + uDat.pArray->append( new Json( dValue ) ); +} + +void Bu::Json::append( bool bValue ) +{ + uDat.pArray->append( new Json( bValue ) ); +} + +Bu::Json &Bu::Json::appendObject() +{ + Json *pOb = new Json( Object ); + uDat.pArray->append( pOb ); + return *pOb; +} + +Bu::Json &Bu::Json::appendArray() +{ + Json *pAr = new Json( Array ); + uDat.pArray->append( pAr ); + return *pAr; +} + void Bu::Json::parse( Bu::Stream &sInput ) { reset(); -- cgit v1.2.3