From 380b36be3352cd9a5c93dbd67db25346166a8547 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 11 Jun 2012 04:05:22 +0000 Subject: All languages now support Null except for python and php, python is proving slightly trickier. --- src/null.cpp | 33 +++++++++++++++++++++++++++++++++ src/null.h | 24 ++++++++++++++++++++++++ src/object.cpp | 14 ++++++++++++++ src/object.h | 3 ++- src/types.h | 1 + src/unit/basic.unit | 21 +++++++++++++++++++++ 6 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/null.cpp create mode 100644 src/null.h (limited to 'src') 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 @@ +#include "gats/null.h" + +#include +#include + +Gats::Null::Null() +{ +} + +Gats::Null::~Null() +{ +} + +Gats::Object *Gats::Null::clone() const +{ + return new Gats::Null(); +} + +void Gats::Null::write( Bu::Stream &rOut ) const +{ + rOut.write("n", 1 ); +} + +void Gats::Null::read( Bu::Stream &rIn, char cType ) +{ + // Nothing to do... +} + +Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ) +{ + return f << "(null)"; +} + 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 @@ +#ifndef GATS_NULL_H +#define GATS_NULL_H + +#include "gats/object.h" + +namespace Gats +{ + class Null : public Gats::Object + { + public: + Null(); + virtual ~Null(); + + virtual Type getType() const { return typeNull; } + virtual Object *clone() const; + + virtual void write( Bu::Stream &rOut ) const; + virtual void read( Bu::Stream &rIn, char cType ); + }; +}; + +Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ); + +#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 @@ #include "gats/string.h" #include "gats/list.h" #include "gats/dictionary.h" +#include "gats/null.h" #include @@ -56,6 +57,10 @@ Gats::Object *Gats::Object::read( Bu::Stream &rIn ) pObj = new Gats::Float(); break; + case 'n': + pObj = new Gats::Null(); + break; + case 'e': return NULL; @@ -250,6 +255,10 @@ Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i ) { return new Gats::Boolean( false ); } + else if( st == "null" ) + { + return new Gats::Null(); + } } } } @@ -288,6 +297,9 @@ Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ) case Gats::typeBoolean: return f << dynamic_cast(obj); + case Gats::typeNull: + return f << dynamic_cast(obj); + default: return f << "***ERROR: Bad Gats type***"; } @@ -303,6 +315,7 @@ Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ) case Gats::typeInteger: return f << "integer"; case Gats::typeFloat: return f << "float"; case Gats::typeBoolean: return f << "boolean"; + case Gats::typeNull: return f << "null"; } return f << "***unknown***"; @@ -318,6 +331,7 @@ const char *Gats::typeToStr( Gats::Type t ) case Gats::typeInteger: return "integer"; case Gats::typeFloat: return "float"; case Gats::typeBoolean: return "boolean"; + case Gats::typeNull: return "null"; } 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 typeString, typeInteger, typeFloat, - typeBoolean + typeBoolean, + typeNull }; /** 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 @@ #include "gats/integer.h" #include "gats/list.h" #include "gats/string.h" +#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 @@ #include "gats/list.h" #include "gats/boolean.h" #include "gats/string.h" +#include "gats/null.h" +#include "gats/gatsstream.h" #include "bu/membuf.h" #include "bu/list.h" @@ -167,4 +169,23 @@ suite Basic delete pDict; } } + + test null + { + MemBuf mb; + { + Gats::Null n; + Gats::GatsStream gs( mb ); + gs.writeObject( &n ); + } + + mb.setPos( 0 ); + + { + Gats::GatsStream gs( mb ); + Gats::Object *pObj = gs.readObject(); + unitTest( pObj->getType() == Gats::typeNull ); + delete pObj; + } + } } -- cgit v1.2.3