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