DCL 4.0
Loading...
Searching...
No Matches
File.h
Go to the documentation of this file.
1#ifndef __DCL_FILE_H__
2#define __DCL_FILE_H__ 20041127
3
4#ifndef __DCL_CONFIG_H__
5#include <dcl/Config.h>
6#endif
7
8#if __DCL_WINDOWS
9 #ifndef _WINDOWS_
10 #error "Required windows.h, See dcl/_windows.h"
11 #endif
12#endif
13
14#ifndef __DCL_OBJECT_H__
15#include <dcl/Object.h>
16#endif
17#ifndef __DCL_STRING_H__
18#include <dcl/String.h>
19#endif
20#ifndef __DCL_CHARSET_H__
21#include <dcl/Charset.h>
22#endif
23#ifndef __DCL_DATE_TIME_H__
24#include <dcl/DateTime.h>
25#endif
26#ifndef __DCL_EXCEPTION_H__
27#include <dcl/Exception.h>
28#endif
29
30__DCL_BEGIN_NAMESPACE
31
37class DCLCAPI File : public Object
38{
40public:
41#if __DCL_WINDOWS
42 typedef HANDLE HandleType;
43 #define STDIN_HANDLE GetStdHandle(STD_INPUT_HANDLE)
44 #define STDOUT_HANDLE GetStdHandle(STD_OUTPUT_HANDLE)
45 #define STDERR_HANDLE GetStdHandle(STD_ERROR_HANDLE)
46 typedef __int64 off_t;
47#else
48 typedef int HandleType;
49 #ifdef STDIN_FILENO
50 #define STDIN_HANDLE STDIN_FILENO
51 #define STDOUT_HANDLE STDOUT_FILENO
52 #define STDERR_HANDLE STDERR_FILENO
53 #else
54 #define STDIN_HANDLE 0
55 #define STDOUT_HANDLE 1
56 #define STDERR_HANDLE 2
57 #endif
58 typedef long long off_t;
59#endif
60
61 enum OpenFlags
62 {
63 READONLY = 0x0001, // O_RDONLY
64 WRITEONLY = 0x0002, // O_WRONLY
65 READWRITE = 0x0004, // O_RDWR
66 CREATE = 0x0010, // O_CREAT
67 EXCLUSIVE = 0x0020, // O_EXCL
68 NOCTTY = 0x0040, // O_NOCTTY
69 APPEND = 0x0100, // O_APPEND
70 TRUNCATE = 0x0200, // O_TRUNC
71 NONBLOCK = 0x1000, // O_NONBLOCK, FILE_FLAG_OVERLAPPED
72 SYNC = 0x2000 // O_SYNC
73 };
74
75protected:
76 File();
77
83 File(HandleType _handle, const String& _path);
84
85public:
86 virtual String toString() const;
87
92 virtual ~File();
93
110 File(const String& _path, int _oflags = READONLY, int _mode = 0666)
112
118 void open(const String& _path, int _oflags = READONLY, int _mode = 0666)
120
136 File(HandleType _handle, int _ohints, bool _closeOnClose)
138
144 void open(HandleType _handle, int _ohints, bool _closeOnClose)
146
151 virtual void sync()
153
157 virtual void close()
159
166 virtual size_t available() const
168
182 virtual size_t read(void* _buf, size_t _n)
184
200 virtual size_t write(const void* _buf, size_t _n)
202
204 {
205 BEGIN, // SEEK_SET
206 CURRENT, // SEEK_CUR
207 END // SEEK_END
208 };
209
219 off_t seek(off_t _offset, int _whence)
221
225 off_t size() const
227
231 DateTime mtime() const
233
234 /*
235 * 파일의 최종 접근, 수정, 생성 시간을 얻는다.
236 */
237 bool time(time_t* _atime, time_t* _mtime, time_t* _ctime) const;
238
242 HandleType handle() const { return __handle; }
243
247 const String& path() const { return __path; }
248
249protected:
250 String __path;
251 HandleType __handle;
253#if __DCL_WINDOWS
254public:
255 enum FileType
256 {
257 UNKNOWN,
258 REGULAR,
259 PIPE,
260 CONSOLE,
261 COMM,
262 SOCKET
263 };
264
268 FileType fileType() const { return __fileType; }
269protected:
270 FileType __fileType;
271 HANDLE __readEvent;
272 HANDLE __writeEvent;
273#endif
274
275public:
276 // "dir/prefixXXXXX" 이름의 파일을 생성하여 파일 기술자를 리턴
277 static File* openTempFile(
278 const String& _dirname,
279 const String& _prefix,
280 unsigned int _mode = 0666
281 ) __DCL_THROWS1(IOException*);
282};
283
284__DCL_END_NAMESPACE
285
286#endif // __DCL_FILE_H__
#define __int64
Definition __xtoa.cpp:15
#define DCLCAPI
Definition Config.h:100
#define __DCL_THROWS1(e)
Definition Config.h:167
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:210
HandleType handle() const
Definition File.h:242
void open(const String &_path, int _oflags=READONLY, int _mode=0666) __DCL_THROWS1(IOException *)
Definition File.cpp:77
Whence
Definition File.h:204
@ CURRENT
Definition File.h:206
@ END
Definition File.h:207
@ BEGIN
Definition File.h:205
HandleType __handle
Definition File.h:251
virtual void close() __DCL_THROWS1(IOException *)
Definition File.cpp:363
virtual ~File()
String __path
Definition File.h:250
virtual size_t read(void *_buf, size_t _n) __DCL_THROWS1(IOException *)
Definition File.cpp:476
virtual String toString() const
const String & path() const
Definition File.h:247
virtual void sync() __DCL_THROWS1(IOException *)
Definition File.cpp:347
virtual size_t write(const void *_buf, size_t _n) __DCL_THROWS1(IOException *)
Definition File.cpp:535
bool __closeOnClose
Definition File.h:252
virtual size_t available() const __DCL_THROWS1(IOException *)
Definition File.cpp:401
File()
Definition File.cpp:59
Object()
Definition Object.cpp:183