TraceFileReader

class TraceFileReader

Abstract base class for reading trace files in various formats.

Note

Thread Safety: Instances are not thread-safe. Concurrent calls on the same reader must be externally synchronized.

Note

Error Strategy: Open returns false and logs to std::cerr on failure. ReadMessage returns std::nullopt when no messages remain, and throws std::runtime_error on deserialization or format errors.

Subclassed by osi3::MCAPTraceFileReader, osi3::SingleChannelBinaryTraceFileReader, osi3::TXTHTraceFileReader

Public Functions

TraceFileReader() = default

Default constructor.

virtual ~TraceFileReader() = default

Virtual destructor.

TraceFileReader(const TraceFileReader&) = delete

Deleted copy constructor.

TraceFileReader &operator=(const TraceFileReader&) = delete

Deleted copy assignment operator.

TraceFileReader(TraceFileReader&&) = delete

Deleted move constructor.

TraceFileReader &operator=(TraceFileReader&&) = delete

Deleted move assignment operator.

virtual bool Open(const std::filesystem::path &file_path) = 0

Opens a trace file for reading.

Parameters:

file_path – Path to the file to be opened

Returns:

true if successful, false otherwise

virtual std::optional<ReadResult> ReadMessage() = 0

Reads the next message from the trace file.

Returns:

Optional ReadResult containing the message if available

virtual void Close() = 0

Closes the trace file.

virtual bool HasNext() = 0

Indicates availability of additional messages.

Returns whether more messages can be read from the trace file. Always call this method before ReadMessage() to verify message availability. For MCAP format files specifically, this may return true even when only non-OSI messages remain in the file.

Returns:

true if there are more messages to read, false otherwise

class TraceFileReaderFactory

Factory class for creating trace file readers based on file extensions.

Public Static Functions

static std::unique_ptr<TraceFileReader> createReader(const std::filesystem::path &file_path)

Creates a reader instance based on the file extension.

Supported formats:

Note

It is still required to call Open(path) on the returned reader instance

Parameters:

file_path – Path to the trace file

Throws:

std::invalid_argument – if the file extension is not supported

Returns:

Unique pointer to a TraceFileReader instance