dasmig-core 1.2.0
Shared random engine, distributions and data tiers for the dasmig generator libraries
Loading...
Searching...
No Matches
dasmig::core::tsv_row Class Reference

One row of a tsv_document. A light view: copy it freely while the document, or any copy of it, is alive. More...

#include <tsv.hpp>

Public Member Functions

std::string_view operator[] (std::string_view column) const
 The cell in a named column.
 
std::string_view cell (std::size_t index) const
 The cell at a column index.
 
bool has (std::string_view column) const
 Whether the document has a column and this row's cell in it is not empty.
 
template<typename T >
T get (std::string_view column) const
 A typed value.
 
template<typename T >
T get_or (std::string_view column, T fallback) const
 A typed value, or a fallback when the column is missing or the cell is empty.
 
std::vector< std::string_view > list (std::string_view column, char separator=';') const
 Split a list cell.
 
std::size_t line () const noexcept
 The 1-based line of this row in its source.
 
const std::string & source () const noexcept
 The source of this row's document.
 
tsv_error error (std::string_view column, const std::string &message) const
 An error located at this row.
 

Friends

class tsv_document
 

Detailed Description

One row of a tsv_document. A light view: copy it freely while the document, or any copy of it, is alive.

Definition at line 289 of file tsv.hpp.

Member Function Documentation

◆ cell()

std::string_view dasmig::core::tsv_row::cell ( std::size_t  index) const
inline

The cell at a column index.

Parameters
index0-based column index.
Returns
The cell text.
Exceptions
std::out_of_rangeIf index is not a column.

Definition at line 701 of file tsv.hpp.

◆ error()

tsv_error dasmig::core::tsv_row::error ( std::string_view  column,
const std::string &  message 
) const
inline

An error located at this row.

Parameters
columnColumn name, or empty for the whole row.
messageWhat is wrong.
Returns
The error, for throwing.

Definition at line 379 of file tsv.hpp.

◆ get()

template<typename T >
T dasmig::core::tsv_row::get ( std::string_view  column) const
inline

A typed value.

Integers are base 10; doubles are decimal or scientific and must be finite; bool accepts 1, 0, true and false; strings are returned as they are.

Template Parameters
TArithmetic type, bool, std::string or std::string_view.
Parameters
columnColumn name.
Returns
The value.
Exceptions
tsv_errorIf the column is missing, the cell is empty, or the text is not a valid T.

Definition at line 322 of file tsv.hpp.

◆ get_or()

template<typename T >
T dasmig::core::tsv_row::get_or ( std::string_view  column,
T  fallback 
) const
inline

A typed value, or a fallback when the column is missing or the cell is empty.

Template Parameters
TAs get().
Parameters
columnColumn name.
fallbackValue for a missing or empty cell.
Returns
The value.
Exceptions
tsv_errorIf the text is not a valid T.

Definition at line 340 of file tsv.hpp.

◆ has()

bool dasmig::core::tsv_row::has ( std::string_view  column) const
inline

Whether the document has a column and this row's cell in it is not empty.

Parameters
columnColumn name.
Returns
True when a value is present.

Definition at line 708 of file tsv.hpp.

◆ line()

std::size_t dasmig::core::tsv_row::line ( ) const
inlinenoexcept

The 1-based line of this row in its source.

Returns
The line number.

Definition at line 714 of file tsv.hpp.

◆ list()

std::vector< std::string_view > dasmig::core::tsv_row::list ( std::string_view  column,
char  separator = ';' 
) const
inline

Split a list cell.

Parameters
columnColumn name.
separatorList separator (; in the shipped data).
Returns
The items; empty for an empty cell. Items are not trimmed.
Exceptions
tsv_errorIf the column is missing.

Definition at line 351 of file tsv.hpp.

◆ operator[]()

std::string_view dasmig::core::tsv_row::operator[] ( std::string_view  column) const
inline

The cell in a named column.

Parameters
columnColumn name.
Returns
The cell text (empty for a missing trailing cell).
Exceptions
tsv_errorIf the document has no such column.

Definition at line 691 of file tsv.hpp.

◆ source()

const std::string & dasmig::core::tsv_row::source ( ) const
inlinenoexcept

The source of this row's document.

Returns
File name or description.

Definition at line 716 of file tsv.hpp.

Friends And Related Symbol Documentation

◆ tsv_document

friend class tsv_document
friend

Definition at line 385 of file tsv.hpp.


The documentation for this class was generated from the following file: