OSDN Git Service

[VM][I386] Apply new state framework (only within libcpu_newdev).
[csp-qt/common_source_project-fm7.git] / source / src / fileio.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2006.08.18 -
6
7         [ file i/o ]
8 */
9
10 #ifndef _FILEIO_H_
11 #define _FILEIO_H_
12
13 #include <stdio.h>
14 #include "common.h"
15
16 #define FILEIO_READ_BINARY              1
17 #define FILEIO_WRITE_BINARY             2
18 #define FILEIO_READ_WRITE_BINARY        3
19 #define FILEIO_READ_WRITE_NEW_BINARY    4
20 #define FILEIO_READ_ASCII               5
21 #define FILEIO_WRITE_ASCII              6
22 #define FILEIO_READ_WRITE_ASCII         7
23 #define FILEIO_READ_WRITE_NEW_ASCII     8
24 #define FILEIO_WRITE_APPEND_ASCII       9
25 #define FILEIO_READ_WRITE_APPEND_ASCII  10
26 #define FILEIO_SEEK_SET                 0
27 #define FILEIO_SEEK_CUR                 1
28 #define FILEIO_SEEK_END                 2
29
30 #ifdef USE_ZLIB
31 struct gzFile_s;
32 typedef struct gzFile_s *gzFile;
33 #endif
34
35 class DLL_PREFIX FILEIO
36 {
37 private:
38 #ifdef USE_ZLIB
39         gzFile gz;
40         long gz_size;
41 #endif
42         FILE* fp;
43         _TCHAR path[_MAX_PATH];
44         
45 public:
46         FILEIO();
47         ~FILEIO();
48         
49         static bool IsFileExisting(const _TCHAR *file_path);
50         static bool IsFileProtected(const _TCHAR *file_path);
51         static bool RemoveFile(const _TCHAR *file_path);
52         static bool RenameFile(const _TCHAR *existing_file_path, const _TCHAR *new_file_path);
53
54         bool Fopen(const _TCHAR *file_path, int mode);
55 #ifdef USE_ZLIB
56         bool Gzopen(const _TCHAR *file_path, int mode);
57 #endif
58         void Fclose();
59         bool IsOpened()
60         {
61 #ifdef USE_ZLIB
62                 if(gz != NULL) {
63                         return true;
64                 } else
65 #endif
66                 return (fp != NULL);
67         }
68         const _TCHAR *FilePath()
69         {
70                 return path;
71         }
72         long FileLength();
73         
74         bool FgetBool();
75         void FputBool(bool val);
76         uint8_t FgetUint8();
77         void FputUint8(uint8_t val);
78         uint16_t FgetUint16();
79         void FputUint16(uint16_t val);
80         uint32_t FgetUint32();
81         void FputUint32(uint32_t val);
82         uint64_t FgetUint64();
83         void FputUint64(uint64_t val);
84         int8_t FgetInt8();
85         void FputInt8(int8_t val);
86         int16_t FgetInt16();
87         void FputInt16(int16_t val);
88         int32_t FgetInt32();
89         void FputInt32(int32_t val);
90         int64_t FgetInt64();
91         void FputInt64(int64_t val);
92         float FgetFloat();
93         void FputFloat(float val);
94         double FgetDouble();
95         void FputDouble(double val);
96         
97         uint16_t FgetUint16_LE();
98         void FputUint16_LE(uint16_t val);
99         uint32_t FgetUint32_LE();
100         void FputUint32_LE(uint32_t val);
101         uint64_t FgetUint64_LE();
102         void FputUint64_LE(uint64_t val);
103         int16_t FgetInt16_LE();
104         void FputInt16_LE(int16_t val);
105         int32_t FgetInt32_LE();
106         void FputInt32_LE(int32_t val);
107         int64_t FgetInt64_LE();
108         void FputInt64_LE(int64_t val);
109         
110         uint16_t FgetUint16_BE();
111         void FputUint16_BE(uint16_t val);
112         uint32_t FgetUint32_BE();
113         void FputUint32_BE(uint32_t val);
114         uint64_t FgetUint64_BE();
115         void FputUint64_BE(uint64_t val);
116         int16_t FgetInt16_BE();
117         void FputInt16_BE(int16_t val);
118         int32_t FgetInt32_BE();
119         void FputInt32_BE(int32_t val);
120         int64_t FgetInt64_BE();
121         void FputInt64_BE(int64_t val);
122         
123         int Fgetc();
124         int Fputc(int c);
125         char *Fgets(char *str, int n);
126         _TCHAR *Fgetts(_TCHAR *str, int n);
127         int Fprintf(const char* format, ...);
128         int Ftprintf(const _TCHAR* format, ...);
129         
130         size_t Fread(void* buffer, size_t size, size_t count);
131         size_t Fwrite(const void* buffer, size_t size, size_t count);
132         int Fseek(long offset, int origin);
133         long Ftell();
134         bool Fcompare(const void* buffer, size_t size);
135 };
136
137 #endif