#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_); }; // relational operators NCURSES_CPP_CONSTEXPR bool operator<(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT { return value_ < rhs.value_; } NCURSES_CPP_CONSTEXPR bool operator<=(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT { return value_ <= rhs.value_; } NCURSES_CPP_CONSTEXPR bool operator>(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT { return value_ > rhs.value_; } NCURSES_CPP_CONSTEXPR bool operator>=(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT { return value_ >= rhs.value_; } NCURSES_CPP_CONSTEXPR bool operator==(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT { return value_ == rhs.value_; } NCURSES_CPP_CONSTEXPR bool operator!=(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT { return value_ != rhs.value_; } // bitwise operators with attr NCURSES_CPP_CONSTEXPR curs_char operator&(attr rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ & static_cast::type>(rhs)); } NCURSES_CPP_CONSTEXPR curs_char operator|(attr rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ | static_cast::type>(rhs)); } NCURSES_CPP_CONSTEXPR curs_char operator^(attr rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ ^ static_cast::type>(rhs)); } // bitwise operators with attr_flags NCURSES_CPP_CONSTEXPR curs_char operator&(attr_flags const &rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ & static_cast(rhs)); } NCURSES_CPP_CONSTEXPR curs_char operator|(attr_flags const &rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ | static_cast(rhs)); } NCURSES_CPP_CONSTEXPR curs_char operator^(attr_flags const &rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ ^ static_cast(rhs)); } // bitwise operators with color_pair NCURSES_CPP_CONSTEXPR curs_char operator&(color_pair const &rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ & static_cast(rhs)); } NCURSES_CPP_CONSTEXPR curs_char operator|(color_pair const &rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ | static_cast(rhs)); } NCURSES_CPP_CONSTEXPR curs_char operator^(color_pair const &rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ ^ static_cast(rhs)); } // bitwise operators with full_attrs NCURSES_CPP_CONSTEXPR curs_char operator&(full_attrs const &rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ & static_cast(rhs)); } NCURSES_CPP_CONSTEXPR curs_char operator|(full_attrs const &rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ | static_cast(rhs)); } NCURSES_CPP_CONSTEXPR curs_char operator^(full_attrs const &rhs) const NCURSES_CPP_NOEXCEPT { return curs_char(value_ ^ static_cast(rhs)); } // assignment with attr NCURSES_CPP_CONSTEXPR_14 curs_char & operator&=(attr rhs) NCURSES_CPP_NOEXCEPT { value_ &= static_cast::type>(rhs); return *this; } NCURSES_CPP_CONSTEXPR_14 curs_char & operator|=(attr rhs) NCURSES_CPP_NOEXCEPT { value_ |= static_cast::type>(rhs); return *this; } NCURSES_CPP_CONSTEXPR_14 curs_char & operator^=(attr rhs) NCURSES_CPP_NOEXCEPT { value_ ^= static_cast::type>(rhs); return *this; } // assignment with attr_flags NCURSES_CPP_CONSTEXPR_14 curs_char & operator&=(attr_flags const &rhs) NCURSES_CPP_NOEXCEPT { value_ &= static_cast(rhs); return *this; } NCURSES_CPP_CONSTEXPR_14 curs_char & operator|=(attr_flags const &rhs) NCURSES_CPP_NOEXCEPT { value_ |= static_cast(rhs); return *this; } NCURSES_CPP_CONSTEXPR_14 curs_char & operator^=(attr_flags const &rhs) NCURSES_CPP_NOEXCEPT { value_ ^= static_cast(rhs); return *this; } NCURSES_CPP_CONSTEXPR_14 curs_char & operator&=(color_pair const &rhs) NCURSES_CPP_NOEXCEPT { value_ &= static_cast(rhs); return *this; } NCURSES_CPP_CONSTEXPR_14 curs_char & operator|=(color_pair const &rhs) NCURSES_CPP_NOEXCEPT { value_ |= static_cast(rhs); return *this; } NCURSES_CPP_CONSTEXPR_14 curs_char & operator^=(color_pair const &rhs) NCURSES_CPP_NOEXCEPT { value_ ^= static_cast(rhs); return *this; } NCURSES_CPP_CONSTEXPR_14 curs_char & operator&=(full_attrs const &rhs) NCURSES_CPP_NOEXCEPT { value_ &= static_cast(rhs); return *this; } NCURSES_CPP_CONSTEXPR_14 curs_char & operator|=(full_attrs const &rhs) NCURSES_CPP_NOEXCEPT { value_ |= static_cast(rhs); return *this; } NCURSES_CPP_CONSTEXPR_14 curs_char & operator^=(full_attrs const &rhs) NCURSES_CPP_NOEXCEPT { value_ ^= static_cast(rhs); return *this; } 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_); } explicit NCURSES_CPP_CONSTEXPR operator value_type() const NCURSES_CPP_NOEXCEPT { return 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 #if !defined(NCURSES_CPP_HAS_SPACESHIP_OPERATOR) // relational operators only needed for pre C++20 NCURSES_CPP_CONSTEXPR_INLINE bool operator<(const char &lhs, const curs_char &rhs) NCURSES_CPP_NOEXCEPT { return rhs.operator>(lhs); } NCURSES_CPP_CONSTEXPR_INLINE bool operator<=(const char &lhs, const curs_char &rhs) NCURSES_CPP_NOEXCEPT { return rhs.operator>=(lhs); } NCURSES_CPP_CONSTEXPR_INLINE bool operator>(const char &lhs, const curs_char &rhs) NCURSES_CPP_NOEXCEPT { return rhs.operator<(lhs); } NCURSES_CPP_CONSTEXPR_INLINE bool operator>=(const char &lhs, const curs_char &rhs) NCURSES_CPP_NOEXCEPT { return rhs.operator<=(lhs); } NCURSES_CPP_CONSTEXPR_INLINE bool operator==(const char &lhs, const curs_char &rhs) NCURSES_CPP_NOEXCEPT { return rhs.operator==(lhs); } NCURSES_CPP_CONSTEXPR_INLINE bool operator!=(const char &lhs, const curs_char &rhs) NCURSES_CPP_NOEXCEPT { return rhs.operator!=(lhs); } #endif // global attr + curs_char and char + attr -> curs_char operators NCURSES_CPP_CONSTEXPR_INLINE curs_char operator&(const attr &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator&(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator&(const char &c, const attr &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) & static_cast(other)); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator|(const attr &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator|(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator|(const char &c, const attr &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) | static_cast(other)); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator^(const attr &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator^(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator^(const char &c, const attr &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) ^ static_cast(other)); } // global attr_flags + curs_char and char + attr_flags -> curs_char operators NCURSES_CPP_CONSTEXPR_INLINE curs_char operator&( const attr_flags &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator&(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator&(const char &c, const attr_flags &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) & static_cast(other)); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator|( const attr_flags &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator|(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator|(const char &c, const attr_flags &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) | static_cast(other)); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator^( const attr_flags &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator^(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator^(const char &c, const attr_flags &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) ^ static_cast(other)); } // global color_pair + curs_char and char + color_pair -> curs_char operators NCURSES_CPP_CONSTEXPR_INLINE curs_char operator&( const color_pair &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator&(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator&(const char &c, const color_pair &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) & static_cast(other)); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator|( const color_pair &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator|(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator|(const char &c, const color_pair &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) | static_cast(other)); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator^( const color_pair &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator^(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator^(const char &c, const color_pair &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) ^ static_cast(other)); } // global full_attrs + curs_char and char + full_attrs -> curs_char operators NCURSES_CPP_CONSTEXPR_INLINE curs_char operator&( const full_attrs &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator&(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator&(const char &c, const full_attrs &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) & static_cast(other)); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator|( const full_attrs &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator|(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator|(const char &c, const full_attrs &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) | static_cast(other)); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator^( const full_attrs &other, curs_char const &symbol) NCURSES_CPP_NOEXCEPT { return symbol.operator^(other); } NCURSES_CPP_CONSTEXPR_INLINE curs_char operator^(const char &c, const full_attrs &other) NCURSES_CPP_NOEXCEPT { return curs_char(static_cast(c) ^ static_cast(other)); } } // namespace NCURSES_CPP_NAMESPACE #endif // INCLUDE_NCURSES_CURS_CHAR_HPP_