aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--c++-qt/src/null.cpp31
-rw-r--r--c++-qt/src/null.h28
-rw-r--r--c++-qt/src/object.cpp5
-rw-r--r--c++-qt/src/object.h3
-rw-r--r--c++-qt/src/types.h1
-rw-r--r--java/com/xagasoft/gats/GatsNull.java40
-rw-r--r--java/com/xagasoft/gats/GatsObject.java5
-rw-r--r--python/gats.py6
-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
14 files changed, 212 insertions, 3 deletions
diff --git a/c++-qt/src/null.cpp b/c++-qt/src/null.cpp
new file mode 100644
index 0000000..f259887
--- /dev/null
+++ b/c++-qt/src/null.cpp
@@ -0,0 +1,31 @@
1#include "gats-qt/null.h"
2
3#include <QIODevice>
4
5Gats::Null::Null()
6{
7}
8
9Gats::Null::~Null()
10{
11}
12
13Gats::Object *Gats::Null::clone() const
14{
15 return new Gats::Null();
16}
17
18void Gats::Null::write( QIODevice &rOut ) const
19{
20 rOut.write("n", 1 );
21}
22
23void Gats::Null::read( QIODevice &rIn, char cType )
24{
25}
26/*
27Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b )
28{
29 return f << "(bool) " << b.getValue();
30}
31*/
diff --git a/c++-qt/src/null.h b/c++-qt/src/null.h
new file mode 100644
index 0000000..354de12
--- /dev/null
+++ b/c++-qt/src/null.h
@@ -0,0 +1,28 @@
1#ifndef GATS_NULL_H
2#define GATS_NULL_H
3
4#include "gats-qt/object.h"
5
6class QIODevice;
7
8namespace Gats
9{
10 class Null : public Gats::Object
11 {
12 Q_OBJECT;
13 public:
14 Null();
15 virtual ~Null();
16
17 virtual Object *clone() const;
18
19 virtual Type getType() const { return typeNull; }
20
21 virtual void write( QIODevice &rOut ) const;
22 virtual void read( QIODevice &rIn, char cType );
23 };
24};
25
26//Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b );
27
28#endif
diff --git a/c++-qt/src/object.cpp b/c++-qt/src/object.cpp
index 3955ced..4290e17 100644
--- a/c++-qt/src/object.cpp
+++ b/c++-qt/src/object.cpp
@@ -6,6 +6,7 @@
6#include "gats-qt/string.h" 6#include "gats-qt/string.h"
7#include "gats-qt/list.h" 7#include "gats-qt/list.h"
8#include "gats-qt/dictionary.h" 8#include "gats-qt/dictionary.h"
9#include "gats-qt/null.h"
9 10
10#include <stdlib.h> 11#include <stdlib.h>
11 12
@@ -52,6 +53,10 @@ Gats::Object *Gats::Object::read( QIODevice &rIn )
52 pObj = new Gats::Float(); 53 pObj = new Gats::Float();
53 break; 54 break;
54 55
56 case 'n':
57 pObj = new Gats::Null();
58 break;
59
55 case 'e': 60 case 'e':
56 return NULL; 61 return NULL;
57 62
diff --git a/c++-qt/src/object.h b/c++-qt/src/object.h
index 10501e4..008ebef 100644
--- a/c++-qt/src/object.h
+++ b/c++-qt/src/object.h
@@ -15,7 +15,8 @@ namespace Gats
15 typeString, 15 typeString,
16 typeInteger, 16 typeInteger,
17 typeFloat, 17 typeFloat,
18 typeBoolean 18 typeBoolean,
19 typeNull
19 }; 20 };
20 21
21 /** 22 /**
diff --git a/c++-qt/src/types.h b/c++-qt/src/types.h
index 1264a9d..bd1c8ae 100644
--- a/c++-qt/src/types.h
+++ b/c++-qt/src/types.h
@@ -5,3 +5,4 @@
5#include "gats-qt/integer.h" 5#include "gats-qt/integer.h"
6#include "gats-qt/list.h" 6#include "gats-qt/list.h"
7#include "gats-qt/string.h" 7#include "gats-qt/string.h"
8#include "gats-qt/null.h"
diff --git a/java/com/xagasoft/gats/GatsNull.java b/java/com/xagasoft/gats/GatsNull.java
new file mode 100644
index 0000000..7919433
--- /dev/null
+++ b/java/com/xagasoft/gats/GatsNull.java
@@ -0,0 +1,40 @@
1package com.xagasoft.gats;
2
3import java.io.InputStream;
4import java.io.OutputStream;
5
6/**
7 * Represents a null value. This is really is the simplest type, GatsBoolean is
8 * a damn liar. This doesn't have any value, it's just null.
9 */
10public class GatsNull extends GatsObject
11{
12 private boolean bValue = false;
13
14 /**
15 * Construct a new GatsNull, the default value is false.
16 */
17 public GatsNull()
18 {
19 }
20
21 public int getType()
22 {
23 return GatsObject.NULL;
24 }
25
26 public String toString()
27 {
28 return "(null)";
29 }
30
31 void read( InputStream is, char cType ) throws java.io.IOException
32 {
33 }
34
35 void write( OutputStream os ) throws java.io.IOException
36 {
37 os.write( (int)'n' );
38 }
39};
40
diff --git a/java/com/xagasoft/gats/GatsObject.java b/java/com/xagasoft/gats/GatsObject.java
index 47602b3..e26ab7b 100644
--- a/java/com/xagasoft/gats/GatsObject.java
+++ b/java/com/xagasoft/gats/GatsObject.java
@@ -18,6 +18,7 @@ public abstract class GatsObject
18 public final static int LIST = 4; 18 public final static int LIST = 4;
19 public final static int DICTIONARY = 5; 19 public final static int DICTIONARY = 5;
20 public final static int BOOLEAN = 6; 20 public final static int BOOLEAN = 6;
21 public final static int NULL = 7;
21 22
22 /** 23 /**
23 * Gets the type of the current object, type can be one of INTEGER, FLOAT, 24 * Gets the type of the current object, type can be one of INTEGER, FLOAT,
@@ -74,6 +75,10 @@ public abstract class GatsObject
74 goRet = new GatsFloat(); 75 goRet = new GatsFloat();
75 break; 76 break;
76 77
78 case 'n':
79 goRet = new GatsNull();
80 break;
81
77 case 'e': 82 case 'e':
78 return null; 83 return null;
79 84
diff --git a/python/gats.py b/python/gats.py
index 40139a2..22463ab 100644
--- a/python/gats.py
+++ b/python/gats.py
@@ -146,6 +146,8 @@ def _readObj( sIn ):
146 return 0.0 146 return 0.0
147 else: 147 else:
148 raise Exception('Invalid exceptional float subtype found.') 148 raise Exception('Invalid exceptional float subtype found.')
149 elif t == 'n':
150 return None
149 elif t == 'e': # End marker 151 elif t == 'e': # End marker
150 return None 152 return None
151 else: 153 else:
@@ -153,7 +155,9 @@ def _readObj( sIn ):
153 return 'not implemented yet'; 155 return 'not implemented yet';
154 156
155def _writeObj( obj, sOut ): 157def _writeObj( obj, sOut ):
156 if isinstance( obj, bool ): 158 if obj is None:
159 sOut.write('n')
160 elif isinstance( obj, bool ):
157 if obj == True: 161 if obj == True:
158 sOut.write('1') 162 sOut.write('1')
159 else: 163 else:
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}