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

◆ read_composite_region()

std::optional< Kakshya::CompositeArray > MayaFlux::IO::CompositeReader::read_composite_region ( const FileRegion &  region)

Read an inclusive one-dimensional file region.

Parameters
regionElement bounds in start_coordinates[0] and end_coordinates[0].
Returns
Owning array, or nullopt for invalid bounds or a short read.
Note
Moves the reader position to the end of the selected region.

Definition at line 8 of file CompositeReader.cpp.

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}
size_t count
virtual std::optional< Kakshya::CompositeArray > read_next(size_t max_elements)=0
Read at most max_elements from the current file position.
virtual bool seek(const std::vector< uint64_t > &position)=0
Seek to a specific position in the file.

References count, MayaFlux::IO::FileRegion::end_coordinates, m_last_error, read_next(), MayaFlux::IO::FileReader::seek(), and MayaFlux::IO::FileRegion::start_coordinates.

+ Here is the call graph for this function: