iceoryx_doc  1.0.1
Public Types | Public Member Functions | List of all members
iox::cxx::FileReader Class Reference

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

enum class  ErrorMode { Ignore , Inform , Terminate }
 

Public Member Functions

 FileReader (const std::string &f_fileName, const std::string &f_filePath="", ErrorMode f_errorMode=ErrorMode::Inform)
 
 FileReader (const FileReader &)=delete
 
 FileReader (FileReader &&)=delete
 
FileReaderoperator= (const FileReader &)=delete
 
FileReaderoperator= (FileReader &&)=delete
 
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

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);

Member Enumeration Documentation

◆ ErrorMode

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

Constructor & Destructor Documentation

◆ FileReader()

iox::cxx::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.


The documentation for this class was generated from the following file: