summaryrefslogtreecommitdiff
path: root/include/ncurses/curs_char.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/ncurses/curs_char.hpp')
-rw-r--r--include/ncurses/curs_char.hpp203
1 files changed, 203 insertions, 0 deletions
diff --git a/include/ncurses/curs_char.hpp b/include/ncurses/curs_char.hpp
new file mode 100644
index 0000000..8c1cf4a
--- /dev/null
+++ b/include/ncurses/curs_char.hpp
@@ -0,0 +1,203 @@
+#ifndef INCLUDE_NCURSES_CURS_CHAR_HPP_
+#define INCLUDE_NCURSES_CURS_CHAR_HPP_
+
+#include "ncurses/utils/macros.hpp"
+#include <ncurses.h>
+#include <ncurses/char_attributes.hpp>
+#include <ncurses/colors.hpp>
+#include <ncurses/utils/multiflags.hpp>
+
+namespace NCURSES_CPP_NAMESPACE {
+
+template <> struct is_applyable<color_pair, attr> : std::true_type {};
+
+using full_attrs = multiflags<attr, color_pair>;
+
+class curs_char {
+public:
+ using value_type = chtype;
+
+ NCURSES_CPP_CONSTEXPR curs_char(char c) NCURSES_CPP_NOEXCEPT
+ : value_(static_cast<chtype>(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<char>(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<std::underlying_type<attr>::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<std::underlying_type<attr>::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<attr_flags::mask_type>(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<attr_flags::mask_type>(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<color_pair::value_type>(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<color_pair::value_type>(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<full_attrs::value_type>(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<full_attrs::value_type>(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<char>(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<curs_char::value_type>(c) \
+ op static_cast<curs_char::value_type>(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_