diff options
Diffstat (limited to 'src/integer.h')
-rw-r--r-- | src/integer.h | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/src/integer.h b/src/integer.h deleted file mode 100644 index a5e0d58..0000000 --- a/src/integer.h +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | #ifndef GATS_INTEGER_H | ||
2 | #define GATS_INTEGER_H | ||
3 | |||
4 | #include "gats/object.h" | ||
5 | |||
6 | #include <stdint.h> | ||
7 | |||
8 | #include <bu/stream.h> | ||
9 | |||
10 | namespace Gats | ||
11 | { | ||
12 | class Integer : public Gats::Object | ||
13 | { | ||
14 | public: | ||
15 | Integer(); | ||
16 | Integer( int64_t iVal ); | ||
17 | virtual ~Integer(); | ||
18 | |||
19 | virtual Object *clone() const; | ||
20 | |||
21 | virtual Type getType() const { return typeInteger; } | ||
22 | int64_t getValue() const { return iVal; } | ||
23 | |||
24 | virtual void write( Bu::Stream &rOut ) const; | ||
25 | virtual void read( Bu::Stream &rIn, char cType ); | ||
26 | |||
27 | template<typename itype> | ||
28 | static void readPackedInt( Bu::Stream &rStream, itype &rOut ) | ||
29 | { | ||
30 | int8_t b; | ||
31 | rOut = 0; | ||
32 | bool bNeg; | ||
33 | |||
34 | rStream.read( &b, 1 ); | ||
35 | bNeg = ( b&0x40 ); | ||
36 | rOut |= (itype(b&0x3F)); | ||
37 | int c = 0; | ||
38 | while( (b&0x80) ) | ||
39 | { | ||
40 | rStream.read( &b, 1 ); | ||
41 | rOut |= (itype(b&0x7F)) << (6+7*(c++)); | ||
42 | } | ||
43 | if( bNeg ) rOut = -rOut; | ||
44 | } | ||
45 | |||
46 | template<typename itype> | ||
47 | static void writePackedInt( Bu::Stream &rStream, itype iIn ) | ||
48 | { | ||
49 | uint8_t b; | ||
50 | |||
51 | if( iIn < 0 ) | ||
52 | { | ||
53 | iIn = -iIn; | ||
54 | b = (iIn&0x3F); | ||
55 | if( iIn > b ) | ||
56 | b |= 0x80 | 0x40; | ||
57 | else | ||
58 | b |= 0x40; | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | b = (iIn&0x3F); | ||
63 | if( iIn > b ) | ||
64 | b |= 0x80; | ||
65 | } | ||
66 | rStream.write( &b, 1 ); | ||
67 | iIn = iIn >> 6; | ||
68 | |||
69 | while( iIn ) | ||
70 | { | ||
71 | b = (iIn&0x7F); | ||
72 | if( iIn > b ) | ||
73 | b |= 0x80; | ||
74 | rStream.write( &b, 1 ); | ||
75 | iIn = iIn >> 7; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | private: | ||
80 | int64_t iVal; | ||
81 | }; | ||
82 | }; | ||
83 | |||
84 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); | ||
85 | |||
86 | #endif | ||