Skip to content

iox::cxx::FileReader🔗

Wrapper class for file reading operations. Tries to open a file in the constructor. Error handling strategy can be decided by means of the ErrorMode argument. More...

#include <file_reader.hpp>

Public Types🔗

Name
enum ErrorMode

Public Functions🔗

Name
FileReader(const std::string & f_fileName, const std::string & f_filePath ="", ErrorMode f_errorMode =ErrorMode::Inform)
FileReader(const FileReader & )
FileReader(FileReader && )
FileReader & operator=(const FileReader & )
FileReader & operator=(FileReader && )
~FileReader() =default
bool IsOpen() const
Check if the associated file is open.
bool ReadLine(std::string & f_string)
Read one line from the file and store the result in f_string.

Detailed Description🔗

class iox::cxx::FileReader;

Wrapper class for file reading operations. Tries to open a file in the constructor. Error handling strategy can be decided by means of the ErrorMode argument.

cxx::FileReader reader("filename");
std::string str;
if(reader.IsOpen()) {
    reader.ReadeLine(str);
}

// Terminates program execution, if file cannot be opened (or found):
cxx::FileReader reader("filename", "path/to/file", cxx::FileReader::ErrorMode::Terminate);

Public Types Documentation🔗

enum ErrorMode🔗

Enumerator Value Description
Ignore
Inform
Terminate

Error handling strategy. Ignore continues execution as if nothing happened. Inform continues, but prints an error message. Terminate causes the process to exit.

Public Functions Documentation🔗

function FileReader🔗

FileReader(
    const std::string & f_fileName,
    const std::string & f_filePath ="",
    ErrorMode f_errorMode =ErrorMode::Inform
)

Opens a file and creates a FileReader object. The file path argument is optional and is ignored if empty. The error mode is evaluated when an error occurs.

function FileReader🔗

FileReader(
    const FileReader & 
)

function FileReader🔗

FileReader(
    FileReader && 
)

function operator=🔗

FileReader & operator=(
    const FileReader & 
)

function operator=🔗

FileReader & operator=(
    FileReader && 
)

function ~FileReader🔗

~FileReader() =default

function IsOpen🔗

bool IsOpen() const

Check if the associated file is open.

function ReadLine🔗

bool ReadLine(
    std::string & f_string
)

Read one line from the file and store the result in f_string.


Updated on 31 May 2022 at 15:29:15 CEST