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

◆ value()

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

Borrow a dynamic value; an absent field returns std::nullopt.

Definition at line 396 of file Composite.cpp.

397{
398 const auto field_index = m_layout->find_field(field_name);
399 if (!field_index || !has(field_name)
400 || m_layout->fields()[*field_index].type != typeid(detail::CompositeDynamic))
401 return std::nullopt;
402
403 const auto& rows = std::get<std::vector<uint8_t>>(*m_rows);
404 DynamicCell cell;
405 std::memcpy(&cell, rows.data() + m_index * m_layout->stride_bytes()
406 + m_layout->fields()[*field_index].offset_bytes, sizeof(cell));
407 if (cell.kind == null_kind)
408 return CompositeValue { std::monostate {} };
409 if (cell.kind == integer_kind) {
410 int64_t result;
411 std::memcpy(&result, &cell.payload, sizeof(result));
412 return CompositeValue { result };
413 }
414 if (cell.kind == real_kind) {
415 double result;
416 std::memcpy(&result, &cell.payload, sizeof(result));
417 return CompositeValue { result };
418 }
419 if (cell.kind == text_kind) {
420 if (auto result = text(field_name))
421 return CompositeValue { *result };
422 }
423 if (cell.kind == blob_kind) {
424 if (auto result = blob(field_name))
425 return CompositeValue { *result };
426 }
427 return std::nullopt;
428}
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::optional< std::span< const uint8_t > > blob(std::string_view field_name) const noexcept
Borrow the bytes of a fixed or dynamic BLOB field.
std::variant< std::monostate, int64_t, double, std::string_view, std::span< const uint8_t > > CompositeValue
Borrowed value of a present dynamic field; monostate represents NULL.
Definition Composite.hpp:29

References rows.