Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Readable.cpp
Go to the documentation of this file.
1#include "joedb/Readable.h"
4
5namespace joedb
6{
7 const std::string Readable::default_table_name = "__unknown_table__";
8 const std::string Readable::default_field_name = "__unknown_field__";
9 Readable::~Readable() = default;
10
11 ////////////////////////////////////////////////////////////////////////////
12 Table_Id Readable::find_table(const std::string &name) const
13 ////////////////////////////////////////////////////////////////////////////
14 {
15 for (const auto &[tid, tname]: get_tables())
16 if (tname == name)
17 return tid;
18 return Table_Id(0);
19 }
20
21 ////////////////////////////////////////////////////////////////////////////
22 Field_Id Readable::find_field(Table_Id table_id, const std::string &name) const
23 ////////////////////////////////////////////////////////////////////////////
24 {
25 try
26 {
27 for (const auto &[fid, fname]: get_fields(table_id))
28 if (fname == name)
29 return fid;
30 }
31 catch (const Exception &)
32 {
33 }
34 return Field_Id(0);
35 }
36
37 ////////////////////////////////////////////////////////////////////////////
38 const std::string &Readable::get_table_name(Table_Id table_id) const
39 ////////////////////////////////////////////////////////////////////////////
40 {
41 const std::map<Table_Id, std::string> &tables = get_tables();
42 const auto it = tables.find(table_id);
43 if (it == tables.end())
44 {
45 return default_table_name;
46 }
47 else
48 return it->second;
49 }
50
51 ////////////////////////////////////////////////////////////////////////////
52 const std::string &Readable::get_field_name
53 ////////////////////////////////////////////////////////////////////////////
54 (
55 Table_Id table_id,
56 Field_Id field_id
57 ) const
58 {
59 try
60 {
61 const std::map<Field_Id, std::string> &fields = get_fields(table_id);
62 const auto it = fields.find(field_id);
63 if (it != fields.end())
64 return it->second;
65 }
66 catch (const Exception &)
67 {
68 }
69
70 return default_field_name;
71 }
72
73 ////////////////////////////////////////////////////////////////////////////
75 ////////////////////////////////////////////////////////////////////////////
76 {
77 return Record_Id(get_freedom(table_id).size());
78 }
79
80 ////////////////////////////////////////////////////////////////////////////
82 ////////////////////////////////////////////////////////////////////////////
83 (
84 Table_Id table_id,
85 Record_Id record_id
86 ) const
87 {
88 return get_freedom(table_id).is_used(to_underlying(record_id) + 1);
89 }
90}
const std::string & get_field_name(Table_Id table_id, Field_Id field_id) const
Definition Readable.cpp:54
Field_Id find_field(Table_Id table_id, const std::string &name) const
Definition Readable.cpp:22
bool is_used(Table_Id table_id, Record_Id record_id) const
Definition Readable.cpp:83
const std::string & get_table_name(Table_Id table_id) const
Definition Readable.cpp:38
Table_Id find_table(const std::string &name) const
Definition Readable.cpp:12
Record_Id get_last_record_id(Table_Id table_id) const
Definition Readable.cpp:74
virtual ~Readable()
Definition Blob.h:7
constexpr std::underlying_type< Table_Id >::type to_underlying(Table_Id id)
Definition index_types.h:15