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

Objects of a CSV input, read one by one (input range). More...

#include <csv.hpp>

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

Classes

class  iterator
 Records iterator (input iterator). More...

Public Member Functions

 Records (std::istream &input, const anch::csv::Options &options)
 Records (const Records &)=delete
iterator begin ()
std::default_sentinel_t end () const noexcept

Detailed Description

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

Objects of a CSV input, read one by one (input range).

The range is read once: each iteration reads the next record (the current object is valid until the next iteration). Errors raise CsvError while iterating. It is built by anch::csv::records .

// Objects read one by one, without loading the whole input
std::stringstream input("id,name\n1,Rex\n2,Médor\n");
std::size_t count = 0;
for(const Pet& record : anch::csv::records<Pet>(input)) {
std::cout << record.name << std::endl;
++count;
}
// Small volumes: vectors
std::vector<Pet> all;
std::stringstream again("id,name\n1,Rex\n2,Médor\n");
std::ostringstream written;
anch::csv::serialize(all, written); // header, then one record per object
Template Parameters
Tthe described type
Author
Vincent Lachenal
Since
0.3

Constructor & Destructor Documentation

◆ Records() [1/2]

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

Records constructor: the header is read

Parameters
inputthe input stream
optionsthe options
Exceptions
CsvErrorinvalid header, UNKNOWN_COLUMN , MISSING_COLUMN
Here is the call graph for this function:

◆ Records() [2/2]

template<typename T>
anch::csv::Records< T >::Records ( const Records< T > & )
delete

Forbids Records copy (readers hold references on each other)

Here is the call graph for this function:

Member Function Documentation

◆ begin()

template<typename T>
iterator anch::csv::Records< T >::begin ( )

Read the first object (the range is read once)

Returns
the iterator on the first object
Exceptions
CsvErrorinvalid record
Here is the call graph for this function:

◆ end()

template<typename T>
std::default_sentinel_t anch::csv::Records< T >::end ( ) const
noexcept

End of range

Returns
the sentinel
Here is the call graph for this function:

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