16 #ifndef OSMANIP_UTILITY_OUTPUTREDIRECTOR_HPP
17 #define OSMANIP_UTILITY_OUTPUTREDIRECTOR_HPP
39 namespace fs = std::filesystem;
78 int32_t sync()
override;
80 void prepare_output();
82 void sanity_check(
const std::string &func_name);
83 void exception_file_not_found();
86 std::atomic<bool> enabled_;
87 std::string file_dir_;
88 std::string filename_;
89 std::string filepath_;
90 std::fstream fstream_;
91 std::stringstream output_str_;
92 int32_t last_ansi_str_index_;
93 int32_t last_ansi_str_size_;
This class is used to redirected output to a file.
Definition: output_redirector.hpp:49
static const std::string DEFAULT_FILEPATH
Definition: output_redirector.hpp:72
std::string & getFilepath()
Get the name of the path to the output file.
Definition: output_redirector.cpp:135
void setFilename(std::string_view filename)
Set the filename of the output file. The filename must be relative to the working directory.
Definition: output_redirector.cpp:102
OutputRedirector()
Construct a new OutputRedirector object. Default constructor will set the main attributes to default ...
Definition: output_redirector.cpp:53
bool isEnabled()
Returns the current state of the output redirection object.
Definition: output_redirector.cpp:195
static const std::string DEFAULT_FILE_DIR
Definition: output_redirector.hpp:71
std::string & getFilename()
Get the filename of the output file.
Definition: output_redirector.cpp:123
static const std::string DEFAULT_FILENAME
Definition: output_redirector.hpp:73
void begin()
Enables output redirection.
Definition: output_redirector.cpp:151
void touch()
Opens the file, if present. Otherwise, creates the file.
Definition: output_redirector.cpp:176
void end()
Flushes the buffer and disables output redirection.
Definition: output_redirector.cpp:163
~OutputRedirector() override
Destructs OutputRedirector object. If redirection is still enabled, the buffer is flushed before bein...
Definition: output_redirector.cpp:84
This class inherits std::stringbuf and adds additional functionality and thread safety.
Definition: sstream.hpp:40
Definition: canvas.cpp:30