From 744fe4ecbcf613ee637d00e8808f69668eac6bb2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 8 Mar 2011 21:03:43 +0000 Subject: Added a whole load of new, cool helpers for working with dictionaries and lists. --- src/dictionary.cpp | 57 ++++++++++++++++++++++++++++++++++ src/dictionary.h | 8 +++++ src/list.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++---- src/list.h | 20 ++++++++++-- 4 files changed, 166 insertions(+), 8 deletions(-) diff --git a/src/dictionary.cpp b/src/dictionary.cpp index aaba7b8..9728804 100644 --- a/src/dictionary.cpp +++ b/src/dictionary.cpp @@ -168,6 +168,63 @@ void Gats::Dictionary::insert( const Bu::String &sKey, const Bu::String &s ) ); } +void Gats::Dictionary::insertBool( const Bu::String &sKey, bool b ) +{ + Bu::Hash::insert( + sKey, new Gats::Boolean( b ) + ); +} + +void Gats::Dictionary::insertInt( const Bu::String &sKey, int64_t i ) +{ + Bu::Hash::insert( + sKey, new Gats::Integer( i ) + ); +} + +void Gats::Dictionary::insertFloat( const Bu::String &sKey, double d ) +{ + Bu::Hash::insert( + sKey, new Gats::Float( d ) + ); +} + +void Gats::Dictionary::insertStr( const Bu::String &sKey, const Bu::String &s ) +{ + Bu::Hash::insert( + sKey, new Gats::String( s ) + ); +} + +void Gats::Dictionary::insertList( const Bu::String &sKey, Gats::List *pL ) +{ + Bu::Hash::insert( + sKey, pL + ); +} + +void Gats::Dictionary::insertDict( const Bu::String &sKey, + Gats::Dictionary *pD ) +{ + Bu::Hash::insert( + sKey, pD + ); +} + +Gats::List *Gats::Dictionary::insertList( const Bu::String &sKey ) +{ + Gats::List *pLst = new Gats::List(); + insertList( sKey, pLst ); + return pLst; +} + +Gats::Dictionary *Gats::Dictionary::insertDict( const Bu::String &sKey ) +{ + Gats::Dictionary *pDict = new Gats::Dictionary(); + insertDict( sKey, pDict ); + return pDict; +} + bool Gats::Dictionary::getBool( const Bu::String &sKey ) { Gats::Boolean *pOb = dynamic_cast( get( sKey ) ); diff --git a/src/dictionary.h b/src/dictionary.h index d421720..cde51be 100644 --- a/src/dictionary.h +++ b/src/dictionary.h @@ -37,6 +37,14 @@ namespace Gats void insert( const Bu::String &sKey, float d ); void insert( const Bu::String &sKey, double d ); using Bu::Hash::insert; + void insertBool( const Bu::String &sKey, bool b ); + void insertInt( const Bu::String &sKey, int64_t i ); + void insertFloat( const Bu::String &sKey, double d ); + void insertStr( const Bu::String &sKey, const Bu::String &s ); + void insertList( const Bu::String &sKey, Gats::List *pL ); + void insertDict( const Bu::String &sKey, Gats::Dictionary *pD ); + Gats::List *insertList( const Bu::String &sKey ); + Gats::Dictionary *insertDict( const Bu::String &sKey ); bool getBool( const Bu::String &sKey ); int64_t getInt( const Bu::String &sKey ); diff --git a/src/list.cpp b/src/list.cpp index 02e2a8d..3e871d6 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -4,6 +4,7 @@ #include "gats/integer.h" #include "gats/float.h" #include "gats/boolean.h" +#include "gats/dictionary.h" #include #include @@ -57,16 +58,54 @@ void Gats::List::append( int64_t i ) Bu::List::append( new Gats::Integer( i ) ); } -void Gats::List::append( bool b ) +void Gats::List::append( double d ) { - Bu::List::append( new Gats::Boolean( b ) ); + Bu::List::append( new Gats::Float( d ) ); } -void Gats::List::append( double d ) +void Gats::List::appendStr( const Bu::String &s ) +{ + Bu::List::append( new Gats::String( s ) ); +} + +void Gats::List::appendInt( int64_t i ) +{ + Bu::List::append( new Gats::Integer( i ) ); +} + +void Gats::List::appendFloat( double d ) { Bu::List::append( new Gats::Float( d ) ); } +void Gats::List::appendBool( bool b ) +{ + Bu::List::append( new Gats::Boolean( b ) ); +} + +void Gats::List::appendList( Gats::List *pL ) +{ + Bu::List::append( pL ); +} + +void Gats::List::appendDict( Gats::Dictionary *pD ) +{ + Bu::List::append( pD ); +} + +Gats::List *Gats::List::appendList() +{ + Gats::List *pLst = new Gats::List(); + appendList( pLst ); + return pLst; +} + +Gats::Dictionary *Gats::List::appendDict() +{ + Gats::Dictionary *pDict = new Gats::Dictionary(); + appendDict( pDict ); + return pDict; +} void Gats::List::prepend( const char *s ) { @@ -88,16 +127,54 @@ void Gats::List::prepend( int64_t i ) Bu::List::prepend( new Gats::Integer( i ) ); } -void Gats::List::prepend( bool b ) +void Gats::List::prepend( double d ) { - Bu::List::prepend( new Gats::Boolean( b ) ); + Bu::List::prepend( new Gats::Float( d ) ); } -void Gats::List::prepend( double d ) +void Gats::List::prependStr( const Bu::String &s ) +{ + Bu::List::prepend( new Gats::String( s ) ); +} + +void Gats::List::prependInt( int64_t i ) +{ + Bu::List::prepend( new Gats::Integer( i ) ); +} + +void Gats::List::prependFloat( double d ) { Bu::List::prepend( new Gats::Float( d ) ); } +void Gats::List::prependBool( bool b ) +{ + Bu::List::prepend( new Gats::Boolean( b ) ); +} + +void Gats::List::prependList( Gats::List *pL ) +{ + Bu::List::prepend( pL ); +} + +void Gats::List::prependDict( Gats::Dictionary *pD ) +{ + Bu::List::prepend( pD ); +} + +Gats::List *Gats::List::prependList() +{ + Gats::List *pLst = new Gats::List(); + prependList( pLst ); + return pLst; +} + +Gats::Dictionary *Gats::List::prependDict() +{ + Gats::Dictionary *pDict = new Gats::Dictionary(); + prependDict( pDict ); + return pDict; +} Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ) { diff --git a/src/list.h b/src/list.h index 5c50fae..52dcf9c 100644 --- a/src/list.h +++ b/src/list.h @@ -7,6 +7,8 @@ namespace Gats { + class Dictionary; + class List : public Gats::Object, public Bu::List { public: @@ -22,17 +24,31 @@ namespace Gats void append( const Bu::String &s ); void append( int32_t i ); void append( int64_t i ); - void append( bool b ); void append( double d ); using Bu::List::append; + void appendStr( const Bu::String &s ); + void appendInt( int64_t i ); + void appendFloat( double d ); + void appendBool( bool b ); + void appendList( Gats::List *pL ); + void appendDict( Gats::Dictionary *pD ); + Gats::List *appendList(); + Gats::Dictionary *appendDict(); void prepend( const char *s ); void prepend( const Bu::String &s ); void prepend( int32_t i ); void prepend( int64_t i ); - void prepend( bool b ); void prepend( double d ); using Bu::List::prepend; + void prependStr( const Bu::String &s ); + void prependInt( int64_t i ); + void prependFloat( double d ); + void prependBool( bool b ); + void prependList( Gats::List *pL ); + void prependDict( Gats::Dictionary *pD ); + Gats::List *prependList(); + Gats::Dictionary *prependDict(); }; }; -- cgit v1.2.3