diff options
-rw-r--r-- | include/ncurses/basic_winbuf.hpp | 48 | ||||
-rw-r--r-- | include/ncurses/colors.hpp | 7 | ||||
-rw-r--r-- | include/ncurses/curs_char.hpp | 424 | ||||
-rw-r--r-- | include/ncurses/utils/flags.hpp | 7 | ||||
-rw-r--r-- | include/ncurses/utils/multiflags.hpp | 12 | ||||
-rw-r--r-- | include/ncurses/window.hpp | 50 | ||||
-rw-r--r-- | samples/01_simple_window/simple_window.cpp | 1 | ||||
-rw-r--r-- | tests/curs_char/curs_char.cpp | 12 | ||||
-rw-r--r-- | tests/multiflags/multiflags.cpp | 4 |
9 files changed, 425 insertions, 140 deletions
diff --git a/include/ncurses/basic_winbuf.hpp b/include/ncurses/basic_winbuf.hpp new file mode 100644 index 0000000..adc424a --- /dev/null +++ b/include/ncurses/basic_winbuf.hpp @@ -0,0 +1,48 @@ +#ifndef INCLUDE_NCURSES_BASIC_WINBUF_HPP_ +#define INCLUDE_NCURSES_BASIC_WINBUF_HPP_ + +#include <streambuf> + +#include <ncurses.h> + +#include <ncurses/utils/preamble.hpp> +#include <ncurses/window.hpp> + +namespace NCURSES_CPP_NAMESPACE { + +template <typename CharT, typename Traits = std::char_traits<CharT>> +class basic_winbuf final : public std::basic_streambuf<CharT, Traits> { +public: + using Base = std::basic_streambuf<CharT, Traits>; + using typename Base::char_type; + using typename Base::int_type; + using typename Base::off_type; + using typename Base::pos_type; + + explicit basic_winbuf(window &win) : win_(win), x_pos_(0), y_pos_(0) {} + + /*int_type uflow() override {}*/ + /*int_type underflow() override {}*/ + int_type overflow(int_type ch = Traits::eof()) override {} + std::streamsize xsputn(const char_type *s, std::streamsize n) override { + // TODO: change to call to new trait's callback for each supported type + // for char/wchar_t/other_chars use wadd(w)nstr + // for curs_char/curs_wchar use for loop of wadd(w)ch + waddnstr(static_cast<WINDOW *>(win_), s, n); + } + // TODO: overload << operator with full_attrs to do attr_on, etc... + + void pos(int y_pos, int x_pos) NCURSES_CPP_NOEXCEPT { + y_pos_ = y_pos; + x_pos_ = x_pos; + } + +private: + window &win_; + int x_pos_; + int y_pos_; +}; + +} // namespace NCURSES_CPP_NAMESPACE + +#endif // INCLUDE_NCURSES_BASIC_WINBUF_HPP_ diff --git a/include/ncurses/colors.hpp b/include/ncurses/colors.hpp index a0622a9..e045ebb 100644 --- a/include/ncurses/colors.hpp +++ b/include/ncurses/colors.hpp @@ -8,6 +8,7 @@ namespace NCURSES_CPP_NAMESPACE { +// TODO: there is no usage for this for now enum class curs_color { black = COLOR_BLACK, red = COLOR_RED, @@ -25,17 +26,19 @@ struct rgb_color { unsigned char b; }; -NCURSES_CPP_CONSTEXPR static int +NCURSES_CPP_CONSTEXPR_INLINE static int rgb_to_curses(unsigned char c) NCURSES_CPP_NOEXCEPT { return static_cast<int>(c) * 1000 / 255; } -NCURSES_CPP_CONSTEXPR static unsigned char +NCURSES_CPP_CONSTEXPR_INLINE static unsigned char curses_to_rgb(int c) NCURSES_CPP_NOEXCEPT { return static_cast<unsigned char>((c * 255 / 1000) + (c * 255 % 1000 == 0 ? 0 : 1)); } +// TODO: start_color maybe needs to be defined somewhere else + inline bool has_colors() { return static_cast<bool>(::has_colors()); } inline bool can_change_color() { 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 diff --git a/include/ncurses/utils/flags.hpp b/include/ncurses/utils/flags.hpp index 69b7aa9..e379aaf 100644 --- a/include/ncurses/utils/flags.hpp +++ b/include/ncurses/utils/flags.hpp @@ -22,7 +22,7 @@ public: : mask_(static_cast<mask_type>(bit)) {} NCURSES_CPP_CONSTEXPR - flags(flags<BitType> const &rhs) NCURSES_CPP_NOEXCEPT = default; + flags(flags<BitType> const &rhs) NCURSES_CPP_NOEXCEPT : mask_(rhs.mask_) {} NCURSES_CPP_CONSTEXPR explicit flags(mask_type flags) : mask_(flags) {} @@ -70,7 +70,10 @@ public: // assignment operators NCURSES_CPP_CONSTEXPR_14 flags<BitType> & - operator=(flags<BitType> const &rhs) NCURSES_CPP_NOEXCEPT = default; + operator=(flags<BitType> const &rhs) NCURSES_CPP_NOEXCEPT { + mask_ = rhs.mask_; + return *this; + } NCURSES_CPP_ASSIGNMENT(&) NCURSES_CPP_ASSIGNMENT(|) diff --git a/include/ncurses/utils/multiflags.hpp b/include/ncurses/utils/multiflags.hpp index e6af6a6..caed9af 100644 --- a/include/ncurses/utils/multiflags.hpp +++ b/include/ncurses/utils/multiflags.hpp @@ -37,8 +37,8 @@ public: : value_(static_cast<value_type>(flag)) {} NCURSES_CPP_CONSTEXPR - multiflags(multiflags<BitType, SecondBitType> const &rhs) - NCURSES_CPP_NOEXCEPT = default; + multiflags(multiflags<BitType, SecondBitType> const &rhs) NCURSES_CPP_NOEXCEPT + : value_(rhs.value_) {} NCURSES_CPP_CONSTEXPR explicit multiflags(value_type multiflags) : value_(multiflags) {} @@ -88,9 +88,11 @@ public: return *this; \ } - NCURSES_CPP_CONSTEXPR_14 multiflags<BitType, SecondBitType> & - operator=(multiflags<BitType, SecondBitType> const &rhs) - NCURSES_CPP_NOEXCEPT = default; + NCURSES_CPP_CONSTEXPR_14 multiflags<BitType, SecondBitType> &operator=( + multiflags<BitType, SecondBitType> const &rhs) NCURSES_CPP_NOEXCEPT { + value_ = rhs.value_; + return *this; + } NCURSES_CPP_ASSIGNMENT(&) NCURSES_CPP_ASSIGNMENT(|) diff --git a/include/ncurses/window.hpp b/include/ncurses/window.hpp index 7d26776..fc1c87c 100644 --- a/include/ncurses/window.hpp +++ b/include/ncurses/window.hpp @@ -1,15 +1,61 @@ #ifndef INCLUDE_NCURSES_WINDOW_HPP_ #define INCLUDE_NCURSES_WINDOW_HPP_ -#include <ncurses/utils/macros.hpp> +#include <vector> + +#include <ncurses/utils/preamble.hpp> namespace NCURSES_CPP_NAMESPACE { class window { public: - window(int i); + // basic + window(int lines, int cols, int begin_y, int begin_x) + : win_(newwin(lines, cols, begin_y, begin_x)), parent_(nullptr) {} + + window(window &parent, int lines, int cols, int begin_y, int begin_x) + : win_(subwin(parent.win_, lines, cols, begin_y, begin_x)), + parent_(&parent) {} + + window(const window &other) + : win_(dupwin(other.win_)), parent_(other.parent_) {} + + window(window &&other) : win_(other.win_) { other.win_ = nullptr; } + + window &operator=(const window &other) { + delwin(win_); + win_ = dupwin(other.win_); + return *this; + } + + window &operator=(window &&other) { + delwin(win_); + win_ = other.win_; + other.win_ = nullptr; + return *this; + } + + explicit operator WINDOW *() const { return win_; } + + virtual ~window() { free_window(); } + + // interface private: + void add_subwin(window &win) { subwins_.push_back(&win); } + void free_window() { + if (win_) { + delwin(win_); + for (auto it : subwins_) { + it->free_window(); + } + } + win_ = nullptr; + } + + WINDOW *win_; + window *parent_; + std::vector<window *> subwins_; }; } // namespace NCURSES_CPP_NAMESPACE diff --git a/samples/01_simple_window/simple_window.cpp b/samples/01_simple_window/simple_window.cpp index adba654..c0853e4 100644 --- a/samples/01_simple_window/simple_window.cpp +++ b/samples/01_simple_window/simple_window.cpp @@ -1,3 +1,4 @@ +#include <ncurses.h> #include <ncurses/ncurses.hpp> int main(int argc, char *argv[]) { diff --git a/tests/curs_char/curs_char.cpp b/tests/curs_char/curs_char.cpp index a076e89..f9a924e 100644 --- a/tests/curs_char/curs_char.cpp +++ b/tests/curs_char/curs_char.cpp @@ -1,4 +1,6 @@ #include <cassert> +#include <iostream> + #define NCURSES_CPP_CHAR_VALUE_AS_PUBLIC #include <ncurses.h> @@ -101,28 +103,28 @@ int main(int argc, char *argv[]) { { curs_char c = 'a'; c |= (attr::altcharset | attr::blink); - assert(c.value_ == ('a' & (A_ALTCHARSET | A_BLINK))); + assert(c.value_ == ('a' | (A_ALTCHARSET | A_BLINK))); } { curs_char c = 'a'; c ^= (attr::altcharset | attr::blink); - assert(c.value_ == ('a' & (A_ALTCHARSET | A_BLINK))); + assert(c.value_ == ('a' ^ (A_ALTCHARSET | A_BLINK))); } // # With color_pair { curs_char c = 'a'; c &= color_pair(7); - assert(c.value_ == ('a' & (COLOR_PAIR(10)))); + assert(c.value_ == ('a' & (COLOR_PAIR(7)))); } { curs_char c = 'a'; c |= color_pair(7); - assert(c.value_ == ('a' | (COLOR_PAIR(10)))); + assert(c.value_ == ('a' | (COLOR_PAIR(7)))); } { curs_char c = 'a'; c ^= color_pair(7); - assert(c.value_ == ('a' ^ (COLOR_PAIR(10)))); + assert(c.value_ == ('a' ^ (COLOR_PAIR(7)))); } // // # With full_attrs diff --git a/tests/multiflags/multiflags.cpp b/tests/multiflags/multiflags.cpp index e689892..f1ff442 100644 --- a/tests/multiflags/multiflags.cpp +++ b/tests/multiflags/multiflags.cpp @@ -8,9 +8,9 @@ using namespace ncurses; -template <> struct is_applyable<color_pair, attr> : std::true_type {}; +template <> struct ncurses::is_applyable<color_pair, attr> : std::true_type {}; -using full_attrs = multiflags<attr, color_pair>; +using full_attrs = ncurses::multiflags<attr, color_pair>; int main(int argc, char *argv[]) { { |