AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::csv Namespace Reference

AnCH CSV library namespace. More...

Classes

class  CsvError
struct  CsvFormat
 CSV format: serialization and deserialization of lists of described objects with options. More...
class  ObjectMapper
 CSV mapper of a described type ( anch::Mapping , anch-utils): fields are columns. More...
class  ObjectReader
 Objects reader: records of a Reader are read as T objects. More...
class  ObjectWriter
 Objects writer: T objects are written as records of a Writer. More...
struct  Options
class  Reader
class  Records
 Objects of a CSV input, read one by one (input range). More...
class  Writer

Concepts

concept  Scalar
 Type of a CSV field value: string, boolean, integer, floating point number, anch::UUID (with ANCH_UUID ), anch::date::DateTime , anch::date::Date and anch::date::Time (RFC 3339, with ANCH_DATE ).
concept  FieldType
 Type of a CSV field: Scalar or std::optional of a scalar.

Enumerations

enum class  ErrorCode {
  INVALID_FORMAT , TOO_LARGE , COLUMN_COUNT , UNKNOWN_COLUMN ,
  MISSING_COLUMN , CONVERSION , CONSTRAINT_VIOLATION
}

Functions

template<typename T>
anch::csv::Records< T > records (std::istream &input, const anch::csv::Options &options=anch::csv::Options())
template<anch::Described T>
void deserialize (std::vector< T > &values, std::istream &input, const anch::csv::Options &options=anch::csv::Options())
template<std::ranges::input_range R>
requires anch::Described<std::remove_cvref_t<std::ranges::range_value_t<R>>>
void serialize (const R &values, std::ostream &out, const anch::csv::Options &options=anch::csv::Options())

Detailed Description

AnCH CSV library namespace.

CSV records reading and writing (RFC 4180). See AnCH CSV library documentation.

Enumeration Type Documentation

◆ ErrorCode

enum class anch::csv::ErrorCode
strong

CSV error code

Since
0.3
Enumerator
INVALID_FORMAT 

Invalid CSV: quote in an unquoted field, character after a closing quote, unterminated quoted field, CR without LF

TOO_LARGE 

Input larger than Options::maxSize , record larger than Options::maxRecordSize or with more than Options::maxColumns columns

COLUMN_COUNT 

Record without the number of columns of the first record (Options::sameColumnCount )

UNKNOWN_COLUMN 

Unknown column (objects mapping)

MISSING_COLUMN 

Missing required column (objects mapping)

CONVERSION 

Value conversion error (objects mapping)

CONSTRAINT_VIOLATION 

Field constraint violation (objects mapping, anch-val constraints)

Function Documentation

◆ deserialize()

template<anch::Described T>
void anch::csv::deserialize ( std::vector< T > & values,
std::istream & input,
const anch::csv::Options & options = anch::csv::Options() )

Read every object of a CSV input (small volumes, see records for large ones)

Template Parameters
Tthe described type
Parameters
valuesthe objects (replaced)
inputthe input stream
optionsthe options
Exceptions
CsvErrorinvalid record, conversion error or constraint violation
Since
0.3
Here is the call graph for this function:

◆ records()

template<typename T>
anch::csv::Records< T > anch::csv::records ( std::istream & input,
const anch::csv::Options & options = anch::csv::Options() )

Objects of a CSV input, read one by one without loading the whole input: for(const Pet& pet : anch::csv::records<Pet>(input))

Template Parameters
Tthe described type
Parameters
inputthe input stream
optionsthe options
Returns
the records (input range)
Exceptions
CsvErrorinvalid header, UNKNOWN_COLUMN , MISSING_COLUMN
Since
0.3
Here is the call graph for this function:

◆ serialize()

template<std::ranges::input_range R>
requires anch::Described<std::remove_cvref_t<std::ranges::range_value_t<R>>>
void anch::csv::serialize ( const R & values,
std::ostream & out,
const anch::csv::Options & options = anch::csv::Options() )

Write objects: header (with Options::header , also when there is no object), then one record per object

Template Parameters
Rthe range type (its values are described objects)
Parameters
valuesthe objects
outthe output stream
optionsthe options
Exceptions
CsvErrorconstraint violation (with Options::writeCheckConstraints )
Since
0.3
Here is the call graph for this function: