aboutsummaryrefslogtreecommitdiff
path: root/c++-qt/src/integer.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--c++-qt/src/integer.h85
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
10namespace 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