aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-06-11 04:05:22 +0000
committerMike Buland <eichlan@xagasoft.com>2012-06-11 04:05:22 +0000
commit380b36be3352cd9a5c93dbd67db25346166a8547 (patch)
treef69613e7b6238744c34af6dc14d6feb68a4f6706 /src
parent3905f9962bbfb312c3804ff9c7b7d1e0fa203cbc (diff)
downloadlibgats-380b36be3352cd9a5c93dbd67db25346166a8547.tar.gz
libgats-380b36be3352cd9a5c93dbd67db25346166a8547.tar.bz2
libgats-380b36be3352cd9a5c93dbd67db25346166a8547.tar.xz
libgats-380b36be3352cd9a5c93dbd67db25346166a8547.zip
All languages now support Null except for python and php, python is proving
slightly trickier.
Diffstat (limited to 'src')
-rw-r--r--src/null.cpp33
-rw-r--r--src/null.h24
-rw-r--r--src/object.cpp14
-rw-r--r--src/object.h3
-rw-r--r--src/types.h1
-rw-r--r--src/unit/basic.unit21
6 files changed, 95 insertions, 1 deletions
diff --git a/src/null.cpp b/src/null.cpp
new file mode 100644
index 0000000..13a61ed
--- /dev/null
+++ b/src/null.cpp
@@ -0,0 +1,33 @@
1#include "gats/null.h"
2
3#include <bu/formatter.h>
4#include <bu/stream.h>
5
6Gats::Null::Null()
7{
8}
9
10Gats::Null::~Null()
11{
12}
13
14Gats::Object *Gats::Null::clone() const
15{
16 return new Gats::Null();
17}
18
19void Gats::Null::write( Bu::Stream &rOut ) const
20{
21 rOut.write("n", 1 );
22}
23
24void Gats::Null::read( Bu::Stream &rIn, char cType )
25{
26 // Nothing to do...
27}
28
29Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b )
30{
31 return f << "(null)";
32}
33
diff --git a/src/null.h b/src/null.h
new file mode 100644
index 0000000..afa2d0a
--- /dev/null
+++ b/src/null.h
@@ -0,0 +1,24 @@
1#ifndef GATS_NULL_H
2#define GATS_NULL_H
3
4#include "gats/object.h"
5
6namespace Gats
7{
8 class Null : public Gats::Object
9 {
10 public:
11 Null();
12 virtual ~Null();
13
14 virtual Type getType() const { return typeNull; }
15 virtual Object *clone() const;
16
17 virtual void write( Bu::Stream &rOut ) const;
18 virtual void read( Bu::Stream &rIn, char cType );
19 };
20};
21
22Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b );
23
24#endif
diff --git a/src/object.cpp b/src/object.cpp
index 9662b6a..15d7cb5 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -6,6 +6,7 @@
6#include "gats/string.h" 6#include "gats/string.h"
7#include "gats/list.h" 7#include "gats/list.h"
8#include "gats/dictionary.h" 8#include "gats/dictionary.h"
9#include "gats/null.h"
9 10
10#include <stdlib.h> 11#include <stdlib.h>
11 12
@@ -56,6 +57,10 @@ Gats::Object *Gats::Object::read( Bu::Stream &rIn )
56 pObj = new Gats::Float(); 57 pObj = new Gats::Float();
57 break; 58 break;
58 59
60 case 'n':
61 pObj = new Gats::Null();
62 break;
63
59 case 'e': 64 case 'e':
60 return NULL; 65 return NULL;
61 66
@@ -250,6 +255,10 @@ Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i )
250 { 255 {
251 return new Gats::Boolean( false ); 256 return new Gats::Boolean( false );
252 } 257 }
258 else if( st == "null" )
259 {
260 return new Gats::Null();
261 }
253 } 262 }
254 } 263 }
255 } 264 }
@@ -288,6 +297,9 @@ Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj )
288 case Gats::typeBoolean: 297 case Gats::typeBoolean:
289 return f << dynamic_cast<const Gats::Boolean &>(obj); 298 return f << dynamic_cast<const Gats::Boolean &>(obj);
290 299
300 case Gats::typeNull:
301 return f << dynamic_cast<const Gats::Null &>(obj);
302
291 default: 303 default:
292 return f << "***ERROR: Bad Gats type***"; 304 return f << "***ERROR: Bad Gats type***";
293 } 305 }
@@ -303,6 +315,7 @@ Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t )
303 case Gats::typeInteger: return f << "integer"; 315 case Gats::typeInteger: return f << "integer";
304 case Gats::typeFloat: return f << "float"; 316 case Gats::typeFloat: return f << "float";
305 case Gats::typeBoolean: return f << "boolean"; 317 case Gats::typeBoolean: return f << "boolean";
318 case Gats::typeNull: return f << "null";
306 } 319 }
307 320
308 return f << "***unknown***"; 321 return f << "***unknown***";
@@ -318,6 +331,7 @@ const char *Gats::typeToStr( Gats::Type t )
318 case Gats::typeInteger: return "integer"; 331 case Gats::typeInteger: return "integer";
319 case Gats::typeFloat: return "float"; 332 case Gats::typeFloat: return "float";
320 case Gats::typeBoolean: return "boolean"; 333 case Gats::typeBoolean: return "boolean";
334 case Gats::typeNull: return "null";
321 } 335 }
322 336
323 return "***unknown***"; 337 return "***unknown***";
diff --git a/src/object.h b/src/object.h
index b2b1b92..2724189 100644
--- a/src/object.h
+++ b/src/object.h
@@ -18,7 +18,8 @@ namespace Gats
18 typeString, 18 typeString,
19 typeInteger, 19 typeInteger,
20 typeFloat, 20 typeFloat,
21 typeBoolean 21 typeBoolean,
22 typeNull
22 }; 23 };
23 24
24 /** 25 /**
diff --git a/src/types.h b/src/types.h
index e6b23dc..81240e8 100644
--- a/src/types.h
+++ b/src/types.h
@@ -5,3 +5,4 @@
5#include "gats/integer.h" 5#include "gats/integer.h"
6#include "gats/list.h" 6#include "gats/list.h"
7#include "gats/string.h" 7#include "gats/string.h"
8#include "gats/null.h"
diff --git a/src/unit/basic.unit b/src/unit/basic.unit
index 3ab8dc2..2c2c31a 100644
--- a/src/unit/basic.unit
+++ b/src/unit/basic.unit
@@ -12,6 +12,8 @@
12#include "gats/list.h" 12#include "gats/list.h"
13#include "gats/boolean.h" 13#include "gats/boolean.h"
14#include "gats/string.h" 14#include "gats/string.h"
15#include "gats/null.h"
16#include "gats/gatsstream.h"
15 17
16#include "bu/membuf.h" 18#include "bu/membuf.h"
17#include "bu/list.h" 19#include "bu/list.h"
@@ -167,4 +169,23 @@ suite Basic
167 delete pDict; 169 delete pDict;
168 } 170 }
169 } 171 }
172
173 test null
174 {
175 MemBuf mb;
176 {
177 Gats::Null n;
178 Gats::GatsStream gs( mb );
179 gs.writeObject( &n );
180 }
181
182 mb.setPos( 0 );
183
184 {
185 Gats::GatsStream gs( mb );
186 Gats::Object *pObj = gs.readObject();
187 unitTest( pObj->getType() == Gats::typeNull );
188 delete pObj;
189 }
190 }
170} 191}