| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#if !defined( INCLUDED_PROFILE_FILE_H ) |
| 36 |
#define INCLUDED_PROFILE_FILE_H |
| 37 |
|
| 38 |
#include "idatastream.h" |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
class IDataStream : public InputStream, public OutputStream |
| 50 |
{ |
| 51 |
public: |
| 52 |
typedef int offset_type; |
| 53 |
typedef std::size_t position_type; |
| 54 |
|
| 55 |
virtual void IncRef() = 0; |
| 56 |
virtual void DecRef() = 0; |
| 57 |
|
| 58 |
virtual position_type GetPosition() const = 0; |
| 59 |
virtual int Seek( offset_type lOff, int nFrom ) = 0; |
| 60 |
|
| 61 |
virtual void SetLength( size_type nNewLen ) = 0; |
| 62 |
virtual size_type GetLength() const = 0; |
| 63 |
|
| 64 |
virtual char* ReadString( char* pBuf, size_type nMax ) = 0; |
| 65 |
virtual int GetChar() = 0; |
| 66 |
|
| 67 |
virtual int PutChar( int c ) = 0; |
| 68 |
virtual void printf( const char*, ... ) = 0; |
| 69 |
|
| 70 |
virtual void Abort() = 0; |
| 71 |
virtual void Flush() = 0; |
| 72 |
virtual void Close() = 0; |
| 73 |
}; |
| 74 |
|
| 75 |
#include <stdio.h> |
| 76 |
|
| 77 |
class MemStream : public IDataStream |
| 78 |
{ |
| 79 |
public: |
| 80 |
MemStream(); |
| 81 |
MemStream( size_type nLen ); |
| 82 |
virtual ~MemStream(); |
| 83 |
|
| 84 |
int refCount; |
| 85 |
void IncRef() { refCount++; } |
| 86 |
void DecRef() { |
| 87 |
refCount--; if ( refCount <= 0 ) { |
| 88 |
delete this; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
protected: |
| 93 |
|
| 94 |
size_type m_nGrowBytes; |
| 95 |
size_type m_nPosition; |
| 96 |
size_type m_nBufferSize; |
| 97 |
size_type m_nFileSize; |
| 98 |
unsigned char* m_pBuffer; |
| 99 |
bool m_bAutoDelete; |
| 100 |
void GrowFile( size_type nNewLen ); |
| 101 |
|
| 102 |
public: |
| 103 |
position_type GetPosition() const; |
| 104 |
int Seek( offset_type lOff, int nFrom ); |
| 105 |
void SetLength( size_type nNewLen ); |
| 106 |
size_type GetLength() const; |
| 107 |
|
| 108 |
unsigned char* GetBuffer() const |
| 109 |
{ return m_pBuffer; } |
| 110 |
|
| 111 |
size_type read( byte_type* buffer, size_type length ); |
| 112 |
size_type write( const byte_type* buffer, size_type length ); |
| 113 |
|
| 114 |
char* ReadString( char* pBuf, size_type nMax ); |
| 115 |
int GetChar(); |
| 116 |
|
| 117 |
int PutChar( int c ); |
| 118 |
void printf( const char*, ... ); |
| 119 |
|
| 120 |
void Abort(); |
| 121 |
void Flush(); |
| 122 |
void Close(); |
| 123 |
bool Open( const char *filename, const char *mode ); |
| 124 |
}; |
| 125 |
|
| 126 |
class FileStream : public IDataStream |
| 127 |
{ |
| 128 |
public: |
| 129 |
FileStream(); |
| 130 |
virtual ~FileStream(); |
| 131 |
|
| 132 |
int refCount; |
| 133 |
void IncRef() { refCount++; } |
| 134 |
void DecRef() { |
| 135 |
refCount--; if ( refCount <= 0 ) { |
| 136 |
delete this; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
protected: |
| 141 |
|
| 142 |
FILE* m_hFile; |
| 143 |
bool m_bCloseOnDelete; |
| 144 |
|
| 145 |
public: |
| 146 |
position_type GetPosition() const; |
| 147 |
int Seek( offset_type lOff, int nFrom ); |
| 148 |
void SetLength( size_type nNewLen ); |
| 149 |
size_type GetLength() const; |
| 150 |
|
| 151 |
size_type read( byte_type* buffer, size_type length ); |
| 152 |
size_type write( const byte_type* buffer, size_type length ); |
| 153 |
|
| 154 |
char* ReadString( char* pBuf, size_type nMax ); |
| 155 |
int GetChar(); |
| 156 |
|
| 157 |
int PutChar( int c ); |
| 158 |
void printf( const char*, ... ); |
| 159 |
|
| 160 |
void Abort(); |
| 161 |
void Flush(); |
| 162 |
void Close(); |
| 163 |
bool Open( const char *filename, const char *mode ); |
| 164 |
}; |
| 165 |
|
| 166 |
#endif |