DCL 3.7.4
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#ifdef __WINNT__
9 #ifndef _WINDOWS_
10 #error "Required windows.h, See dcl/_windows.h"
11 #endif
12 #if 0
13 #include <fileapi.h> // HANDLE
14 #include <precessenv.h> // GetStdHandle
15 #endif
16#endif
17
18#ifndef __DCL_OBJECT_H__
19#include <dcl/Object.h>
20#endif
21#ifndef __DCL_STRING_H__
22#include <dcl/String.h>
23#endif
24#ifndef __DCL_CHARSET_H__
25#include <dcl/Charset.h>
26#endif
27#ifndef __DCL_DATE_TIME_H__
28#include <dcl/DateTime.h>
29#endif
30#ifndef __DCL_EXCEPTION_H__
31#include <dcl/Exception.h>
32#endif
33
34__DCL_BEGIN_NAMESPACE
35
41class DCLCAPI File : public Object
42{
44public:
45#ifdef __WINNT__
46 typedef HANDLE HandleType;
47 #define STDIN_HANDLE GetStdHandle(STD_INPUT_HANDLE)
48 #define STDOUT_HANDLE GetStdHandle(STD_OUTPUT_HANDLE)
49 #define STDERR_HANDLE GetStdHandle(STD_ERROR_HANDLE)
50 typedef __int64 off_t;
51#else
52 typedef int HandleType;
53 #ifdef STDIN_FILENO
54 #define STDIN_HANDLE STDIN_FILENO
55 #define STDOUT_HANDLE STDOUT_FILENO
56 #define STDERR_HANDLE STDERR_FILENO
57 #else
58 #define STDIN_HANDLE 0
59 #define STDOUT_HANDLE 1
60 #define STDERR_HANDLE 2
61 #endif
62 typedef long long off_t;
63#endif
64
65 enum OpenFlags
66 {
67 READONLY = 0x0001, // O_RDONLY
68 WRITEONLY = 0x0002, // O_WRONLY
69 READWRITE = 0x0004, // O_RDWR
70 CREATE = 0x0010, // O_CREAT
71 EXCLUSIVE = 0x0020, // O_EXCL
72 NOCTTY = 0x0040, // O_NOCTTY
73 APPEND = 0x0100, // O_APPEND
74 TRUNCATE = 0x0200, // O_TRUNC
75 NONBLOCK = 0x1000, // O_NONBLOCK, FILE_FLAG_OVERLAPPED
76 SYNC = 0x2000 // O_SYNC
77 };
78
79protected:
80 File();
81
87 File(HandleType _handle, const String& _path);
88
89public:
90 virtual String toString() const;
91
96 virtual ~File();
97
114 File(const String& _path, int _oflags = READONLY, int _mode = 0666)
116
122 void open(const String& _path, int _oflags = READONLY, int _mode = 0666)
124
140 File(HandleType _handle, int _ohints, bool _closeOnClose)
142
148 void open(HandleType _handle, int _ohints, bool _closeOnClose)
150
155 virtual void sync()
157
161 virtual void close()
163
170 virtual size_t available() const
172
186 virtual size_t read(void* _buf, size_t _n)
188
204 virtual size_t write(const void* _buf, size_t _n)
206
208 {
209 BEGIN, // SEEK_SET
210 CURRENT, // SEEK_CUR
211 END // SEEK_END
212 };
213
223 off_t seek(off_t _offset, int _whence)
225
229 off_t size() const
231
235 DateTime mtime() const
237
238 /*
239 * 파일의 최종 접근, 수정, 생성 시간을 얻는다.
240 */
241 bool time(time_t* _atime, time_t* _mtime, time_t* _ctime) const;
242
246 HandleType handle() const { return __handle; }
247
251 const String& path() const { return __path; }
252
253protected:
254 String __path;
255 HandleType __handle;
257#ifdef __WINNT__
258public:
259 enum FileType
260 {
261 UNKNOWN,
262 REGULAR,
263 PIPE,
264 CONSOLE,
265 COMM,
266 SOCKET
267 };
268
272 FileType fileType() const { return __fileType; }
273protected:
274 FileType __fileType;
275 HANDLE __readEvent;
276 HANDLE __writeEvent;
277#endif
278
279public:
280 // "dir/prefixXXXXX" 이름의 파일을 생성하여 파일 기술자를 리턴
281 static File* openTempFile(
282 const String& _dirname,
283 const String& _prefix,
284 unsigned int _mode = 0666
285 ) __DCL_THROWS1(IOException*);
286};
287
288__DCL_END_NAMESPACE
289
290#endif // __DCL_FILE_H__
#define __int64
Definition __xtoa.cpp:15
#define DCLCAPI
Definition Config.h:95
#define __DCL_THROWS1(e)
Definition Config.h:152
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:227
HandleType handle() const
Definition File.h:246
void open(const String &_path, int _oflags=READONLY, int _mode=0666) __DCL_THROWS1(IOException *)
Definition File.cpp:80
Whence
Definition File.h:208
@ CURRENT
Definition File.h:210
@ END
Definition File.h:211
@ BEGIN
Definition File.h:209
HandleType __handle
Definition File.h:255
virtual void close() __DCL_THROWS1(IOException *)
Definition File.cpp:369
virtual ~File()
String __path
Definition File.h:254
virtual size_t read(void *_buf, size_t _n) __DCL_THROWS1(IOException *)
Definition File.cpp:482
virtual String toString() const
const String & path() const
Definition File.h:251
virtual void sync() __DCL_THROWS1(IOException *)
Definition File.cpp:353
virtual size_t write(const void *_buf, size_t _n) __DCL_THROWS1(IOException *)
Definition File.cpp:541
bool __closeOnClose
Definition File.h:256
virtual size_t available() const __DCL_THROWS1(IOException *)
Definition File.cpp:407
File()
Definition File.cpp:62
Object()
Definition Object.cpp:183