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