From aba239479b6e75990cc914331bd2d735b8918628 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 9 May 2021 18:35:49 +0200 Subject: Codechange: remove excessive templating in favour of a single const_cast. The const_cast will be removed again in a later commit. --- src/window_gui.h | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'src/window_gui.h') diff --git a/src/window_gui.h b/src/window_gui.h index 66c867a54..cf4ebcf73 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -813,65 +813,59 @@ public: /** * Iterator to iterate all valid Windows - * @tparam T Type of the class/struct that is going to be iterated * @tparam Tfront Wether we iterate from front */ - template + template struct WindowIterator { - typedef T value_type; - typedef T *pointer; - typedef T &reference; + typedef Window *value_type; + typedef value_type *pointer; + typedef value_type &reference; typedef size_t difference_type; typedef std::forward_iterator_tag iterator_category; - explicit WindowIterator(T *start) : w(start) + explicit WindowIterator(const Window *start) : w(const_cast(start)) { this->Validate(); } bool operator==(const WindowIterator &other) const { return this->w == other.w; } bool operator!=(const WindowIterator &other) const { return !(*this == other); } - T * operator*() const { return this->w; } + Window * operator*() const { return this->w; } WindowIterator & operator++() { this->Next(); this->Validate(); return *this; } private: - T *w; + Window *w; void Validate() { while (this->w != nullptr && this->w->window_class == WC_INVALID) this->Next(); } void Next() { if (this->w != nullptr) this->w = Tfront ? this->w->z_back : this->w->z_front; } }; /** * Iterable ensemble of all valid Windows - * @tparam T Type of the class/struct that is going to be iterated * @tparam Tfront Wether we iterate from front */ - template + template struct Iterate { - Iterate(T *from) : from(from) {} - WindowIterator begin() { return WindowIterator(this->from); } - WindowIterator end() { return WindowIterator(nullptr); } + Iterate(const Window *from) : from(from) {} + WindowIterator begin() { return WindowIterator(this->from); } + WindowIterator end() { return WindowIterator(nullptr); } bool empty() { return this->begin() == this->end(); } private: - T *from; + const Window *from; }; /** * Returns an iterable ensemble of all valid Window from back to front - * @tparam T Type of the class/struct that is going to be iterated * @param from index of the first Window to consider * @return an iterable ensemble of all valid Window */ - template - static Iterate IterateFromBack(T *from = _z_back_window) { return Iterate(from); } + static Iterate IterateFromBack(const Window *from = _z_back_window) { return Iterate(from); } /** * Returns an iterable ensemble of all valid Window from front to back - * @tparam T Type of the class/struct that is going to be iterated * @param from index of the first Window to consider * @return an iterable ensemble of all valid Window */ - template - static Iterate IterateFromFront(T *from = _z_front_window) { return Iterate(from); } + static Iterate IterateFromFront(const Window *from = _z_front_window) { return Iterate(from); } }; /** -- cgit v1.2.3-54-g00ecf