file.h
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
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
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