9class SignalSourceContainer;
44 return safe_any_cast<T>(it->second);
45 }
catch (
const std::bad_any_cast&) {
74 return static_cast<FileReadOptions>(
static_cast<uint32_t
>(
a) |
static_cast<uint32_t
>(
b));
79 return static_cast<FileReadOptions>(
static_cast<uint32_t
>(
a) &
static_cast<uint32_t
>(
b));
128 [[nodiscard]]
virtual bool can_read(
const std::string& filepath)
const = 0;
147 [[nodiscard]]
virtual bool is_open()
const = 0;
153 [[nodiscard]]
virtual std::optional<FileMetadata>
get_metadata()
const = 0;
165 [[nodiscard]]
virtual std::vector<FileRegion>
get_regions()
const = 0;
171 virtual std::vector<Kakshya::DataVariant>
read_all() = 0;
210 virtual bool seek(
const std::vector<uint64_t>& position) = 0;
270 [[nodiscard]]
static std::string
resolve_path(
const std::string& filepath)
272 namespace fs = std::filesystem;
280 auto from_cwd = fs::current_path() /
normalized;
281 if (fs::exists(from_cwd))
282 return from_cwd.string();
283 auto from_root = fs::path(Config::SOURCE_DIR) /
normalized;
284 if (fs::exists(from_root))
285 return from_root.string();
297 static std::unordered_map<std::string, Kakshya::RegionGroup>
329 for (
const auto& ext : extensions) {
339 std::unique_ptr<FileReader>
create_reader(
const std::string& filepath)
const
343 auto ext = std::filesystem::path(resolved).extension().string();
344 if (!ext.empty() && ext[0] ==
'.') {
std::unique_ptr< FileReader > create_reader(const std::string &filepath) const
Create appropriate reader for a file based on extension.
static FileReaderRegistry & instance()
Get the singleton instance of the registry.
void register_reader(const std::vector< std::string > &extensions, const FileReaderFactory &factory)
Register a file reader factory for one or more extensions.
std::unordered_map< std::string, FileReaderFactory > m_factories
Registry for file reader implementations.
virtual bool open(const std::string &filepath, FileReadOptions options=FileReadOptions::ALL)=0
Open a file for reading.
virtual std::vector< std::string > get_supported_extensions() const =0
Get supported file extensions for this reader.
static std::string resolve_path(const std::string &filepath)
Resolve a filepath against the project source root if not found as-is.
virtual bool seek(const std::vector< uint64_t > &position)=0
Seek to a specific position in the file.
virtual std::vector< FileRegion > get_regions() const =0
Get semantic regions from the file.
virtual std::type_index get_container_type() const =0
Get the container type this reader creates.
virtual std::vector< uint64_t > get_dimension_sizes() const =0
Get size of each dimension in the file data.
virtual ~FileReader()=default
virtual std::vector< Kakshya::DataVariant > read_all()=0
Read all data from the file into memory.
virtual bool supports_streaming() const =0
Check if streaming is supported for the current file.
virtual size_t get_num_dimensions() const =0
Get the dimensionality of the file data.
virtual uint64_t get_preferred_chunk_size() const =0
Get the preferred chunk size for streaming.
virtual std::vector< Kakshya::DataVariant > read_region(const FileRegion ®ion)=0
Read a specific region of data.
virtual bool can_read(const std::string &filepath) const =0
Check if a file can be read by this reader.
static std::unordered_map< std::string, Kakshya::RegionGroup > regions_to_groups(const std::vector< FileRegion > ®ions)
Convert file regions to region groups.
virtual std::string get_last_error() const =0
Get the last error message.
virtual std::optional< FileMetadata > get_metadata() const =0
Get metadata from the open file.
virtual bool is_open() const =0
Check if a file is currently open.
virtual void close()=0
Close the currently open file.
virtual std::shared_ptr< Kakshya::SignalSourceContainer > create_container()=0
Create and initialize a container from the file.
virtual bool load_into_container(std::shared_ptr< Kakshya::SignalSourceContainer > container)=0
Load file data into an existing container.
virtual std::type_index get_data_type() const =0
Get the data type this reader produces.
virtual std::vector< uint64_t > get_read_position() const =0
Get current read position in primary dimension.
Abstract interface for reading various file formats into containers.
std::function< std::unique_ptr< FileReader >()> FileReaderFactory
FileReadOptions
Generic options for file reading behavior.
@ EXTRACT_METADATA
Extract file metadata.
@ ALL
All options enabled.
@ HIGH_PRECISION
Use highest precision available.
@ EXTRACT_REGIONS
Extract semantic regions (format-specific)
@ NONE
No special options.
@ STREAMING
Enable streaming mode.
@ PARSE_STRUCTURE
Parse internal structure.
@ DECOMPRESS
Decompress if compressed.
@ VERIFY_INTEGRITY
Verify file integrity/checksums.
@ LAZY_LOAD
Don't load all data immediately.
FileReadOptions operator&(FileReadOptions a, FileReadOptions b)
FileReadOptions operator|(FileReadOptions a, FileReadOptions b)
std::vector< double > normalized(const std::vector< double > &data, double target_peak)
Normalize single-channel data (non-destructive)
std::vector< uint64_t > start_coordinates
N-dimensional start position (e.g., frame, x, y)
Kakshya::Region to_region() const
Convert this FileRegion to a Region for use in processing.
std::string name
Human-readable name for the region.
std::string type
Region type identifier (e.g., "cue", "scene", "block")
std::unordered_map< std::string, std::any > attributes
Region-specific metadata.
std::vector< uint64_t > end_coordinates
N-dimensional end position (inclusive)
Generic region descriptor for any file type.
Represents a point or span in N-dimensional space.