The Battle for Wesnoth  1.17.0-dev
iterator.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2021
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
28 {
29 
30 namespace iteration
31 {
32 
33 /**
34  * The iterator class.
35  *
36  * See @ref gui2_iterator_iterator for more information.
37  */
38 template <class order>
39 class iterator : private order
40 {
41 public:
42  iterator(const iterator&) = delete;
43  iterator& operator=(const iterator&) = delete;
44 
45  /**
46  * Constructor.
47  *
48  * @param root The widget where to start the iteration.
49  */
50  iterator(widget& root) : order(root)
51  {
52  }
53 
54  /**
55  * Has the iterator reached the end?
56  *
57  * @returns The status.
58  * @retval [true] At the end.
59  * @retval [false] Not at the end.
60  */
61  bool at_end() const
62  {
63  return order::at_end();
64  }
65 
66  /**
67  * Visit the next widget.
68  *
69  * @pre The following assertion holds:
70  * @code at_end() == false @endcode
71  *
72  * @throws A @ref range_error exception upon pre
73  * condition violation.
74  *
75  * @returns Whether the next widget can be safely
76  * deferred.
77  */
78  bool next()
79  {
80  return order::next();
81  }
82 
83  /** See @ref next. */
85  {
86  order::next();
87  return *this;
88  }
89 
90  /**
91  * Returns the current widget.
92  *
93  * @returns The current widget.
94  */
96  {
97  return order::operator*();
98  }
99 
100  /** See @ref operator*. */
102  {
103  return &(operator*());
104  }
105 
106  /** See @ref operator*. */
107  widget* get()
108  {
109  return operator->();
110  }
111 };
112 
113 /* Helper aliases templates. */
114 
115 template<bool visit_self, bool visit_internal, bool visit_child>
117 
118 template<bool visit_self, bool visit_internal, bool visit_child>
120 
121 } // namespace iteration
122 
123 } // namespace gui2
bool next()
Visit the next widget.
Definition: iterator.hpp:78
iterator< order > & operator++()
See next.
Definition: iterator.hpp:84
widget * operator->()
See operator*.
Definition: iterator.hpp:101
Base class for all widgets.
Definition: widget.hpp:49
iterator(const iterator &)=delete
Generic file dialog.
Definition: field-fwd.hpp:23
bool at_end() const
Has the iterator reached the end?
Definition: iterator.hpp:61
iterator & operator=(const iterator &)=delete
iterator(widget &root)
Constructor.
Definition: iterator.hpp:50
widget & operator*()
Returns the current widget.
Definition: iterator.hpp:95
The iterator class.
Definition: iterator.hpp:39
#define next(ls)
Definition: llex.cpp:32