Joedb 10.3.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Interpreted_File.cpp
Go to the documentation of this file.
2
3namespace joedb
4{
5 ////////////////////////////////////////////////////////////////////////////
6 void Abstract_Interpreted_File::read_data()
7 ////////////////////////////////////////////////////////////////////////////
8 {
9 interpreter.main_loop(ios, null_stream);
10 ios.clear();
11 ios.seekp(0, std::ios::end);
12
13 if (!interpreter.is_last_line_empty())
14 {
16 (
17 "Interpreted_File: last line of joedbi file must be empty"
18 );
19 }
20
21 journal.soft_checkpoint();
22 }
23
24 ////////////////////////////////////////////////////////////////////////////
26 ////////////////////////////////////////////////////////////////////////////
27 Abstract_File(file.get_mode()),
28 filebuf(file),
29 ios(&filebuf),
30 journal(memory_file),
31 reading_multiplexer{db, journal},
32 interpreter(db, reading_multiplexer, Record_Id::null),
33 interpreter_writable(ios, db),
34 writing_multiplexer{interpreter_writable, db}
35 {
36 interpreter.set_echo(false);
37 interpreter.set_rethrow(true);
38 read_data();
39 }
40
41 ////////////////////////////////////////////////////////////////////////////
43 ////////////////////////////////////////////////////////////////////////////
44 {
45 return memory_file.get_size();
46 }
47
48 ////////////////////////////////////////////////////////////////////////////
50 ////////////////////////////////////////////////////////////////////////////
51 (
52 char *data,
53 size_t size,
54 int64_t offset
55 ) const
56 {
57 return memory_file.pread(data, size, offset);
58 }
59
60 ////////////////////////////////////////////////////////////////////////////
62 ////////////////////////////////////////////////////////////////////////////
63 (
64 const char *buffer,
65 size_t size,
66 int64_t offset
67 )
68 {
69 memory_file.pwrite(buffer, size, offset);
70
71 if (offset < Header::ssize && journal.pull())
72 {
73 journal.play_until_checkpoint(writing_multiplexer);
74 ios.flush();
75 ios.seekg(0, std::ios::end);
76 }
77 }
78
79 ////////////////////////////////////////////////////////////////////////////
81 ////////////////////////////////////////////////////////////////////////////
82 {
84 }
85
86 ////////////////////////////////////////////////////////////////////////////
87 void Abstract_Interpreted_File::shared_lock(int64_t start, int64_t size)
88 ////////////////////////////////////////////////////////////////////////////
89 {
90 filebuf.get_file().shared_lock(start, size);
91 read_data();
92 }
93
94 ////////////////////////////////////////////////////////////////////////////
95 void Abstract_Interpreted_File::exclusive_lock(int64_t start, int64_t size)
96 ////////////////////////////////////////////////////////////////////////////
97 {
98 filebuf.get_file().exclusive_lock(start, size);
99 read_data();
100 }
101
102 ////////////////////////////////////////////////////////////////////////////
103 void Abstract_Interpreted_File::unlock(int64_t start, int64_t size) noexcept
104 ////////////////////////////////////////////////////////////////////////////
105 {
106 filebuf.get_file().unlock(start, size);
107 }
108}
virtual void shared_lock(int64_t start, int64_t size)
Lock a range of bytes for reading (prevents writes, not reads)
virtual void unlock(int64_t start, int64_t size) noexcept
Remove a lock. The range should match the range of a corresponding lock.
virtual void sync()
Write data durably (including file-size change)
virtual void exclusive_lock(int64_t start, int64_t size)
Lock a range of bytes for writing (prevents both writes and reads)
void sync() override
Write data durably (including file-size change)
size_t pread(char *data, size_t size, int64_t offset) const override
Read a range of bytes.
Abstract_Interpreted_File(Abstract_File &file)
void pwrite(const char *buffer, size_t size, int64_t offset) override
Write a range of bytes. Extend file size if necessary.
int64_t get_size() const override
Get the size of the file, or -1 if it is unknown.
void shared_lock(int64_t start, int64_t size) override
Lock a range of bytes for reading (prevents writes, not reads)
void unlock(int64_t start, int64_t size) noexcept override
Remove a lock. The range should match the range of a corresponding lock.
void exclusive_lock(int64_t start, int64_t size) override
Lock a range of bytes for writing (prevents both writes and reads)
void main_loop(std::istream &in, std::ostream &out)
void set_rethrow(bool new_rethrow)
int64_t get_size() const override
Get the size of the file, or -1 if it is unknown.
Definition Memory_File.h:27
https://en.cppreference.com/w/cpp/io/basic_streambuf.html
Definition filebuf.h:17
Abstract_File & get_file()
Definition filebuf.h:50
static constexpr int64_t ssize
Definition Header.h:18