12#ifndef tutorial_Database_declared
13#define tutorial_Database_declared
43 class container_of_city;
44 class container_of_person;
50 std::vector<std::string> field_value_of_name;
51 std::vector<std::map<std::string, id_of_city>::iterator> iterator_over_city_by_name;
55 size_t size()
const {
return freedom_keeper.
size();}
57 void resize(
size_t new_size)
59 field_value_of_name.resize(new_size);
60 iterator_over_city_by_name.resize(new_size);
61 freedom_keeper.
resize(new_size);
67 std::vector<std::string> field_value_of_first_name;
68 std::vector<std::string> field_value_of_last_name;
69 std::vector<id_of_city> field_value_of_home;
70 std::vector<std::multimap<std::tuple<std::string, std::string>, id_of_person>::iterator> iterator_over_person_by_name;
74 size_t size()
const {
return freedom_keeper.
size();}
76 void resize(
size_t new_size)
78 field_value_of_first_name.resize(new_size);
79 field_value_of_last_name.resize(new_size);
80 field_value_of_home.resize(new_size);
81 iterator_over_person_by_name.resize(new_size);
82 freedom_keeper.
resize(new_size);
87 class range_of_person_by_name;
100 template<
typename E = joedb::Exception>
103 throw E(
"tutorial: " + message);
118 auto &iterator =
storage_of_city.iterator_over_city_by_name[to_underlying(record_id)];
129 std::map<std::string, id_of_city>::value_type
137 std::ostringstream out;
138 out <<
"city_by_name unique index failure: (";
140 out <<
") at id = " << record_id <<
' ';
141 out <<
"was already at id = " << result.first->second.get_id();
144 storage_of_city.iterator_over_city_by_name[to_underlying(record_id)] = result.first;
149 auto &iterator =
storage_of_person.iterator_over_person_by_name[to_underlying(record_id)];
160 std::multimap<std::tuple<std::string, std::string>,
id_of_person>::value_type
162 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)]),
166 storage_of_person.iterator_over_person_by_name[to_underlying(record_id)] = result;
224 const std::string& field_value_of_name
228 storage_of_city.field_value_of_name[to_underlying(record_id)] = field_value_of_name;
237 const std::string *value
241 std::string *target = &
storage_of_city.field_value_of_name.data()[to_underlying(record_id)];
243 std::copy_n(value, size, target);
244 for (
size_t i = 0; i < size; i++)
246 for (
size_t i = 0; i < size; i++)
253 const std::string& field_value_of_first_name
257 storage_of_person.field_value_of_first_name[to_underlying(record_id)] = field_value_of_first_name;
266 const std::string *value
270 std::string *target = &
storage_of_person.field_value_of_first_name.data()[to_underlying(record_id)];
272 std::copy_n(value, size, target);
273 for (
size_t i = 0; i < size; i++)
275 for (
size_t i = 0; i < size; i++)
282 const std::string& field_value_of_last_name
286 storage_of_person.field_value_of_last_name[to_underlying(record_id)] = field_value_of_last_name;
295 const std::string *value
299 std::string *target = &
storage_of_person.field_value_of_last_name.data()[to_underlying(record_id)];
301 std::copy_n(value, size, target);
302 for (
size_t i = 0; i < size; i++)
304 for (
size_t i = 0; i < size; i++)
315 storage_of_person.field_value_of_home[to_underlying(record_id)] = field_value_of_home;
328 std::copy_n(value, size, target);
350 template<
class Comparator>
351 std::vector<id_of_city>
sorted_city(Comparator comparator)
const;
382 template<
class Comparator>
383 std::vector<id_of_person>
sorted_person(Comparator comparator)
const;
421 auto iterator =
storage_of_city.iterator_over_city_by_name[
id.get_id()];
424 return iterator->second;
431 auto iterator =
storage_of_city.iterator_over_city_by_name[
id.get_id()];
433 return (--iterator)->second;
463 iterator(
const detail::data_of_city &data): fk(&data.freedom_keeper), index(
joedb::Freedom_Keeper_Constants::used_list) {}
496 template<
class Comparator>
499 std::vector<id_of_city> result;
501 result.emplace_back(x);
502 std::sort(result.begin(), result.end(), comparator);
521 iterator(
const detail::data_of_person &data): fk(&data.freedom_keeper), index(
joedb::Freedom_Keeper_Constants::used_list) {}
554 template<
class Comparator>
557 std::vector<id_of_person> result;
559 result.emplace_back(x);
560 std::sort(result.begin(), result.end(), comparator);
568 std::pair<std::multimap<std::tuple<std::string, std::string>,
id_of_person>::const_iterator, std::multimap<std::tuple<std::string, std::string>,
id_of_person>::const_iterator> range;
578 std::multimap<std::tuple<std::string, std::string>,
id_of_person>::const_iterator map_iterator;
579 iterator(std::multimap<std::tuple<std::string, std::string>,
id_of_person>::const_iterator map_iterator): map_iterator(map_iterator) {}
583 return map_iterator != i.map_iterator;
590 bool empty()
const {
return range.first == range.second;}
591 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_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
const std::map< std::string, id_of_city > & get_index_of_city_by_name()
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)
friend class id_of_person
range_of_person_by_name find_person_by_name(const std::string &field_value_of_last_name, const std::string &field_value_of_first_name) const
std::map< std::string, id_of_city > index_of_city_by_name
detail::data_of_city storage_of_city
void add_index_of_city_by_name(Record_Id record_id)
id_of_city find_city_by_name(const std::string &field_value_of_name) const
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)
id_of_city get_home(id_of_person record) 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
static void throw_exception(const std::string &message)
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_update_person__first_name(Record_Id record_id, const std::string &field_value_of_first_name)
void internal_update_person__last_name(Record_Id record_id, const std::string &field_value_of_last_name)
void internal_insert_city(Record_Id record_id)
container_of_city get_city_table() const
void internal_update_city__name(Record_Id record_id, const std::string &field_value_of_name)
bool is_valid(id_of_person id) const
void internal_delete_person(Record_Id record_id)
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)
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_person next(id_of_person id) const
static id_of_city null_city()
id_of_city next_city_by_name(id_of_city id)
void internal_vector_insert_person(Record_Id record_id, size_t size)
id_of_city previous_city_by_name(id_of_city id)
std::multimap< std::tuple< std::string, std::string >, id_of_person > index_of_person_by_name
const std::multimap< std::tuple< std::string, std::string >, id_of_person > & get_index_of_person_by_name()
Implement the joedb::Readable interface for a compiled database.
bool operator==(const iterator &i) const
bool operator!=(const iterator &i) const
std::forward_iterator_tag iterator_category
id_of_city operator*() const
std::ptrdiff_t difference_type
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
std::ptrdiff_t difference_type
id_of_person operator*() const
std::forward_iterator_tag iterator_category
bool operator!=(const iterator &i) const
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, const std::string &s, bool json)
Automatically generated by joedbc.