-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfile.h
50 lines (46 loc) · 1.19 KB
/
cfile.h
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef _CFILE_H_
#define _CFILE_H_
#include <stdio.h>
#include <string.h>
//--------------------------------------------------------------------------------
const int FMODE_READ= (1<<0);
const int FMODE_WRITE= (1<<1);
const int FMODE_TEXT= (1<<2);
const int FMODE_BIN= (1<<3);
class CFile {
protected:
FILE *m_pFile;
int m_nOpenMode;
bool m_bEndian; // false=Little, true=Big
public:
CFile() {
InitMember();
}
virtual ~CFile() {
Close();
}
bool isValid( void ) { return (m_pFile==NULL)?false:true; }
virtual bool Open(char *pFilename, int bFlag);
virtual void Close( void ) {
if(isValid()) fclose(m_pFile);
}
virtual bool Seek(unsigned long nOffset);
virtual long Tell( void );
bool eof( void ) { return (feof(m_pFile)!=0); }
void SetBigEndian( void ) { m_bEndian = true; }
void SetLittleEndian( void ) { m_bEndian = false; }
unsigned char ReadByte( void );
unsigned short ReadWord( void );
unsigned long ReadDword( void );
void WriteByte( unsigned char nData );
void WriteWord( unsigned short nData );
void WriteDword( unsigned long nData );
protected:
void InitMember( void )
{
m_pFile = NULL;
m_nOpenMode = 0;
m_bEndian = false; // default = little
}
};
#endif // _CFILE_H_