aboutsummaryrefslogtreecommitdiff
path: root/src/astleaf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/astleaf.cpp')
-rw-r--r--src/astleaf.cpp132
1 files changed, 66 insertions, 66 deletions
diff --git a/src/astleaf.cpp b/src/astleaf.cpp
index c192dbf..f9ede90 100644
--- a/src/astleaf.cpp
+++ b/src/astleaf.cpp
@@ -1,137 +1,137 @@
1#include "astleaf.h" 1#include "astleaf.h"
2 2
3AstLeaf::AstLeaf( const Location &loc, Type eType ) : 3AstLeaf::AstLeaf( const Location &loc, Type eType ) :
4 AstNode( loc, eType ), 4 AstNode( loc, eType ),
5 sVal( NULL ) 5 sVal( NULL )
6{ 6{
7} 7}
8 8
9AstLeaf::AstLeaf( const Location &loc, Type eType, int iNew ) : 9AstLeaf::AstLeaf( const Location &loc, Type eType, int iNew ) :
10 AstNode( loc, eType ), 10 AstNode( loc, eType ),
11 sVal( NULL ) 11 sVal( NULL )
12{ 12{
13 setIntValue( iNew ); 13 setIntValue( iNew );
14} 14}
15 15
16AstLeaf::AstLeaf( const Location &loc, Type eType, float fNew ) : 16AstLeaf::AstLeaf( const Location &loc, Type eType, float fNew ) :
17 AstNode( loc, eType ), 17 AstNode( loc, eType ),
18 sVal( NULL ) 18 sVal( NULL )
19{ 19{
20 setFloatValue( fNew ); 20 setFloatValue( fNew );
21} 21}
22 22
23AstLeaf::AstLeaf( const Location &loc, Type eType, bool bNew ) : 23AstLeaf::AstLeaf( const Location &loc, Type eType, bool bNew ) :
24 AstNode( loc, eType ), 24 AstNode( loc, eType ),
25 sVal( NULL ) 25 sVal( NULL )
26{ 26{
27 setBoolValue( bNew ); 27 setBoolValue( bNew );
28} 28}
29 29
30AstLeaf::AstLeaf( const Location &loc, Type eType, const Bu::String &sNew ) : 30AstLeaf::AstLeaf( const Location &loc, Type eType, const Bu::String &sNew ) :
31 AstNode( loc, eType ), 31 AstNode( loc, eType ),
32 sVal( NULL ) 32 sVal( NULL )
33{ 33{
34 setStrValue( sNew ); 34 setStrValue( sNew );
35} 35}
36 36
37AstLeaf::AstLeaf( const Location &loc, Type eType, const char *sNew ) : 37AstLeaf::AstLeaf( const Location &loc, Type eType, const char *sNew ) :
38 AstNode( loc, eType ), 38 AstNode( loc, eType ),
39 sVal( NULL ) 39 sVal( NULL )
40{ 40{
41 setStrValue( sNew ); 41 setStrValue( sNew );
42} 42}
43 43
44AstLeaf::~AstLeaf() 44AstLeaf::~AstLeaf()
45{ 45{
46 if( getDataType() == typeDataString ) 46 if( getDataType() == typeDataString )
47 delete sVal; 47 delete sVal;
48} 48}
49 49
50void AstLeaf::setIntValue( int iNew ) 50void AstLeaf::setIntValue( int iNew )
51{ 51{
52 if( getDataType() != typeDataInt ) 52 if( getDataType() != typeDataInt )
53 throw Bu::ExceptionBase("Type is not int."); 53 throw Bu::ExceptionBase("Type is not int.");
54 iVal = iNew; 54 iVal = iNew;
55} 55}
56 56
57void AstLeaf::setFloatValue( float fNew ) 57void AstLeaf::setFloatValue( float fNew )
58{ 58{
59 if( getDataType() != typeDataFloat ) 59 if( getDataType() != typeDataFloat )
60 throw Bu::ExceptionBase("Type is not float."); 60 throw Bu::ExceptionBase("Type is not float.");
61 fVal = fNew; 61 fVal = fNew;
62} 62}
63 63
64void AstLeaf::setBoolValue( bool bNew ) 64void AstLeaf::setBoolValue( bool bNew )
65{ 65{
66 if( getDataType() != typeDataBool ) 66 if( getDataType() != typeDataBool )
67 throw Bu::ExceptionBase("Type is not bool."); 67 throw Bu::ExceptionBase("Type is not bool.");
68 bVal = bNew; 68 bVal = bNew;
69} 69}
70 70
71void AstLeaf::setStrValue( const Bu::String &sNew ) 71void AstLeaf::setStrValue( const Bu::String &sNew )
72{ 72{
73 if( getDataType() != typeDataString ) 73 if( getDataType() != typeDataString )
74 throw Bu::ExceptionBase("Type is not string."); 74 throw Bu::ExceptionBase("Type is not string.");
75 if( sVal == NULL ) 75 if( sVal == NULL )
76 sVal = new Bu::String( sNew ); 76 sVal = new Bu::String( sNew );
77 else 77 else
78 *sVal = sNew; 78 *sVal = sNew;
79} 79}
80 80
81int AstLeaf::getIntValue() const 81int AstLeaf::getIntValue() const
82{ 82{
83 if( getDataType() != typeDataInt ) 83 if( getDataType() != typeDataInt )
84 throw Bu::ExceptionBase("Type is not int."); 84 throw Bu::ExceptionBase("Type is not int.");
85 return iVal; 85 return iVal;
86} 86}
87 87
88float AstLeaf::getFloatValue() const 88float AstLeaf::getFloatValue() const
89{ 89{
90 if( getDataType() != typeDataFloat ) 90 if( getDataType() != typeDataFloat )
91 throw Bu::ExceptionBase("Type is not float."); 91 throw Bu::ExceptionBase("Type is not float.");
92 return fVal; 92 return fVal;
93} 93}
94 94
95bool AstLeaf::getBoolValue() const 95bool AstLeaf::getBoolValue() const
96{ 96{
97 if( getDataType() != typeDataBool ) 97 if( getDataType() != typeDataBool )
98 throw Bu::ExceptionBase("Type is not bool."); 98 throw Bu::ExceptionBase("Type is not bool.");
99 return bVal; 99 return bVal;
100} 100}
101 101
102Bu::String &AstLeaf::getStrValue() const 102Bu::String &AstLeaf::getStrValue() const
103{ 103{
104 if( getDataType() != typeDataString ) 104 if( getDataType() != typeDataString )
105 throw Bu::ExceptionBase("Type is not string."); 105 throw Bu::ExceptionBase("Type is not string.");
106 return *sVal; 106 return *sVal;
107} 107}
108 108
109Bu::Formatter &operator<<( Bu::Formatter &f, const AstLeaf &l ) 109Bu::Formatter &operator<<( Bu::Formatter &f, const AstLeaf &l )
110{ 110{
111 switch( l.getDataType() ) 111 switch( l.getDataType() )
112 { 112 {
113 case AstNode::typeDataInt: 113 case AstNode::typeDataInt:
114 f << ": " << l.getIntValue(); 114 f << ": " << l.getIntValue();
115 break; 115 break;
116 116
117 case AstNode::typeDataFloat: 117 case AstNode::typeDataFloat:
118 f << ": " << l.getFloatValue(); 118 f << ": " << l.getFloatValue();
119 break; 119 break;
120 120
121 case AstNode::typeDataBool: 121 case AstNode::typeDataBool:
122 f << ": " << l.getBoolValue(); 122 f << ": " << l.getBoolValue();
123 break; 123 break;
124 124
125 case AstNode::typeDataString: 125 case AstNode::typeDataString:
126 f << ": '" << l.getStrValue() << "'"; 126 f << ": '" << l.getStrValue() << "'";
127 break; 127 break;
128 128
129 case AstNode::typeDataNone: 129 case AstNode::typeDataNone:
130 break; 130 break;
131 131
132 default: 132 default:
133 f << ": " << "!! Invalid Type !!"; 133 f << ": " << "!! Invalid Type !!";
134 } 134 }
135 return f; 135 return f;
136} 136}
137 137