| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: StreamableMemBlock.h |
|---|
| 5 | // Purpose: Memory blocks which can be loaded and saved from streams |
|---|
| 6 | // Created: 2003/09/05 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef STREAMABLEMEMBLOCK__H |
|---|
| 11 | #define STREAMABLEMEMBLOCK__H |
|---|
| 12 | |
|---|
| 13 | class IOStream; |
|---|
| 14 | |
|---|
| 15 | // -------------------------------------------------------------------------- |
|---|
| 16 | // |
|---|
| 17 | // Class |
|---|
| 18 | // Name: StreamableMemBlock |
|---|
| 19 | // Purpose: Memory blocks which can be loaded and saved from streams |
|---|
| 20 | // Created: 2003/09/05 |
|---|
| 21 | // |
|---|
| 22 | // -------------------------------------------------------------------------- |
|---|
| 23 | class StreamableMemBlock |
|---|
| 24 | { |
|---|
| 25 | public: |
|---|
| 26 | StreamableMemBlock(); |
|---|
| 27 | StreamableMemBlock(int Size); |
|---|
| 28 | StreamableMemBlock(void *pBuffer, int Size); |
|---|
| 29 | StreamableMemBlock(const StreamableMemBlock &rToCopy); |
|---|
| 30 | ~StreamableMemBlock(); |
|---|
| 31 | |
|---|
| 32 | void Set(const StreamableMemBlock &rBlock); |
|---|
| 33 | void Set(void *pBuffer, int Size); |
|---|
| 34 | void Set(IOStream &rStream, int Timeout); |
|---|
| 35 | StreamableMemBlock &operator=(const StreamableMemBlock &rBlock) |
|---|
| 36 | { |
|---|
| 37 | Set(rBlock); |
|---|
| 38 | return *this; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | void ReadFromStream(IOStream &rStream, int Timeout); |
|---|
| 42 | void WriteToStream(IOStream &rStream) const; |
|---|
| 43 | |
|---|
| 44 | static void WriteEmptyBlockToStream(IOStream &rStream); |
|---|
| 45 | |
|---|
| 46 | void *GetBuffer() const; |
|---|
| 47 | |
|---|
| 48 | // Size of block |
|---|
| 49 | int GetSize() const {return mSize;} |
|---|
| 50 | |
|---|
| 51 | // Buffer empty? |
|---|
| 52 | bool IsEmpty() const {return mSize == 0;} |
|---|
| 53 | |
|---|
| 54 | // Clear the contents of the block |
|---|
| 55 | void Clear() {FreeBlock();} |
|---|
| 56 | |
|---|
| 57 | bool operator==(const StreamableMemBlock &rCompare) const; |
|---|
| 58 | |
|---|
| 59 | void ResizeBlock(int Size); |
|---|
| 60 | |
|---|
| 61 | protected: // be careful with these! |
|---|
| 62 | void AllocateBlock(int Size); |
|---|
| 63 | void FreeBlock(); |
|---|
| 64 | |
|---|
| 65 | private: |
|---|
| 66 | void *mpBuffer; |
|---|
| 67 | int mSize; |
|---|
| 68 | }; |
|---|
| 69 | |
|---|
| 70 | #endif // STREAMABLEMEMBLOCK__H |
|---|
| 71 | |
|---|