MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::IO::DelimitedTextWriter Class Reference

Streaming CSV and TSV writer for Composite arrays. More...

#include <DelimitedTextWriter.hpp>

+ Inheritance diagram for MayaFlux::IO::DelimitedTextWriter:
+ Collaboration diagram for MayaFlux::IO::DelimitedTextWriter:

Public Member Functions

bool can_write (const std::string &filepath) const override
 Check for a .csv or .tsv output path.
 
bool close () override
 Finalize and close the current file.
 
 DelimitedTextWriter ()=default
 
bool flush () override
 Flush the current file without closing it.
 
std::string get_last_error () const override
 Last encoding or file error, if any.
 
std::vector< std::string > get_supported_extensions () const override
 Supported extensions without dots.
 
bool is_open () const override
 Whether an output file is open.
 
bool open (const std::string &filepath, const Kakshya::CompositeLayout &layout) override
 Create or truncate a CSV or TSV file.
 
size_t rows_written () const noexcept
 Number of data elements accepted since open().
 
bool set_delimiter (char delimiter) noexcept
 Override the extension-selected delimiter.
 
bool set_write_header (bool enabled) noexcept
 Select whether a header record is written.
 
bool write_rows (const Kakshya::CompositeSlice &rows) override
 Encode a bounded slice using the open file's layout.
 
 ~DelimitedTextWriter () override
 
- Public Member Functions inherited from MayaFlux::IO::CompositeWriter
bool write (const std::string &filepath, const Kakshya::CompositeArray &array)
 Write a complete array in one call.
 
virtual ~CompositeWriter ()=default
 

Private Member Functions

bool write_cell (std::string_view text, bool force_quote)
 
bool write_element (const Kakshya::Composite &element)
 

Private Attributes

char m_active_delimiter {}
 
char m_delimiter {}
 
std::ofstream m_file
 
std::string m_last_error
 
std::optional< Kakshya::CompositeLayout > m_layout
 
size_t m_rows_written {}
 
bool m_write_header { true }
 

Detailed Description

Streaming CSV and TSV writer for Composite arrays.

The output delimiter defaults to the file extension. A header is written by default, and every record ends with LF. Missing fields become unquoted empty cells; present empty text becomes a quoted empty cell so DelimitedTextReader can restore its presence bit. Numbers use the shortest decimal form that parses back to the same value, and text is quoted when CSV/TSV syntax requires it. A non-finite floating-point value has no CSV form and fails the write.

Usage:

bool saved = writer.write("measurements.csv", array);
bool write(const std::string &filepath, const Kakshya::CompositeArray &array)
Write a complete array in one call.
Streaming CSV and TSV writer for Composite arrays.

For large arrays, call open(), write_rows() with bounded slices, and close(). Every slice must use the layout passed to open().

Definition at line 30 of file DelimitedTextWriter.hpp.


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