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