From d14a4c34d01102baa830c6762ef80b0dc6db6389 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 27 Sep 2010 14:47:21 +0000 Subject: Damn boolean overloads, always getting in the way... --- src/dictionary.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/dictionary.h | 9 +++++++- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/dictionary.cpp b/src/dictionary.cpp index b789bbf..29bbd4e 100644 --- a/src/dictionary.cpp +++ b/src/dictionary.cpp @@ -70,12 +70,12 @@ void Gats::Dictionary::insert( const Bu::FString &sKey, int64_t i ) ); } -void Gats::Dictionary::insert( const Bu::FString &sKey, bool b ) +/*void Gats::Dictionary::insert( const Bu::FString &sKey, bool b ) { Bu::Hash::insert( sKey, new Gats::Boolean( b ) ); -} +}*/ void Gats::Dictionary::insert( const Bu::FString &sKey, double d ) { @@ -158,6 +158,66 @@ Gats::Dictionary *Gats::Dictionary::getDict( const Bu::FString &sKey ) return pOb; } +bool Gats::Dictionary::getBool( const Bu::FString &sKey ) const +{ + Gats::Boolean *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot cast item '%s' to bool.", + sKey.getStr() ); + + return pOb->getValue(); +} + +int64_t Gats::Dictionary::getInt( const Bu::FString &sKey ) const +{ + Gats::Integer *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot cast item '%s' to int.", + sKey.getStr() ); + + return pOb->getValue(); +} + +double Gats::Dictionary::getFloat( const Bu::FString &sKey ) const +{ + Gats::Boolean *pOb = dynamic_cast( get( sKey ) ); + if( pOb ) + throw Bu::ExceptionBase("Cannot cast item '%s' to bool.", + sKey.getStr() ); + + return pOb->getValue(); +} + +Bu::FString Gats::Dictionary::getStr( const Bu::FString &sKey ) const +{ + Gats::String *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot cast item '%s' to string.", + sKey.getStr() ); + + return *pOb; +} + +Gats::List *Gats::Dictionary::getList( const Bu::FString &sKey ) const +{ + Gats::List *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot cast item '%s' to list.", + sKey.getStr() ); + + return pOb; +} + +Gats::Dictionary *Gats::Dictionary::getDict( const Bu::FString &sKey ) const +{ + Gats::Dictionary *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot cast item '%s' to dictionary.", + sKey.getStr() ); + + return pOb; +} + Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ) { f << "(dict) {"; diff --git a/src/dictionary.h b/src/dictionary.h index 39248d2..c9bf1cb 100644 --- a/src/dictionary.h +++ b/src/dictionary.h @@ -24,7 +24,7 @@ namespace Gats void insert( const Bu::FString &sKey, const Bu::FString &s ); void insert( const Bu::FString &sKey, int32_t i ); void insert( const Bu::FString &sKey, int64_t i ); - void insert( const Bu::FString &sKey, bool b ); + //void insert( const Bu::FString &sKey, bool b ); void insert( const Bu::FString &sKey, double d ); using Bu::Hash::insert; @@ -34,6 +34,13 @@ namespace Gats Bu::FString getStr( const Bu::FString &sKey ); Gats::List *getList( const Bu::FString &sKey ); Gats::Dictionary *getDict( const Bu::FString &sKey ); + + bool getBool( const Bu::FString &sKey ) const; + int64_t getInt( const Bu::FString &sKey ) const; + double getFloat( const Bu::FString &sKey ) const; + Bu::FString getStr( const Bu::FString &sKey ) const; + Gats::List *getList( const Bu::FString &sKey ) const; + Gats::Dictionary *getDict( const Bu::FString &sKey ) const; }; }; -- cgit v1.2.3