From: <sv...@ww...> - 2004-08-08 18:45:08
|
Author: mkrose Date: 2004-08-08 11:45:01 -0700 (Sun, 08 Aug 2004) New Revision: 1211 Modified: trunk/CSP/SimData/CHANGES.current trunk/CSP/SimData/Include/SimData/TaggedRecord.h trunk/CSP/SimData/Include/SimData/Uniform.h trunk/CSP/SimData/Tools/TaggedRecordCompiler/BaseTypes.py Log: Added int64 and uint64 types. HashT already served this purpose for the most part, but could not be used in switch statements (which are handy for message decoding). Changed the tagged record compiler to generate uint64 ids. The types should work on both win32 and gnu/linux. Use the SIMDATA_LL and SIMDATA_ULL macros for defining 64-bit constants in a platform neutral way. Note the int64 and uint64 have not been added to the Reader/Writer interfaces yet. Cleanup up tagged record generation slightly to avoid warning messages under g++ (extra comma at end of an enum list). Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1211 Modified: trunk/CSP/SimData/CHANGES.current =================================================================== --- trunk/CSP/SimData/CHANGES.current 2004-08-08 18:39:29 UTC (rev 1210) +++ trunk/CSP/SimData/CHANGES.current 2004-08-08 18:45:01 UTC (rev 1211) @@ -17,6 +17,17 @@ * Made static thread methods inline to avoid declaring them in multiple translation units (silences a g++ warning). + * Added int64 and uint64 types. HashT already served this purpose for the + most part, but could not be used in switch statements (which are handy + for message decoding). Changed the tagged record compiler to generate + uint64 ids. The types should work on both win32 and gnu/linux. Use + the SIMDATA_LL and SIMDATA_ULL macros for defining 64-bit constants in + a platform neutral way. Note the int64 and uint64 have not been added + to the Reader/Writer interfaces yet. + + * Cleanup up tagged record generation slightly to avoid warning messages + under g++ (extra comma at end of an enum list). + 2004-07-26: delta * Removed some not needed SIMDATA_EXPORT for vs 7.1. Modified: trunk/CSP/SimData/Include/SimData/TaggedRecord.h =================================================================== --- trunk/CSP/SimData/Include/SimData/TaggedRecord.h 2004-08-08 18:39:29 UTC (rev 1210) +++ trunk/CSP/SimData/Include/SimData/TaggedRecord.h 2004-08-08 18:45:01 UTC (rev 1211) @@ -57,11 +57,7 @@ NAMESPACE_SIMDATA -// use our own, platform-neutral int64 representation -// TODO the base class (hasht) should probably renamed. -typedef hasht int64; - /** Simple Writer class for serializing to a memory buffer. */ class BufferWriter: public Writer { @@ -94,6 +90,7 @@ virtual Writer & operator<<(int16 const x) { SIMDATA_BW_COPY } virtual Writer & operator<<(int32 const x) { SIMDATA_BW_COPY } virtual Writer & operator<<(int64 const x) { SIMDATA_BW_COPY } + virtual Writer & operator<<(hasht const x) { SIMDATA_BW_COPY } virtual Writer & operator<<(uint8 const x) { SIMDATA_BW_COPY } virtual Writer & operator<<(uint16 const x) { SIMDATA_BW_COPY } virtual Writer & operator<<(uint32 const x) { SIMDATA_BW_COPY } @@ -101,7 +98,7 @@ virtual Writer & operator<<(double const x) { SIMDATA_BW_COPY } virtual Writer & operator<<(bool const x) { SIMDATA_BW_COPY } virtual Writer & operator<<(hasht const &x) { SIMDATA_BW_COPY } - virtual Writer & operator<<(char const *x) { + virtual Writer & operator<<(char const *) { assert(0); return *this; } @@ -146,13 +143,14 @@ virtual Reader & operator>>(int16 &x) { SIMDATA_BR_COPY } virtual Reader & operator>>(int32 &x) { SIMDATA_BR_COPY } virtual Reader & operator>>(int64 &x) { SIMDATA_BR_COPY } + virtual Reader & operator>>(hasht &x) { SIMDATA_BR_COPY } virtual Reader & operator>>(uint8 &x) { SIMDATA_BR_COPY } virtual Reader & operator>>(uint16 &x) { SIMDATA_BR_COPY } virtual Reader & operator>>(uint32 &x) { SIMDATA_BR_COPY } virtual Reader & operator>>(float &x) { SIMDATA_BR_COPY } virtual Reader & operator>>(double &x) { SIMDATA_BR_COPY } virtual Reader & operator>>(bool &x) { SIMDATA_BR_COPY } - virtual Reader & operator>>(char * &x) { + virtual Reader & operator>>(char * &) { assert(0); // avoid allocation issues for now -- no char*'s return *this; } @@ -194,6 +192,10 @@ _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); return *this; } + virtual Writer & operator<<(hasht const x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } virtual Writer & operator<<(uint8 const x) { _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); return *this; @@ -277,6 +279,13 @@ _bytes -= sizeof(x); return *this; } + virtual Reader & operator>>(hasht &x) { + assert(_bytes >= sizeof(x)); + x = *(reinterpret_cast<hasht const*>(_data)); + _data += sizeof(x); + _bytes -= sizeof(x); + return *this; + } virtual Reader & operator>>(uint8 &x) { assert(_bytes >= sizeof(x)); x = *(reinterpret_cast<uint8 const*>(_data)); @@ -436,7 +445,7 @@ class TaggedRecord: public Referenced { public: typedef Ref<TaggedRecord> Ref; - typedef int64 Id; + typedef uint64 Id; virtual void serialize(TagReader &reader) = 0; virtual void serialize(TagWriter &writer) const = 0; virtual Id getId() const=0; Modified: trunk/CSP/SimData/Include/SimData/Uniform.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Uniform.h 2004-08-08 18:39:29 UTC (rev 1210) +++ trunk/CSP/SimData/Include/SimData/Uniform.h 2004-08-08 18:45:01 UTC (rev 1211) @@ -54,6 +54,26 @@ typedef unsigned short uint16; typedef signed int int32; typedef unsigned int uint32; + +#ifdef _WIN32 +typedef __int64 int64; +typedef unsigned __int64 uint64; +# define SIMDATA_ULL(x) x +# define SIMDATA_LL(x) x +#else +// use __extension__ to avoid G++ errors with -pedantic +#ifndef SWIG +__extension__ +#endif // SWIG +typedef long long int64; +#ifndef SWIG +__extension__ +#endif // SWIG +typedef unsigned long long uint64; +# define SIMDATA_ULL(x) x##ULL +# define SIMDATA_LL(x) x##LL +#endif + //@} /** Test for big-endian byte order */ Modified: trunk/CSP/SimData/Tools/TaggedRecordCompiler/BaseTypes.py =================================================================== --- trunk/CSP/SimData/Tools/TaggedRecordCompiler/BaseTypes.py 2004-08-08 18:39:29 UTC (rev 1210) +++ trunk/CSP/SimData/Tools/TaggedRecordCompiler/BaseTypes.py 2004-08-08 18:45:01 UTC (rev 1211) @@ -129,16 +129,21 @@ format.write('enum {') format.indent() idx = 8 - for element in self.elements: + # write all but the last element tag + for element in self.elements[:-1]: format.write('TAG_%s = %d,' % (element.id, idx)) idx = idx + 1 + # write last element without a trailing comma to prevent compiler + # warnings/errors + if self.elements: + element = self.elements[-1] + format.write('TAG_%s = %d' % (element.id, idx)) + idx = idx + 1 format.dedent() format.write('};') format.write() for element in self.elements: format.write('simdata::int32 m_has_%s : 1;' % (element.id)) - format.write() - for element in self.elements: element.dump_private(format); format.dedent() format.write() @@ -430,6 +435,7 @@ if not format: format = CodeFormat.Format(file=file) format.write('int %s::m_CustomId = 0;' % (self.id)) + format.write('const %s::Id %s::_Id;' % (self.id, self.id)) format.write('namespace { simdata::TaggedRecordFactory<%s> __%s_factory; }' % (self.id, self.id)) def _extra(self, format): @@ -440,8 +446,8 @@ except ValueError: print >>sys.stderr, 'ERROR: VERSION option on %s must be an integer' % name sys.exit(1) - id0, id1 = md5hash32('%s_%d' % (name, version)) - d = {'name': name, 'version': version, 'id0': id0, 'id1': id1} + id64 = md5hash64('%s_%d' % (name, version)) + d = {'name': name, 'version': version, 'id64': id64} format.template(Message.TRF_GETID, d) format.template(Message.TRF_GETVERSION, d) format.template(Message.TRF_GETNAME, d) @@ -464,7 +470,8 @@ TRF_GETID = ''' virtual Id getId() const { return _getId(); } - static inline Id _getId() { return Id(%(id0)du, %(id1)du); } + static const Id _Id = SIMDATA_ULL(%(id64)d); + static inline Id _getId() { return _Id; } virtual int getCustomId() const { return _getCustomId(); } static inline int _getCustomId() { return m_CustomId; } static inline void _setCustomId(int id) { m_CustomId = id; } |