MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
CompositeReader.cpp
Go to the documentation of this file.
1#include "CompositeReader.hpp"
2
4
5namespace MayaFlux::IO {
6
7std::optional<Kakshya::CompositeArray>
9{
10 if (region.start_coordinates.size() != 1
11 || region.end_coordinates.size() != 1
12 || region.end_coordinates[0] < region.start_coordinates[0]
13 || region.end_coordinates[0] == std::numeric_limits<uint64_t>::max()) {
14 m_last_error = "Composite region requires valid one-dimensional inclusive bounds";
15 return std::nullopt;
16 }
17
18 const auto start = region.start_coordinates[0];
19 const auto count = region.end_coordinates[0] - start + 1;
20
21 if (start > std::numeric_limits<size_t>::max()
22 || count > std::numeric_limits<size_t>::max()
23 || !seek({ start })) {
24 m_last_error = "Composite region is outside the file";
25 return std::nullopt;
26 }
27
28 auto data = read_next(static_cast<size_t>(count));
29 if (!data || data->size() != count) {
30 if (data)
31 m_last_error = "Composite region extends past the end of the file";
32 return std::nullopt;
33 }
34
35 return data;
36}
37
38std::shared_ptr<Kakshya::CompositeContainer>
40{
41 auto data = read_composite();
42 if (!data)
43 return nullptr;
44
45 return std::make_shared<Kakshya::CompositeContainer>(
46 std::move(*data), batch_size);
47}
48
49std::vector<Kakshya::DataVariant> CompositeReader::read_all()
50{
51 m_last_error = "Composite data requires read_composite()";
52 return {};
53}
54
55std::vector<Kakshya::DataVariant>
57{
58 m_last_error = "Composite data requires read_composite_region()";
59 return {};
60}
61
62std::shared_ptr<Kakshya::SignalSourceContainer>
64{
65 m_last_error = "Composite data requires create_composite_container()";
66 return nullptr;
67}
68
70 std::shared_ptr<Kakshya::SignalSourceContainer>)
71{
72 m_last_error = "Composite data cannot load into SignalSourceContainer";
73 return false;
74}
75
76std::type_index CompositeReader::get_data_type() const
77{
78 return typeid(Kakshya::CompositeArray);
79}
80
82{
83 return typeid(Kakshya::CompositeContainer);
84}
85
86}
size_t count
std::shared_ptr< Kakshya::SignalSourceContainer > create_container() override
CompositeContainer is not a SignalSourceContainer.
std::shared_ptr< Kakshya::CompositeContainer > create_composite_container(size_t batch_size=1)
Read remaining elements into a new CompositeContainer.
std::optional< Kakshya::CompositeArray > read_composite_region(const FileRegion &region)
Read an inclusive one-dimensional file region.
std::vector< Kakshya::DataVariant > read_all() override
Composite data is not a DataVariant channel vector.
virtual std::optional< Kakshya::CompositeArray > read_next(size_t max_elements)=0
Read at most max_elements from the current file position.
virtual std::optional< Kakshya::CompositeArray > read_composite()=0
Read all remaining elements into one owning array.
std::vector< Kakshya::DataVariant > read_region(const FileRegion &) override
Use read_composite_region() for a schema-bearing result.
bool load_into_container(std::shared_ptr< Kakshya::SignalSourceContainer >) override
CompositeContainer is not a SignalSourceContainer.
std::type_index get_data_type() const override
Get the data type this reader produces.
std::type_index get_container_type() const override
Get the container type this reader creates.
virtual bool seek(const std::vector< uint64_t > &position)=0
Seek to a specific position in the file.
Owns a sequence of values that share a CompositeLayout.
Owns composite data and a bounded, independently owned window.
std::vector< uint64_t > start_coordinates
N-dimensional start position (e.g., frame, x, y)
std::vector< uint64_t > end_coordinates
N-dimensional end position (inclusive)
Generic region descriptor for any file type.