|
Vince's CSV Parser
|
Class for writing delimiter separated values files. More...
#include <csv_writer.hpp>
Public Member Functions | |
| DelimWriter (OutputStream &_out, bool _quote_minimal=true) | |
| Construct a DelimWriter over the specified output stream. | |
| template<typename T = OutputStream, csv::enable_if_t< std::is_same< T, std::ofstream >::value, int > = 0> | |
| DelimWriter (const std::string &filename, bool _quote_minimal=true) | |
| Construct a DelimWriter that owns an output file stream. | |
| DelimWriter (const DelimWriter &)=delete | |
| DelimWriter & | operator= (const DelimWriter &)=delete |
| DelimWriter (DelimWriter &&other) noexcept | |
| DelimWriter & | operator= (DelimWriter &&other) noexcept |
| DelimWriter & | set_auto_flush (bool value) &noexcept |
| Configure whether each write operation flushes the underlying stream. | |
| DelimWriter && | set_auto_flush (bool value) &&noexcept |
| Configure whether each write operation flushes the underlying stream. | |
| bool | get_auto_flush () const noexcept |
| Return whether each write operation flushes the underlying stream. | |
| ~DelimWriter () | |
| Best-effort flush. | |
| template<typename T , size_t N> | |
| DelimWriter & | operator<< (const T(&record)[N]) |
| Write a C-style array of strings as one delimited row. | |
| template<typename T , size_t N> | |
| DelimWriter & | operator<< (const std::array< T, N > &record) |
| Write a std::array of strings as one delimited row. | |
| template<typename KeyType > | |
| DelimWriter & | operator<< (const DataFrame< KeyType > &frame) |
| Write a complete DataFrame: visible column names followed by visible rows. | |
| template<typename T > | |
| auto | write_row (T &&record) -> decltype(*this<< std::forward< T >(record)) |
| Write a row from any single argument accepted by operator<< (std::vector, std::array, std::tuple, C-array, C++20 range, etc.). | |
| template<typename T , typename U , typename... Rest> | |
| DelimWriter & | write_row (T &&first, U &&second, Rest &&... rest) |
| Write a row from a variadic list of mixed-type values. | |
| template<std::ranges::input_range Rows> requires internals::csv_write_rows_input_range<Rows> | |
| DelimWriter & | write_rows (Rows &&rows) |
| Write many rows using a shared batch buffer. | |
| template<std::ranges::input_range Range> requires std::ranges::input_range<Range> && std::convertible_to<std::ranges::range_reference_t<Range>, csv::string_view> | |
| DelimWriter & | operator<< (Range &&container) |
| Write a range of string-like fields as one delimited row. | |
| template<typename RowLike > requires internals::has_to_sv_range<RowLike> && (!internals::csv_string_field_range<RowLike>) | |
| DelimWriter & | operator<< (const RowLike &row) |
| Write a row-like object that exposes to_sv_range(). | |
| template<typename... T> | |
| DelimWriter & | operator<< (const std::tuple< T... > &record) |
| Write a C-style array of strings as one delimited row. | |
| void | flush () |
| Flushes the written data. | |
| template<typename T , csv::enable_if_t< internals::has_checked_csv_fields< T >::value||internals::is_data_frame< typename std::decay< T >::type >::value, int > = 0> | |
| bool | try_write_row (CSVError &error, T &&record) |
| Write the same inputs accepted by write_row(), reporting stream failures. | |
| template<typename... Args> | |
| auto | try_write_row (CSVError &error, Args &&... args) -> decltype(this->write_row(std::forward< Args >(args)...), bool()) |
| template<std::ranges::input_range Rows> requires (internals::csv_write_rows_input_range<Rows> || internals::has_checked_csv_fields<std::ranges::range_reference_t<Rows>>::value) | |
| bool | try_write_rows (Rows &&rows, CSVError &error) |
| Write a batch using the same accepted row ranges and buffering policy as write_rows(). | |
| bool | try_flush (CSVError &error) |
| Flush buffered data and the stream, reporting I/O errors. | |
| template<typename T = OutputStream, csv::enable_if_t< std::is_same< T, std::ofstream >::value, int > = 0> | |
| bool | try_close (CSVError &error) |
| Flush and close an owned output file, including after a flush failure. | |
Static Public Member Functions | |
| template<typename T = OutputStream, csv::enable_if_t< std::is_same< T, std::ofstream >::value, int > = 0> | |
| static std::unique_ptr< DelimWriter > | try_open (const std::string &filename, CSVError &error, bool quote_minimal=true) |
| Open an owned output file, returning null on failure. | |
Class for writing delimiter separated values files.
To write formatted strings, one should
| OutputStream | The output stream, e.g. std::ofstream, std::stringstream |
| Delim | The delimiter character |
| Quote | The quote character |
Definition at line 272 of file csv_writer.hpp.
|
inline |
Construct a DelimWriter over the specified output stream.
Definition at line 276 of file csv_writer.hpp.
|
inline |
Construct a DelimWriter that owns an output file stream.
Definition at line 283 of file csv_writer.hpp.
|
inlinenoexcept |
Definition at line 312 of file csv_writer.hpp.
|
inline |
Best-effort flush.
Use try_flush() or try_close() to observe errors.
Definition at line 361 of file csv_writer.hpp.
|
inline |
Flushes the written data.
Definition at line 530 of file csv_writer.hpp.
|
inlinenoexcept |
Return whether each write operation flushes the underlying stream.
Definition at line 356 of file csv_writer.hpp.
|
inline |
Write a complete DataFrame: visible column names followed by visible rows.
Sparse edits and row selections are included. A frame with no rows still writes its header. The writer's delimiter, quoting, and buffering settings apply, and auto-flush flushes the stream once at the end of the document.
Definition at line 396 of file csv_writer.hpp.
|
inline |
Write a row-like object that exposes to_sv_range().
Definition at line 493 of file csv_writer.hpp.
|
inline |
Write a std::array of strings as one delimited row.
Definition at line 384 of file csv_writer.hpp.
|
inline |
Write a C-style array of strings as one delimited row.
Definition at line 524 of file csv_writer.hpp.
|
inline |
Write a C-style array of strings as one delimited row.
Definition at line 377 of file csv_writer.hpp.
|
inline |
Write a range of string-like fields as one delimited row.
Accepts any input_range whose elements are convertible to csv::string_view. This includes std::vector<std::string>, std::vector<csv::string_view>, std::array, C++20 views, etc.
Definition at line 484 of file csv_writer.hpp.
|
inlinenoexcept |
Definition at line 325 of file csv_writer.hpp.
|
inlinenoexcept |
Configure whether each write operation flushes the underlying stream.
Definition at line 350 of file csv_writer.hpp.
|
inlinenoexcept |
Configure whether each write operation flushes the underlying stream.
Definition at line 344 of file csv_writer.hpp.
|
inline |
Flush and close an owned output file, including after a flush failure.
Borrowed streams remain the caller's responsibility to close. Further checked operations on a closed writer report InvalidArgument.
Definition at line 586 of file csv_writer.hpp.
|
inline |
Flush buffered data and the stream, reporting I/O errors.
Definition at line 573 of file csv_writer.hpp.
|
inlinestatic |
Open an owned output file, returning null on failure.
The returned writer owns its stream. Use try_close() to observe final I/O errors.
Definition at line 296 of file csv_writer.hpp.
|
inline |
Definition at line 549 of file csv_writer.hpp.
|
inline |
Write the same inputs accepted by write_row(), reporting stream failures.
With buffering enabled, success means accepted into the buffer; try_flush() or try_close() observes completion. Output already written is not rolled back. Checked operations require a stream exposing fail(). In exception-disabled builds, standard streams must have their exception mask disabled.
Definition at line 544 of file csv_writer.hpp.
|
inline |
Write a batch using the same accepted row ranges and buffering policy as write_rows().
Definition at line 559 of file csv_writer.hpp.
|
inline |
Write a row from a variadic list of mixed-type values.
Requires at least two arguments; for a single container or tuple, use the single-argument overload above.
Definition at line 443 of file csv_writer.hpp.
|
inline |
Write a row from any single argument accepted by operator<< (std::vector, std::array, std::tuple, C-array, C++20 range, etc.).
SFINAE ensures this overload is only viable when the argument type is accepted by an existing operator<< overload.
Definition at line 429 of file csv_writer.hpp.
|
inline |
Write many rows using a shared batch buffer.
Accepts any input_range whose elements are either:
Buffered writers flush the batch when it grows large or when this call ends. Auto-flushing writers additionally flush the underlying stream once at the end of the bulk call.
Passing a DataFrame writes data rows only. Use operator<< to include its column names as a header.
Definition at line 467 of file csv_writer.hpp.