summaryrefslogtreecommitdiff
path: root/lib/common/StreamableMemBlock.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common/StreamableMemBlock.h')
-rw-r--r--lib/common/StreamableMemBlock.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/common/StreamableMemBlock.h b/lib/common/StreamableMemBlock.h
new file mode 100644
index 00000000..250c0aea
--- /dev/null
+++ b/lib/common/StreamableMemBlock.h
@@ -0,0 +1,71 @@
+// --------------------------------------------------------------------------
+//
+// File
+// Name: StreamableMemBlock.h
+// Purpose: Memory blocks which can be loaded and saved from streams
+// Created: 2003/09/05
+//
+// --------------------------------------------------------------------------
+
+#ifndef STREAMABLEMEMBLOCK__H
+#define STREAMABLEMEMBLOCK__H
+
+class IOStream;
+
+// --------------------------------------------------------------------------
+//
+// Class
+// Name: StreamableMemBlock
+// Purpose: Memory blocks which can be loaded and saved from streams
+// Created: 2003/09/05
+//
+// --------------------------------------------------------------------------
+class StreamableMemBlock
+{
+public:
+ StreamableMemBlock();
+ StreamableMemBlock(int Size);
+ StreamableMemBlock(void *pBuffer, int Size);
+ StreamableMemBlock(const StreamableMemBlock &rToCopy);
+ ~StreamableMemBlock();
+
+ void Set(const StreamableMemBlock &rBlock);
+ void Set(void *pBuffer, int Size);
+ void Set(IOStream &rStream, int Timeout);
+ StreamableMemBlock &operator=(const StreamableMemBlock &rBlock)
+ {
+ Set(rBlock);
+ return *this;
+ }
+
+ void ReadFromStream(IOStream &rStream, int Timeout);
+ void WriteToStream(IOStream &rStream) const;
+
+ static void WriteEmptyBlockToStream(IOStream &rStream);
+
+ void *GetBuffer() const;
+
+ // Size of block
+ int GetSize() const {return mSize;}
+
+ // Buffer empty?
+ bool IsEmpty() const {return mSize == 0;}
+
+ // Clear the contents of the block
+ void Clear() {FreeBlock();}
+
+ bool operator==(const StreamableMemBlock &rCompare) const;
+
+ void ResizeBlock(int Size);
+
+protected: // be careful with these!
+ void AllocateBlock(int Size);
+ void FreeBlock();
+
+private:
+ void *mpBuffer;
+ int mSize;
+};
+
+#endif // STREAMABLEMEMBLOCK__H
+