summaryrefslogtreecommitdiff
path: root/src/core/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/common.h')
-rw-r--r--src/core/common.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/core/common.h b/src/core/common.h
index caa305d6..3ea37071 100644
--- a/src/core/common.h
+++ b/src/core/common.h
@@ -317,3 +317,54 @@ _TWEEKCLASS(CTweakUInt32, uint32);
_TWEEKCLASS(CTweakFloat, float);
#undef _TWEEKCLASS
+
+#ifdef VALIDATE_SAVE_SIZE
+static int32 _bufBytesRead;
+#define INITSAVEBUF _bufBytesRead = 0;
+#define VALIDATESAVEBUF(b) assert(_bufBytesRead == b);
+#else
+#define INITSAVEBUF
+#define VALIDATESAVEBUF(b)
+#endif
+
+inline void SkipSaveBuf(uint8 *&buf, int32 skip)
+{
+ buf += skip;
+#ifdef VALIDATE_SAVE_SIZE
+ _bufBytesRead += skip;
+#endif
+}
+
+template<typename T>
+inline const T ReadSaveBuf(uint8 *&buf)
+{
+ T &value = *(T*)buf;
+ SkipSaveBuf(buf, sizeof(T));
+ return value;
+}
+
+template<typename T>
+inline T *WriteSaveBuf(uint8 *&buf, const T &value)
+{
+ T *p = (T*)buf;
+ *p = value;
+ SkipSaveBuf(buf, sizeof(T));
+ return p;
+}
+
+
+#define SAVE_HEADER_SIZE (4*sizeof(char)+sizeof(uint32))
+
+#define WriteSaveHeader(buf,a,b,c,d,size) \
+ WriteSaveBuf(buf, a);\
+ WriteSaveBuf(buf, b);\
+ WriteSaveBuf(buf, c);\
+ WriteSaveBuf(buf, d);\
+ WriteSaveBuf(buf, size);
+
+#define CheckSaveHeader(buf,a,b,c,d,size)\
+ assert(ReadSaveBuf<char>(buf) == a);\
+ assert(ReadSaveBuf<char>(buf) == b);\
+ assert(ReadSaveBuf<char>(buf) == c);\
+ assert(ReadSaveBuf<char>(buf) == d);\
+ assert(ReadSaveBuf<uint32>(buf) == size); \ No newline at end of file