boat
C++23 geospatial library
Loading...
Searching...
No Matches
reflection.hpp
Go to the documentation of this file.
1// Andrew Naplavkov
2
3#ifndef BOAT_DB_REFLECTION_HPP
4#define BOAT_DB_REFLECTION_HPP
5
7#include <boat/db/meta.hpp>
8#include <boost/pfr.hpp>
9#include <boost/type_index/ctti_type_index.hpp>
10
11namespace boat::db {
12
14template <class T>
15constexpr auto kinds_as_array()
16{
17 auto ret = std::array<std::string_view, boost::pfr::tuple_size_v<T>>{};
18 [&]<size_t... Is>(std::integer_sequence<size_t, Is...>) {
19 ((ret[Is] = kind<boost::pfr::tuple_element_t<Is, T>>::value), ...);
20 }(std::make_integer_sequence<size_t, boost::pfr::tuple_size_v<T>>{});
21 return ret;
22}
23
24template <class T>
26{
27 auto ret = table{.table_name{
28 boost::typeindex::ctti_type_index::type_id<T>().pretty_name()}};
29 if (auto pos = ret.table_name.find_last_of(' '); pos != std::string::npos)
30 ret.table_name = ret.table_name.substr(pos + 1);
31 for (auto [k, n] : std::views::zip( //
33 boost::pfr::names_as_array<T>())) {
34 auto col = column{.kind{k}, .column_name{n}};
36 col.epsg = 4326;
37 ret.columns.push_back(std::move(col));
38 }
39 return ret;
40}
41
42} // namespace boat::db
43
44#endif // BOAT_DB_REFLECTION_HPP
Definition geometry.hpp:9
constexpr auto kinds_as_array()
Creates a std::array from kind<Field>::value for each field of T.
Definition reflection.hpp:15
table to_table()
Definition reflection.hpp:25
Definition meta.hpp:27
int epsg
Definition meta.hpp:33
Maps a C++ type to the database-neutral type name used by boat.
Definition variant.hpp:58
Definition meta.hpp:54
std::string table_name
Definition meta.hpp:57