osmanip
Library with useful output stream tools like: color and style manipulators, progress bars and terminal graphics.
Public Member Functions | Static Public Attributes | List of all members
osm::OutputRedirector Class Reference

This class is used to redirected output to a file. More...

#include <output_redirector.hpp>

Inheritance diagram for osm::OutputRedirector:
Inheritance graph
[legend]
Collaboration diagram for osm::OutputRedirector:
Collaboration graph
[legend]

Public Member Functions

 OutputRedirector ()
 Construct a new OutputRedirector object. Default constructor will set the main attributes to default values. More...
 
 OutputRedirector (std::string filename)
 Construct a new OutputRedirector object. The filename must be relative to the working directory. More...
 
 ~OutputRedirector () override
 Destructs OutputRedirector object. If redirection is still enabled, the buffer is flushed before being destroyed. More...
 
void setFilename (std::string_view filename)
 Set the filename of the output file. The filename must be relative to the working directory. More...
 
std::string & getFilename ()
 Get the filename of the output file. More...
 
std::string & getFilepath ()
 Get the name of the path to the output file. More...
 
void end ()
 Flushes the buffer and disables output redirection. More...
 
void begin ()
 Enables output redirection. More...
 
void touch ()
 Opens the file, if present. Otherwise, creates the file. More...
 
bool isEnabled ()
 Returns the current state of the output redirection object. More...
 
- Public Member Functions inherited from osm::Stringbuf
 Stringbuf ()
 Construct a new Stringbuf object. Default constructor will set the main attributes to default values. More...
 
 ~Stringbuf () override
 Destructs OutputRedirector object. Calls this->pubsync() before being destroyed. More...
 
std::mutex & getMutex ()
 Get the mutex for the object. More...
 
int32_t sync () override
 Calls the base class sync() function. More...
 

Static Public Attributes

static const std::string DEFAULT_FILE_DIR = fs::current_path().string()
 
static const std::string DEFAULT_FILEPATH = DEFAULT_FILE_DIR + DEFAULT_FILENAME
 
static const std::string DEFAULT_FILENAME = "redirected_output.txt"
 

Detailed Description

This class is used to redirected output to a file.

Constructor & Destructor Documentation

◆ 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
filenamename of the output file.

◆ ~OutputRedirector()

osm::OutputRedirector::~OutputRedirector ( )
override

Destructs OutputRedirector object. If redirection is still enabled, the buffer is flushed before being destroyed.

Member Function Documentation

◆ begin()

void osm::OutputRedirector::begin ( )

Enables output redirection.

Exceptions
std::runtime_errorif redirection is already enabled.

◆ end()

void osm::OutputRedirector::end ( )

Flushes the buffer and disables output redirection.

Exceptions
std::runtime_errorif 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
filenamethe filename of the output file.

◆ touch()

void osm::OutputRedirector::touch ( )

Opens the file, if present. Otherwise, creates the file.

Exceptions
std::invalid_argumentif the file cannot be opened.

Member Data Documentation

◆ 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

const std::string osm::OutputRedirector::DEFAULT_FILEPATH = DEFAULT_FILE_DIR + DEFAULT_FILENAME
static

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