Joedb 9.6.2
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
index_types.h
Go to the documentation of this file.
1#ifndef joedb_index_types_declared
2#define joedb_index_types_declared
3
4#include <stdint.h>
5#include <stddef.h>
6#include <stdlib.h>
7#include <type_traits>
8
9namespace joedb
10{
11 /// @ingroup joedb
12 enum class Table_Id: uint16_t {};
13
14 /// @ingroup joedb
15 enum class Field_Id: uint16_t {};
16
17 /// @ingroup joedb
18 using index_t = ptrdiff_t;
19
20 /// @ingroup joedb
22 {
23 private:
24 index_t id;
25
26 public:
27 constexpr explicit Record_Id(): id(-1) {}
28 constexpr explicit Record_Id(index_t id): id(id) {}
29 constexpr explicit operator index_t() const {return id;}
30 constexpr explicit operator size_t() const {return size_t(id);}
31 constexpr Record_Id operator+(size_t n) const {return Record_Id(id + n);}
32 constexpr Record_Id operator-(size_t n) const {return Record_Id(id - n);}
33 constexpr Record_Id operator++() {return Record_Id(++id);}
34 constexpr Record_Id operator--() {return Record_Id(--id);}
35 constexpr bool operator==(Record_Id r) const {return id == r.id;}
36 constexpr bool operator!=(Record_Id r) const {return id != r.id;}
37 constexpr bool operator<=(Record_Id r) const {return id <= r.id;}
38 constexpr bool operator>=(Record_Id r) const {return id >= r.id;}
39 constexpr bool operator<(Record_Id r) const {return id < r.id;}
40 constexpr bool operator>(Record_Id r) const {return id > r.id;}
41 constexpr bool is_null() const {return id < 0;}
42 constexpr bool is_not_null() const {return id >= 0;}
43
44 static const Record_Id null;
45 };
46
47 inline constexpr Record_Id Record_Id::null{};
48
49 template<typename T> struct underlying_type
50 {
51 using type = typename std::underlying_type<T>::type;
52 };
53
54 template<> struct underlying_type<Record_Id>
55 {
56 using type = index_t;
57 };
58
59 constexpr index_t to_underlying(Record_Id id) {return index_t(id);}
60
68
76
78 {
79 return id = Table_Id(to_underlying(id) + 1);
80 }
82 {
83 return id = Field_Id(to_underlying(id) + 1);
84 }
85}
86
87#endif
constexpr bool is_null() const
Definition index_types.h:41
constexpr bool operator>(Record_Id r) const
Definition index_types.h:40
constexpr Record_Id()
Definition index_types.h:27
constexpr bool is_not_null() const
Definition index_types.h:42
static const Record_Id null
Definition index_types.h:44
constexpr Record_Id operator+(size_t n) const
Definition index_types.h:31
constexpr bool operator!=(Record_Id r) const
Definition index_types.h:36
constexpr bool operator<(Record_Id r) const
Definition index_types.h:39
constexpr Record_Id operator-(size_t n) const
Definition index_types.h:32
constexpr Record_Id(index_t id)
Definition index_types.h:28
constexpr Record_Id operator--()
Definition index_types.h:34
constexpr Record_Id operator++()
Definition index_types.h:33
constexpr bool operator==(Record_Id r) const
Definition index_types.h:35
constexpr bool operator>=(Record_Id r) const
Definition index_types.h:38
constexpr bool operator<=(Record_Id r) const
Definition index_types.h:37
ptrdiff_t index_t
Definition index_types.h:18
Definition Blob.h:7
Table_Id & operator++(Table_Id &id)
Definition index_types.h:77
constexpr index_t to_underlying(Record_Id id)
Definition index_types.h:59
typename std::underlying_type< T >::type type
Definition index_types.h:51