- Main Page
- Related Pages
- Modules
- Classes
- Files

# MemoryStream.h

Go to the documentation of this file.

    00001 #ifndef FDO_IO_MEMORYSTREAM_H
    00002 #define FDO_IO_MEMORYSTREAM_H
    00003 //
    00004
    00005 //
    00006 // Copyright (C) 2004-2006  Autodesk, Inc.
    00007 //
    00008 // This library is free software; you can redistribute it and/or
    00009 // modify it under the terms of version 2.1 of the GNU Lesser
    00010 // General Public License as published by the Free Software Foundation.
    00011 //
    00012 // This library is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015 // Lesser General Public License for more details.
    00016 //
    00017 // You should have received a copy of the GNU Lesser General Public
    00018 // License along with this library; if not, write to the Free Software
    00019 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    00020 //
    00021
    00022 #include <Common/Io/Stream.h>
    00023 #include <Common/Collection.h>
    00024 #include <Common/Io/BufferStream.h>
    00025
    00026 /// \brief
    00027 /// FdoIoMemoryStream provides streamed I/O to and from memory.
    00028 class FdoIoMemoryStream :
    00029     public FdoIoStream
    00030 {
    00031 public:
    00032     /// \brief
    00033     /// creates the memory stream. The stream manages its own storage.
    00034     ///
    00035     /// \param bufferSize
    00036     /// Input memory allocation increment. Amount of new memory to
    00037     /// allocated when the stream needs more memory.
    00038     ///
    00039     /// \return
    00040     /// Returns the created memory stream.
    00041     ///
    00042     FDO_API_COMMON static FdoIoMemoryStream* Create( FdoSize bufferSize = 4096 );
    00043
    00044     FDO_API_COMMON virtual FdoSize Read( FdoByte* buffer, FdoSize count );
    00045     FDO_API_COMMON virtual void Write( FdoByte* buffer, FdoSize count );
    00046     FDO_API_COMMON virtual void Write( FdoIoStream* stream, FdoSize count = 0 );
    00047     FDO_API_COMMON virtual void SetLength( FdoInt64 length );
    00048     FDO_API_COMMON virtual FdoInt64 GetLength() {
    00049         return( mLength );
    00050     }
    00051
    00052     FDO_API_COMMON virtual FdoInt64 GetIndex()
    00053     {
    00054         return(mPos);
    00055     }
    00056
    00057     FDO_API_COMMON virtual void Skip( FdoInt64 offset );
    00058     FDO_API_COMMON virtual void Reset();
    00059
    00060 protected:
    00061 /// \cond DOXYGEN-IGNORE
    00062     FdoIoMemoryStream(FdoSize bufferSize = 4096);
    00063     virtual ~FdoIoMemoryStream(void);
    00064     void GetBufPosn( FdoSize& bufNum, FdoSize& bufOffset );
    00065 /// \endcond
    00066
    00067 private:
    00068     /// Buffer collection class
    00069     class Buffers : public FdoCollection<FdoIoBufferStream,FdoException>
    00070     {
    00071     public:
    00072         static Buffers* Create() {return new Buffers();}
    00073
    00074     protected:
    00075         Buffers() {}
    00076         ~Buffers() {}
    00077         virtual void Dispose()
    00078         {
    00079             delete this;
    00080         }
    00081
    00082     };
    00083
    00084     /// Collection of buffers where stream contents are stored.
    00085     FdoPtr<Buffers> mBuffers;
    00086     /// Buffer size
    00087     FdoSize mBufferSize;
    00088     /// Stream length
    00089     FdoInt64 mLength;
    00090     /// Current stream position
    00091     FdoInt64 mPos;
    00092
    00093 };
    00094
    00095 /// \ingroup (typedefs)
    00096 /// \brief
    00097 /// FdoIoMemoryStreamP is a FdoPtr on FdoIoMemoryStream, provided for convenience.
    00098 typedef FdoPtr<FdoIoMemoryStream> FdoIoMemoryStreamP;
    00099
    00100 #endif
    00101
    00102

Please send us your comment about this page