A table assembled from layers of TSV data.
More...
#include <table.hpp>
|
| | layered_table (table_schema schema) |
| | An empty table.
|
| |
| const layer_info & | extend (tsv_document doc, layer_mode mode=layer_mode::override, const std::function< void(const tsv_row &)> &validate={}) |
| | Apply a layer.
|
| |
| void | clear () noexcept |
| | Remove every row and layer.
|
| |
| const std::vector< tsv_row > & | rows () const noexcept |
| | The rows in effect, in order.
|
| |
| std::size_t | size () const noexcept |
| | Number of rows in effect.
|
| |
| bool | empty () const noexcept |
| | Whether no rows are in effect.
|
| |
| std::optional< tsv_row > | find (std::initializer_list< std::string_view > key) const |
| | Find a row by key.
|
| |
| const std::vector< layer_info > & | layers () const noexcept |
| | The layers in effect, in order: the last replace layer and those after it.
|
| |
| std::uint64_t | data_hash () const noexcept |
| | Hash of the loaded layers: their content hashes and modes, in order. 0 when nothing is loaded.
|
| |
| const table_schema & | schema () const noexcept |
| | The schema.
|
| |
|
| static constexpr std::string_view | disabled_column = "disabled" |
| | Name of the column that removes a key when set to 1.
|
| |
A table assembled from layers of TSV data.
- Layers apply in the order loaded; later layers win.
- Rows keep the order they first appeared in: an overriding row takes the place of the row it replaces, new rows are appended. Row order is part of the output (weighted choices depend on it).
- A row with
disabled set to 1 removes its key (override and replace modes). A layer needs the key columns; the other required columns are needed only by rows that add or replace data, so a layer that only removes rows can be just key and disabled.
- A layer is validated completely before it is applied; when it fails, the table is unchanged.
.required = {"male_height_cm"}}};
dasmig::core::layer_mode::replace);
for (
const auto& row : table.
rows()) { ... row.get<
double>(
"male_height_cm") ... }
A table assembled from layers of TSV data.
const layer_info & extend(tsv_document doc, layer_mode mode=layer_mode::override, const std::function< void(const tsv_row &)> &validate={})
Apply a layer.
const std::vector< tsv_row > & rows() const noexcept
The rows in effect, in order.
static tsv_document load(const std::filesystem::path &path, std::vector< std::string > columns={})
Read and parse a file.
Definition at line 94 of file table.hpp.
◆ layered_table()
| dasmig::core::layered_table::layered_table |
( |
table_schema |
schema | ) |
|
|
inlineexplicit |
An empty table.
- Parameters
-
- Exceptions
-
| std::invalid_argument | If the schema has no key column. |
Definition at line 103 of file table.hpp.
◆ clear()
| void dasmig::core::layered_table::clear |
( |
| ) |
|
|
inlinenoexcept |
Remove every row and layer.
Definition at line 185 of file table.hpp.
◆ data_hash()
| std::uint64_t dasmig::core::layered_table::data_hash |
( |
| ) |
const |
|
inlinenoexcept |
Hash of the loaded layers: their content hashes and modes, in order. 0 when nothing is loaded.
Put it in the seed_signature of results so a replay can tell whether it runs against the same data.
- Returns
- The hash.
Definition at line 240 of file table.hpp.
◆ empty()
| bool dasmig::core::layered_table::empty |
( |
| ) |
const |
|
inlinenoexcept |
Whether no rows are in effect.
- Returns
- True when empty.
Definition at line 203 of file table.hpp.
◆ extend()
Apply a layer.
validate is called for every row the layer adds or replaces (not for disabled rows) before anything changes; it should parse the row the way the library will and throw tsv_error on bad data.
- Parameters
-
| doc | The layer's data. |
| mode | How it combines with the rows loaded before. |
| validate | Optional void(const tsv_row&) row check. |
- Returns
- What the layer did.
- Exceptions
-
| tsv_error | On a missing key column, a missing required column (for a row that adds or replaces data), an empty or repeated key, an invalid disabled value, a clash in add mode, or an error from validate. The table is then unchanged. |
Definition at line 125 of file table.hpp.
◆ find()
| std::optional< tsv_row > dasmig::core::layered_table::find |
( |
std::initializer_list< std::string_view > |
key | ) |
const |
|
inline |
Find a row by key.
- Parameters
-
| key | The key cells, in schema key order. |
- Returns
- The row, or empty.
- Exceptions
-
| std::invalid_argument | If the number of cells is not the number of key columns. |
Definition at line 210 of file table.hpp.
◆ layers()
| const std::vector< layer_info > & dasmig::core::layered_table::layers |
( |
| ) |
const |
|
inlinenoexcept |
The layers in effect, in order: the last replace layer and those after it.
- Returns
- The layer records.
Definition at line 231 of file table.hpp.
◆ rows()
| const std::vector< tsv_row > & dasmig::core::layered_table::rows |
( |
| ) |
const |
|
inlinenoexcept |
The rows in effect, in order.
- Returns
- The rows.
Definition at line 195 of file table.hpp.
◆ schema()
| const table_schema & dasmig::core::layered_table::schema |
( |
| ) |
const |
|
inlinenoexcept |
The schema.
- Returns
- The columns.
Definition at line 252 of file table.hpp.
◆ size()
| std::size_t dasmig::core::layered_table::size |
( |
| ) |
const |
|
inlinenoexcept |
Number of rows in effect.
- Returns
- The count.
Definition at line 199 of file table.hpp.
◆ disabled_column
| constexpr std::string_view dasmig::core::layered_table::disabled_column = "disabled" |
|
staticconstexpr |
Name of the column that removes a key when set to 1.
Definition at line 98 of file table.hpp.
The documentation for this class was generated from the following file: