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 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'src/dictionary.cpp') 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) {"; -- cgit v1.2.3