mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-04 06:00:30 +00:00
2fabe85e6a
Been a while, apologies :) Added: * Direct: fg_palindex (`ncdirect_fg_palindex`) * Direct: bg_palindex (`ncdirect_bg_palindex`) * Direct: get_palette_size (`ncdirect_palette_size`) * Direct: putstr (`ncdirect_putstr`) * Direct: hline_interp (`ncdirect_hline_interp`) * Direct: vline_interp (`ncdirect_vline_interp`) * Direct: box (`ncdirect_box`) * Direct: rounded_box (`ncdirect_rounded_box`) * Direct: double_box (`ncdirect_double_box`) * Direct: canopen_images (`ncdirect_canopen_images`) * Direct: canutf8 (`ncdirect_canutf8`) * Menu: get_mouse_selected (`ncmenu_mouse_selected`) * NotCurses: version_components (`notcurses_version_components`) * NotCurses: str_blitter (`notcurses_str_blitter`) * NotCurses: str_scalemode (`notcurses_str_scalemode`) * NotCurses: lex_margins (`notcurses_lex_margins`) * NotCurses: lex_blitter (`notcurses_lex_blitter`) * NotCurses: lex_scalemode (`notcurses_lex_scalemode`) * NotCurses: render_to_file (`notcurses_render_to_file`) * Plane: putstr_stainable (`ncplane_putstr_stainable`) * Plane: printf_stainable (`ncplane_printf_stainable`) * Plane: vprintf_stainable (`ncplane_vprintf_stainable`) * Reel: offer_input (`ncreel_offer_input`) Changed: * Direct: set_fg_alpha uses `unsigned alpha` * Direct: set_bg_alpha uses `unsigned alpha` * Plane: set_fg_alpha uses `unsigned alpha` * Plane: set_bg_alpha uses `unsigned alpha` * Root: made `error_guard` and `error_guard_cond` static
105 lines
2.4 KiB
C++
105 lines
2.4 KiB
C++
#ifndef __NCPP_ROOT_HH
|
|
#define __NCPP_ROOT_HH
|
|
|
|
#include <type_traits>
|
|
#include <string>
|
|
#include <notcurses/notcurses.h>
|
|
|
|
#include "_helpers.hh"
|
|
#include "_exceptions.hh"
|
|
|
|
namespace ncpp {
|
|
#if defined (NCPP_EXCEPTIONS_PLEASE)
|
|
#define NOEXCEPT_MAYBE
|
|
#else
|
|
#define NOEXCEPT_MAYBE noexcept
|
|
#endif
|
|
|
|
class NotCurses;
|
|
|
|
class NCPP_API_EXPORT Root
|
|
{
|
|
protected:
|
|
static constexpr char ncpp_invalid_state_message[] = "notcurses++ is in an invalid state (already stopped?)";
|
|
|
|
public:
|
|
notcurses* get_notcurses () const;
|
|
|
|
NotCurses* get_notcurses_cpp () const
|
|
{
|
|
return nc;
|
|
}
|
|
|
|
protected:
|
|
explicit Root (NotCurses *ncinst)
|
|
: nc (ncinst)
|
|
{}
|
|
|
|
template<typename TRet = bool, typename TValue = int>
|
|
static TRet error_guard (TValue ret, TValue error_value)
|
|
{
|
|
static constexpr bool ret_is_bool = std::is_same_v<TRet, bool>;
|
|
|
|
if constexpr (!ret_is_bool) {
|
|
static_assert (std::is_same_v<TRet, TValue>, "Both TRet and TValue must be the same type unless TValue is 'bool'");
|
|
}
|
|
|
|
if (ret != error_value) {
|
|
if constexpr (ret_is_bool) {
|
|
return true;
|
|
} else {
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
#if defined (NCPP_EXCEPTIONS_PLEASE)
|
|
throw call_error ("Call returned an error value");
|
|
#else
|
|
if constexpr (ret_is_bool) {
|
|
return false;
|
|
} else {
|
|
return ret;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
template<typename TRet = bool, typename TValue = int>
|
|
static TRet error_guard_cond ([[maybe_unused]] TValue ret, bool error_value)
|
|
{
|
|
static constexpr bool ret_is_bool = std::is_same_v<TRet, bool>;
|
|
|
|
if constexpr (!ret_is_bool) {
|
|
static_assert (std::is_same_v<TRet, TValue>, "Both TRet and TValue must be the same type unless TValue is 'bool'");
|
|
}
|
|
|
|
if (!error_value) {
|
|
if constexpr (ret_is_bool) {
|
|
return true;
|
|
} else {
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
#if defined (NCPP_EXCEPTIONS_PLEASE)
|
|
throw call_error ("Call returned an error value");
|
|
#else
|
|
if constexpr (ret_is_bool) {
|
|
return false;
|
|
} else {
|
|
return ret;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
// All the objects which need to destroy notcurses entities (planes, panelreel etc etc) **have to** call this
|
|
// function before calling to notcurses from their destructor. This is to prevent a segfault when
|
|
// NotCurses::stop has been called and the app uses smart pointers holding NotCurses objects which may be
|
|
// destructed **after** notcurses is stopped.
|
|
bool is_notcurses_stopped () const noexcept;
|
|
|
|
private:
|
|
NotCurses *nc = nullptr;
|
|
};
|
|
}
|
|
#endif
|