aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mbuland@penny-arcade.com>2017-06-05 07:39:05 -0700
committerMike Buland <mbuland@penny-arcade.com>2017-06-05 07:39:05 -0700
commit19223f8527ef1c0d36cf8b40b9f8d093ea702ca5 (patch)
treed59222d22d96318948b52329e2ee4ec0e0745d1a
parentae3649ec44e9c08dac7553031573ea52c1dfdd82 (diff)
downloadlibgats-19223f8527ef1c0d36cf8b40b9f8d093ea702ca5.tar.gz
libgats-19223f8527ef1c0d36cf8b40b9f8d093ea702ca5.tar.bz2
libgats-19223f8527ef1c0d36cf8b40b9f8d093ea702ca5.tar.xz
libgats-19223f8527ef1c0d36cf8b40b9f8d093ea702ca5.zip
Added better null helpers to libbu++/php
-rw-r--r--.gitignore4
-rw-r--r--c++-libbu++/src/dictionary.cpp25
-rw-r--r--c++-libbu++/src/dictionary.h3
-rw-r--r--php/phpgats2.php11
4 files changed, 41 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 6020bc1..bfa871f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,11 @@
1*.o 1*.o
2*.a 2*.a
3.*.swp 3.*.swp
4.*.un~
5/c++-libbu++/.build_cache
4/c++-libbu++/gats 6/c++-libbu++/gats
7/c++-libbu++/gatsc
8/c++-libbu++/src/version.h
5/c++-qt/Makefile* 9/c++-qt/Makefile*
6*.dll 10*.dll
7/c++-qt/object_script.* 11/c++-qt/object_script.*
diff --git a/c++-libbu++/src/dictionary.cpp b/c++-libbu++/src/dictionary.cpp
index 5ed3834..00d06f7 100644
--- a/c++-libbu++/src/dictionary.cpp
+++ b/c++-libbu++/src/dictionary.cpp
@@ -12,6 +12,7 @@
12#include "gats/float.h" 12#include "gats/float.h"
13#include "gats/string.h" 13#include "gats/string.h"
14#include "gats/list.h" 14#include "gats/list.h"
15#include "gats/null.h"
15 16
16#include <bu/formatter.h> 17#include <bu/formatter.h>
17 18
@@ -249,6 +250,22 @@ Gats::Dictionary *Gats::Dictionary::insertDict( const Bu::String &sKey )
249 return pDict; 250 return pDict;
250} 251}
251 252
253void Gats::Dictionary::insertNull( const Bu::String &sKey )
254{
255 Bu::Hash<Gats::String, Gats::Object *>::insert(
256 sKey,
257 new Gats::Null()
258 );
259}
260
261bool Gats::Dictionary::isNull( const Bu::String &sKey )
262{
263 Gats::Object *pObj = get( sKey );
264 if( pObj->getType() == Gats::typeNull )
265 return true;
266 return false;
267}
268
252bool Gats::Dictionary::getBool( const Bu::String &sKey ) 269bool Gats::Dictionary::getBool( const Bu::String &sKey )
253{ 270{
254 Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); 271 Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) );
@@ -309,6 +326,14 @@ Gats::Dictionary *Gats::Dictionary::getDict( const Bu::String &sKey )
309 return pOb; 326 return pOb;
310} 327}
311 328
329bool Gats::Dictionary::isNull( const Bu::String &sKey ) const
330{
331 Gats::Object *pObj = get( sKey );
332 if( pObj->getType() == Gats::typeNull )
333 return true;
334 return false;
335}
336
312bool Gats::Dictionary::getBool( const Bu::String &sKey ) const 337bool Gats::Dictionary::getBool( const Bu::String &sKey ) const
313{ 338{
314 Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); 339 Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) );
diff --git a/c++-libbu++/src/dictionary.h b/c++-libbu++/src/dictionary.h
index d2cdec0..84cf69f 100644
--- a/c++-libbu++/src/dictionary.h
+++ b/c++-libbu++/src/dictionary.h
@@ -54,7 +54,9 @@ namespace Gats
54 void insertDict( const Bu::String &sKey, Gats::Dictionary *pD ); 54 void insertDict( const Bu::String &sKey, Gats::Dictionary *pD );
55 Gats::List *insertList( const Bu::String &sKey ); 55 Gats::List *insertList( const Bu::String &sKey );
56 Gats::Dictionary *insertDict( const Bu::String &sKey ); 56 Gats::Dictionary *insertDict( const Bu::String &sKey );
57 void insertNull( const Bu::String &sKey );
57 58
59 bool isNull( const Bu::String &sKey );
58 bool getBool( const Bu::String &sKey ); 60 bool getBool( const Bu::String &sKey );
59 int64_t getInt( const Bu::String &sKey ); 61 int64_t getInt( const Bu::String &sKey );
60 double getFloat( const Bu::String &sKey ); 62 double getFloat( const Bu::String &sKey );
@@ -62,6 +64,7 @@ namespace Gats
62 Gats::List *getList( const Bu::String &sKey ); 64 Gats::List *getList( const Bu::String &sKey );
63 Gats::Dictionary *getDict( const Bu::String &sKey ); 65 Gats::Dictionary *getDict( const Bu::String &sKey );
64 66
67 bool isNull( const Bu::String &sKey ) const;
65 bool getBool( const Bu::String &sKey ) const; 68 bool getBool( const Bu::String &sKey ) const;
66 int64_t getInt( const Bu::String &sKey ) const; 69 int64_t getInt( const Bu::String &sKey ) const;
67 double getFloat( const Bu::String &sKey ) const; 70 double getFloat( const Bu::String &sKey ) const;
diff --git a/php/phpgats2.php b/php/phpgats2.php
index effaa78..f97bd89 100644
--- a/php/phpgats2.php
+++ b/php/phpgats2.php
@@ -237,7 +237,11 @@ function _phpgats2_writeDictionary( $d )
237 237
238function _phpgats2__write( $unknown ) 238function _phpgats2__write( $unknown )
239{ 239{
240 if( is_bool( $unknown ) ) 240 if( is_null( $unknown ) )
241 {
242 return 'n';
243 }
244 else if( is_bool( $unknown ) )
241 { 245 {
242 return _phpgats2_writeBoolean( $unknown ); 246 return _phpgats2_writeBoolean( $unknown );
243 } 247 }
@@ -462,7 +466,10 @@ function _phpgats2_parseMaster( $str_data, &$offset, $dbg=0 )
462 case '0': 466 case '0':
463 //echo "false\n"; 467 //echo "false\n";
464 return false; 468 return false;
465 break; 469 break;
470 case 'n':
471 return null;
472 break;
466 default: 473 default:
467 //echo "str:"; 474 //echo "str:";
468 $obj = _phpgats2_parseString( $str_data, $offset, $dbg ); 475 $obj = _phpgats2_parseString( $str_data, $offset, $dbg );