00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _mistream_h
00018 #define _mistream_h
00019
00020 #include <spl/types.h>
00021 #include <spl/Debug.h>
00022
00023 #include <spl/DelegateDispatch.h>
00024 #include <spl/Memory.h>
00025 #include <spl/RefCountPtr.h>
00026 #include <spl/RefCountPtrCast.h>
00027 #include <spl/String.h>
00028
00037 namespace spl
00038 {
00039 class IStream;
00040 typedef RefCountPtr<IStream> IStreamPtr;
00041
00043 class IStream : public IMemoryValidate
00044 {
00045 private:
00046
00047 inline IStream(const IStream& strm) {}
00048 inline void operator =(const IStream& strm) {}
00049
00050 public:
00052 typedef enum _SeekOrigin
00053 {
00054 SEEK_Begin = 0,
00055 SEEK_Current = 1,
00056 SEEK_End = 2
00057 } SeekOrigin;
00058
00059 protected:
00060 IStream();
00061
00062 public:
00063 virtual ~IStream();
00064
00065 virtual void Close() = 0;
00066 virtual void Flush() = 0;
00067 virtual int Read(Array<byte>& buffer, const int offset, int count) = 0;
00068 inline int Read(Array<byte>& buffer) { return Read(buffer, 0, buffer.Length()); }
00069 virtual int ReadByte() = 0;
00070 virtual long Seek(const long offset, const SeekOrigin origin) = 0;
00071 virtual void Write(const Array<byte>& buffer, const int offset, const int count) = 0;
00072 inline void Write(const Array<byte>& buffer) { Write(buffer, 0, buffer.Length()); }
00073 virtual void WriteByte(byte value) = 0;
00074
00075 virtual bool CanRead() const = 0;
00076 virtual bool CanSeek() const = 0;
00077 virtual bool CanWrite() const = 0;
00078
00079 virtual long Length() const = 0;
00080 virtual long Position() const = 0;
00081
00082 #ifdef DEBUG
00083 virtual void ValidateMem() const = 0;
00084 virtual void CheckMem() const = 0;
00085 #endif
00086 };
00087 };
00088
00089 REGISTER_TYPEOF(102, spl::IStreamPtr);
00090 REGISTER_TYPEOF(104, spl::IStream);
00091
00092 class IStreamReadListener;
00093 typedef RefCountPtr<IStreamReadListener> IStreamReadListenerPtr;
00094
00095 REGISTER_TYPEOF(106, IStreamReadListenerPtr);
00096
00098 class IStreamReadListener : public IMemoryValidate
00099 {
00100 public:
00101 virtual ~IStreamReadListener();
00102 virtual void IStreamRead_OnClose() = 0;
00103 virtual void IStreamRead_OnRead(const Array<byte>& buf, int len) = 0;
00104 virtual void IStreamRead_OnError( const String& msg ) = 0;
00105 };
00106
00107 REGISTER_TYPEOF(108, IStreamReadListener);
00108
00111 #endif