The Battle for Wesnoth  1.13.4+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 - 2016 by Mark de Wever <[email protected]>
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 #ifndef GUI_WIDGETS_AUXILIARY_ITERATOR_ITERATOR_HPP_INCLUDED
23 #define GUI_WIDGETS_AUXILIARY_ITERATOR_ITERATOR_HPP_INCLUDED
24 
26 
27 namespace gui2
28 {
29 
30 namespace iterator
31 {
32 
33 /**
34  * The iterator class.
35  *
36  * See @ref gui2_iterator_iterator for more information.
37  */
38 template <class order>
39 class titerator : private order, private boost::noncopyable
40 {
41 public:
42  /**
43  * Constructor.
44  *
45  * @param root The widget where to start the iteration.
46  */
47  titerator(twidget& 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 trange_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 
104 } // namespace iterator
105 
106 } // namespace gui2
107 
108 #endif
GLuint GLdouble GLdouble GLint GLint order
Definition: glew.h:2972
titerator(twidget &root)
Constructor.
Definition: iterator.hpp:47
bool next()
Visit the next widget.
Definition: iterator.hpp:75
twidget & operator*()
Returns the current widget.
Definition: iterator.hpp:92
The iterator class.
Definition: iterator.hpp:39
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
twidget * operator->()
See operator*.
Definition: iterator.hpp:98
titerator< order > & operator++()
See next.
Definition: iterator.hpp:81
#define next(ls)
Definition: llex.cpp:27
tfloat< T, S > operator*(tfloat< T, S > lhs, const tfloat< T, S > rhs)
Base class for all widgets.
Definition: widget.hpp:49
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
bool at_end() const
Has the iterator reached the end?
Definition: iterator.hpp:58