MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
CompositeAccess.cpp
Go to the documentation of this file.
1#include "CompositeAccess.hpp"
2
4
5namespace MayaFlux::Kakshya {
6
7std::optional<CompositeAccess> CompositeArray::access() const
8{
10}
11
12std::optional<CompositeSlice> CompositeArray::slice(size_t start, size_t count) const
13{
14 const auto view = access();
15 return view ? view->slice(start, count) : std::nullopt;
16}
17
18std::optional<CompositeSlice> CompositeArray::slice(const Region& region) const
19{
20 const auto view = access();
21 return view ? view->slice(region) : std::nullopt;
22}
23
24std::optional<CompositeAccess> as_composite_access(
25 const DataVariant& elements, const DataVariant& text, const DataVariant& blob,
26 const CompositeLayout& layout)
27{
28 const auto* element_bytes = std::get_if<std::vector<uint8_t>>(&elements);
29 const auto* text_bytes = std::get_if<std::vector<uint8_t>>(&text);
30 const auto* blob_bytes = std::get_if<std::vector<uint8_t>>(&blob);
31 const size_t stride = layout.stride_bytes();
32 if (!element_bytes || !text_bytes || !blob_bytes || stride == 0
33 || element_bytes->size() % stride != 0) {
35 "as_composite_access: invalid storage or element stride");
36 return std::nullopt;
37 }
38
39 for (const auto& field : layout.fields()) {
40 if (field.offset_bytes > stride || field.size_bytes > stride - field.offset_bytes
41 || ((field.type == typeid(std::string)
42 || field.type == typeid(std::vector<uint8_t>))
43 && field.size_bytes != 2 * sizeof(uint64_t))
44 || (field.type == typeid(detail::CompositeDynamic)
45 && field.size_bytes != 3 * sizeof(uint64_t))) {
47 "as_composite_access: invalid layout for field '{}'", field.name);
48 return std::nullopt;
49 }
50 }
51
52 return CompositeAccess(elements, text, blob, layout);
53}
54
55std::optional<Composite> CompositeAccess::at(size_t index) const noexcept
56{
57 if (index >= size())
58 return std::nullopt;
59 return Composite(*m_layout, *m_elements, *m_text, *m_blob, index);
60}
61
62std::span<const uint8_t> CompositeAccess::element_bytes() const noexcept
63{
64 const auto& elements = std::get<std::vector<uint8_t>>(*m_elements);
65 return { elements.data(), elements.size() };
66}
67
68std::vector<DataDimension> CompositeAccess::byte_dimensions() const
69{
70 return {
73 };
74}
75
76std::optional<CompositeSlice> CompositeAccess::slice(size_t start, size_t count) const noexcept
77{
78 if (start > size() || count > size() - start)
79 return std::nullopt;
80 return CompositeSlice(*this, start, count);
81}
82
83std::optional<CompositeSlice> CompositeAccess::slice(const Region& region) const
84{
85 if (region.start_coordinates.size() != 1 || region.end_coordinates.size() != 1)
86 return std::nullopt;
87
88 const auto start = region.start_coordinates[0];
89 const auto end = region.end_coordinates[0];
90
91 if (start > end || end >= size())
92 return std::nullopt;
93
94 return CompositeSlice(*this, static_cast<size_t>(start),
95 static_cast<size_t>(end - start + 1), region);
96}
97
98std::optional<Composite> CompositeSlice::at(size_t index) const noexcept
99{
100 if (index >= m_count)
101 return std::nullopt;
102 return m_access.at(m_start + index);
103}
104
105std::span<const uint8_t> CompositeSlice::element_bytes() const noexcept
106{
107 const auto bytes = m_access.element_bytes();
108 return bytes.subspan(m_start * layout().stride_bytes(), m_count * layout().stride_bytes());
109}
110
111}
#define MF_WARN(comp, ctx,...)
bool size
uint32_t index
Definition VKDevice.cpp:122
size_t count
size_t element_bytes
std::optional< Composite > at(size_t index) const noexcept
Borrow an element by index.
std::span< const uint8_t > element_bytes() const noexcept
Borrow all packed element bytes without conversion.
std::optional< CompositeSlice > slice(size_t start, size_t count) const noexcept
Borrow count consecutive elements starting at start.
std::vector< DataDimension > byte_dimensions() const
Describe packed bytes as [elements, bytes-per-element].
size_t size() const noexcept
Number of packed elements in the current element store.
Validated, non-owning access to packed Composite NDData storage.
std::optional< CompositeAccess > access() const
Validate and borrow the packed NDData stores and layout.
std::optional< CompositeSlice > slice(size_t start, size_t count) const
Borrow consecutive elements without copying.
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
Shared field description and byte layout for a CompositeArray.
Definition Composite.hpp:52
std::span< const uint8_t > element_bytes() const noexcept
Borrow the selected contiguous packed bytes.
std::optional< Composite > at(size_t index) const noexcept
Borrow a selected element by slice-relative index.
const CompositeLayout & layout() const noexcept
Shared layout of all selected elements.
Borrowed consecutive elements, optionally selected by a Region.
Read view of one value in a CompositeArray.
@ Runtime
General runtime operations (default fallback)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:70
std::optional< CompositeAccess > as_composite_access(const DataVariant &elements, const DataVariant &text, const DataVariant &blob, const CompositeLayout &layout)
Validate and borrow packed Composite-compatible NDData.
@ CUSTOM
User-defined or application-specific.
Minimal dimension descriptor focusing on structure only.
Definition NDData.hpp:197
std::vector< uint64_t > end_coordinates
Ending frame index (inclusive)
Definition Region.hpp:78
std::vector< uint64_t > start_coordinates
Starting frame index (inclusive)
Definition Region.hpp:75
Represents a point or span in N-dimensional space.
Definition Region.hpp:73