Joedb 10.2.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Interpreted_File.h
Go to the documentation of this file.
1#ifndef joedb_Interpreted_File_declared
2#define joedb_Interpreted_File_declared
3
9#include "joedb/Multiplexer.h"
12
13#include <iostream>
14
15namespace joedb
16{
17 ///
18 /// This class allows accessing a file in joedbi text format. It works by
19 /// keeping a binary version of the file in memory, and keeping it in sync
20 /// with the text file. An empty new line is written at each checkpoint.
21 /// Opening the text file fails if it does not end with an empty new line.
22 ///
23 /// @ingroup journal
25 {
26 private:
27 void read_data();
28
30 std::iostream ios;
31
32 Memory_File memory_file;
33 Writable_Journal journal;
34
35 Database db;
36
37 Multiplexer reading_multiplexer;
38 Interpreter interpreter;
39
40 Interpreter_Writable interpreter_writable;
41 Multiplexer writing_multiplexer;
42
43 Abstract_File null_file;
44 joedb::filebuf null_filebuf;
45 std::ostream null_stream;
46
47 public:
49
50 int64_t get_size() const override;
51 size_t pread(char *data, size_t size, int64_t offset) const override;
52 void pwrite(const char *buffer, size_t size, int64_t offset) override;
53 void sync() override;
54 void shared_lock(int64_t start, int64_t size) override;
55 void exclusive_lock(int64_t start, int64_t size) override;
56 void unlock(int64_t start, int64_t size) noexcept override;
57 };
58
59 namespace detail
60 {
61 class Interpreted_File_Parent
62 {
63 protected:
64 File file;
65 public:
66 Interpreted_File_Parent(const char *file_name, Open_Mode mode):
67 file(file_name, mode)
68 {
69 }
70 };
71 }
72
73 /// @ingroup journal
75 private detail::Interpreted_File_Parent,
77 {
78 public:
79 Interpreted_File(const char *file_name, Open_Mode mode):
80 detail::Interpreted_File_Parent(file_name, mode),
82 {
83 }
84 };
85}
86
87#endif
This class allows accessing a file in joedbi text format.
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.
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)
Interpreted_File(const char *file_name, Open_Mode mode)
https://en.cppreference.com/w/cpp/io/basic_streambuf.html
Definition filebuf.h:17
Open_Mode
Definition Open_Mode.h:8
JOEDB_FILE File
Definition File.h:25