Joedb 9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Abstract_File.h
Go to the documentation of this file.
1#ifndef joedb_Abstract_File_declared
2#define joedb_Abstract_File_declared
3
4#include <stddef.h>
5#include <stdint.h>
6
7namespace joedb
8{
9 /// @ingroup journal
11 {
12 public:
13 /// Get the size of the file, or -1 if it is unknown
14 virtual int64_t get_size() const {return -1;}
15
16 /// Read a range of bytes
17 ///
18 /// The returned value may be less than size, even if the end of the file
19 /// is not reached. 0 is returned if the end of the file is reached.
20 virtual size_t pread(char *data, size_t size, int64_t offset) const {return 0;}
21
22 /// Write a range of bytes. Extend file size if necessary.
23 virtual void pwrite(const char *data, size_t size, int64_t offset) {}
24
25 /// Write data and meta-data (such as file size) durably to permanent storage
26 virtual void sync() {}
27
28 /// Write data durably to permanent storage
29 virtual void datasync() {sync();}
30
31 /// Lock a range of bytes for reading (prevents writes, not reads)
32 virtual void shared_lock(int64_t start, int64_t size) {}
33
34 /// Lock a range of bytes for writing (prevents both writes and reads)
35 virtual void exclusive_lock(int64_t start, int64_t size) {}
36
37 /// Remove a lock. The range should match the range of a corresponding lock
38 virtual void unlock(int64_t start, int64_t size) noexcept {}
39
40 virtual ~Abstract_File() = default;
41 };
42}
43
44#endif
virtual void shared_lock(int64_t start, int64_t size)
Lock a range of bytes for reading (prevents writes, not reads)
virtual int64_t get_size() const
Get the size of the file, or -1 if it is unknown.
virtual void datasync()
Write data durably to permanent storage.
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 and meta-data (such as file size) durably to permanent storage.
virtual ~Abstract_File()=default
virtual void pwrite(const char *data, size_t size, int64_t offset)
Write a range of bytes. Extend file size if necessary.
virtual void exclusive_lock(int64_t start, int64_t size)
Lock a range of bytes for writing (prevents both writes and reads)
virtual size_t pread(char *data, size_t size, int64_t offset) const
Read a range of bytes.
Definition Blob.h:7