MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
CompositeWriter.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::IO {
6
7/**
8 * @class CompositeWriter
9 * @brief Typed writer contract for schema-bearing Composite files.
10 *
11 * A concrete writer chooses a file format and encodes Composite fields
12 * without exposing unrestricted byte writes. A file is opened with one
13 * layout, then receives one or more bounded slices before close().
14 *
15 * Usage:
16 * @code
17 * bool save_measurements(
18 * CompositeWriter& writer, const Kakshya::CompositeArray& array)
19 * {
20 * return writer.write("measurements.csv", array);
21 * }
22 * @endcode
23 *
24 * @note The source array must remain alive throughout each write_rows()
25 * call. The writer does not retain the borrowed slice.
26 */
27class MAYAFLUX_API CompositeWriter {
28public:
29 virtual ~CompositeWriter() = default;
30
31 /**
32 * @brief Check whether this writer supports the target path.
33 * @param filepath Output path.
34 * @return True for a supported file format.
35 */
36 [[nodiscard]] virtual bool can_write(
37 const std::string& filepath) const = 0;
38
39 /**
40 * @brief Open a new file with the schema all subsequent slices must use.
41 * @param filepath Output path.
42 * @param layout Finalized or declarative Composite field layout.
43 * @return True when the file is ready to receive elements.
44 */
45 virtual bool open(
46 const std::string& filepath,
47 const Kakshya::CompositeLayout& layout) = 0;
48
49 /**
50 * @brief Write a bounded slice of elements.
51 * @param rows Borrowed elements whose field names, types, and order
52 * must match the layout passed to open().
53 * @return True if every element was accepted by the writer. On failure,
54 * elements before the failing one may already have been written.
55 */
56 virtual bool write_rows(const Kakshya::CompositeSlice& rows) = 0;
57
58 /**
59 * @brief Flush buffered output without closing the file.
60 * @return True when all buffered output has been written.
61 */
62 virtual bool flush() = 0;
63
64 /**
65 * @brief Finish the file and release its output stream.
66 * @return True when the file was finalized successfully.
67 */
68 virtual bool close() = 0;
69
70 /**
71 * @brief Check whether a file is currently open for writing.
72 * @return True when write_rows() may be called.
73 */
74 [[nodiscard]] virtual bool is_open() const = 0;
75
76 /**
77 * @brief Get supported file extensions without dots.
78 * @return Extensions handled by the concrete writer.
79 */
80 [[nodiscard]] virtual std::vector<std::string>
82
83 /**
84 * @brief Get the last writer error.
85 * @return Error text, or an empty string if there is no error.
86 */
87 [[nodiscard]] virtual std::string get_last_error() const = 0;
88
89 /**
90 * @brief Write a complete array in one call.
91 *
92 * Opens with the array's layout, writes all its elements, then closes
93 * the file. A failed write still closes the file before returning, and
94 * a partial file may remain.
95 *
96 * @param filepath Output path.
97 * @param array Source array.
98 * @return True only when open, write, and close all succeed.
99 */
100 bool write(
101 const std::string& filepath,
102 const Kakshya::CompositeArray& array);
103};
104
105}
uint32_t rows
virtual bool flush()=0
Flush buffered output without closing the file.
virtual bool open(const std::string &filepath, const Kakshya::CompositeLayout &layout)=0
Open a new file with the schema all subsequent slices must use.
virtual std::vector< std::string > get_supported_extensions() const =0
Get supported file extensions without dots.
virtual bool close()=0
Finish the file and release its output stream.
virtual std::string get_last_error() const =0
Get the last writer error.
virtual bool is_open() const =0
Check whether a file is currently open for writing.
virtual bool can_write(const std::string &filepath) const =0
Check whether this writer supports the target path.
virtual ~CompositeWriter()=default
virtual bool write_rows(const Kakshya::CompositeSlice &rows)=0
Write a bounded slice of elements.
Typed writer contract for schema-bearing Composite files.
Owns a sequence of values that share a CompositeLayout.
Shared field description and byte layout for a CompositeArray.
Definition Composite.hpp:52
Borrowed consecutive elements, optionally selected by a Region.