Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CAT/CATStreamSub.h Source File

CATStreamSub.h

Go to the documentation of this file.
00001 /// \file CATStreamSub.h
00002 /// \brief Sub-stream class
00003 /// \ingroup CAT
00004 ///
00005 /// Copyright (c) 2003-2007 by Michael Ellison.
00006 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00007 ///
00008 // $Author: mikeellison $
00009 // $Date: 2008-01-21 08:33:12 -0600 (Mon, 21 Jan 2008) $
00010 // $Revision:   $
00011 // $NoKeywords: $
00012 
00013 #ifndef _CATStreamSub_H_
00014 #define _CATStreamSub_H_
00015 
00016 #include "CATStream.h"
00017 
00018 /// \class CATStreamSub CATStreamSub.h
00019 /// \brief sub stream class - should work for all seekable stream types.
00020 /// \ingroup CAT
00021 ///
00022 class CATStreamSub : public CATStream
00023 {
00024    public:
00025          /// Substreams should only be constructed by CreateSubStream() or
00026          /// similar methods. They *must* have a parent stream.
00027          CATStreamSub( CATInt64 offset, CATInt64 length, CATStream* parent);
00028 
00029          /// CATStreamSub() - substream destructor. This should only be
00030          /// called by ReleaseSubStream() or similar methods.
00031          virtual ~CATStreamSub();
00032 
00033          /// Open() should not be called on substreams. They are always open.
00034          /// \sa Close()
00035          virtual CATResult Open(const CATWChar* pathname, OPEN_MODE mode);
00036 
00037          /// OnAcquireSub is used in place of open, and should only be called
00038          /// by the parent stream.
00039          virtual CATResult OnAcquireSub()
00040          {
00041             return CAT_SUCCESS;
00042          }
00043          
00044          /// OnReleaseSub is used in place of close, and should only be
00045          /// called by the parent stream.         
00046          virtual CATResult OnReleaseSub()
00047          {
00048             return CAT_SUCCESS;
00049          }
00050 
00051 
00052          /// Close() should not be called on substreams. 
00053          ///
00054          /// When you are done with a substream, release it by calling
00055          /// CATStream::ReleaseSubStream() with its parent.
00056          /// \sa Open()
00057          virtual CATResult Close();
00058 
00059          /// IsOpen() returns true if the file has been opened, and false otherwise.
00060          ///
00061          /// Substreams should always be open.
00062          ///
00063          /// \return bool - true if file is open.
00064          /// \sa Open(), Close()
00065          virtual bool IsOpen();
00066 
00067          /// Read() reads the requested amount of data into a buffer.
00068          ///
00069          /// Will read up to, but not necessarily, [length] bytes.
00070          /// On return, length is set to the number of bytes actually read.
00071          /// buffer *must* be large enough for max value of length.
00072          /// 
00073          /// \param buffer - target buffer for read
00074          /// \param length - min(length of buffer, desired read length).
00075          ///        Set to amount read on return.
00076          /// \return CATResult - CAT_SUCCESS on success
00077          /// \sa Write()
00078          virtual CATResult Read(void* buffer, CATUInt32& length);
00079 
00080          /// Write() writes the requested amount of data from a buffer.
00081          ///
00082          /// Incomplete writes are treated as an error.
00083          /// 
00084          /// \param buffer - source buffer to write from.
00085          /// \param length - length of data to write.
00086          /// \return CATResult - CAT_SUCCESS on success
00087          /// \sa Read()
00088          virtual CATResult Write(const void* buffer, CATUInt32 length);
00089          
00090          /// Size() returns the size of the object in filesize.
00091          ///
00092          /// This may not be supported on all stream types.
00093          /// \param filesize - 64-bit length of file.
00094          /// \return CATResult - CAT_SUCCESS on success
00095          virtual CATResult Size(CATInt64& filesize);
00096 
00097          /// IsSeekable() returns true for files.
00098          virtual bool     IsSeekable();
00099          
00100          /// SeekRelative() seeks from current position to a
00101          /// relative location.
00102          ///
00103          /// \param offset - signed offset from current position
00104          /// \return CATResult - CAT_SUCCESS on success.
00105          /// \sa IsSeekable(), SeekAbsolute(), SeekFromEnd()
00106          virtual CATResult SeekRelative(CATInt32  offset);         
00107 
00108 
00109          /// SeekAbsolute() seeks from the start of the file
00110          /// to an absolute position.
00111          ///
00112          /// \param position - unsigned absolute position to seek to.
00113          /// \return CATResult - CAT_SUCCESS on success.
00114          /// \sa IsSeekable(), SeekRelative(), SeekFromEnd()
00115          virtual CATResult SeekAbsolute(CATInt64 position);
00116 
00117          /// SeekFromEnd() seeks from the end of the file.
00118          ///
00119          /// \param offset - signed offset from end of stream
00120          /// \return CATResult - CAT_SUCCESS on success.
00121          /// \sa IsSeekable(), SeekRelative(), SeekAbsolute()
00122          virtual CATResult SeekFromEnd(CATInt32 offset);
00123          
00124          /// GetPosition() returns the current position in the stream
00125          /// in position.
00126          ///
00127          /// \param position - current position - set on successful return.
00128          /// \return CATResult - CAT_SUCCESS on success.
00129          /// \sa IsSeekable(), Size()
00130          virtual CATResult GetPosition(CATInt64& position);
00131 
00132          /// GetName() retrieves the filename of the stream.
00133          virtual CATString GetName() const;
00134 
00135          /// ReadAbs() reads from the specified location, but does
00136          /// not change the current stream position.
00137          ///
00138          /// ReadAbs() is mainly for use in substreams, and may not be
00139          /// available from all stream types.  If you're not implementing
00140          /// it, then please return an error from your derived class.
00141          ///
00142          /// \param buffer - target buffer for read
00143          /// \param length - min(length of buffer, desired read length).
00144          ///                 set to amount read on return.
00145          /// \param position - position within stream to read.
00146          ///  \return CATResult - CAT_SUCCESS on success.
00147          virtual CATResult ReadAbs(void *buffer, CATUInt32& length, CATInt64 position);
00148 
00149          /// WriteAbs() Writes from the specified location, but does
00150          /// not change the current stream position.
00151          ///
00152          /// WriteAbs() is mainly for use in substreams, and may not be
00153          /// available from all stream types.  If you're not implementing
00154          /// it, then please return an error from your derived class.
00155          ///
00156          /// \param buffer - target buffer for Write
00157          /// \param length - length of data to write        
00158          /// \param position - position within stream to read.
00159          ///  \return CATResult - CAT_SUCCESS on success.
00160          virtual CATResult WriteAbs(const void *buffer, CATUInt32 length, CATInt64 position);
00161 
00162 
00163       protected:
00164          CATStream*  fParent;
00165          CATInt64    fOffset;
00166          CATInt64    fLength;
00167          CATInt64    fCurPos;
00168 };
00169 
00170 #endif // _CATStreamSub_H_
00171 
00172 

Generated on Mon Feb 11 04:09:48 2008 for Game Accessibility Suite by doxygen 1.5.4