• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/io/IStream.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
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                 // Don't alow copy constructor for streams
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,         //< Seek from the start of the stream, not supported on all streams.
00055                         SEEK_Current = 1,       //< Seek from the current stream pointer.
00056                         SEEK_End = 2            //< Seek from the end of the stream, not supported on all streams.
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