MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ read_next()

std::optional< Kakshya::CompositeArray > MayaFlux::IO::DelimitedTextReader::read_next ( size_t  max_elements)
overridevirtual

Consume a bounded number of records.

Parameters
max_elementsMaximum records to return; zero returns an empty array without advancing.
Returns
Owning array, empty at end of file, or nullopt on failure.

Implements MayaFlux::IO::CompositeReader.

Definition at line 344 of file DelimitedTextReader.cpp.

345{
346 if (!is_open() || !m_layout) {
347 m_last_error = "No delimited text file is open";
348 return std::nullopt;
349 }
350
351 Kakshya::CompositeArray result(*m_layout);
352 std::vector<ParsedField> fields;
353
354 while (result.size() < max_elements && !m_at_end) {
355 bool at_end = false;
356
357 if (!read_record(fields, at_end))
358 return std::nullopt;
359
360 if (at_end) {
361 m_at_end = true;
362 break;
363 }
364
365 if (!append_record(result, fields))
366 return std::nullopt;
367
369 }
370
371 m_last_error.clear();
372 return result;
373}
bool read_record(std::vector< ParsedField > &fields, bool &at_end)
bool is_open() const override
Whether a file is currently open.
bool append_record(Kakshya::CompositeArray &array, const std::vector< ParsedField > &fields)
std::optional< Kakshya::CompositeLayout > m_layout

References append_record(), is_open(), m_at_end, MayaFlux::IO::CompositeReader::m_last_error, m_layout, m_row_position, read_record(), and MayaFlux::Kakshya::CompositeArray::size().

Referenced by read_composite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: