#ifndef INCLUDE_NCURSES_WINDOW_HPP_ #define INCLUDE_NCURSES_WINDOW_HPP_ #include #include namespace NCURSES_CPP_NAMESPACE { class window { public: // 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 subwins_; }; } // namespace NCURSES_CPP_NAMESPACE #endif // INCLUDE_NCURSES_WINDOW_HPP_