The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
walker_grid.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2011 - 2025
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#define GETTEXT_DOMAIN "wesnoth-lib"
17
19
20#include <cassert>
21
22namespace gui2::iteration
23{
24
26 : grid_(grid), widget_(&grid), itor_(grid.begin())
27{
28}
29
31{
32 if(at_end(level)) {
33 return fail;
34 }
35
36 switch(level) {
37 case self:
38 if(widget_) {
39 widget_ = nullptr;
40 return invalid;
41 }
42 [[fallthrough]];
43 case internal:
44 assert(false);
45 return fail;
46 case child:
47 if(itor_ != grid_.end()) {
48 ++itor_;
49 return itor_ == grid_.end() ? invalid : valid;
50 }
51 }
52
53 assert(false);
54 return fail;
55}
56
57bool grid::at_end(const level level) const
58{
59 switch(level) {
60 case self:
61 return widget_ == nullptr;
62 case internal:
63 return true;
64 case child:
65 return (itor_ == grid_.end());
66 }
67
68 assert(false);
69 return true;
70}
71
73{
74 switch(level) {
75 case self:
76 return widget_;
77 case internal:
78 return nullptr;
79 case child:
80 if(itor_ == grid_.end()) {
81 return nullptr;
82 } else {
83 return *itor_;
84 }
85 }
86
87 assert(false);
88 return nullptr;
89}
90
91} // namespace gui2::iteration
Base container class.
Definition grid.hpp:32
iterator end()
Definition grid.hpp:482
A walker for a gui2::grid.
gui2::widget * widget_
The grid which the walker is attached to.
grid(gui2::grid &grid)
Constructor.
virtual gui2::widget * get(const level level)
Inherited from gui2::iteration::walker_base.
virtual bool at_end(const level level) const
Inherited from gui2::iteration::walker_base.
virtual state_t next(const level level)
Inherited from gui2::iteration::walker_base.
gui2::grid & grid_
The grid which the walker is attached to.
gui2::grid::iterator itor_
The iterator to the children of grid_.
level
The level to walk at.
Definition walker.hpp:35
@ internal
Visit its nested grid.
Definition walker.hpp:39
@ self
Visit the widget itself.
Definition walker.hpp:37
@ 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
Base class for all widgets.
Definition widget.hpp:55