csvpp 1.2.0
CSV parsing / writing libraries
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
csv::Map_writer_iter< Header, Default_value > Class Template Reference

Map-based Writer iterator. More...

#include <csv.hpp>

Public Types

using value_type = void
 
using difference_type = void
 
using pointer = void
 
using reference = void
 
using iterator_category = std::output_iterator_tag
 

Public Member Functions

 Map_writer_iter (std::ostream &output_stream, const std::vector< Header > &headers, const Default_value &default_val={}, const char delimiter=',', const char quote='"')
 Use a std::ostream for CSV output.
 
 Map_writer_iter (const std::string &filename, const std::vector< Header > &headers, const Default_value &default_val={}, const char delimiter=',', const char quote='"')
 Open a file for CSV output.
 
Map_writer_iteroperator* ()
 No-op.
 
Map_writer_iteroperator++ ()
 No-op.
 
Map_writer_iteroperator++ (int)
 No-op.
 
template<typename K , typename T , typename std::enable_if_t< std::is_convertible_v< Header, K >, int > = 0>
Map_writer_iteroperator= (const std::map< K, T > &row)
 Write a row.
 

Detailed Description

template<typename Header, typename Default_value = std::string>
class csv::Map_writer_iter< Header, Default_value >

Map-based Writer iterator.

Output iterator accepting a std::map to write as a CSV row

Constructor & Destructor Documentation

◆ Map_writer_iter() [1/2]

template<typename Header , typename Default_value = std::string>
csv::Map_writer_iter< Header, Default_value >::Map_writer_iter ( std::ostream & output_stream,
const std::vector< Header > & headers,
const Default_value & default_val = {},
const char delimiter = ',',
const char quote = '"' )
inline

Use a std::ostream for CSV output.

Parameters
output_streamstd::ostream to write to
headersField headers to use. This specifies the header row and order
default_valDefault value to write to a field if not specified in row input
delimiterDelimiter character
quoteQuote character
Warning
output_stream must not be destroyed or written to during the lifetime of this Writer

◆ Map_writer_iter() [2/2]

template<typename Header , typename Default_value = std::string>
csv::Map_writer_iter< Header, Default_value >::Map_writer_iter ( const std::string & filename,
const std::vector< Header > & headers,
const Default_value & default_val = {},
const char delimiter = ',',
const char quote = '"' )
inline

Open a file for CSV output.

Parameters
filenamePath to file to write to. Any existing file will be overwritten
headersField headers to use. This specifies the header row and order
default_valDefault value to write to a field if not specified in row input
delimiterDelimiter character
quoteQuote character
Warning
output_stream must not be destroyed or written to during the lifetime of this Writer
Exceptions
IO_errorif there is an error opening the file

Member Function Documentation

◆ operator=()

template<typename Header , typename Default_value = std::string>
template<typename K , typename T , typename std::enable_if_t< std::is_convertible_v< Header, K >, int > = 0>
Map_writer_iter & csv::Map_writer_iter< Header, Default_value >::operator= ( const std::map< K, T > & row)
inline

Write a row.

Parameters
rowstd::map containing header to field pairs. If row contains keys not in the specified header, the associated values will be ignored. If the map is missing headers, their values will be filled with default_val
Exceptions
IO_errorif there is an error writing

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