This class is used to redirected output to a file.
More...
#include <output_redirector.hpp>
This class is used to redirected output to a file.
◆ OutputRedirector() [1/2]
osm::OutputRedirector::OutputRedirector |
( |
| ) |
|
Construct a new OutputRedirector object. Default constructor will set the main attributes to default values.
◆ OutputRedirector() [2/2]
osm::OutputRedirector::OutputRedirector |
( |
std::string |
filename | ) |
|
|
explicit |
Construct a new OutputRedirector object. The filename must be relative to the working directory.
- Parameters
-
filename | name of the output file. |
◆ ~OutputRedirector()
osm::OutputRedirector::~OutputRedirector |
( |
| ) |
|
|
override |
Destructs OutputRedirector object. If redirection is still enabled, the buffer is flushed before being destroyed.
◆ begin()
void osm::OutputRedirector::begin |
( |
| ) |
|
Enables output redirection.
- Exceptions
-
std::runtime_error | if redirection is already enabled. |
◆ end()
void osm::OutputRedirector::end |
( |
| ) |
|
Flushes the buffer and disables output redirection.
- Exceptions
-
std::runtime_error | if redirection is currently not enabled. |
◆ getFilename()
std::string & osm::OutputRedirector::getFilename |
( |
| ) |
|
Get the filename of the output file.
- Returns
- string containing the filename of the output file.
◆ getFilepath()
std::string & osm::OutputRedirector::getFilepath |
( |
| ) |
|
Get the name of the path to the output file.
- Returns
- string containing the name of the path to the output file.
◆ isEnabled()
bool osm::OutputRedirector::isEnabled |
( |
| ) |
|
Returns the current state of the output redirection object.
- Returns
- true if enabled. Otherwise, returns false.
◆ setFilename()
void osm::OutputRedirector::setFilename |
( |
std::string_view |
filename | ) |
|
Set the filename of the output file. The filename must be relative to the working directory.
- Parameters
-
filename | the filename of the output file. |
◆ touch()
void osm::OutputRedirector::touch |
( |
| ) |
|
Opens the file, if present. Otherwise, creates the file.
- Exceptions
-
std::invalid_argument | if the file cannot be opened. |
◆ DEFAULT_FILE_DIR
const std::string osm::OutputRedirector::DEFAULT_FILE_DIR = fs::current_path().string() |
|
static |
◆ DEFAULT_FILENAME
const std::string osm::OutputRedirector::DEFAULT_FILENAME = "redirected_output.txt" |
|
static |
◆ DEFAULT_FILEPATH
The documentation for this class was generated from the following files: