The Battle for Wesnoth  1.17.4+dev
iterator.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2022
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Contains the base iterator class for the gui2 widgets.
19  *
20  * See @ref gui2_iterator for more information.
21  */
22 
23 #pragma once
24 
26 
27 namespace gui2::iteration
28 {
29 
30 /**
31  * The iterator class.
32  *
33  * See @ref gui2_iterator_iterator for more information.
34  */
35 template <class order>
36 class iterator : private order
37 {
38 public:
39  iterator(const iterator&) = delete;
40  iterator& operator=(const iterator&) = delete;
41 
42  /**
43  * Constructor.
44  *
45  * @param root The widget where to start the iteration.
46  */
47  iterator(widget& root) : order(root)
48  {
49  }
50 
51  /**
52  * Has the iterator reached the end?
53  *
54  * @returns The status.
55  * @retval [true] At the end.
56  * @retval [false] Not at the end.
57  */
58  bool at_end() const
59  {
60  return order::at_end();
61  }
62 
63  /**
64  * Visit the next widget.
65  *
66  * @pre The following assertion holds:
67  * @code at_end() == false @endcode
68  *
69  * @throws A @ref range_error exception upon pre
70  * condition violation.
71  *
72  * @returns Whether the next widget can be safely
73  * deferred.
74  */
75  bool next()
76  {
77  return order::next();
78  }
79 
80  /** See @ref next. */
82  {
83  order::next();
84  return *this;
85  }
86 
87  /**
88  * Returns the current widget.
89  *
90  * @returns The current widget.
91  */
93  {
94  return order::operator*();
95  }
96 
97  /** See @ref operator*. */
99  {
100  return &(operator*());
101  }
102 
103  /** See @ref operator*. */
104  widget* get()
105  {
106  return operator->();
107  }
108 };
109 
110 /* Helper aliases templates. */
111 
112 template<bool visit_self, bool visit_internal, bool visit_child>
114 
115 template<bool visit_self, bool visit_internal, bool visit_child>
117 
118 } // namespace gui2::iteration
bool next()
Visit the next widget.
Definition: iterator.hpp:75
iterator< order > & operator++()
See next.
Definition: iterator.hpp:81
widget * operator->()
See operator*.
Definition: iterator.hpp:98
Base class for all widgets.
Definition: widget.hpp:49
iterator(const iterator &)=delete
bool at_end() const
Has the iterator reached the end?
Definition: iterator.hpp:58
iterator & operator=(const iterator &)=delete
iterator(widget &root)
Constructor.
Definition: iterator.hpp:47
widget & operator*()
Returns the current widget.
Definition: iterator.hpp:92
The iterator class.
Definition: iterator.hpp:36