summaryrefslogtreecommitdiffstats
path: root/src/save/SaveBuf.h
diff options
context:
space:
mode:
authorSergeanur <s.anureev@yandex.ua>2021-06-28 02:59:07 +0200
committerSergeanur <s.anureev@yandex.ua>2021-06-28 04:12:54 +0200
commitf8297df9c5a7d65d5658d1a8d85d391fbb15b95a (patch)
tree9dcfac13fc3be99320ca7b546c4ff2007bff4121 /src/save/SaveBuf.h
parentRemove waiting for stream closure in multi-thread audio (diff)
downloadre3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar
re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar.gz
re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar.bz2
re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar.lz
re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar.xz
re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar.zst
re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.zip
Diffstat (limited to 'src/save/SaveBuf.h')
-rw-r--r--src/save/SaveBuf.h115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/save/SaveBuf.h b/src/save/SaveBuf.h
new file mode 100644
index 00000000..1ca0066a
--- /dev/null
+++ b/src/save/SaveBuf.h
@@ -0,0 +1,115 @@
+#pragma once
+
+#ifdef VALIDATE_SAVE_SIZE
+extern int32 _saveBufCount;
+#define INITSAVEBUF _saveBufCount = 0;
+#define VALIDATESAVEBUF(b) assert(_saveBufCount == b);
+#else
+#define INITSAVEBUF
+#define VALIDATESAVEBUF(b)
+#endif
+
+inline void
+SkipSaveBuf(uint8 *&buf, int32 skip)
+{
+ buf += skip;
+#ifdef VALIDATE_SAVE_SIZE
+ _saveBufCount += skip;
+#endif
+}
+
+inline void
+SkipSaveBuf(uint8*& buf, uint32 &length, int32 skip)
+{
+ buf += skip;
+ length += skip;
+#ifdef VALIDATE_SAVE_SIZE
+ _saveBufCount += skip;
+#endif
+}
+
+template<typename T>
+inline void
+ReadSaveBuf(T *out, uint8 *&buf)
+{
+ *out = *(T *)buf;
+ SkipSaveBuf(buf, sizeof(T));
+}
+
+template<typename T>
+inline void
+ReadSaveBuf(T *out, uint8 *&buf, uint32 &length)
+{
+ *out = *(T *)buf;
+ SkipSaveBuf(buf, length, sizeof(T));
+}
+
+template<typename T>
+inline T *
+WriteSaveBuf(uint8 *&buf, const T &value)
+{
+ T *p = (T*)buf;
+ *p = value;
+ SkipSaveBuf(buf, sizeof(T));
+ return p;
+}
+
+template<typename T>
+inline T *
+WriteSaveBuf(uint8 *&buf, uint32 &length, const T &value)
+{
+ T *p = (T*)buf;
+ *p = value;
+ SkipSaveBuf(buf, length, 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<uint32>(buf, size);
+
+#define WriteSaveHeaderWithLength(buf,len,a,b,c,d,size) \
+ WriteSaveBuf(buf, len, a);\
+ WriteSaveBuf(buf, len, b);\
+ WriteSaveBuf(buf, len, c);\
+ WriteSaveBuf(buf, len, d);\
+ WriteSaveBuf(buf, len, (uint32)(size));
+
+#ifdef VALIDATE_SAVE_SIZE
+#define CheckSaveHeader(buf, a, b, c, d, size) do { \
+ char _C; uint32 _size;\
+ ReadSaveBuf(&_C, buf);\
+ assert(_C == a);\
+ ReadSaveBuf(&_C, buf);\
+ assert(_C == b);\
+ ReadSaveBuf(&_C, buf);\
+ assert(_C == c);\
+ ReadSaveBuf(&_C, buf);\
+ assert(_C == d);\
+ ReadSaveBuf(&_size, buf);\
+ assert(_size == size);\
+ } while(0)
+
+#define CheckSaveHeaderWithLength(buf,len,a,b,c,d,size) do { \
+ char _C; uint32 _size;\
+ ReadSaveBuf(&_C, buf, len);\
+ assert(_C == a);\
+ ReadSaveBuf(&_C, buf, len);\
+ assert(_C == b);\
+ ReadSaveBuf(&_C, buf, len);\
+ assert(_C == c);\
+ ReadSaveBuf(&_C, buf, len);\
+ assert(_C == d);\
+ ReadSaveBuf(&_size, buf, len);\
+ assert(_size == size);\
+ } while(0)
+#else
+#define CheckSaveHeader(buf, a, b, c, d, size) SkipSaveBuf(buf, 8);
+#define CheckSaveHeaderWithLength(buf, a, b, c, d, size) SkipSaveBuf(buf, 8);
+#endif