From: <sv...@ww...> - 2004-06-12 12:25:30
|
Author: wolverine Date: 2004-06-12 05:25:24 -0700 (Sat, 12 Jun 2004) New Revision: 1014 Modified: trunk/CSP/SimData/Include/SimData/Archive.h trunk/CSP/SimData/Include/SimData/Uniform.h Log: Added a memory writer class to Archive.h Modified: trunk/CSP/SimData/Include/SimData/Archive.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Archive.h 2004-06-12 11:58:42 UTC (rev 1013) +++ trunk/CSP/SimData/Include/SimData/Archive.h 2004-06-12 12:25:24 UTC (rev 1014) @@ -413,6 +413,71 @@ }; +class SIMDATA_EXPORT MemoryWriter: public Writer { + uint8 * _ptr; + int _n; + //void write(const void* x, int n) { + // fwrite(x, n, 1, _f); + //} +public: + MemoryWriter(uint8 * ptr): Writer(), _n(0) { + _ptr = ptr; + assert(_ptr != 0); + } + void resetCount() { _n = 0; } + int getCount() { return _n; } + + Writer& operator<<(const char x) { + memcpy(_ptr+_n, &x, sizeof(char)); + _n += sizeof(char); + return *this; + } + Writer& operator<<(const short x) { + memcpy(_ptr+_n, &x, sizeof(short)); + _n += sizeof(short); + return *this; + } + Writer& operator<<(const int x) { + memcpy(_ptr+_n, &x, sizeof(x)); + _n += sizeof(int); + return *this; + } + Writer& operator<<(const bool x) { + const char c = x ? 1:0; + operator<<(c); + return *this; + } + Writer& operator<<(const float x) { + memcpy(_ptr+_n, &x, sizeof(x)); + _n += sizeof(x); + return *this; + } + Writer& operator<<(const double x) { + memcpy(_ptr+_n, &x, sizeof(x)); + _n += sizeof(x); + return *this; + } + Writer& operator<<(const char* x) { + int n = strlen(x); + operator<<(n); + memcpy(_ptr+_n, x, n); + _n += n; + return *this; + } + Writer& operator<<(const BaseType &x) { + x.serialize(*this); + return *this; + } + Writer& operator<<(const hasht &x) { + memcpy(_ptr+_n, &x, sizeof(x)); + _n += sizeof(x); + return *this; + } + Writer& operator<<(const std::string &x) { + operator<<(x.c_str()); + return *this; + } +}; NAMESPACE_SIMDATA_END Modified: trunk/CSP/SimData/Include/SimData/Uniform.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Uniform.h 2004-06-12 11:58:42 UTC (rev 1013) +++ trunk/CSP/SimData/Include/SimData/Uniform.h 2004-06-12 12:25:24 UTC (rev 1014) @@ -51,6 +51,7 @@ typedef unsigned short uint16; typedef signed int int32; typedef unsigned int uint32; + //@} /** Test for big-endian byte order */ |