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

◆ get()

template<typename T>
requires (ArithmeticData<T> || GlmType<T>)
std::optional< T > MayaFlux::Kakshya::Composite::get ( std::string_view field_name) const
nodiscardnoexcept

Read a present arithmetic or GLM field by exact value type.

Template Parameters
TDeclared fixed value type, or int64_t/double for a dynamic field.
Parameters
field_nameField to read.
Returns
Copied value, or std::nullopt for an absent field or type mismatch.

Definition at line 466 of file Composite.hpp.

467{
468 const auto field_index = m_layout->find_field(field_name);
469 if (!field_index || !has(field_name))
470 return std::nullopt;
471
472 const auto& field = m_layout->fields()[*field_index];
473 if (field.type == typeid(detail::CompositeDynamic)) {
474 if constexpr (std::same_as<T, int64_t> || std::same_as<T, double>) {
475 const auto dynamic = value(field_name);
476 if (dynamic) {
477 if (const auto* typed = std::get_if<T>(&*dynamic))
478 return *typed;
479 }
480 }
481 return std::nullopt;
482 }
483 if (field.type != std::type_index(typeid(T)))
484 return std::nullopt;
485
486 const auto& rows = std::get<std::vector<uint8_t>>(*m_rows);
487 T value {};
488
489 std::memcpy(&value,
490 rows.data() + m_index * m_layout->stride_bytes() + field.offset_bytes,
491 sizeof(T));
492
493 return value;
494}
std::optional< CompositeValue > value(std::string_view field_name) const noexcept
Borrow a dynamic value; an absent field returns std::nullopt.
const CompositeLayout * m_layout
bool has(std::string_view field_name) const noexcept
Whether a named field exists and is present in this element.

References get(), has(), m_index, m_layout, and value().

Referenced by get(), MayaFlux::Kakshya::index_composite_forest(), and MayaFlux::IO::XmlWriter::write_row().

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