12#ifndef tutorial_Database_declared
13#define tutorial_Database_declared
44 class container_of_city;
45 class container_of_person;
54 std::vector<std::string> field_value_of_name;
55 std::vector<type_of_index_of_city_by_name::iterator> iterator_over_city_by_name;
59 size_t size()
const {
return freedom_keeper.
size();}
61 void resize(
size_t new_size)
63 field_value_of_name.resize(new_size);
64 iterator_over_city_by_name.resize(new_size);
65 freedom_keeper.
resize(new_size);
71 std::vector<std::string> field_value_of_first_name;
72 std::vector<std::string> field_value_of_last_name;
73 std::vector<id_of_city> field_value_of_home;
74 std::vector<type_of_index_of_person_by_name::iterator> iterator_over_person_by_name;
78 size_t size()
const {
return freedom_keeper.
size();}
80 void resize(
size_t new_size)
82 field_value_of_first_name.resize(new_size);
83 field_value_of_last_name.resize(new_size);
84 field_value_of_home.resize(new_size);
85 iterator_over_person_by_name.resize(new_size);
86 freedom_keeper.
resize(new_size);
91 class range_of_person_by_name;
102 template<
typename E = joedb::Exception>
105 std::string s(
"tutorial: ");
122 auto &iterator =
storage_of_city.iterator_over_city_by_name[to_underlying(record_id)];
133 type_of_index_of_city_by_name::value_type
141 std::ostringstream out;
142 out <<
"city_by_name unique index failure: (";
144 out <<
") at id = " << record_id <<
' ';
145 out <<
"was already at id = " << result.first->second.get_id();
148 storage_of_city.iterator_over_city_by_name[to_underlying(record_id)] = result.first;
153 auto &iterator =
storage_of_person.iterator_over_person_by_name[to_underlying(record_id)];
164 type_of_index_of_person_by_name::value_type
166 std::tuple<std::string, std::string>(
storage_of_person.field_value_of_last_name[to_underlying(record_id)],
storage_of_person.field_value_of_first_name[to_underlying(record_id)]),
170 storage_of_person.iterator_over_person_by_name[to_underlying(record_id)] = result;
228 std::string_view field_value_of_name
232 storage_of_city.field_value_of_name[to_underlying(record_id)] = field_value_of_name;
241 const std::string *value
245 std::string *target = &
storage_of_city.field_value_of_name.data()[to_underlying(record_id)];
247 std::copy_n(value, size, target);
248 for (
size_t i = 0; i < size; i++)
250 for (
size_t i = 0; i < size; i++)
257 std::string_view field_value_of_first_name
261 storage_of_person.field_value_of_first_name[to_underlying(record_id)] = field_value_of_first_name;
270 const std::string *value
274 std::string *target = &
storage_of_person.field_value_of_first_name.data()[to_underlying(record_id)];
276 std::copy_n(value, size, target);
277 for (
size_t i = 0; i < size; i++)
279 for (
size_t i = 0; i < size; i++)
286 std::string_view field_value_of_last_name
290 storage_of_person.field_value_of_last_name[to_underlying(record_id)] = field_value_of_last_name;
299 const std::string *value
303 std::string *target = &
storage_of_person.field_value_of_last_name.data()[to_underlying(record_id)];
305 std::copy_n(value, size, target);
306 for (
size_t i = 0; i < size; i++)
308 for (
size_t i = 0; i < size; i++)
319 storage_of_person.field_value_of_home[to_underlying(record_id)] = field_value_of_home;
332 std::copy_n(value, size, target);
354 template<
class Comparator>
355 std::vector<id_of_city>
sorted_city(Comparator comparator)
const;
386 template<
class Comparator>
387 std::vector<id_of_person>
sorted_person(Comparator comparator)
const;
425 auto iterator =
storage_of_city.iterator_over_city_by_name[
id.get_id()];
428 return iterator->second;
435 auto iterator =
storage_of_city.iterator_over_city_by_name[
id.get_id()];
437 return (--iterator)->second;
467 iterator(
const detail::data_of_city &data): fk(&data.freedom_keeper), index(
joedb::Freedom_Keeper_Constants::used_list) {}
500 template<
class Comparator>
503 std::vector<id_of_city> result;
505 result.emplace_back(x);
506 std::sort(result.begin(), result.end(), comparator);
525 iterator(
const detail::data_of_person &data): fk(&data.freedom_keeper), index(
joedb::Freedom_Keeper_Constants::used_list) {}
558 template<
class Comparator>
561 std::vector<id_of_person> result;
563 result.emplace_back(x);
564 std::sort(result.begin(), result.end(), comparator);
572 std::pair<type_of_index_of_person_by_name::const_iterator, type_of_index_of_person_by_name::const_iterator> range;
582 type_of_index_of_person_by_name::const_iterator map_iterator;
583 iterator(type_of_index_of_person_by_name::const_iterator map_iterator): map_iterator(map_iterator) {}
587 return map_iterator != i.map_iterator;
594 bool empty()
const {
return range.first == range.second;}
595 size_t size()
const {
return size_t(std::distance(range.first, range.second));}
void resize(Record_Id new_size)
Record_Id get_previous(Record_Id index) const
Record_Id get_next(Record_Id index) const
static const Record_Id null
Store all the tables of the database.
void internal_update_person__last_name(Record_Id record_id, std::string_view field_value_of_last_name)
void internal_update_vector_person__first_name(Record_Id record_id, size_t size, const std::string *value)
id_of_person previous(id_of_person id) const
bool is_valid(id_of_city id) const
const std::string & get_last_name(id_of_person record) const
void internal_update_vector_city__name(Record_Id record_id, size_t size, const std::string *value)
container_of_person get_person_table() const
friend class container_of_city
void internal_insert_person(Record_Id record_id)
const std::string & get_first_name(id_of_person record) const
static void throw_exception(std::string_view message)
friend class container_of_person
void internal_update_vector_person__home(Record_Id record_id, size_t size, const id_of_city *value)
void add_index_of_person_by_name(Record_Id record_id)
void remove_index_of_person_by_name(Record_Id record_id)
void internal_update_person__first_name(Record_Id record_id, std::string_view field_value_of_first_name)
detail::data_of_city storage_of_city
void internal_update_city__name(Record_Id record_id, std::string_view field_value_of_name)
void add_index_of_city_by_name(Record_Id record_id)
friend class range_of_person_by_name
detail::data_of_person storage_of_person
void internal_update_vector_person__last_name(Record_Id record_id, size_t size, const std::string *value)
range_of_person_by_name find_person_by_name(std::string_view field_value_of_last_name, std::string_view field_value_of_first_name) const
type_of_index_of_city_by_name index_of_city_by_name
id_of_city get_home(id_of_person record) const
id_of_city previous_city_by_name(id_of_city id) const
const std::string & get_name(id_of_city record) const
void internal_update_person__home(Record_Id record_id, id_of_city field_value_of_home)
bool is_valid_record_id_for_city(Record_Id record_id) const
std::vector< id_of_city > sorted_city(Comparator comparator) const
bool is_valid_record_id_for_person(Record_Id record_id) const
static id_of_person null_person()
void internal_insert_city(Record_Id record_id)
container_of_city get_city_table() const
id_of_city find_city_by_name(std::string_view field_value_of_name) const
bool is_valid(id_of_person id) const
void internal_delete_person(Record_Id record_id)
const type_of_index_of_city_by_name & get_index_of_city_by_name()
type_of_index_of_person_by_name index_of_person_by_name
id_of_city next(id_of_city id) const
std::vector< id_of_person > sorted_person(Comparator comparator) const
void internal_delete_city(Record_Id record_id)
const type_of_index_of_person_by_name & get_index_of_person_by_name()
void remove_index_of_city_by_name(Record_Id record_id)
void internal_vector_insert_city(Record_Id record_id, size_t size)
id_of_city previous(id_of_city id) const
id_of_city next_city_by_name(id_of_city id) const
id_of_person next(id_of_person id) const
static id_of_city null_city()
void internal_vector_insert_person(Record_Id record_id, size_t size)
Implement the joedb::Readable interface for a compiled database.
std::ptrdiff_t difference_type
bool operator==(const iterator &i) const
bool operator!=(const iterator &i) const
id_of_city operator*() const
std::forward_iterator_tag iterator_category
returned by Database::get_city_table
bool is_valid_at(size_t i)
joedb::index_t get_size() const
id_of_city get_end() const
static id_of_city get_at(size_t i)
bool operator==(const iterator &i) const
id_of_person operator*() const
std::ptrdiff_t difference_type
bool operator!=(const iterator &i) const
std::forward_iterator_tag iterator_category
returned by Database::get_person_table
id_of_person first() const
bool is_valid_at(size_t i)
id_of_person last() const
id_of_person get_end() const
joedb::index_t get_size() const
static id_of_person get_at(size_t i)
Strongly-typed wrapper around an integer representing a row of the city table.
constexpr auto get_id() const
constexpr Record_Id get_record_id() const
Strongly-typed wrapper around an integer representing a row of the person table.
constexpr Record_Id get_record_id() const
constexpr auto get_id() const
bool operator!=(const iterator &i) const
id_of_person operator*() const
returned by Database::find_person_by_name
#define JOEDB_RELEASE_ASSERT(x)
always-tested assertion (release and debug mode)
constexpr const char * get_version()
void write_string(std::ostream &out, std::string_view s, bool json)
Automatically generated by joedbc.
std::map< std::string, id_of_city, std::less<> > type_of_index_of_city_by_name
std::multimap< std::tuple< std::string, std::string >, id_of_person, std::less<> > type_of_index_of_person_by_name