Create or truncate a CSV or TSV file.
- Parameters
-
| filepath | Output path; a relative path resolves through resolve_write_path(). |
| layout | Field names and exact types for every written element. |
- Returns
- True when ready to accept row slices.
Implements MayaFlux::IO::CompositeWriter.
Definition at line 187 of file DelimitedTextWriter.cpp.
190{
192 m_last_error =
"Close the current file before opening another";
193 return false;
194 }
195
197
200 return false;
201 }
202
203 if (layout.fields().empty()) {
204 m_last_error =
"Composite output requires at least one field";
205 return false;
206 }
207
208 for (const auto& field : layout.fields()) {
209 if (!supported_type(field.type)) {
210 m_last_error =
"Unsupported Composite field: " + field.name;
211 return false;
212 }
213 }
214
215 Kakshya::CompositeArray empty(layout);
219 : (extension_of(filepath) == ".tsv" ? '\t' : ',');
220
222 std::ios::binary | std::ios::out | std::ios::trunc);
223
227 return false;
228 }
229
231
233 const auto& fields =
m_layout->fields();
234
235 for (size_t i = 0; i < fields.size(); ++i) {
236 if (i != 0)
238
241 return false;
242 }
243 }
244
246
250 return false;
251 }
252 }
253
254 return true;
255}
bool write_cell(std::string_view text, bool force_quote)
bool close() override
Finalize and close the current file.
bool is_open() const override
Whether an output file is open.
bool can_write(const std::string &filepath) const override
Check for a .csv or .tsv output path.
std::optional< Kakshya::CompositeLayout > m_layout
std::string resolve_write_path(const std::string &filepath, std::string_view default_directory=Config::OUT_DIR)
Resolve a writable path against the configured output directory.
References can_write(), close(), MayaFlux::Kakshya::CompositeLayout::fields(), is_open(), MayaFlux::Kakshya::CompositeArray::layout(), m_active_delimiter, m_delimiter, m_file, m_last_error, m_layout, m_rows_written, m_write_header, name, MayaFlux::IO::resolve_write_path(), and write_cell().