AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::csv::ObjectReader< T > Class Template Reference

Objects reader: records of a Reader are read as T objects. More...

#include <mapper.hpp>

Collaboration diagram for anch::csv::ObjectReader< T >:

Public Member Functions

 ObjectReader (anch::csv::Reader &reader)
bool read (T &value)

Static Public Attributes

static constexpr std::size_t NONE = static_cast<std::size_t>(-1)

Detailed Description

template<typename T>
class anch::csv::ObjectReader< T >

Objects reader: records of a Reader are read as T objects.

With a header, columns are associated with fields by name (columns which are not fields are ignored, or refused with Options::ignoreUnknownColumns ; required fields columns have to be present: MISSING_COLUMN ) ; without header, by position: each registered field is a column, in registration order (columns of fields which are not read, getter only, are skipped), as ObjectWriter writes them. An empty field is an absent value ( std::nullopt ), an empty quoted field ( "" ) an empty string. Conversion errors ( CONVERSION ) and constraints violations ( CONSTRAINT_VIOLATION ) give the line and the column of the field.

anch::csv::Reader petsReader(pets);
anch::csv::ObjectReader<Pet> objectsReader(petsReader); // columns associated with fields by name
Pet pet;
while(objectsReader.read(pet)) {
std::cout << pet.id << ' ' << pet.name << (pet.nickname ? " has a nickname" : "") << std::endl;
}
Template Parameters
Tthe described type
Author
Vincent Lachenal
Since
0.3

Constructor & Destructor Documentation

◆ ObjectReader()

template<typename T>
anch::csv::ObjectReader< T >::ObjectReader ( anch::csv::Reader & reader)
explicit

ObjectReader constructor: header columns are associated with fields

Parameters
readerthe records reader
Exceptions
CsvErrorUNKNOWN_COLUMN or MISSING_COLUMN

Member Function Documentation

◆ read()

template<typename T>
bool anch::csv::ObjectReader< T >::read ( T & value)

Read next object

Parameters
valuethe object to fill (fields whose column is absent are not changed)
Returns
false at the end of the input
Exceptions
CsvErrorinvalid record, conversion error or constraint violation

Member Data Documentation

◆ NONE

template<typename T>
std::size_t anch::csv::ObjectReader< T >::NONE = static_cast<std::size_t>(-1)
staticconstexpr

No column


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