From 76e1ecfabd1f831bc1810aeae65c0faf61d80cee Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 1 Nov 2010 17:19:44 +0000 Subject: Maybe more minor fixes? --- src/dictionary.cpp | 55 ++++++++++++++++++++++++++++++------------------------ src/dictionary.h | 1 + src/object.cpp | 30 +++++++++++++++++++++++++++++ src/object.h | 3 +++ 4 files changed, 65 insertions(+), 24 deletions(-) diff --git a/src/dictionary.cpp b/src/dictionary.cpp index f3a89c8..9791203 100644 --- a/src/dictionary.cpp +++ b/src/dictionary.cpp @@ -140,6 +140,13 @@ void Gats::Dictionary::insert( const Bu::FString &sKey, bool b ) ); }*/ +void Gats::Dictionary::insert( const Bu::FString &sKey, float d ) +{ + Bu::Hash::insert( + sKey, new Gats::Float( d ) + ); +} + void Gats::Dictionary::insert( const Bu::FString &sKey, double d ) { Bu::Hash::insert( @@ -165,8 +172,8 @@ bool Gats::Dictionary::getBool( const Bu::FString &sKey ) { Gats::Boolean *pOb = dynamic_cast( get( sKey ) ); if( !pOb ) - throw Bu::ExceptionBase("Cannot cast item '%s' to bool.", - sKey.getStr() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return pOb->getValue(); } @@ -175,8 +182,8 @@ int64_t Gats::Dictionary::getInt( const Bu::FString &sKey ) { Gats::Integer *pOb = dynamic_cast( get( sKey ) ); if( !pOb ) - throw Bu::ExceptionBase("Cannot cast item '%s' to int.", - sKey.getStr() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return pOb->getValue(); } @@ -185,8 +192,8 @@ double Gats::Dictionary::getFloat( const Bu::FString &sKey ) { Gats::Float *pOb = dynamic_cast( get( sKey ) ); if( pOb ) - throw Bu::ExceptionBase("Cannot cast item '%s' to bool.", - sKey.getStr() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return pOb->getValue(); } @@ -195,8 +202,8 @@ Bu::FString Gats::Dictionary::getStr( const Bu::FString &sKey ) { Gats::String *pOb = dynamic_cast( get( sKey ) ); if( !pOb ) - throw Bu::ExceptionBase("Cannot cast item '%s' to string.", - sKey.getStr() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return *pOb; } @@ -205,8 +212,8 @@ Gats::List *Gats::Dictionary::getList( const Bu::FString &sKey ) { Gats::List *pOb = dynamic_cast( get( sKey ) ); if( !pOb ) - throw Bu::ExceptionBase("Cannot cast item '%s' to list.", - sKey.getStr() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return pOb; } @@ -215,8 +222,8 @@ Gats::Dictionary *Gats::Dictionary::getDict( const Bu::FString &sKey ) { Gats::Dictionary *pOb = dynamic_cast( get( sKey ) ); if( !pOb ) - throw Bu::ExceptionBase("Cannot cast item '%s' to dictionary.", - sKey.getStr() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return pOb; } @@ -225,8 +232,8 @@ 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() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return pOb->getValue(); } @@ -235,8 +242,8 @@ 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() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return pOb->getValue(); } @@ -245,8 +252,8 @@ double Gats::Dictionary::getFloat( const Bu::FString &sKey ) const { Gats::Float *pOb = dynamic_cast( get( sKey ) ); if( pOb ) - throw Bu::ExceptionBase("Cannot cast item '%s' to bool.", - sKey.getStr() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return pOb->getValue(); } @@ -255,8 +262,8 @@ 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() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return *pOb; } @@ -265,8 +272,8 @@ 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() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return pOb; } @@ -275,8 +282,8 @@ 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() ); + throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); return pOb; } diff --git a/src/dictionary.h b/src/dictionary.h index fa11f1d..1197a19 100644 --- a/src/dictionary.h +++ b/src/dictionary.h @@ -34,6 +34,7 @@ namespace Gats void insert( const Bu::FString &sKey, unsigned long long i ); void insert( const Bu::FString &sKey, signed long long i ); //void insert( const Bu::FString &sKey, bool b ); + void insert( const Bu::FString &sKey, float d ); void insert( const Bu::FString &sKey, double d ); using Bu::Hash::insert; diff --git a/src/object.cpp b/src/object.cpp index f5148ad..1908904 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -89,3 +89,33 @@ Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ) } } +Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ) +{ + switch( t ) + { + case Gats::typeDictionary: return f << "dictionary"; + case Gats::typeList: return f << "list"; + case Gats::typeString: return f << "string"; + case Gats::typeInteger: return f << "integer"; + case Gats::typeFloat: return f << "float"; + case Gats::typeBoolean: return f << "boolean"; + } + + return f << "***unknown***"; +} + +const char *Gats::typeToStr( Gats::Type t ) +{ + switch( t ) + { + case Gats::typeDictionary: return "dictionary"; + case Gats::typeList: return "list"; + case Gats::typeString: return "string"; + case Gats::typeInteger: return "integer"; + case Gats::typeFloat: return "float"; + case Gats::typeBoolean: return "boolean"; + } + + return "***unknown***"; +} + diff --git a/src/object.h b/src/object.h index 44f9da7..1c114b3 100644 --- a/src/object.h +++ b/src/object.h @@ -35,8 +35,11 @@ namespace Gats static Object *read( Bu::Stream &rIn ); }; + + const char *typeToStr( Type t ); }; Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ); +Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ); #endif -- cgit v1.2.3