cpp-terminal
1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
terminal_initializer.cpp
Go to the documentation of this file.
1
/*
2
* cpp-terminal
3
* C++ library for writing multi-platform terminal applications.
4
*
5
* SPDX-FileCopyrightText: 2019-2024 cpp-terminal
6
*
7
* SPDX-License-Identifier: MIT
8
*/
9
10
#include "
cpp-terminal/terminal_initializer.hpp
"
11
12
#include "
cpp-terminal/private/exception.hpp
"
13
#include "
cpp-terminal/private/file_initializer.hpp
"
14
#include "
cpp-terminal/private/signals.hpp
"
15
#include "
cpp-terminal/terminal.hpp
"
16
17
#include <new>
18
19
std::size_t
Term::TerminalInitializer::m_counter
{0};
20
21
Term::TerminalInitializer::TerminalInitializer
() noexcept
22
try
23
{
24
if
(0 ==
m_counter
)
25
{
26
static
const
Private::FileInitializer
files_init;
27
static
std::vector<sighandler_t> m_handlers;
28
new
(&
Term::terminal
)
Terminal
();
29
static
Term::Private::Signals
signals(m_handlers);
30
sighandler_t
handler = [](
int
signum) {
Term::Private::Signals::reset_and_raise
(signum, m_handlers,
Term::terminal
); };
31
signals.
setHandler
(handler);
32
}
33
++
m_counter
;
34
}
35
catch
(...)
36
{
37
ExceptionHandler(
Private::ExceptionDestination::StdErr
);
38
}
39
40
Term::TerminalInitializer::~TerminalInitializer
() noexcept
41
try
42
{
43
--m_counter;
44
if
(0 == m_counter) { (&
Term::terminal
)->~
Terminal
(); }
45
}
46
catch
(...)
47
{
48
ExceptionHandler(
Private::ExceptionDestination::StdErr
);
49
}
Term::Private::FileInitializer
Definition
file_initializer.hpp:21
Term::Private::Signals
Definition
signals.hpp:22
Term::Private::Signals::reset_and_raise
static void reset_and_raise(int sign, std::vector< sighandler_t > &m_han, Term::Terminal &) noexcept
Definition
signals.cpp:64
Term::Private::Signals::setHandler
void setHandler(const sighandler_t &handler) noexcept
Definition
signals.cpp:23
Term::TerminalInitializer::TerminalInitializer
TerminalInitializer() noexcept
Definition
terminal_initializer.cpp:21
Term::TerminalInitializer::~TerminalInitializer
~TerminalInitializer() noexcept
Definition
terminal_initializer.cpp:40
Term::TerminalInitializer::m_counter
static std::size_t m_counter
Definition
terminal_initializer.hpp:19
Term::Terminal
Definition
terminal_impl.hpp:22
file_initializer.hpp
Term::Private::ExceptionDestination::StdErr
@ StdErr
Term::terminal
Term::Terminal & terminal
Definition
terminal.cpp:19
exception.hpp
signals.hpp
sighandler_t
void(*)(int) sighandler_t
Definition
signals.hpp:14
terminal.hpp
terminal_initializer.hpp
cpp-terminal
terminal_initializer.cpp
Generated by
1.11.0