|
csvpp 1.2.0
CSV parsing / writing libraries
|
CSV writer. More...
#include <csv.hpp>
Classes | |
| class | Iterator |
| Output iterator for writing CSV data field-by-field. More... | |
Public Member Functions | |
| Writer (std::ostream &output_stream, const char delimiter=',', const char quote='"') | |
| Use a std::ostream for CSV output. | |
| Writer (const std::string &filename, const char delimiter=',', const char quote='"') | |
| Open a file for CSV output. | |
| ~Writer () | |
| Destructor. | |
| Writer (const Writer &)=delete | |
| Writer (Writer &&)=default | |
| Writer & | operator= (const Writer &)=delete |
| Writer & | operator= (Writer &&)=default |
| Iterator | iterator () |
| Get iterator. | |
| void | set_delimiter (const char delimiter) |
| Change the delimiter character. | |
| void | set_quote (const char quote) |
| Change the quote character. | |
| template<typename T > | |
| void | write_field (const T &field) |
| Writes a field to the CSV output. | |
| template<typename T > | |
| Writer & | operator<< (const T &field) |
| Writes a field to the CSV output. | |
| Writer & | operator<< (Writer &(*manip)(Writer &)) |
| Apply a stream manipulator to the CSV output. | |
| void | end_row () |
| End the current row. | |
| template<typename Iter > | |
| void | write_fields (Iter first, Iter last) |
| template<typename T > | |
| void | write_fields (const std::initializer_list< T > &data) |
| template<typename Range > | |
| void | write_fields (const Range &data) |
| Write fields from a range, without ending the row. | |
| template<typename ... Data> | |
| void | write_fields_v (const Data &...data) |
| Write fields from the given variadic parameters, without ending the row. | |
| template<typename ... Args> | |
| void | write_fields (const std::tuple< Args... > &data) |
| Write fields from a tuple, without ending the row. | |
| template<typename Iter > | |
| void | write_row (Iter first, Iter last) |
| template<typename T > | |
| void | write_row (const std::initializer_list< T > &data) |
| template<typename Range > | |
| void | write_row (const Range &data) |
| Write a row from a range. | |
| template<typename ... Data> | |
| void | write_row_v (const Data &...data) |
| Write a row from the given variadic parameters. | |
| template<typename ... Args> | |
| void | write_row (const std::tuple< Args... > &data) |
| Write a row from a tuple. | |
Friends | |
| Writer & | end_row (Writer &w) |
| End row stream manipulator for Writer. | |
CSV writer.
Writes data in CSV format, with correct escaping as needed, according to RFC 4180 rules. Allows writing by rows or field-by-field. Mixing these is not recommended, but is possible. Row-wise methods will append to the row started by any field-wise methods.
|
inlineexplicit |
Use a std::ostream for CSV output.
| output_stream | std::ostream to write to |
| delimiter | Delimiter character |
| quote | Quote character |
output_stream must not be destroyed or written to during the lifetime of this Writer
|
inlineexplicit |
Open a file for CSV output.
| filename | Path to file to write to. Any existing file will be overwritten |
| delimiter | Delimiter character |
| quote | Quote character |
output_stream must not be destroyed or written to during the lifetime of this Writer | IO_error | if there is an error opening the file |
|
inline |
Destructor.
Writes a final newline sequence if needed to close current row
|
inline |
End the current row.
| IO_error | if there is an error writing |
|
inline |
|
inline |
Writes a field to the CSV output.
| field | Data to write. Type must be convertible to std::string either directly, by to_string, or by ostream::operator<< |
| IO_error | if there is an error writing |
Apply a stream manipulator to the CSV output.
Currently only csv::end_row is supported
| manip | Stream manipulator to apply |
|
inline |
Change the delimiter character.
| delimiter | New delimiter character |
|
inline |
Change the quote character.
| quote | New quote character |
|
inline |
Writes a field to the CSV output.
| field | Data to write. Type must be convertible to std::string either directly, by to_string, or by ostream::operator<< |
| IO_error | if there is an error writing |
|
inline |
Write fields from a range, without ending the row.
A range in this context must support std::begin and std::end as at least input iterators. Most STL containers, such as std::vector will work. The ranges type must be convertible to std::string either directly, by to_string, or by ostream::operator<<
| data | Range of fields to write |
| IO_error | if there is an error writing |
|
inline |
Write fields from an initializer_list, without ending the row
| T | Type of data. Must be convertible to std::string either directly, by to_string, or by ostream::operator<< |
| data | list of fields to write |
| IO_error | if there is an error writing |
|
inline |
Write fields from a tuple, without ending the row.
| data | tuple of fields to write. Each element must be convertible to std::string either directly, by to_string, or by ostream::operator<< |
| IO_error | if there is an error writing |
|
inline |
|
inline |
Write fields from the given variadic parameters, without ending the row.
| data | Fields to write. Each must be convertible to std::string either directly, by to_string, or by ostream::operator<< |
| IO_error | if there is an error writing |
|
inline |
Write a row from a range.
A range in this context must support std::begin and std::end as at least input iterators. Most STL containers, such as std::vector will work. The ranges type must be convertible to std::string either directly, by to_string, or by ostream::operator<<
| data | Range of fields to write |
| IO_error | if there is an error writing |
|
inline |
Write a row from an initializer_list
| T | Type of data. Must be convertible to std::string either directly, by to_string, or by ostream::operator<< |
| data | list of fields to write |
| IO_error | if there is an error writing |
|
inline |
Write a row from a tuple.
| data | tuple of fields to write. Each element must be convertible to std::string either directly, by to_string, or by ostream::operator<< |
| IO_error | if there is an error writing |
|
inline |
|
inline |
Write a row from the given variadic parameters.
| data | Fields to write. Each must be convertible to std::string either directly, by to_string, or by ostream::operator<< |
| IO_error | if there is an error writing |
End row stream manipulator for Writer.
Ends the current row, as in: writer << field << csv::end_row;
| IO_error | if there is an error writing |