19using Row = std::vector<std::string>;
52 void appendRows(
const std::vector<Row>& rows)
const;
58 std::size_t
removeRows(
const std::function<
bool(
const Row&)>& shouldRemove)
const;
66 std::size_t
updateRows(
const std::function<
bool(
const Row&)>& shouldUpdate,
67 const std::vector<std::pair<std::size_t, std::string>>& newValues)
const;
82 std::size_t
rewrite(
const std::function<
Change(std::string& line,
const Row& row)>& decide)
const;
The table definitions read from SYSTEM_TABLE: tables, their columns and positions.
std::vector< std::string > Row
One row of a table: one value per column, trailing spaces removed.
Reads and changes the rows of one table's data file.
std::size_t removeRows(const std::function< bool(const Row &)> &shouldRemove) const
Removes the rows that match a test.
long long nextId() const
The ID to give the next new row.
std::size_t updateRows(const std::function< bool(const Row &)> &shouldUpdate, const std::vector< std::pair< std::size_t, std::string > > &newValues) const
Changes some columns in the rows that match a test.
std::size_t rewrite(const std::function< Change(std::string &line, const Row &row)> &decide) const
Rewrites the file through a temporary copy, line by line.
Change
What rewrite() does with one line.
@ Keep
Write the line back unchanged.
@ Update
Write the line back as decide edited it.
@ Remove
Leave the line out.
std::filesystem::path path_
The data file.
void append(const Row &values) const
Adds one row at the end of the file.
const TableSchema & schema_
The table's definition.
std::vector< Row > readRows() const
Reads every row of the file.
Row splitLine(std::string_view line) const
Cuts one line of the file into its column values.
void appendRows(const std::vector< Row > &rows) const
Adds several rows at the end of the file, in one write.
The definition of one table: its name, its columns, and the length of a row.