diff options
author | frosch <frosch@openttd.org> | 2021-05-09 18:35:49 +0200 |
---|---|---|
committer | frosch <github@elsenhans.name> | 2021-05-12 23:22:41 +0200 |
commit | aba239479b6e75990cc914331bd2d735b8918628 (patch) | |
tree | 4769767f8f9608e4693c3dd0273521d197270d73 | |
parent | 95abdfdef9c9c79e79cb3f32bc54aec66e224d7e (diff) | |
download | openttd-aba239479b6e75990cc914331bd2d735b8918628.tar.xz |
Codechange: remove excessive templating in favour of a single const_cast.
The const_cast will be removed again in a later commit.
-rw-r--r-- | src/window_gui.h | 34 |
1 files changed, 14 insertions, 20 deletions
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 <class T, bool Tfront> + template <bool Tfront> 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<Window *>(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 <class T, bool Tfront> + template <bool Tfront> struct Iterate { - Iterate(T *from) : from(from) {} - WindowIterator<T, Tfront> begin() { return WindowIterator<T, Tfront>(this->from); } - WindowIterator<T, Tfront> end() { return WindowIterator<T, Tfront>(nullptr); } + Iterate(const Window *from) : from(from) {} + WindowIterator<Tfront> begin() { return WindowIterator<Tfront>(this->from); } + WindowIterator<Tfront> end() { return WindowIterator<Tfront>(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 <class T = Window> - static Iterate<T, false> IterateFromBack(T *from = _z_back_window) { return Iterate<T, false>(from); } + static Iterate<false> IterateFromBack(const Window *from = _z_back_window) { return Iterate<false>(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 <class T = Window> - static Iterate<T, true> IterateFromFront(T *from = _z_front_window) { return Iterate<T, true>(from); } + static Iterate<true> IterateFromFront(const Window *from = _z_front_window) { return Iterate<true>(from); } }; /** |