OSDN Git Service

[VM][General][WIP] Start to merge upstream 2018-10-14.Open branch upstream_20181014 .
[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         int open_mode;
45         
46 public:
47         FILEIO();
48         ~FILEIO();
49         
50         static bool IsFileExisting(const _TCHAR *file_path);
51         static bool IsFileProtected(const _TCHAR *file_path);
52         static bool RemoveFile(const _TCHAR *file_path);
53         static bool RenameFile(const _TCHAR *existing_file_path, const _TCHAR *new_file_path);
54         
55         bool Fopen(const _TCHAR *file_path, int mode);
56 #ifdef USE_ZLIB
57         bool Gzopen(const _TCHAR *file_path, int mode);
58 #endif
59         void Fclose();
60         bool IsOpened()
61         {
62 #ifdef USE_ZLIB
63                 if(gz != NULL) {
64                         return true;
65                 } else
66 #endif
67                 return (fp != NULL);
68         }
69         const _TCHAR *FilePath()
70         {
71                 return path;
72         }
73         long FileLength();
74         
75         bool FgetBool();
76         void FputBool(bool val);
77         uint8_t FgetUint8();
78         void FputUint8(uint8_t val);
79         uint16_t FgetUint16();
80         void FputUint16(uint16_t val);
81         uint32_t FgetUint32();
82         void FputUint32(uint32_t val);
83         uint64_t FgetUint64();
84         void FputUint64(uint64_t val);
85         int8_t FgetInt8();
86         void FputInt8(int8_t val);
87         int16_t FgetInt16();
88         void FputInt16(int16_t val);
89         int32_t FgetInt32();
90         void FputInt32(int32_t val);
91         int64_t FgetInt64();
92         void FputInt64(int64_t val);
93         float FgetFloat();
94         void FputFloat(float val);
95         double FgetDouble();
96         void FputDouble(double val);
97         
98         uint16_t FgetUint16_LE();
99         void FputUint16_LE(uint16_t val);
100         uint32_t FgetUint32_LE();
101         void FputUint32_LE(uint32_t val);
102         uint64_t FgetUint64_LE();
103         void FputUint64_LE(uint64_t val);
104         int16_t FgetInt16_LE();
105         void FputInt16_LE(int16_t val);
106         int32_t FgetInt32_LE();
107         void FputInt32_LE(int32_t val);
108         int64_t FgetInt64_LE();
109         void FputInt64_LE(int64_t val);
110         float FgetFloat_LE();
111         void FputFloat_LE(float val);
112         double FgetDouble_LE();
113         void FputDouble_LE(double val);
114         _TCHAR FgetTCHAR_LE();
115         void FputTCHAR_LE(_TCHAR val);
116         
117         uint16_t FgetUint16_BE();
118         void FputUint16_BE(uint16_t val);
119         uint32_t FgetUint32_BE();
120         void FputUint32_BE(uint32_t val);
121         uint64_t FgetUint64_BE();
122         void FputUint64_BE(uint64_t val);
123         int16_t FgetInt16_BE();
124         void FputInt16_BE(int16_t val);
125         int32_t FgetInt32_BE();
126         void FputInt32_BE(int32_t val);
127         int64_t FgetInt64_BE();
128         void FputInt64_BE(int64_t val);
129         float FgetFloat_BE();
130         void FputFloat_BE(float val);
131         double FgetDouble_BE();
132         void FputDouble_BE(double val);
133         _TCHAR FgetTCHAR_BE();
134         void FputTCHAR_BE(_TCHAR val);
135         
136         int Fgetc();
137         int Fputc(int c);
138         char *Fgets(char *str, int n);
139         _TCHAR *Fgetts(_TCHAR *str, int n);
140         int Fprintf(const char* format, ...);
141         int Ftprintf(const _TCHAR* format, ...);
142         
143         size_t Fread(void* buffer, size_t size, size_t count);
144         size_t Fwrite(const void* buffer, size_t size, size_t count);
145         int Fseek(long offset, int origin);
146         long Ftell();
147         bool Fcompare(const void* buffer, size_t size);
148         bool Fcompare(const void* buffer, size_t size, size_t count);
149         bool Fflush(); // Pls.Add 20181013 K.O
150         
151         bool StateCheckUint32(uint32_t val);
152         bool StateCheckInt32(int32_t val);
153         bool StateCheckBuffer(const _TCHAR *buffer, size_t size, size_t count);
154         
155         void StateValue(bool &val);
156         void StateValue(uint8_t &val);
157         void StateValue(uint16_t &val);
158         void StateValue(uint32_t &val);
159         void StateValue(uint64_t &val);
160         void StateValue(int8_t &val);
161         void StateValue(int16_t &val);
162         void StateValue(int32_t &val);
163         void StateValue(int64_t &val);
164         void StateValue(pair16_t &val);
165         void StateValue(pair32_t &val);
166         void StateValue(pair64_t &val);
167         void StateValue(float &val);
168         void StateValue(double &val);
169         void StateValue(_TCHAR &val);
170         
171         void StateArray(bool *buffer, size_t size, size_t count);
172         void StateArray(uint8_t *buffer, size_t size, size_t count);
173         void StateArray(uint16_t *buffer, size_t size, size_t count);
174         void StateArray(uint32_t *buffer, size_t size, size_t count);
175         void StateArray(uint64_t *buffer, size_t size, size_t count);
176         void StateArray(int8_t *buffer, size_t size, size_t count);
177         void StateArray(int16_t *buffer, size_t size, size_t count);
178         void StateArray(int32_t *buffer, size_t size, size_t count);
179         void StateArray(int64_t *buffer, size_t size, size_t count);
180         void StateArray(pair16_t *buffer, size_t size, size_t count);
181         void StateArray(pair32_t *buffer, size_t size, size_t count);
182         void StateArray(pair64_t *buffer, size_t size, size_t count);
183         void StateArray(float *buffer, size_t size, size_t count);
184         void StateArray(double *buffer, size_t size, size_t count);
185         void StateArray(_TCHAR *buffer, size_t size, size_t count);
186         
187         // obsolete function
188         void StateBuffer(void *buffer, size_t size, size_t count);
189 };
190
191 #endif