]> git.tdb.fi Git - libs/core.git/blob - source/file.h
Drop copyright and license notices from files
[libs/core.git] / source / file.h
1 #ifndef MSP_IO_FILE_H_
2 #define MSP_IO_FILE_H_
3
4 #include <string>
5 #include "base.h"
6 #include "buffered.h"
7 #include "filtered.h"
8 #include "seek.h"
9
10 namespace Msp {
11 namespace IO {
12
13 /**
14 A class for reading and writing files.
15
16 Non-blocking mode is not supported on Win32.
17 */
18 class File: public Base
19 {
20 public:
21         enum CreateMode
22         {
23                 C_NONE = 0,
24                 C_CREATE = 1,
25                 C_TRUNCATE = 2
26         };
27
28         File(const std::string &, Mode = M_READ, CreateMode =CreateMode(C_CREATE+C_TRUNCATE));
29
30         void close();
31
32         void set_block(bool);
33
34         virtual void sync();
35
36         virtual int  seek(int, SeekType);
37         virtual int  tell() const;
38
39         virtual Handle get_event_handle() { return handle; }
40
41         virtual ~File();
42 private:
43         Handle handle;
44
45         void              check_access(Mode) const;
46 protected:
47         virtual unsigned  do_write(const char *, unsigned);
48         virtual unsigned  do_read(char *, unsigned);
49 };
50
51 inline File::CreateMode operator|(File::CreateMode m, File::CreateMode n)
52 { return File::CreateMode(static_cast<int>(m)|static_cast<int>(n)); }
53
54 inline File::CreateMode operator&(File::CreateMode m, File::CreateMode n)
55 { return File::CreateMode(static_cast<int>(m)&static_cast<int>(n)); }
56
57 inline File::CreateMode operator~(File::CreateMode m)
58 { return File::CreateMode(~static_cast<int>(m)); }
59
60 typedef Filtered<File, Buffered> BufferedFile;
61
62 } // namespace IO
63 } // namespace Msp
64
65 #endif