aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-04-06 06:16:33 +0000
committerMike Buland <eichlan@xagasoft.com>2012-04-06 06:16:33 +0000
commitfba73219e3c7bf65b459a3303f579fd83c8fd0af (patch)
tree7de25030a1ef0e5899da243c2fb5c0e4900c0a49
parentb01618b1be4831d30dbf8706a48e71c62d617b99 (diff)
downloadlibgats-fba73219e3c7bf65b459a3303f579fd83c8fd0af.tar.gz
libgats-fba73219e3c7bf65b459a3303f579fd83c8fd0af.tar.bz2
libgats-fba73219e3c7bf65b459a3303f579fd83c8fd0af.tar.xz
libgats-fba73219e3c7bf65b459a3303f579fd83c8fd0af.zip
Everything supports clone now.
-rw-r--r--src/boolean.cpp5
-rw-r--r--src/boolean.h1
-rw-r--r--src/dictionary.cpp12
-rw-r--r--src/dictionary.h1
-rw-r--r--src/float.cpp5
-rw-r--r--src/float.h2
-rw-r--r--src/integer.cpp5
-rw-r--r--src/integer.h2
-rw-r--r--src/list.cpp10
-rw-r--r--src/list.h1
-rw-r--r--src/object.cpp11
-rw-r--r--src/object.h1
-rw-r--r--src/string.cpp5
-rw-r--r--src/string.h1
14 files changed, 62 insertions, 0 deletions
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()
17{ 17{
18} 18}
19 19
20Gats::Object *Gats::Boolean::clone() const
21{
22 return new Gats::Boolean( bVal );
23}
24
20void Gats::Boolean::write( Bu::Stream &rOut ) const 25void Gats::Boolean::write( Bu::Stream &rOut ) const
21{ 26{
22 if( bVal ) 27 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
15 virtual Type getType() const { return typeBoolean; } 15 virtual Type getType() const { return typeBoolean; }
16 bool getValue() const { return bVal; } 16 bool getValue() const { return bVal; }
17 void setValue( bool b ) { bVal = b; } 17 void setValue( bool b ) { bVal = b; }
18 virtual Object *clone() const;
18 19
19 virtual void write( Bu::Stream &rOut ) const; 20 virtual void write( Bu::Stream &rOut ) const;
20 virtual void read( Bu::Stream &rIn, char cType ); 21 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()
26 } 26 }
27} 27}
28 28
29Gats::Object *Gats::Dictionary::clone() const
30{
31 Gats::Dictionary *pClone = new Gats::Dictionary;
32 for( const_iterator i = begin(); i; i++ )
33 {
34 Bu::String s(i.getKey());
35 pClone->insert( s.clone(), (*i)->clone() );
36 }
37
38 return pClone;
39}
40
29void Gats::Dictionary::write( Bu::Stream &rOut ) const 41void Gats::Dictionary::write( Bu::Stream &rOut ) const
30{ 42{
31 rOut.write("d", 1 ); 43 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
17 virtual ~Dictionary(); 17 virtual ~Dictionary();
18 18
19 virtual Type getType() const { return typeDictionary; } 19 virtual Type getType() const { return typeDictionary; }
20 virtual Object *clone() const;
20 virtual void write( Bu::Stream &rOut ) const; 21 virtual void write( Bu::Stream &rOut ) const;
21 virtual void read( Bu::Stream &rIn, char cType ); 22 virtual void read( Bu::Stream &rIn, char cType );
22 23
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()
20{ 20{
21} 21}
22 22
23Gats::Object *Gats::Float::clone() const
24{
25 return new Gats::Float( fVal );
26}
27
23void Gats::Float::write( Bu::Stream &rOut ) const 28void Gats::Float::write( Bu::Stream &rOut ) const
24{ 29{
25 if( fVal == 0.0 ) 30 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
14 Float( double f ); 14 Float( double f );
15 virtual ~Float(); 15 virtual ~Float();
16 16
17 virtual Object *clone() const;
18
17 virtual Type getType() const { return typeFloat; } 19 virtual Type getType() const { return typeFloat; }
18 double getValue() const { return fVal; } 20 double getValue() const { return fVal; }
19 21
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()
16{ 16{
17} 17}
18 18
19Gats::Object *Gats::Integer::clone() const
20{
21 return new Gats::Integer( iVal );
22}
23
19void Gats::Integer::write( Bu::Stream &rOut ) const 24void Gats::Integer::write( Bu::Stream &rOut ) const
20{ 25{
21 rOut.write("i", 1 ); 26 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
16 Integer( int64_t iVal ); 16 Integer( int64_t iVal );
17 virtual ~Integer(); 17 virtual ~Integer();
18 18
19 virtual Object *clone() const;
20
19 virtual Type getType() const { return typeInteger; } 21 virtual Type getType() const { return typeInteger; }
20 int64_t getValue() const { return iVal; } 22 int64_t getValue() const { return iVal; }
21 23
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()
21 } 21 }
22} 22}
23 23
24Gats::Object *Gats::List::clone() const
25{
26 Gats::List *pClone = new Gats::List;
27 for( const_iterator i = begin(); i; i++ )
28 {
29 pClone->append( (*i)->clone() );
30 }
31 return pClone;
32}
33
24void Gats::List::write( Bu::Stream &rOut ) const 34void Gats::List::write( Bu::Stream &rOut ) const
25{ 35{
26 rOut.write("l", 1 ); 36 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
15 List(); 15 List();
16 virtual ~List(); 16 virtual ~List();
17 17
18 virtual Object *clone() const;
18 virtual Type getType() const { return typeList; } 19 virtual Type getType() const { return typeList; }
19 20
20 virtual void write( Bu::Stream &rOut ) const; 21 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 )
111 i++; 111 i++;
112 for(;;) 112 for(;;)
113 { 113 {
114 skipWs( i );
115 if( *i == ']' )
116 {
117 i++;
118 return pLst;
119 }
114 Gats::Object *pObj = strToGats( i ); 120 Gats::Object *pObj = strToGats( i );
115 if( !pObj ) 121 if( !pObj )
116 break; 122 break;
@@ -140,6 +146,11 @@ Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i )
140 for(;;) 146 for(;;)
141 { 147 {
142 skipWs( i ); 148 skipWs( i );
149 if( *i == '}' )
150 {
151 i++;
152 return pDict;
153 }
143 if( *i != '\"' ) 154 if( *i != '\"' )
144 throw Bu::ExceptionBase("Keys must be quoted strings."); 155 throw Bu::ExceptionBase("Keys must be quoted strings.");
145 Bu::String sKey = token( i ); 156 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
34 34
35 virtual void write( Bu::Stream &rOut ) const=0; 35 virtual void write( Bu::Stream &rOut ) const=0;
36 virtual void read( Bu::Stream &rIn, char cType )=0; 36 virtual void read( Bu::Stream &rIn, char cType )=0;
37 virtual Object *clone() const=0;
37 38
38 static Object *read( Bu::Stream &rIn ); 39 static Object *read( Bu::Stream &rIn );
39 static Object *strToGats( const Bu::String &sStr ); 40 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()
37{ 37{
38} 38}
39 39
40Gats::Object *Gats::String::clone() const
41{
42 return new Gats::String( Bu::String::clone() );
43}
44
40void Gats::String::write( Bu::Stream &rOut ) const 45void Gats::String::write( Bu::Stream &rOut ) const
41{ 46{
42 rOut.write("s", 1 ); 47 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
17 String( const Bu::String &s ); 17 String( const Bu::String &s );
18 virtual ~String(); 18 virtual ~String();
19 19
20 virtual Object *clone() const;
20 virtual Type getType() const { return typeString; } 21 virtual Type getType() const { return typeString; }
21 22
22 virtual void write( Bu::Stream &rOut ) const; 23 virtual void write( Bu::Stream &rOut ) const;