From fba73219e3c7bf65b459a3303f579fd83c8fd0af Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 6 Apr 2012 06:16:33 +0000 Subject: Everything supports clone now. --- src/boolean.cpp | 5 +++++ src/boolean.h | 1 + src/dictionary.cpp | 12 ++++++++++++ src/dictionary.h | 1 + src/float.cpp | 5 +++++ src/float.h | 2 ++ src/integer.cpp | 5 +++++ src/integer.h | 2 ++ src/list.cpp | 10 ++++++++++ src/list.h | 1 + src/object.cpp | 11 +++++++++++ src/object.h | 1 + src/string.cpp | 5 +++++ src/string.h | 1 + 14 files changed, 62 insertions(+) (limited to 'src') diff --git a/src/boolean.cpp b/src/boolean.cpp index e0600f2..729e644 100644 --- a/src/boolean.cpp +++ b/src/boolean.cpp @@ -17,6 +17,11 @@ Gats::Boolean::~Boolean() { } +Gats::Object *Gats::Boolean::clone() const +{ + return new Gats::Boolean( bVal ); +} + void Gats::Boolean::write( Bu::Stream &rOut ) const { if( bVal ) diff --git a/src/boolean.h b/src/boolean.h index 270e578..6b256c5 100644 --- a/src/boolean.h +++ b/src/boolean.h @@ -15,6 +15,7 @@ namespace Gats virtual Type getType() const { return typeBoolean; } bool getValue() const { return bVal; } void setValue( bool b ) { bVal = b; } + virtual Object *clone() const; virtual void write( Bu::Stream &rOut ) const; virtual void read( Bu::Stream &rIn, char cType ); diff --git a/src/dictionary.cpp b/src/dictionary.cpp index 9728804..b59d652 100644 --- a/src/dictionary.cpp +++ b/src/dictionary.cpp @@ -26,6 +26,18 @@ Gats::Dictionary::~Dictionary() } } +Gats::Object *Gats::Dictionary::clone() const +{ + Gats::Dictionary *pClone = new Gats::Dictionary; + for( const_iterator i = begin(); i; i++ ) + { + Bu::String s(i.getKey()); + pClone->insert( s.clone(), (*i)->clone() ); + } + + return pClone; +} + void Gats::Dictionary::write( Bu::Stream &rOut ) const { rOut.write("d", 1 ); diff --git a/src/dictionary.h b/src/dictionary.h index cde51be..3dd1000 100644 --- a/src/dictionary.h +++ b/src/dictionary.h @@ -17,6 +17,7 @@ namespace Gats virtual ~Dictionary(); virtual Type getType() const { return typeDictionary; } + virtual Object *clone() const; virtual void write( Bu::Stream &rOut ) const; virtual void read( Bu::Stream &rIn, char cType ); diff --git a/src/float.cpp b/src/float.cpp index 1b4ebae..c01d824 100644 --- a/src/float.cpp +++ b/src/float.cpp @@ -20,6 +20,11 @@ Gats::Float::~Float() { } +Gats::Object *Gats::Float::clone() const +{ + return new Gats::Float( fVal ); +} + void Gats::Float::write( Bu::Stream &rOut ) const { if( fVal == 0.0 ) diff --git a/src/float.h b/src/float.h index ad02d28..ba38d6c 100644 --- a/src/float.h +++ b/src/float.h @@ -14,6 +14,8 @@ namespace Gats Float( double f ); virtual ~Float(); + virtual Object *clone() const; + virtual Type getType() const { return typeFloat; } double getValue() const { return fVal; } diff --git a/src/integer.cpp b/src/integer.cpp index 2a713e3..e89ac1d 100644 --- a/src/integer.cpp +++ b/src/integer.cpp @@ -16,6 +16,11 @@ Gats::Integer::~Integer() { } +Gats::Object *Gats::Integer::clone() const +{ + return new Gats::Integer( iVal ); +} + void Gats::Integer::write( Bu::Stream &rOut ) const { rOut.write("i", 1 ); diff --git a/src/integer.h b/src/integer.h index b54bf5d..a5e0d58 100644 --- a/src/integer.h +++ b/src/integer.h @@ -16,6 +16,8 @@ namespace Gats Integer( int64_t iVal ); virtual ~Integer(); + virtual Object *clone() const; + virtual Type getType() const { return typeInteger; } int64_t getValue() const { return iVal; } diff --git a/src/list.cpp b/src/list.cpp index d15f3b9..d081a22 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -21,6 +21,16 @@ Gats::List::~List() } } +Gats::Object *Gats::List::clone() const +{ + Gats::List *pClone = new Gats::List; + for( const_iterator i = begin(); i; i++ ) + { + pClone->append( (*i)->clone() ); + } + return pClone; +} + void Gats::List::write( Bu::Stream &rOut ) const { rOut.write("l", 1 ); diff --git a/src/list.h b/src/list.h index 52dcf9c..5c1cd6e 100644 --- a/src/list.h +++ b/src/list.h @@ -15,6 +15,7 @@ namespace Gats List(); virtual ~List(); + virtual Object *clone() const; virtual Type getType() const { return typeList; } virtual void write( Bu::Stream &rOut ) const; diff --git a/src/object.cpp b/src/object.cpp index da77ff8..9662b6a 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -111,6 +111,12 @@ Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i ) i++; for(;;) { + skipWs( i ); + if( *i == ']' ) + { + i++; + return pLst; + } Gats::Object *pObj = strToGats( i ); if( !pObj ) break; @@ -140,6 +146,11 @@ Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i ) for(;;) { skipWs( i ); + if( *i == '}' ) + { + i++; + return pDict; + } if( *i != '\"' ) throw Bu::ExceptionBase("Keys must be quoted strings."); Bu::String sKey = token( i ); diff --git a/src/object.h b/src/object.h index 91c48ad..b2b1b92 100644 --- a/src/object.h +++ b/src/object.h @@ -34,6 +34,7 @@ namespace Gats virtual void write( Bu::Stream &rOut ) const=0; virtual void read( Bu::Stream &rIn, char cType )=0; + virtual Object *clone() const=0; static Object *read( Bu::Stream &rIn ); static Object *strToGats( const Bu::String &sStr ); diff --git a/src/string.cpp b/src/string.cpp index c4c156b..ddf3486 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -37,6 +37,11 @@ Gats::String::~String() { } +Gats::Object *Gats::String::clone() const +{ + return new Gats::String( Bu::String::clone() ); +} + void Gats::String::write( Bu::Stream &rOut ) const { rOut.write("s", 1 ); diff --git a/src/string.h b/src/string.h index f708e22..de8eedd 100644 --- a/src/string.h +++ b/src/string.h @@ -17,6 +17,7 @@ namespace Gats String( const Bu::String &s ); virtual ~String(); + virtual Object *clone() const; virtual Type getType() const { return typeString; } virtual void write( Bu::Stream &rOut ) const; -- cgit v1.2.3