1 | /* -*- c-basic-offset: 2 -*- */ |
2 | /* |
3 | Copyright(C) 2011-2016 Brazil |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License version 2.1 as published by the Free Software Foundation. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with this library; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | |
19 | #pragma once |
20 | |
21 | #ifdef WIN32 |
22 | # include <windows.h> |
23 | #endif // WIN32 |
24 | |
25 | #include "dat.hpp" |
26 | |
27 | namespace grn { |
28 | namespace dat { |
29 | |
30 | class FileImpl { |
31 | public: |
32 | FileImpl(); |
33 | ~FileImpl(); |
34 | |
35 | void create(const char *path, UInt64 size); |
36 | void open(const char *path); |
37 | void close(); |
38 | |
39 | void *ptr() const { |
40 | return ptr_; |
41 | } |
42 | UInt64 size() const { |
43 | return size_; |
44 | } |
45 | |
46 | void swap(FileImpl *rhs); |
47 | |
48 | void flush(); |
49 | |
50 | private: |
51 | void *ptr_; |
52 | UInt64 size_; |
53 | |
54 | #ifdef WIN32 |
55 | HANDLE file_; |
56 | HANDLE map_; |
57 | LPVOID addr_; |
58 | #else // WIN32 |
59 | int fd_; |
60 | void *addr_; |
61 | ::size_t length_; |
62 | #endif // WIN32 |
63 | |
64 | void create_(const char *path, UInt64 size); |
65 | void open_(const char *path); |
66 | |
67 | // Disallows copy and assignment. |
68 | FileImpl(const FileImpl &); |
69 | FileImpl &operator=(const FileImpl &); |
70 | }; |
71 | |
72 | } // namespace dat |
73 | } // namespace grn |
74 | |