diff options
Diffstat (limited to '')
30 files changed, 1670 insertions, 0 deletions
diff --git a/c++-qt/gats-qt/boolean.h b/c++-qt/gats-qt/boolean.h new file mode 120000 index 0000000..27e9ba3 --- /dev/null +++ b/c++-qt/gats-qt/boolean.h | |||
@@ -0,0 +1 @@ | |||
../src/boolean.h \ No newline at end of file | |||
diff --git a/c++-qt/gats-qt/dictionary.h b/c++-qt/gats-qt/dictionary.h new file mode 120000 index 0000000..cdca1b6 --- /dev/null +++ b/c++-qt/gats-qt/dictionary.h | |||
@@ -0,0 +1 @@ | |||
../src/dictionary.h \ No newline at end of file | |||
diff --git a/c++-qt/gats-qt/float.h b/c++-qt/gats-qt/float.h new file mode 120000 index 0000000..6d057eb --- /dev/null +++ b/c++-qt/gats-qt/float.h | |||
@@ -0,0 +1 @@ | |||
../src/float.h \ No newline at end of file | |||
diff --git a/c++-qt/gats-qt/gatsstream.h b/c++-qt/gats-qt/gatsstream.h new file mode 120000 index 0000000..38d4d0e --- /dev/null +++ b/c++-qt/gats-qt/gatsstream.h | |||
@@ -0,0 +1 @@ | |||
../src/gatsstream.h \ No newline at end of file | |||
diff --git a/c++-qt/gats-qt/integer.h b/c++-qt/gats-qt/integer.h new file mode 120000 index 0000000..a2bfb2d --- /dev/null +++ b/c++-qt/gats-qt/integer.h | |||
@@ -0,0 +1 @@ | |||
../src/integer.h \ No newline at end of file | |||
diff --git a/c++-qt/gats-qt/list.h b/c++-qt/gats-qt/list.h new file mode 120000 index 0000000..1a01fc0 --- /dev/null +++ b/c++-qt/gats-qt/list.h | |||
@@ -0,0 +1 @@ | |||
../src/list.h \ No newline at end of file | |||
diff --git a/c++-qt/gats-qt/object.h b/c++-qt/gats-qt/object.h new file mode 120000 index 0000000..04b70ec --- /dev/null +++ b/c++-qt/gats-qt/object.h | |||
@@ -0,0 +1 @@ | |||
../src/object.h \ No newline at end of file | |||
diff --git a/c++-qt/gats-qt/protocolgats.h b/c++-qt/gats-qt/protocolgats.h new file mode 120000 index 0000000..034a523 --- /dev/null +++ b/c++-qt/gats-qt/protocolgats.h | |||
@@ -0,0 +1 @@ | |||
../src/protocolgats.h \ No newline at end of file | |||
diff --git a/c++-qt/gats-qt/string.h b/c++-qt/gats-qt/string.h new file mode 120000 index 0000000..ef7336d --- /dev/null +++ b/c++-qt/gats-qt/string.h | |||
@@ -0,0 +1 @@ | |||
../src/string.h \ No newline at end of file | |||
diff --git a/c++-qt/gats-qt/types.h b/c++-qt/gats-qt/types.h new file mode 120000 index 0000000..a21c97e --- /dev/null +++ b/c++-qt/gats-qt/types.h | |||
@@ -0,0 +1 @@ | |||
../src/types.h \ No newline at end of file | |||
diff --git a/c++-qt/gats-qt/version.h b/c++-qt/gats-qt/version.h new file mode 120000 index 0000000..0489181 --- /dev/null +++ b/c++-qt/gats-qt/version.h | |||
@@ -0,0 +1 @@ | |||
../src/version.h \ No newline at end of file | |||
diff --git a/c++-qt/libgats.pro b/c++-qt/libgats.pro new file mode 100644 index 0000000..dea8c9d --- /dev/null +++ b/c++-qt/libgats.pro | |||
@@ -0,0 +1,11 @@ | |||
1 | TEMPLATE = lib | ||
2 | TARGET = gats-qt | ||
3 | RCC_DIR = tmp/qrc | ||
4 | UI_DIR = tmp/ui | ||
5 | MOC_DIR = tmp/moc | ||
6 | OBJECTS_DIR = tmp/obj | ||
7 | QMAKE_CXXFLAGS += -ggdb -W -Wall | ||
8 | |||
9 | HEADERS += src/*.h | ||
10 | SOURCES += src/*.cpp | ||
11 | |||
diff --git a/c++-qt/src/boolean.cpp b/c++-qt/src/boolean.cpp new file mode 100644 index 0000000..9610f50 --- /dev/null +++ b/c++-qt/src/boolean.cpp | |||
@@ -0,0 +1,47 @@ | |||
1 | #include "gats-qt/boolean.h" | ||
2 | |||
3 | #include <QIODevice> | ||
4 | |||
5 | Gats::Boolean::Boolean() : | ||
6 | bVal( false ) | ||
7 | { | ||
8 | } | ||
9 | |||
10 | Gats::Boolean::Boolean( bool bVal ) : | ||
11 | bVal( bVal ) | ||
12 | { | ||
13 | } | ||
14 | |||
15 | Gats::Boolean::~Boolean() | ||
16 | { | ||
17 | } | ||
18 | |||
19 | void Gats::Boolean::write( QIODevice &rOut ) const | ||
20 | { | ||
21 | if( bVal ) | ||
22 | { | ||
23 | rOut.write("1", 1 ); | ||
24 | } | ||
25 | else | ||
26 | { | ||
27 | rOut.write("0", 1 ); | ||
28 | } | ||
29 | } | ||
30 | |||
31 | void Gats::Boolean::read( QIODevice &rIn, char cType ) | ||
32 | { | ||
33 | if( cType == '1' ) | ||
34 | { | ||
35 | bVal = true; | ||
36 | } | ||
37 | else | ||
38 | { | ||
39 | bVal = false; | ||
40 | } | ||
41 | } | ||
42 | /* | ||
43 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ) | ||
44 | { | ||
45 | return f << "(bool) " << b.getValue(); | ||
46 | } | ||
47 | */ | ||
diff --git a/c++-qt/src/boolean.h b/c++-qt/src/boolean.h new file mode 100644 index 0000000..4eec690 --- /dev/null +++ b/c++-qt/src/boolean.h | |||
@@ -0,0 +1,32 @@ | |||
1 | #ifndef GATS_BOOLEAN_H | ||
2 | #define GATS_BOOLEAN_H | ||
3 | |||
4 | #include "gats-qt/object.h" | ||
5 | |||
6 | class QIODevice; | ||
7 | |||
8 | namespace Gats | ||
9 | { | ||
10 | class Boolean : public Gats::Object | ||
11 | { | ||
12 | Q_OBJECT; | ||
13 | public: | ||
14 | Boolean(); | ||
15 | Boolean( bool bVal ); | ||
16 | virtual ~Boolean(); | ||
17 | |||
18 | virtual Type getType() const { return typeBoolean; } | ||
19 | bool getValue() const { return bVal; } | ||
20 | void setValue( bool b ) { bVal = b; } | ||
21 | |||
22 | virtual void write( QIODevice &rOut ) const; | ||
23 | virtual void read( QIODevice &rIn, char cType ); | ||
24 | |||
25 | private: | ||
26 | bool bVal; | ||
27 | }; | ||
28 | }; | ||
29 | |||
30 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ); | ||
31 | |||
32 | #endif | ||
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 | |||
9 | Gats::Dictionary::Dictionary() | ||
10 | { | ||
11 | } | ||
12 | |||
13 | Gats::Dictionary::~Dictionary() | ||
14 | { | ||
15 | for( iterator i = begin(); i != end(); i++ ) | ||
16 | { | ||
17 | delete *i; | ||
18 | } | ||
19 | } | ||
20 | |||
21 | void 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 | |||
33 | void 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 | |||
52 | void 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 | |||
59 | void 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 | |||
66 | void 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 | |||
73 | void 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 | |||
80 | void 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 | |||
87 | void 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 | |||
94 | void 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 | |||
101 | void 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 | |||
108 | void 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 | |||
115 | void 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 | |||
122 | void 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 | /* | ||
129 | void Gats::Dictionary::insert( const QByteArray &sKey, bool b ) | ||
130 | { | ||
131 | QHash<QByteArray, Gats::Object *>::insert( | ||
132 | sKey, new Gats::Boolean( b ) | ||
133 | ); | ||
134 | }*/ | ||
135 | |||
136 | void Gats::Dictionary::insert( const QByteArray &sKey, float d ) | ||
137 | { | ||
138 | QHash<QByteArray, Gats::Object *>::insert( | ||
139 | sKey, new Gats::Float( d ) | ||
140 | ); | ||
141 | } | ||
142 | |||
143 | void Gats::Dictionary::insert( const QByteArray &sKey, double d ) | ||
144 | { | ||
145 | QHash<QByteArray, Gats::Object *>::insert( | ||
146 | sKey, new Gats::Float( d ) | ||
147 | ); | ||
148 | } | ||
149 | |||
150 | void 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 | |||
157 | void 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 | |||
164 | void Gats::Dictionary::insertBool( const QByteArray &sKey, bool b ) | ||
165 | { | ||
166 | QHash<QByteArray, Gats::Object *>::insert( | ||
167 | sKey, new Gats::Boolean( b ) | ||
168 | ); | ||
169 | } | ||
170 | |||
171 | void 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 | |||
178 | void Gats::Dictionary::insertFloat( const QByteArray &sKey, double d ) | ||
179 | { | ||
180 | QHash<QByteArray, Gats::Object *>::insert( | ||
181 | sKey, new Gats::Float( d ) | ||
182 | ); | ||
183 | } | ||
184 | |||
185 | void 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 | |||
192 | void Gats::Dictionary::insertList( const QByteArray &sKey, Gats::List *pL ) | ||
193 | { | ||
194 | QHash<QByteArray, Gats::Object *>::insert( | ||
195 | sKey, pL | ||
196 | ); | ||
197 | } | ||
198 | |||
199 | void Gats::Dictionary::insertDict( const QByteArray &sKey, | ||
200 | Gats::Dictionary *pD ) | ||
201 | { | ||
202 | QHash<QByteArray, Gats::Object *>::insert( | ||
203 | sKey, pD | ||
204 | ); | ||
205 | } | ||
206 | |||
207 | Gats::List *Gats::Dictionary::insertList( const QByteArray &sKey ) | ||
208 | { | ||
209 | Gats::List *pLst = new Gats::List(); | ||
210 | insertList( sKey, pLst ); | ||
211 | return pLst; | ||
212 | } | ||
213 | |||
214 | Gats::Dictionary *Gats::Dictionary::insertDict( const QByteArray &sKey ) | ||
215 | { | ||
216 | Gats::Dictionary *pDict = new Gats::Dictionary(); | ||
217 | insertDict( sKey, pDict ); | ||
218 | return pDict; | ||
219 | } | ||
220 | |||
221 | bool 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 | |||
230 | int64_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 | |||
239 | double 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 | |||
248 | QByteArray 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 | |||
257 | Gats::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 | |||
266 | Gats::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 | |||
275 | bool 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 | |||
284 | int64_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 | |||
293 | double 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 | |||
302 | QByteArray 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 | |||
311 | Gats::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 | |||
320 | Gats::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 | /* | ||
329 | Bu::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 | */ | ||
diff --git a/c++-qt/src/dictionary.h b/c++-qt/src/dictionary.h new file mode 100644 index 0000000..6db94b2 --- /dev/null +++ b/c++-qt/src/dictionary.h | |||
@@ -0,0 +1,68 @@ | |||
1 | #ifndef GATS_DICTIONARY_H | ||
2 | #define GATS_DICTIONARY_H | ||
3 | |||
4 | #include "gats-qt/object.h" | ||
5 | #include "gats-qt/string.h" | ||
6 | #include <QHash> | ||
7 | |||
8 | namespace Gats | ||
9 | { | ||
10 | class List; | ||
11 | |||
12 | class Dictionary : public Gats::Object, | ||
13 | public QHash<QByteArray, Gats::Object *> | ||
14 | { | ||
15 | Q_OBJECT; | ||
16 | public: | ||
17 | Dictionary(); | ||
18 | virtual ~Dictionary(); | ||
19 | |||
20 | virtual Type getType() const { return typeDictionary; } | ||
21 | virtual void write( QIODevice &rOut ) const; | ||
22 | virtual void read( QIODevice &rIn, char cType ); | ||
23 | |||
24 | void insert( const QByteArray &sKey, const char *s ); | ||
25 | void insert( const QByteArray &sKey, const QByteArray &s ); | ||
26 | void insert( const QByteArray &sKey, char i ); | ||
27 | void insert( const QByteArray &sKey, unsigned char i ); | ||
28 | void insert( const QByteArray &sKey, signed char i ); | ||
29 | void insert( const QByteArray &sKey, unsigned short i ); | ||
30 | void insert( const QByteArray &sKey, signed short i ); | ||
31 | void insert( const QByteArray &sKey, unsigned int i ); | ||
32 | void insert( const QByteArray &sKey, signed int i ); | ||
33 | void insert( const QByteArray &sKey, unsigned long i ); | ||
34 | void insert( const QByteArray &sKey, signed long i ); | ||
35 | void insert( const QByteArray &sKey, unsigned long long i ); | ||
36 | void insert( const QByteArray &sKey, signed long long i ); | ||
37 | //void insert( const QByteArray &sKey, bool b ); | ||
38 | void insert( const QByteArray &sKey, float d ); | ||
39 | void insert( const QByteArray &sKey, double d ); | ||
40 | using QHash<QByteArray, Gats::Object *>::insert; | ||
41 | void insertBool( const QByteArray &sKey, bool b ); | ||
42 | void insertInt( const QByteArray &sKey, int64_t i ); | ||
43 | void insertFloat( const QByteArray &sKey, double d ); | ||
44 | void insertStr( const QByteArray &sKey, const QByteArray &s ); | ||
45 | void insertList( const QByteArray &sKey, Gats::List *pL ); | ||
46 | void insertDict( const QByteArray &sKey, Gats::Dictionary *pD ); | ||
47 | Gats::List *insertList( const QByteArray &sKey ); | ||
48 | Gats::Dictionary *insertDict( const QByteArray &sKey ); | ||
49 | |||
50 | bool valueBool( const QByteArray &sKey ); | ||
51 | int64_t valueInt( const QByteArray &sKey ); | ||
52 | double valueFloat( const QByteArray &sKey ); | ||
53 | QByteArray valueStr( const QByteArray &sKey ); | ||
54 | Gats::List *valueList( const QByteArray &sKey ); | ||
55 | Gats::Dictionary *valueDict( const QByteArray &sKey ); | ||
56 | |||
57 | bool valueBool( const QByteArray &sKey ) const; | ||
58 | int64_t valueInt( const QByteArray &sKey ) const; | ||
59 | double valueFloat( const QByteArray &sKey ) const; | ||
60 | QByteArray valueStr( const QByteArray &sKey ) const; | ||
61 | Gats::List *valueList( const QByteArray &sKey ) const; | ||
62 | Gats::Dictionary *valueDict( const QByteArray &sKey ) const; | ||
63 | }; | ||
64 | }; | ||
65 | |||
66 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ); | ||
67 | |||
68 | #endif | ||
diff --git a/c++-qt/src/float.cpp b/c++-qt/src/float.cpp new file mode 100644 index 0000000..a82edec --- /dev/null +++ b/c++-qt/src/float.cpp | |||
@@ -0,0 +1,122 @@ | |||
1 | #include "gats-qt/float.h" | ||
2 | #include "gats-qt/integer.h" | ||
3 | |||
4 | #include <math.h> | ||
5 | |||
6 | Gats::Float::Float() : | ||
7 | fVal( 0.0 ) | ||
8 | { | ||
9 | } | ||
10 | |||
11 | Gats::Float::Float( double f ) : | ||
12 | fVal( f ) | ||
13 | { | ||
14 | } | ||
15 | |||
16 | Gats::Float::~Float() | ||
17 | { | ||
18 | } | ||
19 | |||
20 | void Gats::Float::write( QIODevice &rOut ) const | ||
21 | { | ||
22 | if( fVal == 0.0 ) | ||
23 | { | ||
24 | if( signbit( fVal ) ) | ||
25 | rOut.write("FZ", 2 ); | ||
26 | else | ||
27 | rOut.write("Fz", 2 ); | ||
28 | } | ||
29 | else if( !isfinite( fVal ) ) | ||
30 | { | ||
31 | if( isnan( fVal ) ) | ||
32 | { | ||
33 | if( signbit( fVal ) ) | ||
34 | rOut.write("FN", 2 ); | ||
35 | else | ||
36 | rOut.write("Fn", 2 ); | ||
37 | } | ||
38 | else | ||
39 | { | ||
40 | if( signbit( fVal ) ) | ||
41 | rOut.write("FI", 2 ); | ||
42 | else | ||
43 | rOut.write("Fi", 2 ); | ||
44 | } | ||
45 | } | ||
46 | else | ||
47 | { | ||
48 | rOut.write("f", 1 ); | ||
49 | double d = fVal; | ||
50 | bool bNeg = false; | ||
51 | int64_t iScale=0; | ||
52 | if( signbit( d ) ) | ||
53 | { | ||
54 | bNeg = true; | ||
55 | d = -d; | ||
56 | } | ||
57 | |||
58 | iScale = log( d ) / 0x1.62e42fefa39efp+2; // log( 256.0 ) | ||
59 | if( iScale < 0 ) iScale--; | ||
60 | d /= pow( 256.0, iScale ); | ||
61 | |||
62 | QByteArray s; | ||
63 | s += (uint8_t)(d); | ||
64 | d -= (int)d; | ||
65 | for( int j = 0; j < 150 && d; j++ ) | ||
66 | { | ||
67 | d = d*256.0; | ||
68 | s += (uint8_t)d; | ||
69 | d -= (int)d; | ||
70 | } | ||
71 | Gats::Integer::writePackedInt( rOut, bNeg?-s.size():s.size() ); | ||
72 | rOut.write( s.constData(), s.size() ); | ||
73 | Gats::Integer::writePackedInt( rOut, iScale ); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | void Gats::Float::read( QIODevice &rIn, char cType ) | ||
78 | { | ||
79 | if( cType == 'F' ) | ||
80 | { | ||
81 | char buf; | ||
82 | rIn.read( &buf, 1 ); | ||
83 | switch( buf ) | ||
84 | { | ||
85 | case 'N': fVal = -NAN; break; | ||
86 | case 'n': fVal = NAN; break; | ||
87 | case 'I': fVal = -INFINITY; break; | ||
88 | case 'i': fVal = INFINITY; break; | ||
89 | case 'Z': fVal = -0.0; break; | ||
90 | case 'z': fVal = 0.0; break; | ||
91 | } | ||
92 | } | ||
93 | else if( cType == 'f' ) | ||
94 | { | ||
95 | int64_t iStr; | ||
96 | Gats::Integer::readPackedInt( rIn, iStr ); | ||
97 | bool bNeg = false; | ||
98 | if( iStr < 0 ) | ||
99 | { | ||
100 | bNeg = true; | ||
101 | iStr = -iStr; | ||
102 | } | ||
103 | QByteArray s( iStr, '\0' ); | ||
104 | rIn.read( s.data(), iStr ); | ||
105 | fVal = 0.0; | ||
106 | for( int j = iStr-1; j > 0; j-- ) | ||
107 | { | ||
108 | fVal = (fVal+(uint8_t)s[j])*0x1p-8; | ||
109 | } | ||
110 | fVal += (uint8_t)s[0]; | ||
111 | int64_t iScale; | ||
112 | Gats::Integer::readPackedInt( rIn, iScale ); | ||
113 | fVal *= pow( 256.0, iScale ); | ||
114 | if( bNeg ) fVal = -fVal; | ||
115 | } | ||
116 | } | ||
117 | /* | ||
118 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ) | ||
119 | { | ||
120 | return f << "(float) " << flt.getValue(); | ||
121 | }*/ | ||
122 | |||
diff --git a/c++-qt/src/float.h b/c++-qt/src/float.h new file mode 100644 index 0000000..74225aa --- /dev/null +++ b/c++-qt/src/float.h | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef GATS_FLOAT_H | ||
2 | #define GATS_FLOAT_H | ||
3 | |||
4 | #include "gats-qt/object.h" | ||
5 | |||
6 | namespace Gats | ||
7 | { | ||
8 | class Float : public Gats::Object | ||
9 | { | ||
10 | Q_OBJECT; | ||
11 | public: | ||
12 | Float(); | ||
13 | Float( double f ); | ||
14 | virtual ~Float(); | ||
15 | |||
16 | virtual Type getType() const { return typeFloat; } | ||
17 | double getValue() const { return fVal; } | ||
18 | |||
19 | virtual void write( QIODevice &rOut ) const; | ||
20 | virtual void read( QIODevice &rIn, char cType ); | ||
21 | |||
22 | private: | ||
23 | double fVal; | ||
24 | mutable QByteArray sWriteCache; | ||
25 | }; | ||
26 | } | ||
27 | |||
28 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ); | ||
29 | |||
30 | #endif | ||
diff --git a/c++-qt/src/gatsstream.cpp b/c++-qt/src/gatsstream.cpp new file mode 100644 index 0000000..d32b2b2 --- /dev/null +++ b/c++-qt/src/gatsstream.cpp | |||
@@ -0,0 +1,116 @@ | |||
1 | #include "gats-qt/gatsstream.h" | ||
2 | #include "gats-qt/object.h" | ||
3 | |||
4 | #ifdef WIN32 | ||
5 | #include <winsock2.h> | ||
6 | #else | ||
7 | #include <arpa/inet.h> | ||
8 | #endif | ||
9 | |||
10 | #include <QBuffer> | ||
11 | |||
12 | Gats::GatsStream::GatsStream( QIODevice &rStream ) : | ||
13 | rStream( rStream ) | ||
14 | { | ||
15 | } | ||
16 | |||
17 | Gats::GatsStream::~GatsStream() | ||
18 | { | ||
19 | } | ||
20 | |||
21 | Gats::Object *Gats::GatsStream::readObject() | ||
22 | { | ||
23 | char buf[1500]; | ||
24 | |||
25 | do | ||
26 | { | ||
27 | if( qbRead.size() < 5 ) | ||
28 | { | ||
29 | int iRead = rStream.read( buf, 5-qbRead.size() ); | ||
30 | qbRead.append( buf, iRead ); | ||
31 | |||
32 | if( qbRead.size() < 5 ) | ||
33 | return NULL; | ||
34 | } | ||
35 | } while( !skipReadNulls() ); | ||
36 | |||
37 | uint8_t uVer; | ||
38 | uVer = qbRead[0]; | ||
39 | |||
40 | int32_t iSize; | ||
41 | memcpy( &iSize, qbRead.constData()+1, 4 ); | ||
42 | iSize = ntohl( iSize ); | ||
43 | while( qbRead.size() < iSize ) | ||
44 | { | ||
45 | int32_t iRead = iSize - qbRead.size(); | ||
46 | if( iRead > 1500 ) | ||
47 | iRead = 1500; | ||
48 | int32_t iReal = rStream.read( buf, iRead ); | ||
49 | qbRead.append( buf, iReal ); | ||
50 | if( iReal < iRead ) | ||
51 | { | ||
52 | return NULL; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | if( qbRead.size() < iSize ) | ||
57 | { | ||
58 | return NULL; | ||
59 | } | ||
60 | |||
61 | QBuffer rTmp( &qbRead ); | ||
62 | rTmp.open( QIODevice::ReadOnly ); | ||
63 | rTmp.seek( 5 ); | ||
64 | Gats::Object *pObj = Gats::Object::read( rTmp ); | ||
65 | |||
66 | return pObj; | ||
67 | } | ||
68 | |||
69 | void Gats::GatsStream::writeObject( Gats::Object *pObject ) | ||
70 | { | ||
71 | QIODevice *pTmp; | ||
72 | if( rStream.isSequential() ) | ||
73 | { | ||
74 | pTmp = new QBuffer(); | ||
75 | pTmp->open( QIODevice::WriteOnly ); | ||
76 | } | ||
77 | else | ||
78 | { | ||
79 | pTmp = &rStream; | ||
80 | } | ||
81 | |||
82 | uint8_t uBuf = 1; | ||
83 | uint32_t iSize = 0; | ||
84 | pTmp->write( (const char *)&uBuf, 1 ); | ||
85 | uint64_t iSizePos = pTmp->pos(); | ||
86 | pTmp->write( (const char *)&iSize, 4 ); | ||
87 | pObject->write( *pTmp ); | ||
88 | iSize = htonl( pTmp->pos() ); | ||
89 | pTmp->seek( iSizePos ); | ||
90 | pTmp->write( (const char *)&iSize, 4 ); | ||
91 | pTmp->close(); | ||
92 | |||
93 | if( rStream.isSequential() ) | ||
94 | { | ||
95 | rStream.write( ((QBuffer *)pTmp)->data() ); | ||
96 | delete pTmp; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | bool Gats::GatsStream::skipReadNulls() | ||
101 | { | ||
102 | bool bHaveSeeked = false; | ||
103 | for(;;) | ||
104 | { | ||
105 | if( qbRead.size() == 0 ) | ||
106 | return false; | ||
107 | if( qbRead.at(0) != 0 ) | ||
108 | return !bHaveSeeked; //true; | ||
109 | else | ||
110 | { | ||
111 | qbRead.remove( 0, 1 ); | ||
112 | bHaveSeeked = true; | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | |||
diff --git a/c++-qt/src/gatsstream.h b/c++-qt/src/gatsstream.h new file mode 100644 index 0000000..3cf1081 --- /dev/null +++ b/c++-qt/src/gatsstream.h | |||
@@ -0,0 +1,57 @@ | |||
1 | #ifndef GATS_STREAM_H | ||
2 | #define GATS_STREAM_H | ||
3 | |||
4 | #include <QIODevice> | ||
5 | #include <QByteArray> | ||
6 | |||
7 | namespace Gats | ||
8 | { | ||
9 | class Object; | ||
10 | |||
11 | class GatsStream : public QObject | ||
12 | { | ||
13 | Q_OBJECT; | ||
14 | public: | ||
15 | GatsStream( QIODevice &rStream ); | ||
16 | virtual ~GatsStream(); | ||
17 | |||
18 | /** | ||
19 | * Read an object packet from the assosiated stream. This will make | ||
20 | * every effort to only read exactly enough data to describe one packet, | ||
21 | * in case you want to do other things with your stream. It will | ||
22 | * automatically skip NULL byte spacing between packets, which makes | ||
23 | * a convinient padding method for encrypted data streams. Since | ||
24 | * sizing information is available in the packet header exact amounts | ||
25 | * of data can be read, however this function doesn't assume that it | ||
26 | * can read the entire object in one operation. If it fails to read | ||
27 | * a complete packet in one call, it will keep the data it's read so | ||
28 | * far buffered and return NULL, ready for another attempt. You can | ||
29 | * use the function hasReadBuffer() to deterimne if readObject() | ||
30 | * has read part of an object packet or not. If readObject returns | ||
31 | * non-null then hasReadBuffer should return false on it's next call. | ||
32 | */ | ||
33 | Gats::Object *readObject(); | ||
34 | |||
35 | /** | ||
36 | * Write an object | ||
37 | */ | ||
38 | void writeObject( Gats::Object *pObject ); | ||
39 | |||
40 | /** | ||
41 | * Tells you if there is data still in the read buffer, i.e. that a | ||
42 | * packet is part way through being read. If readObject has returned | ||
43 | * non-null in the most recent call, this should always be false. | ||
44 | */ | ||
45 | bool hasReadBuffer() { return qbRead.size() > 0; } | ||
46 | int getReadBufferSize() { return qbRead.size(); } | ||
47 | |||
48 | private: | ||
49 | bool skipReadNulls(); | ||
50 | |||
51 | private: | ||
52 | QIODevice &rStream; | ||
53 | QByteArray qbRead; | ||
54 | }; | ||
55 | }; | ||
56 | |||
57 | #endif | ||
diff --git a/c++-qt/src/integer.cpp b/c++-qt/src/integer.cpp new file mode 100644 index 0000000..bb6da80 --- /dev/null +++ b/c++-qt/src/integer.cpp | |||
@@ -0,0 +1,32 @@ | |||
1 | #include "gats-qt/integer.h" | ||
2 | |||
3 | Gats::Integer::Integer() : | ||
4 | iVal( 0 ) | ||
5 | { | ||
6 | } | ||
7 | |||
8 | Gats::Integer::Integer( int64_t iVal ) : | ||
9 | iVal( iVal ) | ||
10 | { | ||
11 | } | ||
12 | |||
13 | Gats::Integer::~Integer() | ||
14 | { | ||
15 | } | ||
16 | |||
17 | void Gats::Integer::write( QIODevice &rOut ) const | ||
18 | { | ||
19 | rOut.write("i", 1 ); | ||
20 | writePackedInt( rOut, iVal ); | ||
21 | } | ||
22 | |||
23 | void Gats::Integer::read( QIODevice &rIn, char cType ) | ||
24 | { | ||
25 | readPackedInt( rIn, iVal ); | ||
26 | } | ||
27 | /* | ||
28 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ) | ||
29 | { | ||
30 | return f << "(int) " << i.getValue(); | ||
31 | } | ||
32 | */ | ||
diff --git a/c++-qt/src/integer.h b/c++-qt/src/integer.h new file mode 100644 index 0000000..8695a12 --- /dev/null +++ b/c++-qt/src/integer.h | |||
@@ -0,0 +1,85 @@ | |||
1 | #ifndef GATS_INTEGER_H | ||
2 | #define GATS_INTEGER_H | ||
3 | |||
4 | #include "gats-qt/object.h" | ||
5 | |||
6 | #include <stdint.h> | ||
7 | |||
8 | #include <QIODevice> | ||
9 | |||
10 | namespace Gats | ||
11 | { | ||
12 | class Integer : public Gats::Object | ||
13 | { | ||
14 | Q_OBJECT; | ||
15 | public: | ||
16 | Integer(); | ||
17 | Integer( int64_t iVal ); | ||
18 | virtual ~Integer(); | ||
19 | |||
20 | virtual Type getType() const { return typeInteger; } | ||
21 | int64_t getValue() const { return iVal; } | ||
22 | |||
23 | virtual void write( QIODevice &rOut ) const; | ||
24 | virtual void read( QIODevice &rIn, char cType ); | ||
25 | |||
26 | template<typename itype> | ||
27 | static void readPackedInt( QIODevice &rStream, itype &rOut ) | ||
28 | { | ||
29 | int8_t b; | ||
30 | rOut = 0; | ||
31 | bool bNeg; | ||
32 | |||
33 | rStream.read( (char *)&b, 1 ); | ||
34 | bNeg = ( b&0x40 ); | ||
35 | rOut |= (itype(b&0x3F)); | ||
36 | int c = 0; | ||
37 | while( (b&0x80) ) | ||
38 | { | ||
39 | rStream.read( (char *)&b, 1 ); | ||
40 | rOut |= (itype(b&0x7F)) << (6+7*(c++)); | ||
41 | } | ||
42 | if( bNeg ) rOut = -rOut; | ||
43 | } | ||
44 | |||
45 | template<typename itype> | ||
46 | static void writePackedInt( QIODevice &rStream, itype iIn ) | ||
47 | { | ||
48 | uint8_t b; | ||
49 | |||
50 | if( iIn < 0 ) | ||
51 | { | ||
52 | iIn = -iIn; | ||
53 | b = (iIn&0x3F); | ||
54 | if( iIn > b ) | ||
55 | b |= 0x80 | 0x40; | ||
56 | else | ||
57 | b |= 0x40; | ||
58 | } | ||
59 | else | ||
60 | { | ||
61 | b = (iIn&0x3F); | ||
62 | if( iIn > b ) | ||
63 | b |= 0x80; | ||
64 | } | ||
65 | rStream.write( (const char *)&b, 1 ); | ||
66 | iIn = iIn >> 6; | ||
67 | |||
68 | while( iIn ) | ||
69 | { | ||
70 | b = (iIn&0x7F); | ||
71 | if( iIn > b ) | ||
72 | b |= 0x80; | ||
73 | rStream.write( (const char *)&b, 1 ); | ||
74 | iIn = iIn >> 7; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | private: | ||
79 | int64_t iVal; | ||
80 | }; | ||
81 | }; | ||
82 | |||
83 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); | ||
84 | |||
85 | #endif | ||
diff --git a/c++-qt/src/list.cpp b/c++-qt/src/list.cpp new file mode 100644 index 0000000..59e1770 --- /dev/null +++ b/c++-qt/src/list.cpp | |||
@@ -0,0 +1,192 @@ | |||
1 | #include "gats-qt/list.h" | ||
2 | |||
3 | #include "gats-qt/string.h" | ||
4 | #include "gats-qt/integer.h" | ||
5 | #include "gats-qt/float.h" | ||
6 | #include "gats-qt/boolean.h" | ||
7 | #include "gats-qt/dictionary.h" | ||
8 | |||
9 | Gats::List::List() | ||
10 | { | ||
11 | } | ||
12 | |||
13 | Gats::List::~List() | ||
14 | { | ||
15 | for( iterator i = begin(); i != end(); i++ ) | ||
16 | { | ||
17 | delete *i; | ||
18 | } | ||
19 | } | ||
20 | |||
21 | void Gats::List::write( QIODevice &rOut ) const | ||
22 | { | ||
23 | rOut.write("l", 1 ); | ||
24 | for( const_iterator i = begin(); i != end(); i++ ) | ||
25 | { | ||
26 | (*i)->write( rOut ); | ||
27 | } | ||
28 | rOut.write("e", 1 ); | ||
29 | } | ||
30 | |||
31 | void Gats::List::read( QIODevice &rIn, char cType ) | ||
32 | { | ||
33 | for(;;) | ||
34 | { | ||
35 | Gats::Object *pObj = Gats::Object::read( rIn ); | ||
36 | if( pObj == NULL ) | ||
37 | break; | ||
38 | append( pObj ); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | void Gats::List::append( const char *s ) | ||
43 | { | ||
44 | QList<Gats::Object *>::append( new Gats::String( s ) ); | ||
45 | } | ||
46 | |||
47 | void Gats::List::append( const QByteArray &s ) | ||
48 | { | ||
49 | QList<Gats::Object *>::append( new Gats::String( s ) ); | ||
50 | } | ||
51 | |||
52 | void Gats::List::append( int32_t i ) | ||
53 | { | ||
54 | QList<Gats::Object *>::append( new Gats::Integer( i ) ); | ||
55 | } | ||
56 | |||
57 | void Gats::List::append( int64_t i ) | ||
58 | { | ||
59 | QList<Gats::Object *>::append( new Gats::Integer( i ) ); | ||
60 | } | ||
61 | |||
62 | void Gats::List::append( double d ) | ||
63 | { | ||
64 | QList<Gats::Object *>::append( new Gats::Float( d ) ); | ||
65 | } | ||
66 | |||
67 | void Gats::List::appendStr( const QByteArray &s ) | ||
68 | { | ||
69 | QList<Gats::Object *>::append( new Gats::String( s ) ); | ||
70 | } | ||
71 | |||
72 | void Gats::List::appendInt( int64_t i ) | ||
73 | { | ||
74 | QList<Gats::Object *>::append( new Gats::Integer( i ) ); | ||
75 | } | ||
76 | |||
77 | void Gats::List::appendFloat( double d ) | ||
78 | { | ||
79 | QList<Gats::Object *>::append( new Gats::Float( d ) ); | ||
80 | } | ||
81 | |||
82 | void Gats::List::appendBool( bool b ) | ||
83 | { | ||
84 | QList<Gats::Object *>::append( new Gats::Boolean( b ) ); | ||
85 | } | ||
86 | |||
87 | void Gats::List::appendList( Gats::List *pL ) | ||
88 | { | ||
89 | QList<Gats::Object *>::append( pL ); | ||
90 | } | ||
91 | |||
92 | void Gats::List::appendDict( Gats::Dictionary *pD ) | ||
93 | { | ||
94 | QList<Gats::Object *>::append( pD ); | ||
95 | } | ||
96 | |||
97 | Gats::List *Gats::List::appendList() | ||
98 | { | ||
99 | Gats::List *pLst = new Gats::List(); | ||
100 | appendList( pLst ); | ||
101 | return pLst; | ||
102 | } | ||
103 | |||
104 | Gats::Dictionary *Gats::List::appendDict() | ||
105 | { | ||
106 | Gats::Dictionary *pDict = new Gats::Dictionary(); | ||
107 | appendDict( pDict ); | ||
108 | return pDict; | ||
109 | } | ||
110 | |||
111 | void Gats::List::prepend( const char *s ) | ||
112 | { | ||
113 | QList<Gats::Object *>::prepend( new Gats::String( s ) ); | ||
114 | } | ||
115 | |||
116 | void Gats::List::prepend( const QByteArray &s ) | ||
117 | { | ||
118 | QList<Gats::Object *>::prepend( new Gats::String( s ) ); | ||
119 | } | ||
120 | |||
121 | void Gats::List::prepend( int32_t i ) | ||
122 | { | ||
123 | QList<Gats::Object *>::prepend( new Gats::Integer( i ) ); | ||
124 | } | ||
125 | |||
126 | void Gats::List::prepend( int64_t i ) | ||
127 | { | ||
128 | QList<Gats::Object *>::prepend( new Gats::Integer( i ) ); | ||
129 | } | ||
130 | |||
131 | void Gats::List::prepend( double d ) | ||
132 | { | ||
133 | QList<Gats::Object *>::prepend( new Gats::Float( d ) ); | ||
134 | } | ||
135 | |||
136 | void Gats::List::prependStr( const QByteArray &s ) | ||
137 | { | ||
138 | QList<Gats::Object *>::prepend( new Gats::String( s ) ); | ||
139 | } | ||
140 | |||
141 | void Gats::List::prependInt( int64_t i ) | ||
142 | { | ||
143 | QList<Gats::Object *>::prepend( new Gats::Integer( i ) ); | ||
144 | } | ||
145 | |||
146 | void Gats::List::prependFloat( double d ) | ||
147 | { | ||
148 | QList<Gats::Object *>::prepend( new Gats::Float( d ) ); | ||
149 | } | ||
150 | |||
151 | void Gats::List::prependBool( bool b ) | ||
152 | { | ||
153 | QList<Gats::Object *>::prepend( new Gats::Boolean( b ) ); | ||
154 | } | ||
155 | |||
156 | void Gats::List::prependList( Gats::List *pL ) | ||
157 | { | ||
158 | QList<Gats::Object *>::prepend( pL ); | ||
159 | } | ||
160 | |||
161 | void Gats::List::prependDict( Gats::Dictionary *pD ) | ||
162 | { | ||
163 | QList<Gats::Object *>::prepend( pD ); | ||
164 | } | ||
165 | |||
166 | Gats::List *Gats::List::prependList() | ||
167 | { | ||
168 | Gats::List *pLst = new Gats::List(); | ||
169 | prependList( pLst ); | ||
170 | return pLst; | ||
171 | } | ||
172 | |||
173 | Gats::Dictionary *Gats::List::prependDict() | ||
174 | { | ||
175 | Gats::Dictionary *pDict = new Gats::Dictionary(); | ||
176 | prependDict( pDict ); | ||
177 | return pDict; | ||
178 | } | ||
179 | /* | ||
180 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ) | ||
181 | { | ||
182 | f << "(list) ["; | ||
183 | f.incIndent(); | ||
184 | for( Gats::List::const_iterator i = l.begin(); i; i++ ) | ||
185 | { | ||
186 | f << f.nl << **i; | ||
187 | } | ||
188 | f.decIndent(); | ||
189 | f << f.nl << "]"; | ||
190 | return f; | ||
191 | } | ||
192 | */ | ||
diff --git a/c++-qt/src/list.h b/c++-qt/src/list.h new file mode 100644 index 0000000..f712fa5 --- /dev/null +++ b/c++-qt/src/list.h | |||
@@ -0,0 +1,57 @@ | |||
1 | #ifndef GATS_LIST_H | ||
2 | #define GATS_LIST_H | ||
3 | |||
4 | #include "gats-qt/object.h" | ||
5 | #include <QList> | ||
6 | |||
7 | namespace Gats | ||
8 | { | ||
9 | class Dictionary; | ||
10 | |||
11 | class List : public Gats::Object, public QList<Gats::Object *> | ||
12 | { | ||
13 | Q_OBJECT; | ||
14 | public: | ||
15 | List(); | ||
16 | virtual ~List(); | ||
17 | |||
18 | virtual Type getType() const { return typeList; } | ||
19 | |||
20 | virtual void write( QIODevice &rOut ) const; | ||
21 | virtual void read( QIODevice &rIn, char cType ); | ||
22 | |||
23 | void append( const char *s ); | ||
24 | void append( const QByteArray &s ); | ||
25 | void append( int32_t i ); | ||
26 | void append( int64_t i ); | ||
27 | void append( double d ); | ||
28 | using QList<Gats::Object *>::append; | ||
29 | void appendStr( const QByteArray &s ); | ||
30 | void appendInt( int64_t i ); | ||
31 | void appendFloat( double d ); | ||
32 | void appendBool( bool b ); | ||
33 | void appendList( Gats::List *pL ); | ||
34 | void appendDict( Gats::Dictionary *pD ); | ||
35 | Gats::List *appendList(); | ||
36 | Gats::Dictionary *appendDict(); | ||
37 | |||
38 | void prepend( const char *s ); | ||
39 | void prepend( const QByteArray &s ); | ||
40 | void prepend( int32_t i ); | ||
41 | void prepend( int64_t i ); | ||
42 | void prepend( double d ); | ||
43 | using QList<Gats::Object *>::prepend; | ||
44 | void prependStr( const QByteArray &s ); | ||
45 | void prependInt( int64_t i ); | ||
46 | void prependFloat( double d ); | ||
47 | void prependBool( bool b ); | ||
48 | void prependList( Gats::List *pL ); | ||
49 | void prependDict( Gats::Dictionary *pD ); | ||
50 | Gats::List *prependList(); | ||
51 | Gats::Dictionary *prependDict(); | ||
52 | }; | ||
53 | }; | ||
54 | |||
55 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ); | ||
56 | |||
57 | #endif | ||
diff --git a/c++-qt/src/object.cpp b/c++-qt/src/object.cpp new file mode 100644 index 0000000..3955ced --- /dev/null +++ b/c++-qt/src/object.cpp | |||
@@ -0,0 +1,310 @@ | |||
1 | #include "gats-qt/object.h" | ||
2 | |||
3 | #include "gats-qt/integer.h" | ||
4 | #include "gats-qt/float.h" | ||
5 | #include "gats-qt/boolean.h" | ||
6 | #include "gats-qt/string.h" | ||
7 | #include "gats-qt/list.h" | ||
8 | #include "gats-qt/dictionary.h" | ||
9 | |||
10 | #include <stdlib.h> | ||
11 | |||
12 | #include <QIODevice> | ||
13 | |||
14 | Gats::Object::Object() | ||
15 | { | ||
16 | } | ||
17 | |||
18 | Gats::Object::~Object() | ||
19 | { | ||
20 | } | ||
21 | |||
22 | Gats::Object *Gats::Object::read( QIODevice &rIn ) | ||
23 | { | ||
24 | char buf; | ||
25 | rIn.read( &buf, 1 ); | ||
26 | Object *pObj = NULL; | ||
27 | switch( buf ) | ||
28 | { | ||
29 | case 'i': | ||
30 | pObj = new Gats::Integer(); | ||
31 | break; | ||
32 | |||
33 | case 's': | ||
34 | pObj = new Gats::String(); | ||
35 | break; | ||
36 | |||
37 | case '0': | ||
38 | case '1': | ||
39 | pObj = new Gats::Boolean(); | ||
40 | break; | ||
41 | |||
42 | case 'l': | ||
43 | pObj = new Gats::List(); | ||
44 | break; | ||
45 | |||
46 | case 'd': | ||
47 | pObj = new Gats::Dictionary(); | ||
48 | break; | ||
49 | |||
50 | case 'f': // Normal floats | ||
51 | case 'F': // Special float values | ||
52 | pObj = new Gats::Float(); | ||
53 | break; | ||
54 | |||
55 | case 'e': | ||
56 | return NULL; | ||
57 | |||
58 | default: | ||
59 | throw "Invalid Gats type discovered: "; | ||
60 | } | ||
61 | |||
62 | pObj->read( rIn, buf ); | ||
63 | |||
64 | return pObj; | ||
65 | } | ||
66 | /* | ||
67 | void Gats::Object::skipWs( QByteArray::const_iterator &i ) | ||
68 | { | ||
69 | for(; *i == ' ' || *i == '\t' || *i == '\r' || *i == '\n'; i++ ) { } | ||
70 | } | ||
71 | |||
72 | QByteArray Gats::Object::token( QByteArray::const_iterator &i ) | ||
73 | { | ||
74 | QByteArray sRet; | ||
75 | if( *i == '\"' ) | ||
76 | { | ||
77 | for( i++; i && *i != '\"' ; i++ ) | ||
78 | { | ||
79 | if( *i == '\\' ) | ||
80 | i++; | ||
81 | sRet += i; | ||
82 | } | ||
83 | i++; | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | for(; i && *i != ' ' && *i != '\t' && *i != '\r' && *i != '\n' && | ||
88 | *i != ',' && *i != ']' && *i != '}' && *i != '[' && | ||
89 | *i != '{'; i++ ) | ||
90 | { | ||
91 | sRet += i; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | return sRet; | ||
96 | } | ||
97 | |||
98 | Gats::Object *Gats::Object::strToGats( QByteArray::const_iterator &i ) | ||
99 | { | ||
100 | skipWs( i ); | ||
101 | |||
102 | switch( *i ) | ||
103 | { | ||
104 | case '[': | ||
105 | { | ||
106 | Gats::List *pLst = new Gats::List(); | ||
107 | i++; | ||
108 | for(;;) | ||
109 | { | ||
110 | Gats::Object *pObj = strToGats( i ); | ||
111 | if( !pObj ) | ||
112 | break; | ||
113 | pLst->append( pObj ); | ||
114 | skipWs( i ); | ||
115 | switch( *i ) | ||
116 | { | ||
117 | case ',': | ||
118 | i++; | ||
119 | break; | ||
120 | |||
121 | case ']': | ||
122 | i++; | ||
123 | return pLst; | ||
124 | |||
125 | default: | ||
126 | throw "PUT GOOD EXCEPTION HERE"; | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | break; | ||
131 | |||
132 | case '{': | ||
133 | { | ||
134 | Gats::Dictionary *pDict = new Gats::Dictionary(); | ||
135 | i++; | ||
136 | for(;;) | ||
137 | { | ||
138 | skipWs( i ); | ||
139 | if( *i != '\"' ) | ||
140 | throw "PUT GOOD EXCEPTION HERE"; | ||
141 | QByteArray sKey = token( i ); | ||
142 | skipWs( i ); | ||
143 | if( *i != ':' ) | ||
144 | throw "PUT GOOD EXCEPTION HERE"; | ||
145 | "seperated with colons."); | ||
146 | i++; | ||
147 | Gats::Object *pObj = strToGats( i ); | ||
148 | if( !pObj ) | ||
149 | throw "PUT GOOD EXCEPTION HERE"; | ||
150 | pDict->insert( sKey, pObj ); | ||
151 | skipWs( i ); | ||
152 | switch( *i ) | ||
153 | { | ||
154 | case ',': | ||
155 | i++; | ||
156 | break; | ||
157 | |||
158 | case '}': | ||
159 | i++; | ||
160 | return pDict; | ||
161 | |||
162 | default: | ||
163 | throw "PUT GOOD EXCEPTION HERE"; | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | break; | ||
168 | |||
169 | case '\"': | ||
170 | return new Gats::String( token( i ) ); | ||
171 | break; | ||
172 | |||
173 | case '0': | ||
174 | case '1': | ||
175 | case '2': | ||
176 | case '3': | ||
177 | case '4': | ||
178 | case '5': | ||
179 | case '6': | ||
180 | case '7': | ||
181 | case '8': | ||
182 | case '9': | ||
183 | case '.': | ||
184 | case '+': | ||
185 | case '-': | ||
186 | { | ||
187 | QByteArray s = token( i ); | ||
188 | int iSize = s.getSize(); | ||
189 | if( s[iSize-1] == 'i' ) | ||
190 | { | ||
191 | return new Gats::Integer( | ||
192 | strtoll( s.getStr(), NULL, 10 ) | ||
193 | ); | ||
194 | } | ||
195 | else if( s[iSize-1] == 'f' ) | ||
196 | { | ||
197 | return new Gats::Float( | ||
198 | strtod( s.getStr(), NULL ) | ||
199 | ); | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | for( QByteArray::iterator i = s.begin(); i; i++ ) | ||
204 | { | ||
205 | if( *i == '.' ) | ||
206 | return new Gats::Float( | ||
207 | strtod( s.getStr(), NULL ) | ||
208 | ); | ||
209 | } | ||
210 | return new Gats::Integer( | ||
211 | strtoll( s.getStr(), NULL, 10 ) | ||
212 | ); | ||
213 | } | ||
214 | } | ||
215 | break; | ||
216 | |||
217 | default: | ||
218 | { | ||
219 | QByteArray s = token( i ); | ||
220 | int iSize = s.getSize(); | ||
221 | // Test for explicit types first | ||
222 | if( iSize > 2 ) | ||
223 | { | ||
224 | if( (s[0] >= '0' && s[0] <= '9') || s[0] == '+' || s[0] == '-' ) | ||
225 | { | ||
226 | } | ||
227 | else | ||
228 | { | ||
229 | QByteArray st = s.toLower(); | ||
230 | if( st == "true" ) | ||
231 | { | ||
232 | return new Gats::Boolean( true ); | ||
233 | } | ||
234 | else if( st == "false" ) | ||
235 | { | ||
236 | return new Gats::Boolean( false ); | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | } | ||
241 | break; | ||
242 | } | ||
243 | |||
244 | return NULL; | ||
245 | } | ||
246 | |||
247 | Gats::Object *Gats::Object::strToGats( const QByteArray &sStr ) | ||
248 | { | ||
249 | QByteArray::const_iterator i = sStr.begin(); | ||
250 | |||
251 | return strToGats( i ); | ||
252 | } | ||
253 | |||
254 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ) | ||
255 | { | ||
256 | switch( obj.getType() ) | ||
257 | { | ||
258 | case Gats::typeDictionary: | ||
259 | return f << dynamic_cast<const Gats::Dictionary &>(obj); | ||
260 | |||
261 | case Gats::typeList: | ||
262 | return f << dynamic_cast<const Gats::List &>(obj); | ||
263 | |||
264 | case Gats::typeString: | ||
265 | return f << dynamic_cast<const Gats::String &>(obj); | ||
266 | |||
267 | case Gats::typeInteger: | ||
268 | return f << dynamic_cast<const Gats::Integer &>(obj); | ||
269 | |||
270 | case Gats::typeFloat: | ||
271 | return f << dynamic_cast<const Gats::Float &>(obj); | ||
272 | |||
273 | case Gats::typeBoolean: | ||
274 | return f << dynamic_cast<const Gats::Boolean &>(obj); | ||
275 | |||
276 | default: | ||
277 | return f << "***ERROR: Bad Gats type***"; | ||
278 | } | ||
279 | } | ||
280 | |||
281 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ) | ||
282 | { | ||
283 | switch( t ) | ||
284 | { | ||
285 | case Gats::typeDictionary: return f << "dictionary"; | ||
286 | case Gats::typeList: return f << "list"; | ||
287 | case Gats::typeString: return f << "string"; | ||
288 | case Gats::typeInteger: return f << "integer"; | ||
289 | case Gats::typeFloat: return f << "float"; | ||
290 | case Gats::typeBoolean: return f << "boolean"; | ||
291 | } | ||
292 | |||
293 | return f << "***unknown***"; | ||
294 | } | ||
295 | */ | ||
296 | const char *Gats::typeToStr( Gats::Type t ) | ||
297 | { | ||
298 | switch( t ) | ||
299 | { | ||
300 | case Gats::typeDictionary: return "dictionary"; | ||
301 | case Gats::typeList: return "list"; | ||
302 | case Gats::typeString: return "string"; | ||
303 | case Gats::typeInteger: return "integer"; | ||
304 | case Gats::typeFloat: return "float"; | ||
305 | case Gats::typeBoolean: return "boolean"; | ||
306 | } | ||
307 | |||
308 | return "***unknown***"; | ||
309 | } | ||
310 | |||
diff --git a/c++-qt/src/object.h b/c++-qt/src/object.h new file mode 100644 index 0000000..0c08d41 --- /dev/null +++ b/c++-qt/src/object.h | |||
@@ -0,0 +1,51 @@ | |||
1 | #ifndef GATS_OBJECT_H | ||
2 | #define GATS_OBJECT_H | ||
3 | |||
4 | #include <QObject> | ||
5 | #include <QByteArray> | ||
6 | |||
7 | class QIODevice; | ||
8 | |||
9 | namespace Gats | ||
10 | { | ||
11 | enum Type | ||
12 | { | ||
13 | typeDictionary, | ||
14 | typeList, | ||
15 | typeString, | ||
16 | typeInteger, | ||
17 | typeFloat, | ||
18 | typeBoolean | ||
19 | }; | ||
20 | |||
21 | /** | ||
22 | * The baseclass for every type that can be stored in a packet. | ||
23 | */ | ||
24 | class Object : public QObject | ||
25 | { | ||
26 | Q_OBJECT; | ||
27 | public: | ||
28 | Object(); | ||
29 | virtual ~Object(); | ||
30 | |||
31 | virtual Type getType() const =0; | ||
32 | |||
33 | virtual void write( QIODevice &rOut ) const=0; | ||
34 | virtual void read( QIODevice &rIn, char cType )=0; | ||
35 | |||
36 | static Object *read( QIODevice &rIn ); | ||
37 | // static Object *strToGats( const &sStr ); | ||
38 | |||
39 | private: | ||
40 | // static Object *strToGats( QByteArray::const_iterator &i ); | ||
41 | // static QByteArray token( QByteArray::const_iterator &i ); | ||
42 | // static void skipWs( QByteArray::const_iterator &i ); | ||
43 | }; | ||
44 | |||
45 | const char *typeToStr( Type t ); | ||
46 | }; | ||
47 | |||
48 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ); | ||
49 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ); | ||
50 | |||
51 | #endif | ||
diff --git a/c++-qt/src/string.cpp b/c++-qt/src/string.cpp new file mode 100644 index 0000000..0b9e4d8 --- /dev/null +++ b/c++-qt/src/string.cpp | |||
@@ -0,0 +1,58 @@ | |||
1 | #include "gats-qt/string.h" | ||
2 | |||
3 | #include "gats-qt/integer.h" | ||
4 | |||
5 | Gats::String::String() | ||
6 | { | ||
7 | } | ||
8 | |||
9 | Gats::String::String( const char *s ) : | ||
10 | QByteArray( s ) | ||
11 | { | ||
12 | } | ||
13 | |||
14 | Gats::String::String( const char *s, long iLength ) : | ||
15 | QByteArray( s, iLength ) | ||
16 | { | ||
17 | } | ||
18 | |||
19 | Gats::String::String( long iLength ) : | ||
20 | QByteArray( iLength, '\0' ) | ||
21 | { | ||
22 | } | ||
23 | |||
24 | Gats::String::String( const String &s ) : | ||
25 | QByteArray( s ) | ||
26 | { | ||
27 | } | ||
28 | |||
29 | Gats::String::String( const QByteArray &s ) : | ||
30 | QByteArray( s ) | ||
31 | { | ||
32 | } | ||
33 | |||
34 | Gats::String::~String() | ||
35 | { | ||
36 | } | ||
37 | |||
38 | void Gats::String::write( QIODevice &rOut ) const | ||
39 | { | ||
40 | rOut.write("s", 1 ); | ||
41 | uint32_t iSize = size(); | ||
42 | Gats::Integer::writePackedInt( rOut, iSize ); | ||
43 | rOut.write( constData(), iSize ); | ||
44 | } | ||
45 | |||
46 | void Gats::String::read( QIODevice &rIn, char cType ) | ||
47 | { | ||
48 | uint32_t iSize; | ||
49 | Gats::Integer::readPackedInt( rIn, iSize ); | ||
50 | fill( '\0', iSize ); | ||
51 | rIn.read( data(), iSize ); | ||
52 | } | ||
53 | /* | ||
54 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ) | ||
55 | { | ||
56 | return f << "(str) \"" << dynamic_cast<const QByteArray &>(s) << "\""; | ||
57 | } | ||
58 | */ | ||
diff --git a/c++-qt/src/string.h b/c++-qt/src/string.h new file mode 100644 index 0000000..2acd946 --- /dev/null +++ b/c++-qt/src/string.h | |||
@@ -0,0 +1,32 @@ | |||
1 | #ifndef GATS_STRING_H | ||
2 | #define GATS_STRING_H | ||
3 | |||
4 | #include "gats-qt/object.h" | ||
5 | #include <QByteArray> | ||
6 | |||
7 | namespace Gats | ||
8 | { | ||
9 | class String : public Gats::Object, public QByteArray | ||
10 | { | ||
11 | Q_OBJECT; | ||
12 | public: | ||
13 | String(); | ||
14 | String( const char *s ); | ||
15 | String( const char *s, long iLength ); | ||
16 | String( long iLength ); | ||
17 | String( const String &s ); | ||
18 | String( const QByteArray &s ); | ||
19 | virtual ~String(); | ||
20 | |||
21 | virtual Type getType() const { return typeString; } | ||
22 | |||
23 | virtual void write( QIODevice &rOut ) const; | ||
24 | virtual void read( QIODevice &rIn, char cType ); | ||
25 | |||
26 | private: | ||
27 | }; | ||
28 | }; | ||
29 | |||
30 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ); | ||
31 | |||
32 | #endif | ||
diff --git a/c++-qt/src/types.h b/c++-qt/src/types.h new file mode 100644 index 0000000..1264a9d --- /dev/null +++ b/c++-qt/src/types.h | |||
@@ -0,0 +1,7 @@ | |||
1 | #include "gats-qt/object.h" | ||
2 | #include "gats-qt/boolean.h" | ||
3 | #include "gats-qt/dictionary.h" | ||
4 | #include "gats-qt/float.h" | ||
5 | #include "gats-qt/integer.h" | ||
6 | #include "gats-qt/list.h" | ||
7 | #include "gats-qt/string.h" | ||
diff --git a/c++-qt/src/version.h b/c++-qt/src/version.h new file mode 100644 index 0000000..544dd00 --- /dev/null +++ b/c++-qt/src/version.h | |||
@@ -0,0 +1,3 @@ | |||
1 | #ifndef LIBGATS_VC_ID | ||
2 | #define LIBGATS_VC_ID "68:71" | ||
3 | #endif | ||