1#ifndef joedb_Buffered_File_declared
2#define joedb_Buffered_File_declared
24 size_t read_buffer_size;
27 static void reading_past_end_of_file()
30 throw Exception(
"Trying to read past the end of file");
37 return buffer.
index > 0 && !read_buffer_size;
41 bool buffer_has_read_data()
const
44 return read_buffer_size;
56 if (read_buffer_size == 0)
57 reading_past_end_of_file();
71 void check_write_buffer()
150 static_assert(
sizeof(
T) <=
decltype(buffer)::extra_size);
152 check_write_buffer();
169 check_write_buffer();
176 if (buffer.
index + 8 <= read_buffer_size)
189 return T(
compact_read<
typename std::underlying_type<T>::type>());
216 std::copy_n(data,
n, buffer.
data + buffer.
index);
218 check_write_buffer();
226 std::copy_n(data,
n, buffer.
data + buffer.
index);
228 check_write_buffer();
245 if (buffer.
index +
n <= read_buffer_size)
247 std::copy_n(buffer.
data + buffer.
index,
n, data);
253 size_t n0 = read_buffer_size - buffer.
index;
257 if (
n <= buffer.
size)
261 while (
n0 <
n && buffer.
index < read_buffer_size)
270 reading_past_end_of_file();
284 if (buffer.
index +
n <= read_buffer_size)
virtual void shared_lock(int64_t start, int64_t size)
virtual int64_t get_size() const
virtual void unlock(int64_t start, int64_t size) noexcept
virtual void exclusive_lock(int64_t start, int64_t size)
int64_t get_position() const noexcept
static constexpr size_t extra_size
char data[size+extra_size]
static constexpr size_t size
void ignore(const int64_t n)
void exclusive_lock_tail()
void write_reference(Record_Id id)
void write_blob(Blob blob)
void set_position(int64_t position)
bool is_shared() const noexcept
void unlock_head() noexcept
bool tail_is_locked() const noexcept
void exclusive_lock_head()
static constexpr int64_t last_position
size_t read_data(char *data, const size_t n)
void write_string(const std::string &s)
virtual std::string read_blob_data(Blob blob) const
bool is_readonly() const noexcept
void unlock_tail() noexcept
std::string read_string()
void destructor_flush() noexcept
void write_data(const char *data, size_t n)
virtual void copy_to(Buffered_File &destination, int64_t start, int64_t size)
Record_Id read_reference()
std::string safe_read_string(int64_t max_size)
void copy_to(Buffered_File &destination)
int64_t get_position() const noexcept
size_t sequential_read(char *data, size_t size)
void sequential_write(const char *data, size_t size)
int64_t get_position() const
@ write_existing
fails if does not exist or locked, locks the file for writing
@ shared_write
like write_existing_or_create_new, but does not lock the file, and does not fail if locked
@ read_existing
fails if does not exist
constexpr std::underlying_type< Table_Id >::type to_underlying(Table_Id id)