diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-03-31 17:34:11 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-03-31 17:34:11 +0000 |
commit | 82da0238a8171cf8bba6bb1c82d5abba207a10aa (patch) | |
tree | 83ff9b022b658e7a056fc85f132937b8bda4c1c3 /c++-qt/src/integer.h | |
parent | 7dd5c386611e31930e7ccfb83cb585df27696881 (diff) | |
download | libgats-82da0238a8171cf8bba6bb1c82d5abba207a10aa.tar.gz libgats-82da0238a8171cf8bba6bb1c82d5abba207a10aa.tar.bz2 libgats-82da0238a8171cf8bba6bb1c82d5abba207a10aa.tar.xz libgats-82da0238a8171cf8bba6bb1c82d5abba207a10aa.zip |
Gats for QT is here. It's a pretty basic conversion right now, it doesn't
support debugging formatting (Bu::sio), it doesn't support gats-text string
parsing, and the exceptions need to be fixed to be real exceptions.
The basic functions have been renamed to match the Qt API and we use QT types
for everything (QHash, QList, QByteArray). It needs more testing, but it's a
great start.
Diffstat (limited to '')
-rw-r--r-- | c++-qt/src/integer.h | 85 |
1 files changed, 85 insertions, 0 deletions
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 | ||