| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: CollectInBufferStream.h |
|---|
| 5 | // Purpose: Collect data in a buffer, and then read it out. |
|---|
| 6 | // Created: 2003/08/26 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef COLLECTINBUFFERSTREAM__H |
|---|
| 11 | #define COLLECTINBUFFERSTREAM__H |
|---|
| 12 | |
|---|
| 13 | #include "IOStream.h" |
|---|
| 14 | #include "Guards.h" |
|---|
| 15 | |
|---|
| 16 | // -------------------------------------------------------------------------- |
|---|
| 17 | // |
|---|
| 18 | // Class |
|---|
| 19 | // Name: CollectInBufferStream |
|---|
| 20 | // Purpose: Collect data in a buffer, and then read it out. |
|---|
| 21 | // Created: 2003/08/26 |
|---|
| 22 | // |
|---|
| 23 | // -------------------------------------------------------------------------- |
|---|
| 24 | class CollectInBufferStream : public IOStream |
|---|
| 25 | { |
|---|
| 26 | public: |
|---|
| 27 | CollectInBufferStream(); |
|---|
| 28 | ~CollectInBufferStream(); |
|---|
| 29 | private: |
|---|
| 30 | // No copying |
|---|
| 31 | CollectInBufferStream(const CollectInBufferStream &); |
|---|
| 32 | CollectInBufferStream(const IOStream &); |
|---|
| 33 | public: |
|---|
| 34 | |
|---|
| 35 | virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite); |
|---|
| 36 | virtual pos_type BytesLeftToRead(); |
|---|
| 37 | virtual void Write(const void *pBuffer, int NBytes); |
|---|
| 38 | virtual pos_type GetPosition() const; |
|---|
| 39 | virtual void Seek(pos_type Offset, int SeekType); |
|---|
| 40 | virtual bool StreamDataLeft(); |
|---|
| 41 | virtual bool StreamClosed(); |
|---|
| 42 | |
|---|
| 43 | void SetForReading(); |
|---|
| 44 | |
|---|
| 45 | void Reset(); |
|---|
| 46 | |
|---|
| 47 | void *GetBuffer() const; |
|---|
| 48 | int GetSize() const; |
|---|
| 49 | bool IsSetForReading() const {return !mInWritePhase;} |
|---|
| 50 | |
|---|
| 51 | private: |
|---|
| 52 | MemoryBlockGuard<char*> mBuffer; |
|---|
| 53 | int mBufferSize; |
|---|
| 54 | int mBytesInBuffer; |
|---|
| 55 | int mReadPosition; |
|---|
| 56 | bool mInWritePhase; |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | #endif // COLLECTINBUFFERSTREAM__H |
|---|
| 60 | |
|---|