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.hpp424
1 files changed, 302 insertions, 122 deletions
diff --git a/include/ncurses/curs_char.hpp b/include/ncurses/curs_char.hpp
index 8c1cf4a..18d250a 100644
--- a/include/ncurses/curs_char.hpp
+++ b/include/ncurses/curs_char.hpp
@@ -35,103 +35,156 @@ public:
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_; \
+ // relational operators
+ NCURSES_CPP_CONSTEXPR bool
+ operator<(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return value_ < 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)); \
+ NCURSES_CPP_CONSTEXPR bool
+ operator<=(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return value_ <= rhs.value_;
}
-
-#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; \
+ NCURSES_CPP_CONSTEXPR bool
+ operator>(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return value_ > rhs.value_;
}
-
-#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)); \
+ NCURSES_CPP_CONSTEXPR bool
+ operator>=(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return value_ >= rhs.value_;
}
-
-#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; \
+ NCURSES_CPP_CONSTEXPR bool
+ operator==(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return value_ == rhs.value_;
}
-
-#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)); \
+ NCURSES_CPP_CONSTEXPR bool
+ operator!=(curs_char const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return value_ != rhs.value_;
}
-#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; \
+ // bitwise operators with attr
+ NCURSES_CPP_CONSTEXPR curs_char
+ operator&(attr rhs) const NCURSES_CPP_NOEXCEPT {
+ return curs_char(value_ &
+ static_cast<std ::underlying_type<attr>::type>(rhs));
}
-
-#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)); \
+ NCURSES_CPP_CONSTEXPR curs_char
+ operator|(attr rhs) const NCURSES_CPP_NOEXCEPT {
+ return curs_char(value_ |
+ static_cast<std ::underlying_type<attr>::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_CONSTEXPR curs_char
+ operator^(attr rhs) const NCURSES_CPP_NOEXCEPT {
+ return curs_char(value_ ^
+ static_cast<std ::underlying_type<attr>::type>(rhs));
}
- 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(^)
+ // 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<attr_flags ::mask_type>(rhs));
+ }
+ NCURSES_CPP_CONSTEXPR curs_char
+ operator|(attr_flags const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return curs_char(value_ | static_cast<attr_flags ::mask_type>(rhs));
+ }
+ NCURSES_CPP_CONSTEXPR curs_char
+ operator^(attr_flags const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return curs_char(value_ ^ static_cast<attr_flags ::mask_type>(rhs));
+ }
- NCURSES_CPP_BITWISE_COLORS(&)
- NCURSES_CPP_BITWISE_COLORS(|)
- NCURSES_CPP_BITWISE_COLORS(^)
+ // 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<color_pair ::value_type>(rhs));
+ }
+ NCURSES_CPP_CONSTEXPR curs_char
+ operator|(color_pair const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return curs_char(value_ | static_cast<color_pair ::value_type>(rhs));
+ }
+ NCURSES_CPP_CONSTEXPR curs_char
+ operator^(color_pair const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return curs_char(value_ ^ static_cast<color_pair ::value_type>(rhs));
+ }
- NCURSES_CPP_BITWISE_FATTRS(&)
- NCURSES_CPP_BITWISE_FATTRS(|)
- NCURSES_CPP_BITWISE_FATTRS(^)
+ // 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<full_attrs ::value_type>(rhs));
+ }
+ NCURSES_CPP_CONSTEXPR curs_char
+ operator|(full_attrs const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return curs_char(value_ | static_cast<full_attrs ::value_type>(rhs));
+ }
+ NCURSES_CPP_CONSTEXPR curs_char
+ operator^(full_attrs const &rhs) const NCURSES_CPP_NOEXCEPT {
+ return curs_char(value_ ^ static_cast<full_attrs ::value_type>(rhs));
+ }
- NCURSES_CPP_ASSIGNMENT_ATTR(&)
- NCURSES_CPP_ASSIGNMENT_ATTR(|)
- NCURSES_CPP_ASSIGNMENT_ATTR(^)
+ // assignment with attr
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator&=(attr rhs) NCURSES_CPP_NOEXCEPT {
+ value_ &= static_cast<std ::underlying_type<attr>::type>(rhs);
+ return *this;
+ }
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator|=(attr rhs) NCURSES_CPP_NOEXCEPT {
+ value_ |= static_cast<std ::underlying_type<attr>::type>(rhs);
+ return *this;
+ }
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator^=(attr rhs) NCURSES_CPP_NOEXCEPT {
+ value_ ^= static_cast<std ::underlying_type<attr>::type>(rhs);
+ return *this;
+ }
- NCURSES_CPP_ASSIGNMENT_ATTRS(&)
- NCURSES_CPP_ASSIGNMENT_ATTRS(|)
- NCURSES_CPP_ASSIGNMENT_ATTRS(^)
+ // assignment with attr_flags
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator&=(attr_flags const &rhs) NCURSES_CPP_NOEXCEPT {
+ value_ &= static_cast<attr_flags ::mask_type>(rhs);
+ return *this;
+ }
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator|=(attr_flags const &rhs) NCURSES_CPP_NOEXCEPT {
+ value_ |= static_cast<attr_flags ::mask_type>(rhs);
+ return *this;
+ }
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator^=(attr_flags const &rhs) NCURSES_CPP_NOEXCEPT {
+ value_ ^= static_cast<attr_flags ::mask_type>(rhs);
+ return *this;
+ }
- NCURSES_CPP_ASSIGNMENT_COLORS(&)
- NCURSES_CPP_ASSIGNMENT_COLORS(|)
- NCURSES_CPP_ASSIGNMENT_COLORS(^)
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator&=(color_pair const &rhs) NCURSES_CPP_NOEXCEPT {
+ value_ &= static_cast<color_pair ::value_type>(rhs);
+ return *this;
+ }
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator|=(color_pair const &rhs) NCURSES_CPP_NOEXCEPT {
+ value_ |= static_cast<color_pair ::value_type>(rhs);
+ return *this;
+ }
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator^=(color_pair const &rhs) NCURSES_CPP_NOEXCEPT {
+ value_ ^= static_cast<color_pair ::value_type>(rhs);
+ return *this;
+ }
- NCURSES_CPP_ASSIGNMENT_FATTRS(&)
- NCURSES_CPP_ASSIGNMENT_FATTRS(|)
- NCURSES_CPP_ASSIGNMENT_FATTRS(^)
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator&=(full_attrs const &rhs) NCURSES_CPP_NOEXCEPT {
+ value_ &= static_cast<full_attrs ::value_type>(rhs);
+ return *this;
+ }
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator|=(full_attrs const &rhs) NCURSES_CPP_NOEXCEPT {
+ value_ |= static_cast<full_attrs ::value_type>(rhs);
+ return *this;
+ }
+ NCURSES_CPP_CONSTEXPR_14 curs_char &
+ operator^=(full_attrs const &rhs) NCURSES_CPP_NOEXCEPT {
+ value_ ^= static_cast<full_attrs ::value_type>(rhs);
+ return *this;
+ }
NCURSES_CPP_CONSTEXPR bool operator!() const NCURSES_CPP_NOEXCEPT {
return !value_;
@@ -141,6 +194,11 @@ public:
return static_cast<char>(value_);
}
+ explicit NCURSES_CPP_CONSTEXPR
+ operator value_type() const NCURSES_CPP_NOEXCEPT {
+ return value_;
+ }
+
#if defined(NCURSES_CPP_CHAR_VALUE_AS_PUBLIC)
public:
#else
@@ -150,53 +208,175 @@ private:
};
// 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(!=)
+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
-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(^)
+// 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<curs_char ::value_type>(c) &
+ static_cast<curs_char ::value_type>(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<curs_char ::value_type>(c) |
+ static_cast<curs_char ::value_type>(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<curs_char ::value_type>(c) ^
+ static_cast<curs_char ::value_type>(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<curs_char ::value_type>(c) &
+ static_cast<curs_char ::value_type>(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<curs_char ::value_type>(c) |
+ static_cast<curs_char ::value_type>(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<curs_char ::value_type>(c) ^
+ static_cast<curs_char ::value_type>(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<curs_char ::value_type>(c) &
+ static_cast<curs_char ::value_type>(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<curs_char ::value_type>(c) |
+ static_cast<curs_char ::value_type>(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<curs_char ::value_type>(c) ^
+ static_cast<curs_char ::value_type>(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<curs_char ::value_type>(c) &
+ static_cast<curs_char ::value_type>(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<curs_char ::value_type>(c) |
+ static_cast<curs_char ::value_type>(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<curs_char ::value_type>(c) ^
+ static_cast<curs_char ::value_type>(other));
+}
} // namespace NCURSES_CPP_NAMESPACE