diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 17:20:11 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 17:20:11 +0000 |
commit | d534a56d95bca7bdd812be024d9eacba4734e2b7 (patch) | |
tree | f9b98ee2b80e645a7b54e7934882be6c9f73c165 /c++-libbu++/src/integer.h | |
parent | 61ccc86fdf06f12cb72a8b7e65286f812cf62154 (diff) | |
download | libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.tar.gz libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.tar.bz2 libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.tar.xz libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.zip |
Many changes: tabconv'd the C++ code, added a license, BSD, and docs.
Diffstat (limited to 'c++-libbu++/src/integer.h')
-rw-r--r-- | c++-libbu++/src/integer.h | 147 |
1 files changed, 77 insertions, 70 deletions
diff --git a/c++-libbu++/src/integer.h b/c++-libbu++/src/integer.h index a5e0d58..dc4ae4c 100644 --- a/c++-libbu++/src/integer.h +++ b/c++-libbu++/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,76 +16,76 @@ | |||
9 | 16 | ||
10 | namespace Gats | 17 | namespace Gats |
11 | { | 18 | { |
12 | class Integer : public Gats::Object | 19 | class Integer : public Gats::Object |
13 | { | 20 | { |
14 | public: | 21 | public: |
15 | Integer(); | 22 | Integer(); |
16 | Integer( int64_t iVal ); | 23 | Integer( int64_t iVal ); |
17 | virtual ~Integer(); | 24 | virtual ~Integer(); |
18 | 25 | ||
19 | virtual Object *clone() const; | 26 | virtual Object *clone() const; |
20 | 27 | ||
21 | virtual Type getType() const { return typeInteger; } | 28 | virtual Type getType() const { return typeInteger; } |
22 | int64_t getValue() const { return iVal; } | 29 | int64_t getValue() const { return iVal; } |
23 | 30 | ||
24 | virtual void write( Bu::Stream &rOut ) const; | 31 | virtual void write( Bu::Stream &rOut ) const; |
25 | virtual void read( Bu::Stream &rIn, char cType ); | 32 | virtual void read( Bu::Stream &rIn, char cType ); |
26 | 33 | ||
27 | template<typename itype> | 34 | template<typename itype> |
28 | static void readPackedInt( Bu::Stream &rStream, itype &rOut ) | 35 | static void readPackedInt( Bu::Stream &rStream, itype &rOut ) |
29 | { | 36 | { |
30 | int8_t b; | 37 | int8_t b; |
31 | rOut = 0; | 38 | rOut = 0; |
32 | bool bNeg; | 39 | bool bNeg; |
33 | 40 | ||
34 | rStream.read( &b, 1 ); | 41 | rStream.read( &b, 1 ); |
35 | bNeg = ( b&0x40 ); | 42 | bNeg = ( b&0x40 ); |
36 | rOut |= (itype(b&0x3F)); | 43 | rOut |= (itype(b&0x3F)); |
37 | int c = 0; | 44 | int c = 0; |
38 | while( (b&0x80) ) | 45 | while( (b&0x80) ) |
39 | { | 46 | { |
40 | rStream.read( &b, 1 ); | 47 | rStream.read( &b, 1 ); |
41 | rOut |= (itype(b&0x7F)) << (6+7*(c++)); | 48 | rOut |= (itype(b&0x7F)) << (6+7*(c++)); |
42 | } | 49 | } |
43 | if( bNeg ) rOut = -rOut; | 50 | if( bNeg ) rOut = -rOut; |
44 | } | 51 | } |
45 | 52 | ||
46 | template<typename itype> | 53 | template<typename itype> |
47 | static void writePackedInt( Bu::Stream &rStream, itype iIn ) | 54 | static void writePackedInt( Bu::Stream &rStream, itype iIn ) |
48 | { | 55 | { |
49 | uint8_t b; | 56 | uint8_t b; |
50 | 57 | ||
51 | if( iIn < 0 ) | 58 | if( iIn < 0 ) |
52 | { | 59 | { |
53 | iIn = -iIn; | 60 | iIn = -iIn; |
54 | b = (iIn&0x3F); | 61 | b = (iIn&0x3F); |
55 | if( iIn > b ) | 62 | if( iIn > b ) |
56 | b |= 0x80 | 0x40; | 63 | b |= 0x80 | 0x40; |
57 | else | 64 | else |
58 | b |= 0x40; | 65 | b |= 0x40; |
59 | } | 66 | } |
60 | else | 67 | else |
61 | { | 68 | { |
62 | b = (iIn&0x3F); | 69 | b = (iIn&0x3F); |
63 | if( iIn > b ) | 70 | if( iIn > b ) |
64 | b |= 0x80; | 71 | b |= 0x80; |
65 | } | 72 | } |
66 | rStream.write( &b, 1 ); | 73 | rStream.write( &b, 1 ); |
67 | iIn = iIn >> 6; | 74 | iIn = iIn >> 6; |
68 | 75 | ||
69 | while( iIn ) | 76 | while( iIn ) |
70 | { | 77 | { |
71 | b = (iIn&0x7F); | 78 | b = (iIn&0x7F); |
72 | if( iIn > b ) | 79 | if( iIn > b ) |
73 | b |= 0x80; | 80 | b |= 0x80; |
74 | rStream.write( &b, 1 ); | 81 | rStream.write( &b, 1 ); |
75 | iIn = iIn >> 7; | 82 | iIn = iIn >> 7; |
76 | } | 83 | } |
77 | } | 84 | } |
78 | 85 | ||
79 | private: | 86 | private: |
80 | int64_t iVal; | 87 | int64_t iVal; |
81 | }; | 88 | }; |
82 | }; | 89 | }; |
83 | 90 | ||
84 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); | 91 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); |