#include "gats/object.h" #include "gats/integer.h" #include "gats/float.h" #include "gats/boolean.h" #include "gats/string.h" #include "gats/list.h" #include "gats/dictionary.h" #include #include Gats::Object::Object() { } Gats::Object::~Object() { } Gats::Object *Gats::Object::read( Bu::Stream &rIn ) { char buf; rIn.read( &buf, 1 ); Object *pObj = NULL; switch( buf ) { case 'i': pObj = new Gats::Integer(); break; case 's': pObj = new Gats::String(); break; case '0': case '1': pObj = new Gats::Boolean(); break; case 'l': pObj = new Gats::List(); break; case 'd': pObj = new Gats::Dictionary(); break; case 'f': // Normal floats case 'F': // Special float values pObj = new Gats::Float(); break; case 'e': return NULL; default: throw Bu::ExceptionBase("Invalid Gats type discovered: %c.", buf ); } pObj->read( rIn, buf ); return pObj; } Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ) { switch( obj.getType() ) { case Gats::typeDictionary: return f << dynamic_cast(obj); case Gats::typeList: return f << dynamic_cast(obj); case Gats::typeString: return f << dynamic_cast(obj); case Gats::typeInteger: return f << dynamic_cast(obj); case Gats::typeFloat: return f << dynamic_cast(obj); case Gats::typeBoolean: return f << dynamic_cast(obj); default: return f << "***ERROR: Bad Gats type***"; } } 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***"; }