boat
C++23 geospatial library
Loading...
Searching...
No Matches
io.hpp
Go to the documentation of this file.
1// Andrew Naplavkov
2
3#ifndef BOAT_DB_IO_HPP
4#define BOAT_DB_IO_HPP
5
6#include <boat/db/detail/manip.hpp>
7#include <boat/db/meta.hpp>
8#include <boat/db/rowset.hpp>
9
10namespace boat::db {
11
12auto& operator<<(ostream auto& out, rowset const& in)
13{
14 using char_t = std::remove_cvref_t<decltype(out)>::char_type;
15 auto sizes = std::vector<size_t>(in.columns.size());
16 auto cols = in.columns | std::ranges::to<std::vector<variant>>();
17 auto line = std::vector<variant>(cols.size());
18 manip{sizes, cols}.resize(out);
19 for (auto& row : in)
20 manip{sizes, row}.resize(out);
21 out << '\n'
22 << std::setfill<char_t>(' ') << manip{sizes, cols}
23 << std::setfill<char_t>('-') << manip{sizes, line}
24 << std::setfill<char_t>(' ');
25 for (auto& row : in)
26 out << manip{sizes, row};
27 return out;
28}
29
30auto& operator<<(ostream auto& out, table const& in)
31{
32 auto rs = rowset{
33 {concat(
34 in.schema_name, in.schema_name.empty() ? "" : ".", in.table_name),
35 in.dbms}};
36 for (auto& col : in.columns) {
37 auto suf = col.srid > 0 ? col.srid : col.length > 0 ? col.length : 0;
38 rs.rows.push_back({
39 col.column_name,
40 suf > 0 ? concat(col.type_name, ":", suf) : col.type_name,
41 });
42 }
43 for (auto idx : in.indices()) {
44 auto key = std::ranges::begin(idx);
45 auto spatial = std::ranges::any_of(in.columns, [&](auto& col) {
46 return col.has_coord_sys() && col.column_name == key->column_name;
47 });
48 rs.columns.push_back(concat( //
49 key->partial ? "part:"
50 : key->primary ? "pk:"
51 : spatial ? "spat:"
52 : key->unique ? "uniq:"
53 : "idx:",
54 std::ranges::size(idx)));
55 for (auto [col, row] : std::views::zip(in.columns, rs.rows)) {
56 key = std::ranges::find(
57 idx, col.column_name, &index_key::column_name);
58 row.push_back(
59 key == std::ranges::end(idx)
60 ? variant{}
61 : variant{key->ordinal * (key->descending ? -1 : 1)});
62 }
63 }
64 return out << rs;
65}
66
67auto& operator<<(ostream auto& out, raster const& in)
68{
69 out << "\n{ name: " << in.schema_name << (in.schema_name.empty() ? "" : ".")
70 << in.table_name << "." << in.column_name << "\n, bands: {";
71 for (auto sep = ""; auto& band : in.bands)
72 out << std::exchange(sep, ", ") << band.color_name << ":"
73 << band.type_name;
74 return out << "}\n, width: " << in.width << "\n, height: " << in.height
75 << "\n, xorig: " << in.xorig << "\n, yorig: " << in.yorig
76 << "\n, xscale: " << in.xscale << "\n, yscale: " << in.yscale
77 << "\n, xskew: " << in.xskew << "\n, yskew: " << in.yskew
78 << "\n, srid: " << in.srid << " }\n";
79}
80
81} // namespace boat::db
82
83#endif // BOAT_DB_IO_HPP
Definition geometry.hpp:9
auto & operator<<(ostream auto &out, rowset const &in)
Definition io.hpp:12
Definition meta.hpp:93
std::string color_name
lower case
Definition meta.hpp:94
std::string type_name
lower case
Definition meta.hpp:95
std::string column_name
Definition meta.hpp:46
Definition meta.hpp:98
double xorig
Definition meta.hpp:105
std::string column_name
Definition meta.hpp:101
double yskew
Definition meta.hpp:110
int height
Definition meta.hpp:104
std::vector< band > bands
Definition meta.hpp:102
std::string table_name
Definition meta.hpp:100
double xscale
Definition meta.hpp:107
double yorig
Definition meta.hpp:106
int width
Definition meta.hpp:103
int srid
Definition meta.hpp:111
double yscale
Definition meta.hpp:108
std::string schema_name
Definition meta.hpp:99
double xskew
Definition meta.hpp:109
Definition rowset.hpp:12
std::vector< std::string > columns
Definition rowset.hpp:13
Definition meta.hpp:54
auto indices() const
Definition meta.hpp:61
std::string table_name
Definition meta.hpp:57
std::string schema_name
Definition meta.hpp:56
std::vector< column > columns
Definition meta.hpp:58
std::string dbms
lower case
Definition meta.hpp:55
Definition variant.hpp:14