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