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

◆ text()

std::optional< std::string_view > MayaFlux::Kakshya::Composite::text ( std::string_view  field_name) const
noexcept

Read a present std::string field as borrowed UTF-8 bytes.

Parameters
field_nameField to read.
Returns
Text view, or std::nullopt for an absent field, type mismatch, or invalid stored text bounds. An empty string is a present value.

Definition at line 332 of file Composite.cpp.

333{
334 const auto field_index = m_layout->find_field(field_name);
335 if (!field_index || !has(field_name))
336 return std::nullopt;
337
338 const auto& field = m_layout->fields()[*field_index];
339 if (field.type != typeid(std::string) && field.type != typeid(detail::CompositeDynamic))
340 return std::nullopt;
341
342 const auto& rows = std::get<std::vector<uint8_t>>(*m_rows);
343 const auto* source = rows.data() + m_index * m_layout->stride_bytes() + field.offset_bytes;
344 TextSlice slice;
345 if (field.type == typeid(detail::CompositeDynamic)) {
346 DynamicCell cell;
347 std::memcpy(&cell, source, sizeof(cell));
348 if (cell.kind != text_kind)
349 return std::nullopt;
350 slice = { cell.payload, cell.length };
351 } else {
352 std::memcpy(&slice, source, sizeof(slice));
353 }
354
355 const auto& text = std::get<std::vector<uint8_t>>(*m_text);
356 if (slice.offset > text.size() || slice.length > text.size() - slice.offset)
357 return std::nullopt;
358
359 if (slice.length == 0)
360 return std::string_view {};
361
362 return std::string_view(
363 reinterpret_cast<const char*>(text.data() + slice.offset),
364 static_cast<size_t>(slice.length));
365}
uint32_t rows
size_t stride_bytes() const noexcept
Bytes per packed element after finalization.
Definition Composite.hpp:86
const std::vector< CompositeField > & fields() const noexcept
Declared fields in element order, with finalized byte offsets.
Definition Composite.hpp:82
std::optional< size_t > find_field(std::string_view name) const noexcept
Find a field index by name, or std::nullopt if absent.
Definition Composite.cpp:54
std::optional< std::string_view > text(std::string_view field_name) const noexcept
Read a present std::string field as borrowed UTF-8 bytes.
const CompositeLayout * m_layout
bool has(std::string_view field_name) const noexcept
Whether a named field exists and is present in this element.
std::vector< double > slice(std::span< const double > data, double start_ratio, double end_ratio)
Extract a contiguous slice by ratio, returning a new vector.
Source source()
Begin a Source chain.
Definition Plot.hpp:127

References MayaFlux::Kakshya::CompositeLayout::find_field(), and rows.

Referenced by MayaFlux::IO::DelimitedTextWriter::write_element().

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