From 16a5fdbed6f57d62f2ac44f37988c35319222d79 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 18 Dec 2011 01:26:16 -0700 Subject: Added list & dictionary types to Variable. Also, all the operators to use against other Variables. --- src/variable.cpp | 38 ++++++++++++++++++++++++++++++++++++-- src/variable.h | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/variable.cpp b/src/variable.cpp index 3954ccd..fab0c46 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -1,12 +1,46 @@ #include "variable.h" Variable::Variable() : - eType( Undef ), - bNull( true ), + eType( Null ), iValue( 0 ) { } +Variable::Variable( Type eType ) : + eType( eType ), + iValue( 0 ) +{ + if( eType == String ) + { + sValue = new Bu::String(); + } +} + +Variable::Variable( int64_t iValue ) : + eType( Int ), + iValue( iValue ) +{ +} + +Variable::Variable( double fValue ) : + eType( Float ), + fValue( fValue ) +{ +} + +Variable::Variable( bool bValue ) : + eType( Bool ), + bValue( bValue ) +{ +} + +Variable::Variable( const Bu::String &sValue ) : + eType( String ), + iValue( 0 ) +{ + this->sValue = new Bu::String( sValue ); +} + Variable::~Variable() { if( eType == String ) diff --git a/src/variable.h b/src/variable.h index 3df9255..c9665f5 100644 --- a/src/variable.h +++ b/src/variable.h @@ -4,26 +4,51 @@ #include #include +#include class Variable { public: enum Type { - Undef, + Null, Int, Float, Bool, - String + String, + List, + Dictionary }; public: Variable(); + Variable( Type eType ); + Variable( int64_t iValue ); + Variable( double fValue ); + Variable( bool bValue ); + Variable( const Bu::String &sValue ); virtual ~Variable(); + Variable &operator=( const Variable &rhs ); + Variable &operator+=( const Variable &rhs ); + Variable &operator-=( const Variable &rhs ); + Variable &operator*=( const Variable &rhs ); + Variable &operator/=( const Variable &rhs ); + Variable &operator+( const Variable &rhs ); + Variable &operator-( const Variable &rhs ); + Variable &operator*( const Variable &rhs ); + Variable &operator/( const Variable &rhs ); + Variable &operator!=( const Variable &rhs ); + Variable &operator>( const Variable &rhs ); + Variable &operator<( const Variable &rhs ); + Variable &operator>=( const Variable &rhs ); + Variable &operator<=( const Variable &rhs ); + private: Type eType; - bool bNull; + + typedef Bu::List VList; + typedef Bu::Hash VHash; union { @@ -31,6 +56,8 @@ private: double fValue; bool bValue; Bu::String *sValue; + VList *lValue; + VHash *hValue; }; }; -- cgit v1.2.3