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