OSDN Git Service

[WIP] Update to upstream 2018-10-05.This still not finish.May cause FTBFS.
[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         
115         uint16_t FgetUint16_BE();
116         void FputUint16_BE(uint16_t val);
117         uint32_t FgetUint32_BE();
118         void FputUint32_BE(uint32_t val);
119         uint64_t FgetUint64_BE();
120         void FputUint64_BE(uint64_t val);
121         int16_t FgetInt16_BE();
122         void FputInt16_BE(int16_t val);
123         int32_t FgetInt32_BE();
124         void FputInt32_BE(int32_t val);
125         int64_t FgetInt64_BE();
126         void FputInt64_BE(int64_t val);
127         float FgetFloat_BE();
128         void FputFloat_BE(float val);
129         double FgetDouble_BE();
130         void FputDouble_BE(double val);
131         
132         int Fgetc();
133         int Fputc(int c);
134         char *Fgets(char *str, int n);
135         _TCHAR *Fgetts(_TCHAR *str, int n);
136         int Fprintf(const char* format, ...);
137         int Ftprintf(const _TCHAR* format, ...);
138         
139         size_t Fread(void* buffer, size_t size, size_t count);
140         size_t Fwrite(const void* buffer, size_t size, size_t count);
141         int Fseek(long offset, int origin);
142         long Ftell();
143         bool Fcompare(const void* buffer, size_t size);
144         bool Fcompare(const void* buffer, size_t size, size_t count);
145         
146         bool StateCheckUint32(uint32_t val);
147         bool StateCheckInt32(int32_t val);
148         bool StateCheckBuffer(const void *buffer, size_t size, size_t count);
149         
150         void StateBool(bool &val);
151         void StateUint8(uint8_t &val);
152         void StateUint16(uint16_t &val);
153         void StateUint32(uint32_t &val);
154         void StateUint64(uint64_t &val);
155         void StateInt8(int8_t &val);
156         void StateInt16(int16_t &val);
157         void StateInt32(int32_t &val);
158         void StateInt64(int64_t &val);
159         void StateFloat(float &val);
160         void StateDouble(double &val);
161         void StateBuffer(void *buffer, size_t size, size_t count);
162 };
163
164 #endif