#ifndef INCLUDE_NCURSES_CURS_CHAR_HPP_ #define INCLUDE_NCURSES_CURS_CHAR_HPP_ #include "ncurses/utils/macros.hpp" #include #include #include #include namespace NCURSES_CPP_NAMESPACE { template <> struct is_applyable : std::true_type {}; using full_attrs = multiflags; class curs_char { public: using value_type = chtype; NCURSES_CPP_CONSTEXPR curs_char(char c) NCURSES_CPP_NOEXCEPT : value_(static_cast(c)) {} explicit NCURSES_CPP_CONSTEXPR curs_char(value_type c) NCURSES_CPP_NOEXCEPT : value_(c) {} NCURSES_CPP_CONSTEXPR attr_flags attributes() const NCURSES_CPP_NOEXCEPT { return {}; }; NCURSES_CPP_CONSTEXPR int color() const NCURSES_CPP_NOEXCEPT { return PAIR_NUMBER(value_); }; NCURSES_CPP_CONSTEXPR char ch() const NCURSES_CPP_NOEXCEPT { return static_cast(value_); }; #define NCURSES_CPP_RELATIONAL(op) \ NCURSES_CPP_CONSTEXPR bool operator op(curs_char const &rhs) \ const NCURSES_CPP_NOEXCEPT { \ return value_ op rhs.value_; \ } #define NCURSES_CPP_BITWISE_ATTR(op) \ NCURSES_CPP_CONSTEXPR curs_char operator op(attr rhs) \ const NCURSES_CPP_NOEXCEPT { \ return curs_char( \ value_ op static_cast::type>(rhs)); \ } #define NCURSES_CPP_ASSIGNMENT_ATTR(op) \ NCURSES_CPP_CONSTEXPR_14 curs_char &operator op##=(attr rhs) \ NCURSES_CPP_NOEXCEPT { \ value_ op## = static_cast::type>(rhs); \ return *this; \ } #define NCURSES_CPP_BITWISE_ATTRS(op) \ NCURSES_CPP_CONSTEXPR curs_char operator op(attr_flags const &rhs) \ const NCURSES_CPP_NOEXCEPT { \ return curs_char(value_ op static_cast(rhs)); \ } #define NCURSES_CPP_ASSIGNMENT_ATTRS(op) \ NCURSES_CPP_CONSTEXPR_14 curs_char &operator op##=(attr_flags const &rhs) \ NCURSES_CPP_NOEXCEPT { \ value_ op## = static_cast(rhs); \ return *this; \ } #define NCURSES_CPP_BITWISE_COLORS(op) \ NCURSES_CPP_CONSTEXPR curs_char operator op(color_pair const &rhs) \ const NCURSES_CPP_NOEXCEPT { \ return curs_char(value_ op static_cast(rhs)); \ } #define NCURSES_CPP_ASSIGNMENT_COLORS(op) \ NCURSES_CPP_CONSTEXPR_14 curs_char &operator op##=(color_pair const &rhs) \ NCURSES_CPP_NOEXCEPT { \ value_ op## = static_cast(rhs); \ return *this; \ } #define NCURSES_CPP_BITWISE_FATTRS(op) \ NCURSES_CPP_CONSTEXPR curs_char operator op(full_attrs const &rhs) \ const NCURSES_CPP_NOEXCEPT { \ return curs_char(value_ op static_cast(rhs)); \ } #define NCURSES_CPP_ASSIGNMENT_FATTRS(op) \ NCURSES_CPP_CONSTEXPR_14 curs_char &operator op##=(full_attrs const &rhs) \ NCURSES_CPP_NOEXCEPT { \ value_ op## = static_cast(rhs); \ return *this; \ } NCURSES_CPP_RELATIONAL(<) NCURSES_CPP_RELATIONAL(<=) NCURSES_CPP_RELATIONAL(>) NCURSES_CPP_RELATIONAL(>=) NCURSES_CPP_RELATIONAL(==) NCURSES_CPP_RELATIONAL(!=) NCURSES_CPP_BITWISE_ATTR(&) NCURSES_CPP_BITWISE_ATTR(|) NCURSES_CPP_BITWISE_ATTR(^) NCURSES_CPP_BITWISE_ATTRS(&) NCURSES_CPP_BITWISE_ATTRS(|) NCURSES_CPP_BITWISE_ATTRS(^) NCURSES_CPP_BITWISE_COLORS(&) NCURSES_CPP_BITWISE_COLORS(|) NCURSES_CPP_BITWISE_COLORS(^) NCURSES_CPP_BITWISE_FATTRS(&) NCURSES_CPP_BITWISE_FATTRS(|) NCURSES_CPP_BITWISE_FATTRS(^) NCURSES_CPP_ASSIGNMENT_ATTR(&) NCURSES_CPP_ASSIGNMENT_ATTR(|) NCURSES_CPP_ASSIGNMENT_ATTR(^) NCURSES_CPP_ASSIGNMENT_ATTRS(&) NCURSES_CPP_ASSIGNMENT_ATTRS(|) NCURSES_CPP_ASSIGNMENT_ATTRS(^) NCURSES_CPP_ASSIGNMENT_COLORS(&) NCURSES_CPP_ASSIGNMENT_COLORS(|) NCURSES_CPP_ASSIGNMENT_COLORS(^) NCURSES_CPP_ASSIGNMENT_FATTRS(&) NCURSES_CPP_ASSIGNMENT_FATTRS(|) NCURSES_CPP_ASSIGNMENT_FATTRS(^) NCURSES_CPP_CONSTEXPR bool operator!() const NCURSES_CPP_NOEXCEPT { return !value_; } explicit NCURSES_CPP_CONSTEXPR operator char() const NCURSES_CPP_NOEXCEPT { return static_cast(value_); } #if defined(NCURSES_CPP_CHAR_VALUE_AS_PUBLIC) public: #else private: #endif chtype value_; }; // TODO:const otype& - link may be not as good as copy #define NPP_DEF_GLOB_OP(type, op, otype) \ NCURSES_CPP_CONSTEXPR_INLINE type operator op( \ const otype &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { \ return symbol.operator op(other); \ } \ NCURSES_CPP_CONSTEXPR_INLINE type operator op(const char &c, \ const otype &other) { \ return curs_char(static_cast(c) \ op static_cast(other)); \ } #define NPP_DEF_GLOB_OP_BOOL(op) \ NCURSES_CPP_CONSTEXPR_INLINE bool operator op(const char &lhs, \ const curs_char &rhs) { \ return rhs.operator op(lhs); \ } #define NPP_DEF_GLOB_OP_ATTR(op) NPP_DEF_GLOB_OP(curs_char, op, attr) #define NPP_DEF_GLOB_OP_ATTRS(op) NPP_DEF_GLOB_OP(curs_char, op, attr_flags) #define NPP_DEF_GLOB_OP_COLORS(op) NPP_DEF_GLOB_OP(curs_char, op, color_pair) #define NPP_DEF_GLOB_OP_FATTRS(op) NPP_DEF_GLOB_OP(curs_char, op, full_attrs) #if !defined(NCURSES_CPP_HAS_SPACESHIP_OPERATOR) // relational operators only needed for pre C++20 NPP_DEF_GLOB_OP_BOOL(<) NPP_DEF_GLOB_OP_BOOL(<=) NPP_DEF_GLOB_OP_BOOL(>) NPP_DEF_GLOB_OP_BOOL(>=) NPP_DEF_GLOB_OP_BOOL(==) NPP_DEF_GLOB_OP_BOOL(!=) #endif NPP_DEF_GLOB_OP_ATTR(&) NPP_DEF_GLOB_OP_ATTR(|) NPP_DEF_GLOB_OP_ATTR(^) NPP_DEF_GLOB_OP_ATTRS(&) NPP_DEF_GLOB_OP_ATTRS(|) NPP_DEF_GLOB_OP_ATTRS(^) NPP_DEF_GLOB_OP_COLORS(&) NPP_DEF_GLOB_OP_COLORS(|) NPP_DEF_GLOB_OP_COLORS(^) NPP_DEF_GLOB_OP_FATTRS(&) NPP_DEF_GLOB_OP_FATTRS(|) NPP_DEF_GLOB_OP_FATTRS(^) } // namespace NCURSES_CPP_NAMESPACE #endif // INCLUDE_NCURSES_CURS_CHAR_HPP_