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

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

Inheritance diagram for Term::Private::InputFileHandler:
Term::Private::FileHandler

Public Member Functions

 InputFileHandler (std::recursive_mutex &io_mutex) noexcept
 
 InputFileHandler (const InputFileHandler &)=delete
 
 InputFileHandler (InputFileHandler &&)=delete
 
InputFileHandleroperator= (InputFileHandler &&)=delete
 
InputFileHandleroperator= (const InputFileHandler &)=delete
 
 ~InputFileHandler () override=default
 
std::string read () 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 {"CONIN$"}
 

Additional Inherited Members

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

Detailed Description

Definition at line 75 of file file.hpp.

Constructor & Destructor Documentation

◆ InputFileHandler() [1/3]

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

Definition at line 172 of file file.cpp.

173 : FileHandler(io_mutex, m_file, "r")
174{
175 //noop
176}
177catch(...)
178{
180}
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:87
void ExceptionHandler(const ExceptionDestination &destination=ExceptionDestination::StdErr) noexcept

◆ InputFileHandler() [2/3]

Term::Private::InputFileHandler::InputFileHandler ( const InputFileHandler & )
delete

◆ InputFileHandler() [3/3]

Term::Private::InputFileHandler::InputFileHandler ( InputFileHandler && )
delete

◆ ~InputFileHandler()

Term::Private::InputFileHandler::~InputFileHandler ( )
overridedefault

Member Function Documentation

◆ operator=() [1/2]

InputFileHandler & Term::Private::InputFileHandler::operator= ( const InputFileHandler & )
delete

◆ operator=() [2/2]

InputFileHandler & Term::Private::InputFileHandler::operator= ( InputFileHandler && )
delete

◆ read()

std::string Term::Private::InputFileHandler::read ( ) const

Definition at line 127 of file file.cpp.

128{
129#if defined(_WIN32)
130 DWORD nread{0};
131 std::string ret(4096, '\0');
132 errno = 0;
133 ReadConsole(Private::in.handle(), &ret[0], static_cast<DWORD>(ret.size()), &nread, nullptr);
134 return ret.c_str();
135#else
136 #if defined(MAX_INPUT)
137 static const constexpr std::size_t max_input{MAX_INPUT};
138 #else
139 static const constexpr std::size_t max_input{256};
140 #endif
141 #if defined(_POSIX_MAX_INPUT)
142 static const constexpr std::size_t posix_max_input{_POSIX_MAX_INPUT};
143 #else
144 static const constexpr std::size_t posix_max_input{256};
145 #endif
146 static std::size_t nread{std::max(max_input, posix_max_input)};
147 if(is_stdin_a_tty()) Term::Private::Errno().check_if(::ioctl(Private::in.fd(), FIONREAD, &nread) != 0).throw_exception("::ioctl(Private::in.fd(), FIONREAD, &nread)"); //NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
148 std::string ret(nread, '\0');
149 if(nread != 0)
150 {
151 Term::Private::Errno().check_if(::read(Private::in.fd(), &ret[0], ret.size()) == -1).throw_exception("::read(Private::in.fd(), &ret[0], ret.size())"); //NOLINT(readability-container-data-pointer)
152 }
153 return ret;
154#endif
155}
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::string read() const
Definition file.cpp:127
InputFileHandler & in
Definition file.cpp:43
bool is_stdin_a_tty()
Check if stdin is a tty.
Definition tty.cpp:32

Member Data Documentation

◆ m_file

const constexpr char* Term::Private::InputFileHandler::m_file {"CONIN$"}
staticconstexpr

Definition at line 87 of file file.hpp.

87{"CONIN$"};

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