MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
CompositeReader.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Kakshya {
7class CompositeContainer;
8}
9
10namespace MayaFlux::IO {
11
12/**
13 * @class CompositeReader
14 * @brief Typed FileReader boundary for schema-bearing Composite data.
15 *
16 * Concrete readers return CompositeArray values without flattening their
17 * layout or text storage into unrelated DataVariant channels. The inherited
18 * DataVariant and SignalSourceContainer result methods are unsupported.
19 * get_layout() exposes the schema a concrete reader established on open(),
20 * so a caller can inspect field names and types before reading any data.
21 *
22 * Usage:
23 * @code
24 * std::unique_ptr<CompositeReader> reader =
25 * std::make_unique<DelimitedTextReader>();
26 * if (reader->open("measurements.csv")) {
27 * auto first = reader->read_next(1024);
28 * auto remaining = reader->read_composite();
29 * }
30 * @endcode
31 *
32 * @note read_composite() reads from the current position. Call seek({0})
33 * first to read the complete file after earlier bounded reads.
34 */
35class MAYAFLUX_API CompositeReader : public FileReader {
36public:
37 ~CompositeReader() override = default;
38
39 /**
40 * @brief Read all remaining elements into one owning array.
41 * @return Array, including an empty array at end of file, or nullopt
42 * on failure.
43 */
44 [[nodiscard]] virtual std::optional<Kakshya::CompositeArray>
46
47 /**
48 * @brief Read at most max_elements from the current file position.
49 * @param max_elements Maximum number of elements to read.
50 * @return Owning array, including an empty array at end of file, or
51 * nullopt on failure.
52 */
53 [[nodiscard]] virtual std::optional<Kakshya::CompositeArray>
54 read_next(size_t max_elements) = 0;
55
56 /**
57 * @brief Inspect the schema established by open() without reading data.
58 * @return Copy of the active layout, or std::nullopt when no file is
59 * currently open or open() did not succeed in establishing one.
60 * @note Returned by value: the copy remains valid after the reader is
61 * closed or destroyed, unlike a borrowed CompositeArray::layout().
62 * Implementations must return a finalized layout, one whose
63 * stride_bytes() and field offsets are already assigned; a layout only
64 * becomes finalized when a CompositeArray is constructed from it.
65 */
66 [[nodiscard]] virtual std::optional<Kakshya::CompositeLayout>
67 get_layout() const = 0;
68
69 /**
70 * @brief Read an inclusive one-dimensional file region.
71 * @param region Element bounds in start_coordinates[0] and
72 * end_coordinates[0].
73 * @return Owning array, or nullopt for invalid bounds or a short read.
74 * @note Moves the reader position to the end of the selected region.
75 */
76 [[nodiscard]] std::optional<Kakshya::CompositeArray>
77 read_composite_region(const FileRegion& region);
78
79 /**
80 * @brief Read remaining elements into a new CompositeContainer.
81 * @param batch_size Default materialization batch size.
82 * @return Owning container, or nullptr on failure.
83 */
84 [[nodiscard]] std::shared_ptr<Kakshya::CompositeContainer>
85 create_composite_container(size_t batch_size = 1);
86
87 /** @brief Composite data is not a DataVariant channel vector. */
88 std::vector<Kakshya::DataVariant> read_all() override;
89 /** @brief Use read_composite_region() for a schema-bearing result. */
90 std::vector<Kakshya::DataVariant> read_region(const FileRegion&) override;
91 /** @brief CompositeContainer is not a SignalSourceContainer. */
92 std::shared_ptr<Kakshya::SignalSourceContainer> create_container() override;
93 /** @brief CompositeContainer is not a SignalSourceContainer. */
94 bool load_into_container(std::shared_ptr<Kakshya::SignalSourceContainer>) override;
95
96 [[nodiscard]] std::type_index get_data_type() const override;
97 [[nodiscard]] std::type_index get_container_type() const override;
98 [[nodiscard]] std::string get_last_error() const override { return m_last_error; }
99
100protected:
101 std::string m_last_error;
102};
103
104}
~CompositeReader() override=default
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::string get_last_error() const override
Get the last error message.
virtual std::optional< Kakshya::CompositeLayout > get_layout() const =0
Inspect the schema established by open() without reading data.
Typed FileReader boundary for schema-bearing Composite data.
Abstract interface for reading various file formats into containers.
auto create_container(Args &&... args) -> std::shared_ptr< ContainerType >
creates a new container of the specified type
Definition Depot.hpp:67
Generic region descriptor for any file type.