-
Notifications
You must be signed in to change notification settings - Fork 0
/
File.h
89 lines (57 loc) · 2.13 KB
/
File.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef FILE_H
#define FILE_H
/** @file */
/**
* Enumerations for use with RFile functions requiring file modes.
* Enum to specify a range of bit values that can be masked together to specify the
* mode in which to open a file, using the RFile class.
*/
enum TFileMode
{
EFileRead = 0x00, /**< Opens the file in read only mode */
EFileWrite = 0x200, /**< Opens the file in read/write mode */
EFileExclusive = 0x400 /**< Opens the file in exclusive mode, preventing access by other */
/**< processes or instances of the RFile class */
};
/**
* Interface for all file access classes.
* This pure virtual base class defines the interface that all file access classes will adhere to. Instances
* of these classes can either be used directly, or obtained from RRemoteFactory::getFileObject().
*/
class RFileObject
{
public:
virtual int create(const char *a_fileName, TUint a_fileMode) = 0;
virtual int replace(const char *a_fileName, TUint a_fileMode) = 0;
virtual int open(const char *a_fileName, TUint a_fileMode) = 0;
virtual int read(unsigned char *a_buffer, int a_length) = 0;
virtual int seek(int a_bytes) = 0;
virtual int write(const unsigned char *a_buffer, int a_length) = 0;
virtual int close() = 0;
};
/**
* A class for reading from or writing to local files.
* This class enables the local creation, reading and writing of files in a platform independent manner.
*/
class RFile : public RFileObject
{
private:
#ifdef __amigaos__
TUint m_fileMode; /* Mode in which file was opened for access */
BPTR m_handle; /* Handle to the open file or 0 if closed */
#elif defined(__unix__)
int m_handle; /* Handle to the open file or 0 if closed */
#else /* ! __unix__ */
HANDLE m_handle; /**< Handle to the open file or 0 if closed */
#endif /* ! __unix__ */
public:
RFile();
int create(const char *a_fileName, TUint a_fileMode);
int replace(const char *a_fileName, TUint a_fileMode);
int open(const char *a_fileName, TUint a_fileMode);
int read(unsigned char *a_buffer, int a_length);
int seek(int a_bytes);
int write(const unsigned char *a_buffer, int a_length);
int close();
};
#endif /* ! FILE_H */