Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Writable.h
Go to the documentation of this file.
1#ifndef joedb_Writable_declared
2#define joedb_Writable_declared
3
4#include "joedb/Type.h"
5
6#include <string>
7
8namespace joedb
9{
10 /// Superclass with all joedb journal event listeners as virtual functions
11 ///
12 /// insert_vector and delete_vector are pure virtual because they do not
13 /// check size limits, so they can be dangerously slow.
14 ///
15 /// @ingroup joedb
17 {
18 public:
19 virtual int64_t get_position() const {return 0;}
20 virtual void start_writing(int64_t position) {}
21 virtual void end_writing(int64_t position) {}
22
23 virtual void soft_checkpoint() {}
24 virtual void hard_checkpoint() {soft_checkpoint();}
25
26 virtual void create_table(const std::string &name) {}
27 virtual void drop_table(Table_Id table_id) {}
28 virtual void rename_table(Table_Id table_id, const std::string &name) {}
29
30 virtual void add_field
31 (
32 Table_Id table_id,
33 const std::string &name,
34 Type type
35 ) {}
36 virtual void drop_field(Table_Id table_id, Field_Id field_id) {}
37 virtual void rename_field
38 (
39 Table_Id table_id,
40 Field_Id field_id,
41 const std::string &name
42 ) {}
43
44 virtual void custom(const std::string &name) {}
45 virtual void comment(const std::string &comment) {}
46 virtual void timestamp(int64_t timestamp) {}
47 virtual void valid_data() {}
48 virtual void flush() {}
49
50 virtual void insert_into(Table_Id table_id, Record_Id record_id) {}
51 virtual void delete_from(Table_Id table_id, Record_Id record_id) {}
52
53 virtual void insert_vector
54 (
55 Table_Id table_id,
56 Record_Id record_id,
57 size_t size
58 ) = 0;
59
60 virtual void delete_vector
61 (
62 Table_Id table_id,
63 Record_Id record_id,
64 size_t size
65 ) = 0;
66
67 #define TYPE_MACRO(type, return_type, type_id, R, W)\
68 virtual void update_##type_id\
69 (\
70 Table_Id table_id,\
71 Record_Id record_id,\
72 Field_Id field_id,\
73 return_type value\
74 );
75 #include "joedb/TYPE_MACRO.h"
76
77 #define TYPE_MACRO(type, return_type, type_id, R, W)\
78 virtual void update_vector_##type_id\
79 (\
80 Table_Id table_id,\
81 Record_Id record_id,\
82 Field_Id field_id,\
83 size_t size,\
84 const type *value\
85 );\
86 virtual type *get_own_##type_id##_storage\
87 (\
88 Table_Id table_id,\
89 Record_Id record_id,\
90 Field_Id field_id,\
91 size_t &capacity\
92 )\
93 {\
94 capacity = 0;\
95 return nullptr;\
96 }\
97 const type *get_own_##type_id##_const_storage\
98 (\
99 Table_Id table_id,\
100 Record_Id record_id,\
101 Field_Id field_id,\
102 size_t &capacity\
103 ) const\
104 {\
105 return (const_cast<Writable *>(this))->get_own_##type_id##_storage(table_id, record_id, field_id, capacity);\
106 }
107 #include "joedb/TYPE_MACRO.h"
108
109 virtual void on_blob(Blob blob) {}
110 virtual bool wants_blob_data() const {return false;}
111 virtual Blob write_blob(const std::string &data) {return Blob();}
112
113 virtual ~Writable() = default;
114 };
115
116 /// Writable with empty insert_vector and delete_vector
117 ///
118 /// @ingroup joedb
120 {
121 public:
123 (
124 Table_Id table_id,
125 Record_Id record_id,
126 size_t size
127 ) override
128 {
129 }
130
132 (
133 Table_Id table_id,
134 Record_Id record_id,
135 size_t size
136 ) override
137 {
138 }
139 };
140
141 /// Writable with looping insert_vector and delete_vector
142 ///
143 /// @ingroup joedb
145 {
146 public:
148 (
149 Table_Id table_id,
150 Record_Id record_id,
151 size_t size
152 ) override
153 {
154 Writable::insert_vector(table_id, record_id, size);
155 }
156
158 (
159 Table_Id table_id,
160 Record_Id record_id,
161 size_t size
162 ) override
163 {
164 Writable::delete_vector(table_id, record_id, size);
165 }
166 };
167}
168
169#endif
Writable with empty insert_vector and delete_vector.
Definition Writable.h:120
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) override
Definition Writable.h:123
void delete_vector(Table_Id table_id, Record_Id record_id, size_t size) override
Definition Writable.h:132
Writable with looping insert_vector and delete_vector.
Definition Writable.h:145
void delete_vector(Table_Id table_id, Record_Id record_id, size_t size) override
Definition Writable.h:158
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) override
Definition Writable.h:148
Superclass with all joedb journal event listeners as virtual functions.
Definition Writable.h:17
virtual void insert_vector(Table_Id table_id, Record_Id record_id, size_t size)=0
Definition Writable.cpp:33
virtual Blob write_blob(const std::string &data)
Definition Writable.h:111
virtual void insert_into(Table_Id table_id, Record_Id record_id)
Definition Writable.h:50
virtual void drop_table(Table_Id table_id)
Definition Writable.h:27
virtual void create_table(const std::string &name)
Definition Writable.h:26
virtual void hard_checkpoint()
Definition Writable.h:24
virtual void drop_field(Table_Id table_id, Field_Id field_id)
Definition Writable.h:36
virtual void rename_table(Table_Id table_id, const std::string &name)
Definition Writable.h:28
virtual void delete_vector(Table_Id table_id, Record_Id record_id, size_t size)=0
Definition Writable.cpp:44
virtual void soft_checkpoint()
Definition Writable.h:23
virtual bool wants_blob_data() const
Definition Writable.h:110
virtual void custom(const std::string &name)
Definition Writable.h:44
virtual void start_writing(int64_t position)
Definition Writable.h:20
virtual void flush()
Definition Writable.h:48
virtual ~Writable()=default
virtual void add_field(Table_Id table_id, const std::string &name, Type type)
Definition Writable.h:31
virtual void delete_from(Table_Id table_id, Record_Id record_id)
Definition Writable.h:51
virtual void end_writing(int64_t position)
Definition Writable.h:21
virtual int64_t get_position() const
Definition Writable.h:19
virtual void comment(const std::string &comment)
Definition Writable.h:45
virtual void on_blob(Blob blob)
Definition Writable.h:109
virtual void valid_data()
Definition Writable.h:47
virtual void rename_field(Table_Id table_id, Field_Id field_id, const std::string &name)
Definition Writable.h:38
virtual void timestamp(int64_t timestamp)
Definition Writable.h:46
Definition Blob.h:7