aboutsummaryrefslogtreecommitdiff
path: root/c++-qt/src/integer.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--c++-qt/src/integer.h151
1 files changed, 79 insertions, 72 deletions
diff --git a/c++-qt/src/integer.h b/c++-qt/src/integer.h
index db36e30..9178796 100644
--- a/c++-qt/src/integer.h
+++ b/c++-qt/src/integer.h
@@ -1,3 +1,10 @@
1/*
2 * Copyright (C) 2007-2012 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libgats library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
1#ifndef GATS_INTEGER_H 8#ifndef GATS_INTEGER_H
2#define GATS_INTEGER_H 9#define GATS_INTEGER_H
3 10
@@ -9,78 +16,78 @@
9 16
10namespace Gats 17namespace Gats
11{ 18{
12 class Integer : public Gats::Object 19 class Integer : public Gats::Object
13 { 20 {
14 Q_OBJECT; 21 Q_OBJECT;
15 public: 22 public:
16 Integer(); 23 Integer();
17 Integer( int64_t iVal ); 24 Integer( int64_t iVal );
18 virtual ~Integer(); 25 virtual ~Integer();
19 26
20 virtual Object *clone() const; 27 virtual Object *clone() const;
21 28
22 virtual Type getType() const { return typeInteger; } 29 virtual Type getType() const { return typeInteger; }
23 int64_t getValue() const { return iVal; } 30 int64_t getValue() const { return iVal; }
24 void setValue( int64_t iNewVal ) { iVal = iNewVal; } 31 void setValue( int64_t iNewVal ) { iVal = iNewVal; }
25 32
26 virtual void write( QIODevice &rOut ) const; 33 virtual void write( QIODevice &rOut ) const;
27 virtual void read( QIODevice &rIn, char cType ); 34 virtual void read( QIODevice &rIn, char cType );
28 35
29 template<typename itype> 36 template<typename itype>
30 static void readPackedInt( QIODevice &rStream, itype &rOut ) 37 static void readPackedInt( QIODevice &rStream, itype &rOut )
31 { 38 {
32 int8_t b; 39 int8_t b;
33 rOut = 0; 40 rOut = 0;
34 bool bNeg; 41 bool bNeg;
35 42
36 rStream.read( (char *)&b, 1 ); 43 rStream.read( (char *)&b, 1 );
37 bNeg = ( b&0x40 ); 44 bNeg = ( b&0x40 );
38 rOut |= (itype(b&0x3F)); 45 rOut |= (itype(b&0x3F));
39 int c = 0; 46 int c = 0;
40 while( (b&0x80) ) 47 while( (b&0x80) )
41 { 48 {
42 rStream.read( (char *)&b, 1 ); 49 rStream.read( (char *)&b, 1 );
43 rOut |= (itype(b&0x7F)) << (6+7*(c++)); 50 rOut |= (itype(b&0x7F)) << (6+7*(c++));
44 } 51 }
45 if( bNeg ) rOut = -rOut; 52 if( bNeg ) rOut = -rOut;
46 } 53 }
47 54
48 template<typename itype> 55 template<typename itype>
49 static void writePackedInt( QIODevice &rStream, itype iIn ) 56 static void writePackedInt( QIODevice &rStream, itype iIn )
50 { 57 {
51 uint8_t b; 58 uint8_t b;
52 59
53 if( iIn < 0 ) 60 if( iIn < 0 )
54 { 61 {
55 iIn = -iIn; 62 iIn = -iIn;
56 b = (iIn&0x3F); 63 b = (iIn&0x3F);
57 if( iIn > b ) 64 if( iIn > b )
58 b |= 0x80 | 0x40; 65 b |= 0x80 | 0x40;
59 else 66 else
60 b |= 0x40; 67 b |= 0x40;
61 } 68 }
62 else 69 else
63 { 70 {
64 b = (iIn&0x3F); 71 b = (iIn&0x3F);
65 if( iIn > b ) 72 if( iIn > b )
66 b |= 0x80; 73 b |= 0x80;
67 } 74 }
68 rStream.write( (const char *)&b, 1 ); 75 rStream.write( (const char *)&b, 1 );
69 iIn = iIn >> 6; 76 iIn = iIn >> 6;
70 77
71 while( iIn ) 78 while( iIn )
72 { 79 {
73 b = (iIn&0x7F); 80 b = (iIn&0x7F);
74 if( iIn > b ) 81 if( iIn > b )
75 b |= 0x80; 82 b |= 0x80;
76 rStream.write( (const char *)&b, 1 ); 83 rStream.write( (const char *)&b, 1 );
77 iIn = iIn >> 7; 84 iIn = iIn >> 7;
78 } 85 }
79 } 86 }
80 87
81 private: 88 private:
82 int64_t iVal; 89 int64_t iVal;
83 }; 90 };
84}; 91};
85 92
86//Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); 93//Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i );