Sources

Namespace: dftracer::utils::utilities::fileio::lines::sources

class IndexedFileBytesIterator

Zero-copy iterator for reading lines within byte boundaries from indexed files.

Uses StreamType::LINE_BYTES to read lines one at a time within a byte range. The stream handles line boundaries automatically, so no complex buffering is needed.

Usage:

auto reader = ReaderFactory::create("file.gz", "file.gz.idx");
IndexedFileBytesIterator it(reader, 1000, 5000);  // Bytes 1000-5000
while (it.has_next()) {
    Line line = it.next();  // Zero-copy string_view
    // Use line.content immediately
}

Public Types

using Iterator = LineIterator<IndexedFileBytesIterator>

Public Functions

inline IndexedFileBytesIterator(std::shared_ptr<dftracer::utils::utilities::reader::internal::Reader> reader, std::size_t start_byte, std::size_t end_byte, std::size_t buffer_size = 1024 * 1024)

Construct iterator from existing Reader.

Parameters:
  • reader – Shared pointer to Reader

  • start_byte – Starting byte offset (0-based, inclusive)

  • end_byte – Ending byte offset (0-based, exclusive)

  • buffer_size – Size of buffer for reading (default 1MB)

inline bool has_next() const

Check if more lines are available.

inline Line next()

Get the next line (zero-copy).

Throws:

std::runtime_error – if no more lines available

Returns:

Line object with string_view content (valid until next call)

inline std::size_t current_position() const

Get the current line number.

inline std::shared_ptr<dftracer::utils::utilities::reader::internal::Reader> get_reader() const

Get the underlying Reader.

inline Iterator begin()

Get an iterator to the beginning.

inline Iterator end()

Get an iterator to the end.

class IndexedFileLineIterator

Unified zero-copy line iterator over indexed archive files.

This iterator returns one line at a time. It automatically selects the appropriate stream type based on the range:

  • LINE_RANGE: Uses StreamType::LINE (line-number based seeking)

  • BYTE_RANGE: Uses StreamType::LINE_BYTES (byte-offset based seeking)

Both stream types return one complete line per read(), so no complex buffering or newline splitting is needed.

Usage:

auto reader =
dftracer::utils::utilities::reader::internal::ReaderFactory::create("file.gz",
"file.gz.idx");

auto config = IndexedFileLineIteratorConfig()
    .with_reader(reader)
    .with_line_range(1, 100);
IndexedFileLineIterator lines(config);

// Iterate
for (const auto& line : lines) {
    std::cout << line.content << "\n";
}

Public Types

using Iterator = LineIterator<IndexedFileLineIterator>

Public Functions

inline explicit IndexedFileLineIterator(const IndexedFileLineIteratorConfig &config)

Construct iterator from config object.

Parameters:

config – Configuration object with builder pattern

inline bool has_next() const

Check if more lines are available.

inline Line next()

Get the next line (zero-copy).

Throws:

std::runtime_error – if no more lines available

Returns:

Line object with string_view content (valid until next call)

inline std::size_t current_position() const

Get the current position.

Interpretation depends on range_type:

  • LINE_RANGE: Current line number (1-based)

  • BYTE_RANGE: Current byte offset

inline std::size_t total_count() const

Get total count in this range.

Interpretation depends on range_type:

  • LINE_RANGE: Number of lines

  • BYTE_RANGE: Number of bytes

inline dftracer::utils::utilities::reader::internal::RangeType range_type() const

Get the range type being used.

inline std::shared_ptr<dftracer::utils::utilities::reader::internal::Reader> get_reader() const

Get the underlying Reader.

inline Iterator begin()

Get an iterator to the beginning.

inline Iterator end()

Get an iterator to the end.

class IndexedFileLineIteratorConfig

Configuration for IndexedFileLineIterator.

The iterator automatically selects the appropriate stream type:

  • LINE_RANGE: Uses StreamType::LINE

  • BYTE_RANGE: Uses StreamType::LINE_BYTES

Usage:

// Option 1: From file path
auto config = IndexedFileLineIteratorConfig()
    .with_file("file.gz", "file.gz.idx")
    .with_line_range(1, 100)
    .with_buffer_size(128 * 1024);

// Option 2: From existing reader
auto config = IndexedFileLineIteratorConfig()
    .with_reader(reader)
    .with_line_range(1, 100);

IndexedFileLineIterator iter(config);

Public Functions

IndexedFileLineIteratorConfig() = default
inline IndexedFileLineIteratorConfig &with_file(const std::string &file_path, const std::string &index_path = "")
inline IndexedFileLineIteratorConfig &with_reader(std::shared_ptr<dftracer::utils::utilities::reader::internal::Reader> reader)
inline IndexedFileLineIteratorConfig &with_range_type(dftracer::utils::utilities::reader::internal::RangeType type)
inline IndexedFileLineIteratorConfig &with_line_range(std::size_t start_line, std::size_t end_line)
inline IndexedFileLineIteratorConfig &with_byte_range(std::size_t start_bytes, std::size_t end_bytes)
inline IndexedFileLineIteratorConfig &with_buffer_size(std::size_t size)
inline std::shared_ptr<dftracer::utils::utilities::reader::internal::Reader> reader() const
inline dftracer::utils::utilities::reader::internal::RangeType range_type() const
inline std::size_t start() const
inline std::size_t end() const
inline std::size_t buffer_size() const
class PlainFileBytesIterator

Public Types

using Iterator = LineIterator<PlainFileBytesIterator>

Public Functions

inline PlainFileBytesIterator(const std::string &path, std::size_t start, std::size_t end)
inline bool has_next() const
inline Line next()
inline std::size_t current_position() const noexcept
inline Iterator begin()
inline Iterator end()
class PlainFileLineIterator

Lazy, single‑buffer line‑by‑line iterator over plain text files.

Reads directly from std::ifstream without loading the whole file. Uses a single string buffer; the string_view returned by next() remains valid until the next call to next().

Usage:

PlainFileLineIterator it("data.txt");
while (it.has_next()) {
    Line line = it.next();
    process(line.content);
}

Public Types

using Iterator = LineIterator<PlainFileLineIterator>

Public Functions

inline explicit PlainFileLineIterator(std::string file_path)
inline PlainFileLineIterator(std::string file_path, std::size_t start_line, std::size_t end_line)
inline bool has_next() const
inline Line next()
inline std::size_t current_position() const
inline const std::string &get_file_path() const
inline Iterator begin()
inline Iterator end()