diff options
Diffstat (limited to '')
-rw-r--r-- | c++-libbu++/src/dictionary.cpp | 373 |
1 files changed, 190 insertions, 183 deletions
diff --git a/c++-libbu++/src/dictionary.cpp b/c++-libbu++/src/dictionary.cpp index b59d652..c6b08a1 100644 --- a/c++-libbu++/src/dictionary.cpp +++ b/c++-libbu++/src/dictionary.cpp | |||
@@ -1,3 +1,10 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libgats library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
1 | #include "gats/dictionary.h" | 8 | #include "gats/dictionary.h" |
2 | 9 | ||
3 | #include "gats/boolean.h" | 10 | #include "gats/boolean.h" |
@@ -11,7 +18,7 @@ | |||
11 | template<> | 18 | template<> |
12 | uint32_t Bu::__calcHashCode<Gats::String>( const Gats::String &s ) | 19 | uint32_t Bu::__calcHashCode<Gats::String>( const Gats::String &s ) |
13 | { | 20 | { |
14 | return __calcHashCode( dynamic_cast<const Bu::String &>(s) ); | 21 | return __calcHashCode( dynamic_cast<const Bu::String &>(s) ); |
15 | } | 22 | } |
16 | 23 | ||
17 | Gats::Dictionary::Dictionary() | 24 | Gats::Dictionary::Dictionary() |
@@ -20,361 +27,361 @@ Gats::Dictionary::Dictionary() | |||
20 | 27 | ||
21 | Gats::Dictionary::~Dictionary() | 28 | Gats::Dictionary::~Dictionary() |
22 | { | 29 | { |
23 | for( iterator i = begin(); i; i++ ) | 30 | for( iterator i = begin(); i; i++ ) |
24 | { | 31 | { |
25 | delete *i; | 32 | delete *i; |
26 | } | 33 | } |
27 | } | 34 | } |
28 | 35 | ||
29 | Gats::Object *Gats::Dictionary::clone() const | 36 | Gats::Object *Gats::Dictionary::clone() const |
30 | { | 37 | { |
31 | Gats::Dictionary *pClone = new Gats::Dictionary; | 38 | Gats::Dictionary *pClone = new Gats::Dictionary; |
32 | for( const_iterator i = begin(); i; i++ ) | 39 | for( const_iterator i = begin(); i; i++ ) |
33 | { | 40 | { |
34 | Bu::String s(i.getKey()); | 41 | Bu::String s(i.getKey()); |
35 | pClone->insert( s.clone(), (*i)->clone() ); | 42 | pClone->insert( s.clone(), (*i)->clone() ); |
36 | } | 43 | } |
37 | 44 | ||
38 | return pClone; | 45 | return pClone; |
39 | } | 46 | } |
40 | 47 | ||
41 | void Gats::Dictionary::write( Bu::Stream &rOut ) const | 48 | void Gats::Dictionary::write( Bu::Stream &rOut ) const |
42 | { | 49 | { |
43 | rOut.write("d", 1 ); | 50 | rOut.write("d", 1 ); |
44 | for( const_iterator i= begin(); i; i++ ) | 51 | for( const_iterator i= begin(); i; i++ ) |
45 | { | 52 | { |
46 | i.getKey().write( rOut ); | 53 | i.getKey().write( rOut ); |
47 | (*i)->write( rOut ); | 54 | (*i)->write( rOut ); |
48 | } | 55 | } |
49 | rOut.write("e", 1 ); | 56 | rOut.write("e", 1 ); |
50 | } | 57 | } |
51 | 58 | ||
52 | void Gats::Dictionary::read( Bu::Stream &rIn, char cType ) | 59 | void Gats::Dictionary::read( Bu::Stream &rIn, char cType ) |
53 | { | 60 | { |
54 | for(;;) | 61 | for(;;) |
55 | { | 62 | { |
56 | char cNext; | 63 | char cNext; |
57 | rIn.read( &cNext, 1 ); | 64 | rIn.read( &cNext, 1 ); |
58 | if( cNext == 'e' ) | 65 | if( cNext == 'e' ) |
59 | break; | 66 | break; |
60 | if( cNext != 's' ) | 67 | if( cNext != 's' ) |
61 | throw Bu::ExceptionBase("You can only use strings as keys."); | 68 | throw Bu::ExceptionBase("You can only use strings as keys."); |
62 | Gats::String sKey; | 69 | Gats::String sKey; |
63 | sKey.read( rIn, cNext ); | 70 | sKey.read( rIn, cNext ); |
64 | 71 | ||
65 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 72 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
66 | sKey, Gats::Object::read( rIn ) | 73 | sKey, Gats::Object::read( rIn ) |
67 | ); | 74 | ); |
68 | } | 75 | } |
69 | } | 76 | } |
70 | 77 | ||
71 | void Gats::Dictionary::insert( const Bu::String &sKey, char i ) | 78 | void Gats::Dictionary::insert( const Bu::String &sKey, char i ) |
72 | { | 79 | { |
73 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 80 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
74 | sKey, new Gats::Integer( i ) | 81 | sKey, new Gats::Integer( i ) |
75 | ); | 82 | ); |
76 | } | 83 | } |
77 | 84 | ||
78 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned char i ) | 85 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned char i ) |
79 | { | 86 | { |
80 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 87 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
81 | sKey, new Gats::Integer( i ) | 88 | sKey, new Gats::Integer( i ) |
82 | ); | 89 | ); |
83 | } | 90 | } |
84 | 91 | ||
85 | void Gats::Dictionary::insert( const Bu::String &sKey, signed char i ) | 92 | void Gats::Dictionary::insert( const Bu::String &sKey, signed char i ) |
86 | { | 93 | { |
87 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 94 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
88 | sKey, new Gats::Integer( i ) | 95 | sKey, new Gats::Integer( i ) |
89 | ); | 96 | ); |
90 | } | 97 | } |
91 | 98 | ||
92 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned short i ) | 99 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned short i ) |
93 | { | 100 | { |
94 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 101 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
95 | sKey, new Gats::Integer( i ) | 102 | sKey, new Gats::Integer( i ) |
96 | ); | 103 | ); |
97 | } | 104 | } |
98 | 105 | ||
99 | void Gats::Dictionary::insert( const Bu::String &sKey, signed short i ) | 106 | void Gats::Dictionary::insert( const Bu::String &sKey, signed short i ) |
100 | { | 107 | { |
101 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 108 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
102 | sKey, new Gats::Integer( i ) | 109 | sKey, new Gats::Integer( i ) |
103 | ); | 110 | ); |
104 | } | 111 | } |
105 | 112 | ||
106 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned int i ) | 113 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned int i ) |
107 | { | 114 | { |
108 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 115 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
109 | sKey, new Gats::Integer( i ) | 116 | sKey, new Gats::Integer( i ) |
110 | ); | 117 | ); |
111 | } | 118 | } |
112 | 119 | ||
113 | void Gats::Dictionary::insert( const Bu::String &sKey, signed int i ) | 120 | void Gats::Dictionary::insert( const Bu::String &sKey, signed int i ) |
114 | { | 121 | { |
115 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 122 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
116 | sKey, new Gats::Integer( i ) | 123 | sKey, new Gats::Integer( i ) |
117 | ); | 124 | ); |
118 | } | 125 | } |
119 | 126 | ||
120 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned long i ) | 127 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned long i ) |
121 | { | 128 | { |
122 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 129 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
123 | sKey, new Gats::Integer( i ) | 130 | sKey, new Gats::Integer( i ) |
124 | ); | 131 | ); |
125 | } | 132 | } |
126 | 133 | ||
127 | void Gats::Dictionary::insert( const Bu::String &sKey, signed long i ) | 134 | void Gats::Dictionary::insert( const Bu::String &sKey, signed long i ) |
128 | { | 135 | { |
129 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 136 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
130 | sKey, new Gats::Integer( i ) | 137 | sKey, new Gats::Integer( i ) |
131 | ); | 138 | ); |
132 | } | 139 | } |
133 | 140 | ||
134 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned long long i ) | 141 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned long long i ) |
135 | { | 142 | { |
136 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 143 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
137 | sKey, new Gats::Integer( i ) | 144 | sKey, new Gats::Integer( i ) |
138 | ); | 145 | ); |
139 | } | 146 | } |
140 | 147 | ||
141 | void Gats::Dictionary::insert( const Bu::String &sKey, signed long long i ) | 148 | void Gats::Dictionary::insert( const Bu::String &sKey, signed long long i ) |
142 | { | 149 | { |
143 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 150 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
144 | sKey, new Gats::Integer( i ) | 151 | sKey, new Gats::Integer( i ) |
145 | ); | 152 | ); |
146 | } | 153 | } |
147 | /* | 154 | /* |
148 | void Gats::Dictionary::insert( const Bu::String &sKey, bool b ) | 155 | void Gats::Dictionary::insert( const Bu::String &sKey, bool b ) |
149 | { | 156 | { |
150 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 157 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
151 | sKey, new Gats::Boolean( b ) | 158 | sKey, new Gats::Boolean( b ) |
152 | ); | 159 | ); |
153 | }*/ | 160 | }*/ |
154 | 161 | ||
155 | void Gats::Dictionary::insert( const Bu::String &sKey, float d ) | 162 | void Gats::Dictionary::insert( const Bu::String &sKey, float d ) |
156 | { | 163 | { |
157 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 164 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
158 | sKey, new Gats::Float( d ) | 165 | sKey, new Gats::Float( d ) |
159 | ); | 166 | ); |
160 | } | 167 | } |
161 | 168 | ||
162 | void Gats::Dictionary::insert( const Bu::String &sKey, double d ) | 169 | void Gats::Dictionary::insert( const Bu::String &sKey, double d ) |
163 | { | 170 | { |
164 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 171 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
165 | sKey, new Gats::Float( d ) | 172 | sKey, new Gats::Float( d ) |
166 | ); | 173 | ); |
167 | } | 174 | } |
168 | 175 | ||
169 | void Gats::Dictionary::insert( const Bu::String &sKey, const char *s ) | 176 | void Gats::Dictionary::insert( const Bu::String &sKey, const char *s ) |
170 | { | 177 | { |
171 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 178 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
172 | sKey, new Gats::String( s ) | 179 | sKey, new Gats::String( s ) |
173 | ); | 180 | ); |
174 | } | 181 | } |
175 | 182 | ||
176 | void Gats::Dictionary::insert( const Bu::String &sKey, const Bu::String &s ) | 183 | void Gats::Dictionary::insert( const Bu::String &sKey, const Bu::String &s ) |
177 | { | 184 | { |
178 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 185 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
179 | sKey, new Gats::String( s ) | 186 | sKey, new Gats::String( s ) |
180 | ); | 187 | ); |
181 | } | 188 | } |
182 | 189 | ||
183 | void Gats::Dictionary::insertBool( const Bu::String &sKey, bool b ) | 190 | void Gats::Dictionary::insertBool( const Bu::String &sKey, bool b ) |
184 | { | 191 | { |
185 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 192 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
186 | sKey, new Gats::Boolean( b ) | 193 | sKey, new Gats::Boolean( b ) |
187 | ); | 194 | ); |
188 | } | 195 | } |
189 | 196 | ||
190 | void Gats::Dictionary::insertInt( const Bu::String &sKey, int64_t i ) | 197 | void Gats::Dictionary::insertInt( const Bu::String &sKey, int64_t i ) |
191 | { | 198 | { |
192 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 199 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
193 | sKey, new Gats::Integer( i ) | 200 | sKey, new Gats::Integer( i ) |
194 | ); | 201 | ); |
195 | } | 202 | } |
196 | 203 | ||
197 | void Gats::Dictionary::insertFloat( const Bu::String &sKey, double d ) | 204 | void Gats::Dictionary::insertFloat( const Bu::String &sKey, double d ) |
198 | { | 205 | { |
199 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 206 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
200 | sKey, new Gats::Float( d ) | 207 | sKey, new Gats::Float( d ) |
201 | ); | 208 | ); |
202 | } | 209 | } |
203 | 210 | ||
204 | void Gats::Dictionary::insertStr( const Bu::String &sKey, const Bu::String &s ) | 211 | void Gats::Dictionary::insertStr( const Bu::String &sKey, const Bu::String &s ) |
205 | { | 212 | { |
206 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 213 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
207 | sKey, new Gats::String( s ) | 214 | sKey, new Gats::String( s ) |
208 | ); | 215 | ); |
209 | } | 216 | } |
210 | 217 | ||
211 | void Gats::Dictionary::insertList( const Bu::String &sKey, Gats::List *pL ) | 218 | void Gats::Dictionary::insertList( const Bu::String &sKey, Gats::List *pL ) |
212 | { | 219 | { |
213 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 220 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
214 | sKey, pL | 221 | sKey, pL |
215 | ); | 222 | ); |
216 | } | 223 | } |
217 | 224 | ||
218 | void Gats::Dictionary::insertDict( const Bu::String &sKey, | 225 | void Gats::Dictionary::insertDict( const Bu::String &sKey, |
219 | Gats::Dictionary *pD ) | 226 | Gats::Dictionary *pD ) |
220 | { | 227 | { |
221 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 228 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
222 | sKey, pD | 229 | sKey, pD |
223 | ); | 230 | ); |
224 | } | 231 | } |
225 | 232 | ||
226 | Gats::List *Gats::Dictionary::insertList( const Bu::String &sKey ) | 233 | Gats::List *Gats::Dictionary::insertList( const Bu::String &sKey ) |
227 | { | 234 | { |
228 | Gats::List *pLst = new Gats::List(); | 235 | Gats::List *pLst = new Gats::List(); |
229 | insertList( sKey, pLst ); | 236 | insertList( sKey, pLst ); |
230 | return pLst; | 237 | return pLst; |
231 | } | 238 | } |
232 | 239 | ||
233 | Gats::Dictionary *Gats::Dictionary::insertDict( const Bu::String &sKey ) | 240 | Gats::Dictionary *Gats::Dictionary::insertDict( const Bu::String &sKey ) |
234 | { | 241 | { |
235 | Gats::Dictionary *pDict = new Gats::Dictionary(); | 242 | Gats::Dictionary *pDict = new Gats::Dictionary(); |
236 | insertDict( sKey, pDict ); | 243 | insertDict( sKey, pDict ); |
237 | return pDict; | 244 | return pDict; |
238 | } | 245 | } |
239 | 246 | ||
240 | bool Gats::Dictionary::getBool( const Bu::String &sKey ) | 247 | bool Gats::Dictionary::getBool( const Bu::String &sKey ) |
241 | { | 248 | { |
242 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); | 249 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); |
243 | if( !pOb ) | 250 | if( !pOb ) |
244 | throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", | 251 | throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", |
245 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 252 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
246 | 253 | ||
247 | return pOb->getValue(); | 254 | return pOb->getValue(); |
248 | } | 255 | } |
249 | 256 | ||
250 | int64_t Gats::Dictionary::getInt( const Bu::String &sKey ) | 257 | int64_t Gats::Dictionary::getInt( const Bu::String &sKey ) |
251 | { | 258 | { |
252 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); | 259 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); |
253 | if( !pOb ) | 260 | if( !pOb ) |
254 | throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", | 261 | throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", |
255 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 262 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
256 | 263 | ||
257 | return pOb->getValue(); | 264 | return pOb->getValue(); |
258 | } | 265 | } |
259 | 266 | ||
260 | double Gats::Dictionary::getFloat( const Bu::String &sKey ) | 267 | double Gats::Dictionary::getFloat( const Bu::String &sKey ) |
261 | { | 268 | { |
262 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); | 269 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); |
263 | if( !pOb ) | 270 | if( !pOb ) |
264 | throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", | 271 | throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", |
265 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 272 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
266 | 273 | ||
267 | return pOb->getValue(); | 274 | return pOb->getValue(); |
268 | } | 275 | } |
269 | 276 | ||
270 | Bu::String Gats::Dictionary::getStr( const Bu::String &sKey ) | 277 | Bu::String Gats::Dictionary::getStr( const Bu::String &sKey ) |
271 | { | 278 | { |
272 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); | 279 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); |
273 | if( !pOb ) | 280 | if( !pOb ) |
274 | throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", | 281 | throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", |
275 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 282 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
276 | 283 | ||
277 | return *pOb; | 284 | return *pOb; |
278 | } | 285 | } |
279 | 286 | ||
280 | Gats::List *Gats::Dictionary::getList( const Bu::String &sKey ) | 287 | Gats::List *Gats::Dictionary::getList( const Bu::String &sKey ) |
281 | { | 288 | { |
282 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); | 289 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); |
283 | if( !pOb ) | 290 | if( !pOb ) |
284 | throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", | 291 | throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", |
285 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 292 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
286 | 293 | ||
287 | return pOb; | 294 | return pOb; |
288 | } | 295 | } |
289 | 296 | ||
290 | Gats::Dictionary *Gats::Dictionary::getDict( const Bu::String &sKey ) | 297 | Gats::Dictionary *Gats::Dictionary::getDict( const Bu::String &sKey ) |
291 | { | 298 | { |
292 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); | 299 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); |
293 | if( !pOb ) | 300 | if( !pOb ) |
294 | throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", | 301 | throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", |
295 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 302 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
296 | 303 | ||
297 | return pOb; | 304 | return pOb; |
298 | } | 305 | } |
299 | 306 | ||
300 | bool Gats::Dictionary::getBool( const Bu::String &sKey ) const | 307 | bool Gats::Dictionary::getBool( const Bu::String &sKey ) const |
301 | { | 308 | { |
302 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); | 309 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); |
303 | if( !pOb ) | 310 | if( !pOb ) |
304 | throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", | 311 | throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", |
305 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 312 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
306 | 313 | ||
307 | return pOb->getValue(); | 314 | return pOb->getValue(); |
308 | } | 315 | } |
309 | 316 | ||
310 | int64_t Gats::Dictionary::getInt( const Bu::String &sKey ) const | 317 | int64_t Gats::Dictionary::getInt( const Bu::String &sKey ) const |
311 | { | 318 | { |
312 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); | 319 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); |
313 | if( !pOb ) | 320 | if( !pOb ) |
314 | throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", | 321 | throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", |
315 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 322 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
316 | 323 | ||
317 | return pOb->getValue(); | 324 | return pOb->getValue(); |
318 | } | 325 | } |
319 | 326 | ||
320 | double Gats::Dictionary::getFloat( const Bu::String &sKey ) const | 327 | double Gats::Dictionary::getFloat( const Bu::String &sKey ) const |
321 | { | 328 | { |
322 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); | 329 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); |
323 | if( !pOb ) | 330 | if( !pOb ) |
324 | throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", | 331 | throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", |
325 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 332 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
326 | 333 | ||
327 | return pOb->getValue(); | 334 | return pOb->getValue(); |
328 | } | 335 | } |
329 | 336 | ||
330 | Bu::String Gats::Dictionary::getStr( const Bu::String &sKey ) const | 337 | Bu::String Gats::Dictionary::getStr( const Bu::String &sKey ) const |
331 | { | 338 | { |
332 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); | 339 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); |
333 | if( !pOb ) | 340 | if( !pOb ) |
334 | throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", | 341 | throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", |
335 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 342 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
336 | 343 | ||
337 | return *pOb; | 344 | return *pOb; |
338 | } | 345 | } |
339 | 346 | ||
340 | Gats::List *Gats::Dictionary::getList( const Bu::String &sKey ) const | 347 | Gats::List *Gats::Dictionary::getList( const Bu::String &sKey ) const |
341 | { | 348 | { |
342 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); | 349 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); |
343 | if( !pOb ) | 350 | if( !pOb ) |
344 | throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", | 351 | throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", |
345 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 352 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
346 | 353 | ||
347 | return pOb; | 354 | return pOb; |
348 | } | 355 | } |
349 | 356 | ||
350 | Gats::Dictionary *Gats::Dictionary::getDict( const Bu::String &sKey ) const | 357 | Gats::Dictionary *Gats::Dictionary::getDict( const Bu::String &sKey ) const |
351 | { | 358 | { |
352 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); | 359 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); |
353 | if( !pOb ) | 360 | if( !pOb ) |
354 | throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", | 361 | throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", |
355 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 362 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
356 | 363 | ||
357 | return pOb; | 364 | return pOb; |
358 | } | 365 | } |
359 | 366 | ||
360 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ) | 367 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ) |
361 | { | 368 | { |
362 | f << "(dict) {"; | 369 | f << "(dict) {"; |
363 | f.incIndent(); | 370 | f.incIndent(); |
364 | int iMax = 0; | 371 | int iMax = 0; |
365 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) | 372 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) |
366 | { | 373 | { |
367 | if( i.getKey().getSize() > iMax ) | 374 | if( i.getKey().getSize() > iMax ) |
368 | iMax = i.getKey().getSize(); | 375 | iMax = i.getKey().getSize(); |
369 | } | 376 | } |
370 | iMax += 2; | 377 | iMax += 2; |
371 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) | 378 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) |
372 | { | 379 | { |
373 | f << f.nl << Bu::Fmt( iMax ) << i.getKey() + ": " << *i.getValue(); | 380 | f << f.nl << Bu::Fmt( iMax ) << i.getKey() + ": " << *i.getValue(); |
374 | } | 381 | } |
375 | f.decIndent(); | 382 | f.decIndent(); |
376 | f << f.nl << "}"; | 383 | f << f.nl << "}"; |
377 | 384 | ||
378 | return f; | 385 | return f; |
379 | } | 386 | } |
380 | 387 | ||