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

◆ get()

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

Read a present arithmetic field by exact value type.

Template Parameters
TDeclared arithmetic 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 352 of file Composite.hpp.

353{
354 const auto field_index = m_layout->find_field(field_name);
355 if (!field_index || !has(field_name))
356 return std::nullopt;
357
358 const auto& field = m_layout->fields()[*field_index];
359 if (field.type == typeid(detail::CompositeDynamic)) {
360 if constexpr (std::same_as<T, int64_t> || std::same_as<T, double>) {
361 const auto dynamic = value(field_name);
362 if (dynamic) {
363 if (const auto* typed = std::get_if<T>(&*dynamic))
364 return *typed;
365 }
366 }
367 return std::nullopt;
368 }
369 if (field.type != std::type_index(typeid(T)))
370 return std::nullopt;
371
372 const auto& rows = std::get<std::vector<uint8_t>>(*m_rows);
373 T value {};
374
375 std::memcpy(&value,
376 rows.data() + m_index * m_layout->stride_bytes() + field.offset_bytes,
377 sizeof(T));
378
379 return value;
380}
uint32_t rows
glm::vec3 value
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
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 rows, and value.