1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
// --------------------------------------------------------------------------
//
// File
// Name: MemBlockStream.h
// Purpose: Stream out data from any memory block
// Created: 2003/09/05
//
// --------------------------------------------------------------------------
#ifndef MEMBLOCKSTREAM__H
#define MEMBLOCKSTREAM__H
#include "CollectInBufferStream.h"
#include "IOStream.h"
class StreamableMemBlock;
// --------------------------------------------------------------------------
//
// Class
// Name: MemBlockStream
// Purpose: Stream out data from any memory block -- be careful the lifetime
// of the block is greater than the lifetime of this stream.
// Created: 2003/09/05
//
// --------------------------------------------------------------------------
class MemBlockStream : public IOStream
{
public:
MemBlockStream();
MemBlockStream(const void *pBuffer, int Size);
MemBlockStream(const std::string& rMessage);
MemBlockStream(const StreamableMemBlock &rBlock);
MemBlockStream(const CollectInBufferStream &rBuffer);
MemBlockStream(const MemBlockStream &rToCopy);
~MemBlockStream();
public:
virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
virtual pos_type BytesLeftToRead();
virtual void Write(const void *pBuffer, int NBytes,
int Timeout = IOStream::TimeOutInfinite);
virtual pos_type GetPosition() const;
virtual void Seek(pos_type Offset, int SeekType);
virtual bool StreamDataLeft();
virtual bool StreamClosed();
virtual const void* GetBuffer() const { return mpBuffer; }
virtual int GetSize() const { return mBytesInBuffer; }
private:
// Use mTempBuffer when we need to hold a copy of the memory block,
// and free it ourselves when done.
CollectInBufferStream mTempBuffer;
const char *mpBuffer;
int mBytesInBuffer;
int mReadPosition;
};
#endif // MEMBLOCKSTREAM__H
|