Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Windows_File.h
Go to the documentation of this file.
1#ifndef joedb_Windows_File_declared
2#define joedb_Windows_File_declared
3
5
6#include <windows.h>
7#include <array>
8
9namespace joedb
10{
12 {
13 private:
14 static constexpr size_t mode_count = static_cast<size_t>(joedb::Open_Mode::mode_count);
15 static const std::array<DWORD, mode_count> desired_access;
16 static const std::array<DWORD, mode_count> share_mode;
17 static const std::array<DWORD, mode_count> creation_disposition;
18
19 private:
20 const HANDLE file;
21
22 static void throw_last_error
23 (
24 const char *action,
25 const char *file_name
26 );
27
28 enum class Lock_Operation
29 {
32 unlock
33 };
34
35 BOOL lock(Lock_Operation op, int64_t start, int64_t size);
36
37 public:
38 Windows_Handle(const char *file_name, Open_Mode mode);
39
40 Windows_Handle(const Windows_Handle &) = delete;
42
43 int64_t get_size() const override;
44 size_t pread(char* data, size_t size, int64_t offset) const override;
45 void pwrite(const char* data, size_t size, int64_t offset) override;
46
47 void sync() override;
48
49 void shared_lock(int64_t start, int64_t size) override;
50 void exclusive_lock(int64_t start, int64_t size) override;
51 void unlock(int64_t start, int64_t size) noexcept override;
52
53 ~Windows_Handle() override;
54 };
55
56 /// @ingroup journal
58 {
59 public:
60 inline static constexpr bool lockable = true;
61 Windows_File(const char *file_name, Open_Mode mode);
62 Windows_File(const std::string &file_name, Open_Mode mode):
64 {
65 }
66 };
67}
68
69#endif
static constexpr bool lockable
Windows_File(const std::string &file_name, Open_Mode mode)
void exclusive_lock(int64_t start, int64_t size) override
void pwrite(const char *data, size_t size, int64_t offset) override
int64_t get_size() const override
size_t pread(char *data, size_t size, int64_t offset) const override
Windows_Handle & operator=(const Windows_Handle &)=delete
void shared_lock(int64_t start, int64_t size) override
void unlock(int64_t start, int64_t size) noexcept override
Windows_Handle(const Windows_Handle &)=delete
Open_Mode
Definition Open_Mode.h:8
@ mode_count
number of modes
Definition Blob.h:7