00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _memorystream_h
00018 #define _memorystream_h
00019
00020 #include <spl/Debug.h>
00021 #include <spl/collection/Array.h>
00022 #include <spl/io/IStream.h>
00023 #include <spl/RefCountPtr.h>
00024 #include <spl/collection/Vector.h>
00025 #include <spl/WeakReference.h>
00026
00033 class MemoryStream;
00034 typedef RefCountPtrCast<MemoryStream, spl::IStream, spl::IStreamPtr> MemoryStreamPtr;
00035 typedef WeakReference<MemoryStream, spl::IStreamPtr> MemoryStreamRef;
00036
00037 REGISTER_TYPEOF(110, MemoryStreamPtr);
00038 REGISTER_TYPEOF( 459, MemoryStreamRef );
00039
00043 class MemoryStream : public spl::IStream
00044 {
00045 protected:
00046
00047 Vector<byte> m_buf;
00048 int m_ptr;
00049
00050 public:
00051 MemoryStream();
00052
00053 inline MemoryStream(const MemoryStream& ms)
00054 : m_buf(ms.m_buf), m_ptr(ms.m_ptr)
00055 {
00056 }
00057
00058 virtual ~MemoryStream();
00059
00060 inline MemoryStream& operator =(const MemoryStream &ms)
00061 {
00062 m_buf = ms.m_buf;
00063 m_ptr = ms.m_ptr;
00064 return *this;
00065 }
00066
00067 virtual void Close();
00068 virtual void Flush();
00069 virtual int Read(Array<byte>& buffer, const int offset, int count);
00070 inline int Read(Array<byte>& buffer) { return Read(buffer, 0, buffer.Length()); }
00071 virtual int ReadByte();
00072 virtual long Seek(const long offset, const SeekOrigin origin);
00073 virtual void Write(const Array<byte>& buffer, const int offset, const int count);
00074 inline void Write(const Array<byte>& buffer) { Write(buffer, 0, buffer.Length()); }
00075 virtual void WriteByte(byte value);
00076
00077 virtual bool CanRead() const;
00078 virtual bool CanSeek() const;
00079 virtual bool CanWrite() const;
00080
00081 virtual long Length() const;
00082 virtual long Position() const;
00083
00084 StringPtr ToString();
00085
00086 #ifdef DEBUG
00087 virtual void ValidateMem() const;
00088 virtual void CheckMem() const;
00089 #endif
00090 };
00091
00092 REGISTER_TYPEOF(112, MemoryStream);
00093
00096 #endif