summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-12-18 01:26:16 -0700
committerMike Buland <eichlan@xagasoft.com>2011-12-18 01:26:16 -0700
commit16a5fdbed6f57d62f2ac44f37988c35319222d79 (patch)
tree2e127c3276425fcc4e102db642553086e07f7065 /src
parenteb053bb851d729fbe4db7959143df5cfb2063793 (diff)
downloadstage-16a5fdbed6f57d62f2ac44f37988c35319222d79.tar.gz
stage-16a5fdbed6f57d62f2ac44f37988c35319222d79.tar.bz2
stage-16a5fdbed6f57d62f2ac44f37988c35319222d79.tar.xz
stage-16a5fdbed6f57d62f2ac44f37988c35319222d79.zip
Added list & dictionary types to Variable.
Also, all the operators to use against other Variables.
Diffstat (limited to 'src')
-rw-r--r--src/variable.cpp38
-rw-r--r--src/variable.h33
2 files changed, 66 insertions, 5 deletions
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 @@
1#include "variable.h" 1#include "variable.h"
2 2
3Variable::Variable() : 3Variable::Variable() :
4 eType( Undef ), 4 eType( Null ),
5 bNull( true ),
6 iValue( 0 ) 5 iValue( 0 )
7{ 6{
8} 7}
9 8
9Variable::Variable( Type eType ) :
10 eType( eType ),
11 iValue( 0 )
12{
13 if( eType == String )
14 {
15 sValue = new Bu::String();
16 }
17}
18
19Variable::Variable( int64_t iValue ) :
20 eType( Int ),
21 iValue( iValue )
22{
23}
24
25Variable::Variable( double fValue ) :
26 eType( Float ),
27 fValue( fValue )
28{
29}
30
31Variable::Variable( bool bValue ) :
32 eType( Bool ),
33 bValue( bValue )
34{
35}
36
37Variable::Variable( const Bu::String &sValue ) :
38 eType( String ),
39 iValue( 0 )
40{
41 this->sValue = new Bu::String( sValue );
42}
43
10Variable::~Variable() 44Variable::~Variable()
11{ 45{
12 if( eType == String ) 46 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 @@
4#include <stdint.h> 4#include <stdint.h>
5 5
6#include <bu/string.h> 6#include <bu/string.h>
7#include <bu/hash.h>
7 8
8class Variable 9class Variable
9{ 10{
10public: 11public:
11 enum Type 12 enum Type
12 { 13 {
13 Undef, 14 Null,
14 Int, 15 Int,
15 Float, 16 Float,
16 Bool, 17 Bool,
17 String 18 String,
19 List,
20 Dictionary
18 }; 21 };
19 22
20public: 23public:
21 Variable(); 24 Variable();
25 Variable( Type eType );
26 Variable( int64_t iValue );
27 Variable( double fValue );
28 Variable( bool bValue );
29 Variable( const Bu::String &sValue );
22 virtual ~Variable(); 30 virtual ~Variable();
23 31
32 Variable &operator=( const Variable &rhs );
33 Variable &operator+=( const Variable &rhs );
34 Variable &operator-=( const Variable &rhs );
35 Variable &operator*=( const Variable &rhs );
36 Variable &operator/=( const Variable &rhs );
37 Variable &operator+( const Variable &rhs );
38 Variable &operator-( const Variable &rhs );
39 Variable &operator*( const Variable &rhs );
40 Variable &operator/( const Variable &rhs );
41 Variable &operator!=( const Variable &rhs );
42 Variable &operator>( const Variable &rhs );
43 Variable &operator<( const Variable &rhs );
44 Variable &operator>=( const Variable &rhs );
45 Variable &operator<=( const Variable &rhs );
46
24private: 47private:
25 Type eType; 48 Type eType;
26 bool bNull; 49
50 typedef Bu::List<Variable> VList;
51 typedef Bu::Hash<Variable, Variable> VHash;
27 52
28 union 53 union
29 { 54 {
@@ -31,6 +56,8 @@ private:
31 double fValue; 56 double fValue;
32 bool bValue; 57 bool bValue;
33 Bu::String *sValue; 58 Bu::String *sValue;
59 VList *lValue;
60 VHash *hValue;
34 }; 61 };
35}; 62};
36 63