FDO API Reference Feature Data Objects

FileStream.h

Go to the documentation of this file.
00001 #ifndef FDO_IO_FILESTREAM_H
00002 #define FDO_IO_FILESTREAM_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 
00024 /// \brief
00025 /// FdoIoFileStream provides streamed I/O on a disk file.
00026 class FdoIoFileStream :
00027     public FdoIoStream
00028 {
00029 public:
00030     /// \brief
00031     /// creates the stream for a named file.
00032     /// 
00033     /// \param fileName 
00034     /// Input the file name
00035     /// \param accessModes 
00036     /// Input File access modes. Same as the fopen() C run-time library function
00037     /// (mode parameter).
00038     /// 
00039     /// \return
00040     /// Returns the created file stream.
00041     /// 
00042     static FDO_API_COMMON FdoIoFileStream* Create(FdoString* fileName, FdoString* accessModes );
00043 
00044     /// \brief
00045     /// creates the stream around a C Runtime file stream.
00046     /// 
00047     /// \param fp 
00048     /// Input the file stream pointer.
00049     /// 
00050     /// \return
00051     /// Returns the created file stream.
00052     /// 
00053     FDO_API_COMMON static FdoIoFileStream* Create(FILE* fp);
00054 
00055     FDO_API_COMMON virtual FdoSize Read( FdoByte* buffer, FdoSize count );
00056     FDO_API_COMMON virtual void Write( FdoByte* buffer, FdoSize count );
00057     FDO_API_COMMON virtual void Write( FdoIoStream* stream, FdoSize count = 0 );
00058     FDO_API_COMMON virtual void SetLength( FdoInt64 length );
00059     FDO_API_COMMON virtual FdoInt64 GetLength();
00060     FDO_API_COMMON virtual FdoInt64 GetIndex();
00061     FDO_API_COMMON virtual void Skip( FdoInt64 offset );
00062     FDO_API_COMMON virtual void Reset();
00063 
00064     FDO_API_COMMON virtual FdoBoolean CanRead();
00065     FDO_API_COMMON virtual FdoBoolean CanWrite();
00066     FDO_API_COMMON virtual FdoBoolean HasContext();
00067 
00068 protected:
00069 /// \cond DOXYGEN-IGNORE
00070     /// Default constructor to satisfy Linux
00071     FdoIoFileStream() {}
00072     FdoIoFileStream(FdoString* fileName, FdoString* accessModes );
00073     FdoIoFileStream(FILE* fp);
00074     virtual ~FdoIoFileStream(void);
00075 
00076     int GetFd()
00077     {
00078         return mFd;
00079     }
00080 
00081     /// Sets up the canRead and canWrite flags.
00082     void InitFileStatus();
00083 
00084     /// Throw exception if this stream has no context.
00085     /// Context is lost when the file size exceeds MAX_LONG.
00086     void CheckContext( FdoString* caller );
00087 
00088     /// Buffer size for writing from another stream.
00089     static const size_t mBufferSize = 1024;
00090 /// \endcond
00091 
00092 private:
00093     FILE*         mFp;
00094     int           mFd;
00095     FdoBoolean    mbMyFp;
00096     FdoBoolean    mbCanRead;
00097     FdoBoolean    mbCanWrite;
00098     FdoBoolean    mbHasContext;
00099     FdoBoolean    mbTextMode;
00100 };
00101 
00102 /// \brief
00103 /// FdoIoFileStreamP is a FdoPtr on FdoIoFileStream, provided for convenience.
00104 typedef FdoPtr<FdoIoFileStream> FdoIoFileStreamP;
00105 
00106 #endif
00107 
00108 

Comments or suggestions? Send us feedback.