cpp-terminal 1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
Term::Private::OutputFileHandler Class Reference

#include <cpp-terminal/private/file.hpp>

Inheritance diagram for Term::Private::OutputFileHandler:
Term::Private::FileHandler

Public Member Functions

 OutputFileHandler (std::recursive_mutex &io_mutex) noexcept
 
 OutputFileHandler (const OutputFileHandler &other)=delete
 
 OutputFileHandler (OutputFileHandler &&other)=delete
 
OutputFileHandleroperator= (OutputFileHandler &&rhs)=delete
 
OutputFileHandleroperator= (const OutputFileHandler &rhs)=delete
 
 ~OutputFileHandler () override=default
 
std::size_t write (const std::string &str) const
 
std::size_t write (const char &character) const
 
- Public Member Functions inherited from Term::Private::FileHandler
 FileHandler (std::recursive_mutex &mutex, const std::string &file, const std::string &mode) noexcept
 
 FileHandler (const FileHandler &)=delete
 
 FileHandler (FileHandler &&)=delete
 
FileHandleroperator= (const FileHandler &)=delete
 
FileHandleroperator= (FileHandler &&)=delete
 
virtual ~FileHandler () noexcept
 
Handle handle () const noexcept
 
bool null () const noexcept
 
std::FILE * file () const noexcept
 
std::int32_t fd () const noexcept
 
void lockIO ()
 
void unlockIO ()
 
void flush ()
 

Static Public Attributes

static const constexpr char * m_file {"CONOUT$"}
 

Additional Inherited Members

- Public Types inherited from Term::Private::FileHandler
using Handle = void*
 

Detailed Description

Definition at line 56 of file file.hpp.

Constructor & Destructor Documentation

◆ OutputFileHandler() [1/3]

Term::Private::OutputFileHandler::OutputFileHandler ( std::recursive_mutex & io_mutex)
explicitnoexcept

Definition at line 162 of file file.cpp.

163 : FileHandler(io_mutex, m_file, "w")
164{
165 //noop
166}
167catch(...)
168{
170}
FileHandler(std::recursive_mutex &mutex, const std::string &file, const std::string &mode) noexcept
Definition file.cpp:48
static const constexpr char * m_file
Definition file.hpp:69
void ExceptionHandler(const ExceptionDestination &destination=ExceptionDestination::StdErr) noexcept

◆ OutputFileHandler() [2/3]

Term::Private::OutputFileHandler::OutputFileHandler ( const OutputFileHandler & other)
delete

◆ OutputFileHandler() [3/3]

Term::Private::OutputFileHandler::OutputFileHandler ( OutputFileHandler && other)
delete

◆ ~OutputFileHandler()

Term::Private::OutputFileHandler::~OutputFileHandler ( )
overridedefault

Member Function Documentation

◆ operator=() [1/2]

OutputFileHandler & Term::Private::OutputFileHandler::operator= ( const OutputFileHandler & rhs)
delete

◆ operator=() [2/2]

OutputFileHandler & Term::Private::OutputFileHandler::operator= ( OutputFileHandler && rhs)
delete

◆ write() [1/2]

std::size_t Term::Private::OutputFileHandler::write ( const char & character) const

Definition at line 114 of file file.cpp.

115{
116#if defined(_WIN32)
117 DWORD written{0};
118 Term::Private::WindowsError().check_if(0 == WriteConsole(handle(), &character, 1, &written, nullptr)).throw_exception("WriteConsole(handle(), &character, 1, &written, nullptr)");
119 return static_cast<std::size_t>(written);
120#else
121 ssize_t written{0};
122 Term::Private::Errno().check_if((written = ::write(fd(), &character, 1)) == -1).throw_exception("::write(fd(), &character, 1)");
123 return static_cast<std::size_t>(written);
124#endif
125}
void throw_exception(const std::string &str={}) const
Errno & check_if(const bool &ret) noexcept
Handle handle() const noexcept
Definition file.cpp:99
std::int32_t fd() const noexcept
Definition file.cpp:97
std::size_t write(const std::string &str) const
Definition file.cpp:101
WindowsError & check_if(const bool &ret) noexcept
Definition exception.cpp:75
void throw_exception(const std::string &str=std::string()) const
Definition exception.cpp:82

◆ write() [2/2]

std::size_t Term::Private::OutputFileHandler::write ( const std::string & str) const

Definition at line 101 of file file.cpp.

102{
103#if defined(_WIN32)
104 DWORD written{0};
105 if(!str.empty()) { Term::Private::WindowsError().check_if(0 == WriteConsole(handle(), &str[0], static_cast<DWORD>(str.size()), &written, nullptr)).throw_exception("WriteConsole(handle(), &str[0], static_cast<DWORD>(str.size()), &written, nullptr)"); }
106 return static_cast<std::size_t>(written);
107#else
108 ssize_t written{0};
109 if(!str.empty()) { Term::Private::Errno().check_if((written = ::write(fd(), str.data(), str.size())) == -1).throw_exception("::write(fd(), str.data(), str.size())"); }
110 return static_cast<std::size_t>(written);
111#endif
112}

Member Data Documentation

◆ m_file

const constexpr char* Term::Private::OutputFileHandler::m_file {"CONOUT$"}
staticconstexpr

Definition at line 69 of file file.hpp.

69{"CONOUT$"};

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