The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
walker.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 #pragma once
16 
17 namespace gui2
18 {
19 
20 class widget;
21 
22 namespace iteration
23 {
24 
25 /** The walker abstract base class. */
27 {
28 public:
29  virtual ~walker_base()
30  {
31  }
32 
33  /** The level to walk at. */
34  enum level {
35  /** Visit the widget itself. */
36  self,
37  /** Visit its nested grid. */
38  internal,
39  /** Visit the children of its nested grid. */
41  };
42 
43  /**
44  * The state of the walker.
45  *
46  * The enum is used to return the state of @ref next.
47  */
48  enum state_t {
49  /**
50  * When calling next the following it has the following results.
51  *
52  * @pre at_end == false
53  *
54  * @post the next widget became the current one.
55  * @post at_end == false
56  */
58 
59  /**
60  * When calling next the following it has the following results.
61  *
62  * @pre at_end == false
63  *
64  * @post there is no longer a current widget.
65  * @post at_end == true
66  */
67  ,
69 
70  /**
71  * When calling next the following it has the following results.
72  *
73  * @pre at_end == true
74  *
75  * @post at_end == true
76  */
77  ,
79  };
80 
81  /**
82  * Make the next widget the current one.
83  *
84  * @param level Determines on which level the next one should
85  * be selected.
86  *
87  * @returns The status of the operation.
88  */
89  virtual state_t next(const level level) = 0;
90 
91  /**
92  * Returns whether the current widget is valid.
93  *
94  * @param level Determines on which level the test should be
95  * executed.
96  *
97  *
98  * @returns Whether the current widget is valid.
99  */
100  virtual bool at_end(const level level) const = 0;
101 
102  /**
103  * Returns a pointer to the current widget.
104  *
105  * @pre The following assertion holds:
106  * @code at_end(level) == false @endcode
107  *
108  * @param level Determines from which level should the
109  * current widget be returned.
110  *
111  * @returns Pointer to the current widget.
112  */
113  virtual gui2::widget* get(const level level) = 0;
114 };
115 
116 } // namespace iteration
117 
118 } // namespace gui2
When calling next the following it has the following results.
Definition: walker.hpp:68
When calling next the following it has the following results.
Definition: walker.hpp:57
level
The level to walk at.
Definition: walker.hpp:34
Base class for all widgets.
Definition: widget.hpp:48
virtual state_t next(const level level)=0
Make the next widget the current one.
Generic file dialog.
Definition: field-fwd.hpp:22
state_t
The state of the walker.
Definition: walker.hpp:48
The walker abstract base class.
Definition: walker.hpp:26
virtual bool at_end(const level level) const =0
Returns whether the current widget is valid.
Visit the children of its nested grid.
Definition: walker.hpp:40