TuttleOFX
1
|
00001 /// -*- mode: C++; tab-width: 4 -*- 00002 // vi: ts=4 00003 00004 /*! \file DPXStream.h */ 00005 00006 /* 00007 * Copyright (c) 2009, Patrick A. Palmer. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions are met: 00012 * 00013 * - Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 00016 * - Redistributions in binary form must reproduce the above copyright 00017 * notice, this list of conditions and the following disclaimer in the 00018 * documentation and/or other materials provided with the distribution. 00019 * 00020 * - Neither the name of Patrick A. Palmer nor the names of its 00021 * contributors may be used to endorse or promote products derived from 00022 * this software without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00027 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00028 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00029 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00030 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00031 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00032 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00033 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 */ 00036 00037 00038 #ifndef _DPX_DPXSTREAM_H 00039 #define _DPX_DPXSTREAM_H 1 00040 00041 00042 #include <cstdio> 00043 00044 00045 00046 /*! 00047 * \class InStream 00048 * \brief Input Stream for reading files 00049 */ 00050 class InStream 00051 { 00052 00053 public: 00054 00055 /*! 00056 * \enum Origin 00057 * \brief file pointing positioning offset 00058 */ 00059 enum Origin 00060 { 00061 kStart, //!< beginning of the file 00062 kCurrent, //!< current file pointer 00063 kEnd //!< end of the file 00064 }; 00065 00066 00067 /*! 00068 * \brief Constructor 00069 */ 00070 InStream(); 00071 00072 /*! 00073 * \brief Destructor 00074 */ 00075 virtual ~InStream(); 00076 00077 /*! 00078 * \brief Open file 00079 * \param fn File name 00080 * \return success true/false 00081 */ 00082 virtual bool Open(const char * fn); 00083 00084 /*! 00085 * \brief Close file 00086 */ 00087 virtual void Close(); 00088 00089 /*! 00090 * \brief Rewind file pointer to beginning of file 00091 */ 00092 virtual void Rewind(); 00093 00094 /*! 00095 * \brief Read data from file 00096 * \param buf data buffer 00097 * \param size bytes to read 00098 * \return number of bytes read 00099 */ 00100 virtual size_t Read(void * buf, const size_t size); 00101 00102 00103 /*! 00104 * \brief Read data from file without any buffering as fast as possible 00105 * \param buf data buffer 00106 * \param size bytes to read 00107 * \return number of bytes read 00108 */ 00109 virtual size_t ReadDirect(void * buf, const size_t size); 00110 00111 /*! 00112 * \brief Query if end of file has been reached 00113 * \return end of file true/false 00114 */ 00115 virtual bool EndOfFile() const; 00116 00117 /*! 00118 * \brief Seek to a position in the file 00119 * \param offset offset from originating position 00120 * \param origin originating position 00121 * \return success true/false 00122 */ 00123 virtual bool Seek(long offset, Origin origin); 00124 00125 protected: 00126 FILE *fp; 00127 }; 00128 00129 00130 00131 /*! 00132 * \class OutStream 00133 * \brief Output Stream for writing files 00134 */ 00135 class OutStream 00136 { 00137 00138 public: 00139 00140 /*! 00141 * \enum Origin 00142 * \brief file pointing positioning offset 00143 */ 00144 enum Origin 00145 { 00146 kStart, //!< beginning of the file 00147 kCurrent, //!< current file pointer 00148 kEnd //!< end of the file 00149 }; 00150 00151 /*! 00152 * \brief Constructor 00153 */ 00154 OutStream(); 00155 00156 /*! 00157 * \brief Destructor 00158 */ 00159 virtual ~OutStream(); 00160 00161 /*! 00162 * \brief Open file 00163 * \param fn File name 00164 * \return success true/false 00165 */ 00166 virtual bool Open(const char *fn); 00167 00168 /*! 00169 * \brief Close file 00170 */ 00171 virtual void Close(); 00172 00173 /*! 00174 * \brief Write data to file 00175 * \param buf data buffer 00176 * \param size bytes to write 00177 * \return number of bytes written 00178 */ 00179 virtual size_t Write(void * buf, const size_t size); 00180 00181 /*! 00182 * \brief Seek to a position in the file 00183 * \param offset offset from originating position 00184 * \param origin originating position 00185 * \return success true/false 00186 */ 00187 virtual bool Seek(long offset, Origin origin); 00188 00189 /*! 00190 * \brief Flush any buffers 00191 */ 00192 virtual void Flush(); 00193 00194 00195 protected: 00196 FILE *fp; 00197 }; 00198 00199 00200 00201 00202 00203 #endif 00204