diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-11-01 17:19:44 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-11-01 17:19:44 +0000 |
commit | 76e1ecfabd1f831bc1810aeae65c0faf61d80cee (patch) | |
tree | 50e5f7c8acd7ed30ee19e54c592c12a2a4f69b07 /src | |
parent | 8093111697385c1f9e8f72e2a7f8e12c924670e2 (diff) | |
download | libgats-76e1ecfabd1f831bc1810aeae65c0faf61d80cee.tar.gz libgats-76e1ecfabd1f831bc1810aeae65c0faf61d80cee.tar.bz2 libgats-76e1ecfabd1f831bc1810aeae65c0faf61d80cee.tar.xz libgats-76e1ecfabd1f831bc1810aeae65c0faf61d80cee.zip |
Maybe more minor fixes?
Diffstat (limited to 'src')
-rw-r--r-- | src/dictionary.cpp | 55 | ||||
-rw-r--r-- | src/dictionary.h | 1 | ||||
-rw-r--r-- | src/object.cpp | 30 | ||||
-rw-r--r-- | src/object.h | 3 |
4 files changed, 65 insertions, 24 deletions
diff --git a/src/dictionary.cpp b/src/dictionary.cpp index f3a89c8..9791203 100644 --- a/src/dictionary.cpp +++ b/src/dictionary.cpp | |||
@@ -140,6 +140,13 @@ void Gats::Dictionary::insert( const Bu::FString &sKey, bool b ) | |||
140 | ); | 140 | ); |
141 | }*/ | 141 | }*/ |
142 | 142 | ||
143 | void Gats::Dictionary::insert( const Bu::FString &sKey, float d ) | ||
144 | { | ||
145 | Bu::Hash<Gats::String, Gats::Object *>::insert( | ||
146 | sKey, new Gats::Float( d ) | ||
147 | ); | ||
148 | } | ||
149 | |||
143 | void Gats::Dictionary::insert( const Bu::FString &sKey, double d ) | 150 | void Gats::Dictionary::insert( const Bu::FString &sKey, double d ) |
144 | { | 151 | { |
145 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 152 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
@@ -165,8 +172,8 @@ bool Gats::Dictionary::getBool( const Bu::FString &sKey ) | |||
165 | { | 172 | { |
166 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); | 173 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); |
167 | if( !pOb ) | 174 | if( !pOb ) |
168 | throw Bu::ExceptionBase("Cannot cast item '%s' to bool.", | 175 | throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", |
169 | sKey.getStr() ); | 176 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
170 | 177 | ||
171 | return pOb->getValue(); | 178 | return pOb->getValue(); |
172 | } | 179 | } |
@@ -175,8 +182,8 @@ int64_t Gats::Dictionary::getInt( const Bu::FString &sKey ) | |||
175 | { | 182 | { |
176 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); | 183 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); |
177 | if( !pOb ) | 184 | if( !pOb ) |
178 | throw Bu::ExceptionBase("Cannot cast item '%s' to int.", | 185 | throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", |
179 | sKey.getStr() ); | 186 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
180 | 187 | ||
181 | return pOb->getValue(); | 188 | return pOb->getValue(); |
182 | } | 189 | } |
@@ -185,8 +192,8 @@ double Gats::Dictionary::getFloat( const Bu::FString &sKey ) | |||
185 | { | 192 | { |
186 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); | 193 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); |
187 | if( pOb ) | 194 | if( pOb ) |
188 | throw Bu::ExceptionBase("Cannot cast item '%s' to bool.", | 195 | throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", |
189 | sKey.getStr() ); | 196 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
190 | 197 | ||
191 | return pOb->getValue(); | 198 | return pOb->getValue(); |
192 | } | 199 | } |
@@ -195,8 +202,8 @@ Bu::FString Gats::Dictionary::getStr( const Bu::FString &sKey ) | |||
195 | { | 202 | { |
196 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); | 203 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); |
197 | if( !pOb ) | 204 | if( !pOb ) |
198 | throw Bu::ExceptionBase("Cannot cast item '%s' to string.", | 205 | throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", |
199 | sKey.getStr() ); | 206 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
200 | 207 | ||
201 | return *pOb; | 208 | return *pOb; |
202 | } | 209 | } |
@@ -205,8 +212,8 @@ Gats::List *Gats::Dictionary::getList( const Bu::FString &sKey ) | |||
205 | { | 212 | { |
206 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); | 213 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); |
207 | if( !pOb ) | 214 | if( !pOb ) |
208 | throw Bu::ExceptionBase("Cannot cast item '%s' to list.", | 215 | throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", |
209 | sKey.getStr() ); | 216 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
210 | 217 | ||
211 | return pOb; | 218 | return pOb; |
212 | } | 219 | } |
@@ -215,8 +222,8 @@ Gats::Dictionary *Gats::Dictionary::getDict( const Bu::FString &sKey ) | |||
215 | { | 222 | { |
216 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); | 223 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); |
217 | if( !pOb ) | 224 | if( !pOb ) |
218 | throw Bu::ExceptionBase("Cannot cast item '%s' to dictionary.", | 225 | throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", |
219 | sKey.getStr() ); | 226 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
220 | 227 | ||
221 | return pOb; | 228 | return pOb; |
222 | } | 229 | } |
@@ -225,8 +232,8 @@ bool Gats::Dictionary::getBool( const Bu::FString &sKey ) const | |||
225 | { | 232 | { |
226 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); | 233 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); |
227 | if( !pOb ) | 234 | if( !pOb ) |
228 | throw Bu::ExceptionBase("Cannot cast item '%s' to bool.", | 235 | throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", |
229 | sKey.getStr() ); | 236 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
230 | 237 | ||
231 | return pOb->getValue(); | 238 | return pOb->getValue(); |
232 | } | 239 | } |
@@ -235,8 +242,8 @@ int64_t Gats::Dictionary::getInt( const Bu::FString &sKey ) const | |||
235 | { | 242 | { |
236 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); | 243 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); |
237 | if( !pOb ) | 244 | if( !pOb ) |
238 | throw Bu::ExceptionBase("Cannot cast item '%s' to int.", | 245 | throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", |
239 | sKey.getStr() ); | 246 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
240 | 247 | ||
241 | return pOb->getValue(); | 248 | return pOb->getValue(); |
242 | } | 249 | } |
@@ -245,8 +252,8 @@ double Gats::Dictionary::getFloat( const Bu::FString &sKey ) const | |||
245 | { | 252 | { |
246 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); | 253 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); |
247 | if( pOb ) | 254 | if( pOb ) |
248 | throw Bu::ExceptionBase("Cannot cast item '%s' to bool.", | 255 | throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", |
249 | sKey.getStr() ); | 256 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
250 | 257 | ||
251 | return pOb->getValue(); | 258 | return pOb->getValue(); |
252 | } | 259 | } |
@@ -255,8 +262,8 @@ Bu::FString Gats::Dictionary::getStr( const Bu::FString &sKey ) const | |||
255 | { | 262 | { |
256 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); | 263 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); |
257 | if( !pOb ) | 264 | if( !pOb ) |
258 | throw Bu::ExceptionBase("Cannot cast item '%s' to string.", | 265 | throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", |
259 | sKey.getStr() ); | 266 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
260 | 267 | ||
261 | return *pOb; | 268 | return *pOb; |
262 | } | 269 | } |
@@ -265,8 +272,8 @@ Gats::List *Gats::Dictionary::getList( const Bu::FString &sKey ) const | |||
265 | { | 272 | { |
266 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); | 273 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); |
267 | if( !pOb ) | 274 | if( !pOb ) |
268 | throw Bu::ExceptionBase("Cannot cast item '%s' to list.", | 275 | throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", |
269 | sKey.getStr() ); | 276 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
270 | 277 | ||
271 | return pOb; | 278 | return pOb; |
272 | } | 279 | } |
@@ -275,8 +282,8 @@ Gats::Dictionary *Gats::Dictionary::getDict( const Bu::FString &sKey ) const | |||
275 | { | 282 | { |
276 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); | 283 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); |
277 | if( !pOb ) | 284 | if( !pOb ) |
278 | throw Bu::ExceptionBase("Cannot cast item '%s' to dictionary.", | 285 | throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", |
279 | sKey.getStr() ); | 286 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
280 | 287 | ||
281 | return pOb; | 288 | return pOb; |
282 | } | 289 | } |
diff --git a/src/dictionary.h b/src/dictionary.h index fa11f1d..1197a19 100644 --- a/src/dictionary.h +++ b/src/dictionary.h | |||
@@ -34,6 +34,7 @@ namespace Gats | |||
34 | void insert( const Bu::FString &sKey, unsigned long long i ); | 34 | void insert( const Bu::FString &sKey, unsigned long long i ); |
35 | void insert( const Bu::FString &sKey, signed long long i ); | 35 | void insert( const Bu::FString &sKey, signed long long i ); |
36 | //void insert( const Bu::FString &sKey, bool b ); | 36 | //void insert( const Bu::FString &sKey, bool b ); |
37 | void insert( const Bu::FString &sKey, float d ); | ||
37 | void insert( const Bu::FString &sKey, double d ); | 38 | void insert( const Bu::FString &sKey, double d ); |
38 | using Bu::Hash<Gats::String, Gats::Object *>::insert; | 39 | using Bu::Hash<Gats::String, Gats::Object *>::insert; |
39 | 40 | ||
diff --git a/src/object.cpp b/src/object.cpp index f5148ad..1908904 100644 --- a/src/object.cpp +++ b/src/object.cpp | |||
@@ -89,3 +89,33 @@ Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ) | |||
89 | } | 89 | } |
90 | } | 90 | } |
91 | 91 | ||
92 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ) | ||
93 | { | ||
94 | switch( t ) | ||
95 | { | ||
96 | case Gats::typeDictionary: return f << "dictionary"; | ||
97 | case Gats::typeList: return f << "list"; | ||
98 | case Gats::typeString: return f << "string"; | ||
99 | case Gats::typeInteger: return f << "integer"; | ||
100 | case Gats::typeFloat: return f << "float"; | ||
101 | case Gats::typeBoolean: return f << "boolean"; | ||
102 | } | ||
103 | |||
104 | return f << "***unknown***"; | ||
105 | } | ||
106 | |||
107 | const char *Gats::typeToStr( Gats::Type t ) | ||
108 | { | ||
109 | switch( t ) | ||
110 | { | ||
111 | case Gats::typeDictionary: return "dictionary"; | ||
112 | case Gats::typeList: return "list"; | ||
113 | case Gats::typeString: return "string"; | ||
114 | case Gats::typeInteger: return "integer"; | ||
115 | case Gats::typeFloat: return "float"; | ||
116 | case Gats::typeBoolean: return "boolean"; | ||
117 | } | ||
118 | |||
119 | return "***unknown***"; | ||
120 | } | ||
121 | |||
diff --git a/src/object.h b/src/object.h index 44f9da7..1c114b3 100644 --- a/src/object.h +++ b/src/object.h | |||
@@ -35,8 +35,11 @@ namespace Gats | |||
35 | 35 | ||
36 | static Object *read( Bu::Stream &rIn ); | 36 | static Object *read( Bu::Stream &rIn ); |
37 | }; | 37 | }; |
38 | |||
39 | const char *typeToStr( Type t ); | ||
38 | }; | 40 | }; |
39 | 41 | ||
40 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ); | 42 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ); |
43 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ); | ||
41 | 44 | ||
42 | #endif | 45 | #endif |