]> git.tdb.fi Git - libs/core.git/blob - source/io/mode.h
2e7527dc5202d3158895f8c20feb3f90236b17dd
[libs/core.git] / source / io / mode.h
1 #ifndef MSP_IO_MODE_H_
2 #define MSP_IO_MODE_H_
3
4 #include <stdexcept>
5
6 namespace Msp {
7 namespace IO {
8
9 enum Mode
10 {
11         M_NONE = 0,
12         M_READ = 1,
13         M_WRITE = 2,
14         M_RDWR = M_READ|M_WRITE,
15         M_APPEND = 4,
16         M_NONBLOCK = 8
17 };
18
19 inline Mode operator|(Mode m, Mode n)
20 { return Mode(static_cast<int>(m)|static_cast<int>(n)); }
21
22 inline Mode operator&(Mode m, Mode n)
23 { return Mode(static_cast<int>(m)&static_cast<int>(n)); }
24
25 inline Mode operator~(Mode m)
26 { return Mode(~static_cast<int>(m)); }
27
28 inline void adjust_mode(Mode &m, Mode f, bool b)
29 { m = b ? (m|f) : (m&~f); }
30
31
32 class invalid_access: public std::logic_error
33 {
34 public:
35         invalid_access(Mode);
36         ~invalid_access() throw() { }
37 };
38
39 } // namespace IO
40 } // namespace Msp
41
42 #endif