Skip to content

FileReader

class FileReader

Provides an interface for reading files, with support for caching and binary files.

method std::vector< Symbol > file_names()

Get the names of all files that have been read.

ReturnsDescription
std::vector< Symbol >

A vector of file names.

method const std::string &get_line(Symbol file, size_t line_number)

Get a specific line from a file.

ParameterDescription
file

The name of the file.

TYPE: Symbol

line_number

The line number to retrieve (0-based).

TYPE: size_t

ReturnsDescription
const std::string &

The requested line.

ThrowsDescription
Exception

If the file has not been read or the line does not exist.

method const std::vector< std::string > &read(Symbol file_name, bool optional = false)

Get the contents of a text file.

ParameterDescription
file_name

The name of the file to read.

TYPE: Symbol

optional

If true, return an empty file if the file does not exist.

TYPE: boolDEFAULT: false

ReturnsDescription
const std::vector< std::string > &

The contents of the file as a vector of lines.

ThrowsDescription
Exception

If the file does not exist and optional is false.

method std::string read_binary(Symbol file_name, bool optional = false)

Get the contents of a binary file.

ParameterDescription
file_name

The name of the file to read.

TYPE: Symbol

optional

If true, return an empty string if the file does not exist.

TYPE: boolDEFAULT: false

ReturnsDescription
std::string

The contents of the file as a string.

ThrowsDescription
Exception

If the file does not exist and optional is false.

member global

The global file reader instance.