Joedb 10.2.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
File_Buffer.cpp
Go to the documentation of this file.
3
4namespace joedb
5{
6 //////////////////////////////////////////////////////////////////////////
8 //////////////////////////////////////////////////////////////////////////
9 File_Iterator(file)
10 {
11 read_buffer_size = 0;
12 buffer.index = 0;
13 }
14
15 ////////////////////////////////////////////////////////////////////////////
17 ////////////////////////////////////////////////////////////////////////////
18 {
19 if (buffer_has_write_data())
20 write_buffer();
21 else
22 {
24 read_buffer_size = 0;
25 }
26 buffer.index = 0;
27 }
28
29 ////////////////////////////////////////////////////////////////////////////
30 void File_Buffer::set_position(int64_t new_position)
31 ////////////////////////////////////////////////////////////////////////////
32 {
33 flush();
34 File_Iterator::seek(new_position);
35 }
36
37 ////////////////////////////////////////////////////////////////////////////
38 void File_Buffer::write_string(const std::string &s)
39 ////////////////////////////////////////////////////////////////////////////
40 {
41 compact_write<size_t>(s.size());
42 write_data(s.data(), s.size());
43 }
44
45 ////////////////////////////////////////////////////////////////////////////
47 ////////////////////////////////////////////////////////////////////////////
48 {
49 const size_t size = compact_read<size_t>();
50 std::string s(size, 0);
51 read_data(s.data(), size);
52 return s;
53 }
54
55 ////////////////////////////////////////////////////////////////////////////
56 std::string File_Buffer::safe_read_string(int64_t max_size)
57 ////////////////////////////////////////////////////////////////////////////
58 {
59 std::string s;
60 const int64_t size = compact_read<int64_t>();
61 if (size > 0 && size < max_size)
62 {
63 s.resize(size_t(size));
64 read_data(s.data(), size_t(size));
65 }
66 return s;
67 }
68
69 ////////////////////////////////////////////////////////////////////////////
71 ////////////////////////////////////////////////////////////////////////////
72 {
73 if (buffer_has_write_data())
74 {
75 Destructor_Logger::warning("flusing File_Buffer");
76 try { write_buffer(); } catch (...) {}
77 }
78 }
79}
size_t index
Definition Buffer.h:20
static void warning(std::string_view message) noexcept
size_t read_data(char *data, const size_t n)
std::string safe_read_string(int64_t max_size)
void write_data(const char *data, size_t n)
int64_t get_position() const noexcept
Definition File_Buffer.h:75
File_Buffer(Abstract_File &file)
std::string read_string()
void set_position(int64_t position)
void write_string(const std::string &s)
void seek(int64_t new_position) noexcept