file.h

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (c) 2001, Loki software, inc.
00007 All rights reserved.
00008 
00009 Redistribution and use in source and binary forms, with or without modification,
00010 are permitted provided that the following conditions are met:
00011 
00012 Redistributions of source code must retain the above copyright notice, this list
00013 of conditions and the following disclaimer.
00014 
00015 Redistributions in binary form must reproduce the above copyright notice, this
00016 list of conditions and the following disclaimer in the documentation and/or
00017 other materials provided with the distribution.
00018 
00019 Neither the name of Loki software nor the names of its contributors may be used
00020 to endorse or promote products derived from this software without specific prior
00021 written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00026 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
00027 DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00028 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00030 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00031 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 */
00034 
00035 #if !defined(INCLUDED_PROFILE_FILE_H)
00036 #define INCLUDED_PROFILE_FILE_H
00037 
00038 #include "idatastream.h"
00039 
00040 
00049 class IDataStream : public InputStream, public OutputStream {
00050 public:
00051     typedef int offset_type;
00052     typedef std::size_t position_type;
00053 
00054     virtual void IncRef() = 0;  
00055     virtual void DecRef() = 0; 
00056 
00057     virtual position_type GetPosition() const = 0;
00058     virtual int Seek(offset_type lOff, int nFrom) = 0;
00059 
00060     virtual void SetLength(size_type nNewLen) = 0;
00061     virtual size_type GetLength() const = 0;
00062 
00063     virtual char* ReadString(char* pBuf, size_type nMax) = 0;
00064     virtual int GetChar() = 0;
00065 
00066     virtual int PutChar(int c) = 0;
00067     virtual void printf(const char*, ...) = 0; 
00068 
00069     virtual void Abort() = 0;
00070     virtual void Flush() = 0;
00071     virtual void Close() = 0;
00072 };
00073 
00074 #include <stdio.h>
00075 
00076 class MemStream : public IDataStream {
00077 public:
00078     MemStream();
00079     MemStream(size_type nLen);
00080     virtual ~MemStream();
00081 
00082     int refCount;
00083     void IncRef() {
00084         refCount++;
00085     }
00086     void DecRef() {
00087         refCount--;
00088         if (refCount <= 0) delete this;
00089     }
00090 
00091 protected:
00092     // MemFile specific:
00093     size_type m_nGrowBytes;
00094     size_type m_nPosition;
00095     size_type m_nBufferSize;
00096     size_type m_nFileSize;
00097     unsigned char* m_pBuffer;
00098     bool m_bAutoDelete;
00099     void GrowFile(size_type nNewLen);
00100 
00101 public:
00102     position_type GetPosition() const;
00103     int Seek(offset_type lOff, int nFrom);
00104     void SetLength(size_type nNewLen);
00105     size_type GetLength() const;
00106 
00107     unsigned char* GetBuffer() const {
00108         return m_pBuffer;
00109     }
00110 
00111     size_type read(byte_type* buffer, size_type length);
00112     size_type write(const byte_type* buffer, size_type length);
00113 
00114     char* ReadString(char* pBuf, size_type nMax);
00115     int GetChar();
00116 
00117     int PutChar(int c);
00118     void printf(const char*, ...); 
00119 
00120     void Abort();
00121     void Flush();
00122     void Close();
00123     bool Open(const char *filename, const char *mode);
00124 };
00125 
00126 class FileStream : public IDataStream {
00127 public:
00128     FileStream();
00129     virtual ~FileStream();
00130 
00131     int refCount;
00132     void IncRef() {
00133         refCount++;
00134     }
00135     void DecRef() {
00136         refCount--;
00137         if (refCount <= 0) delete this;
00138     }
00139 
00140 protected:
00141     // DiscFile specific:
00142     FILE* m_hFile;
00143     bool m_bCloseOnDelete;
00144 
00145 public:
00146     position_type GetPosition() const;
00147     int Seek(offset_type lOff, int nFrom);
00148     void SetLength(size_type nNewLen);
00149     size_type GetLength() const;
00150 
00151     size_type read(byte_type* buffer, size_type length);
00152     size_type write(const byte_type* buffer, size_type length);
00153 
00154     char* ReadString(char* pBuf, size_type nMax);
00155     int GetChar();
00156 
00157     int PutChar(int c);
00158     void printf(const char*, ...); 
00159 
00160     void Abort();
00161     void Flush();
00162     void Close();
00163     bool Open(const char *filename, const char *mode);
00164 };
00165 
00166 #endif

Generated by  doxygen 1.6.2