From 82da0238a8171cf8bba6bb1c82d5abba207a10aa Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 31 Mar 2012 17:34:11 +0000 Subject: 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. --- c++-qt/src/integer.h | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 c++-qt/src/integer.h (limited to 'c++-qt/src/integer.h') 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 @@ +#ifndef GATS_INTEGER_H +#define GATS_INTEGER_H + +#include "gats-qt/object.h" + +#include + +#include + +namespace Gats +{ + class Integer : public Gats::Object + { + Q_OBJECT; + public: + Integer(); + Integer( int64_t iVal ); + virtual ~Integer(); + + virtual Type getType() const { return typeInteger; } + int64_t getValue() const { return iVal; } + + virtual void write( QIODevice &rOut ) const; + virtual void read( QIODevice &rIn, char cType ); + + template + static void readPackedInt( QIODevice &rStream, itype &rOut ) + { + int8_t b; + rOut = 0; + bool bNeg; + + rStream.read( (char *)&b, 1 ); + bNeg = ( b&0x40 ); + rOut |= (itype(b&0x3F)); + int c = 0; + while( (b&0x80) ) + { + rStream.read( (char *)&b, 1 ); + rOut |= (itype(b&0x7F)) << (6+7*(c++)); + } + if( bNeg ) rOut = -rOut; + } + + template + static void writePackedInt( QIODevice &rStream, itype iIn ) + { + uint8_t b; + + if( iIn < 0 ) + { + iIn = -iIn; + b = (iIn&0x3F); + if( iIn > b ) + b |= 0x80 | 0x40; + else + b |= 0x40; + } + else + { + b = (iIn&0x3F); + if( iIn > b ) + b |= 0x80; + } + rStream.write( (const char *)&b, 1 ); + iIn = iIn >> 6; + + while( iIn ) + { + b = (iIn&0x7F); + if( iIn > b ) + b |= 0x80; + rStream.write( (const char *)&b, 1 ); + iIn = iIn >> 7; + } + } + + private: + int64_t iVal; + }; +}; + +//Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); + +#endif -- cgit v1.2.3