The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
walker_grid.cpp
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 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include "asserts.hpp"
20 
21 namespace gui2
22 {
23 
24 namespace iterator
25 {
26 
28  : grid_(grid), widget_(&grid), itor_(grid.begin())
29 {
30 }
31 
33 {
34  if(at_end(level)) {
35  return fail;
36  }
37 
38  switch(level) {
39  case widget:
40  if(widget_) {
41  widget_ = nullptr;
42  return invalid;
43  } else {
44  /* FALL DOWN */
45  }
46  case grid:
47  assert(false);
48  return fail;
49  case child:
50  if(itor_ == grid_.end()) {
51  /* FALL DOWN */
52  } else {
53  ++itor_;
54  return itor_ == grid_.end() ? invalid : valid;
55  }
56  }
57 
58  assert(false);
59  return fail;
60 }
61 
62 bool tgrid::at_end(const tlevel level) const
63 {
64  switch(level) {
65  case widget:
66  return widget_ == nullptr;
67  case grid:
68  return true;
69  case child:
70  return (itor_ == grid_.end());
71  }
72 
73  assert(false);
74  return true;
75 }
76 
78 {
79  switch(level) {
80  case widget:
81  return widget_;
82  case grid:
83  return nullptr;
84  case child:
85  if(itor_ == grid_.end()) {
86  return nullptr;
87  } else {
88  return *itor_;
89  }
90  }
91 
92  assert(false);
93  return nullptr;
94 }
95 
96 } // namespace iterator
97 
98 } // namespace gui2
Visit the widget itself.
Definition: walker.hpp:37
GLint level
Definition: glew.h:1220
virtual tstate next(const tlevel level)
Inherited from gui2::iterator::twalker_.
Definition: walker_grid.cpp:32
tstate
The state of the walker.
Definition: walker.hpp:51
Base container class.
Definition: grid.hpp:29
gui2::tgrid & grid_
The grid which the walker is attached to.
Definition: walker_grid.hpp:50
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
gui2::twidget * widget_
The grid which the walker is attached to.
Definition: walker_grid.hpp:58
virtual bool at_end(const tlevel level) const
Inherited from gui2::iterator::twalker_.
Definition: walker_grid.cpp:62
When calling next the following it has the following results.
Definition: walker.hpp:60
virtual gui2::twidget * get(const tlevel level)
Inherited from gui2::iterator::twalker_.
Definition: walker_grid.cpp:77
gui2::tgrid::iterator itor_
The iterator to the children of grid_.
Definition: walker_grid.hpp:66
When calling next the following it has the following results.
Definition: walker.hpp:71
tgrid(gui2::tgrid &grid)
Constructor.
Definition: walker_grid.cpp:27
tlevel
The level to walk at.
Definition: walker.hpp:35
Base class for all widgets.
Definition: widget.hpp:49
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
iterator end()
Definition: grid.hpp:444
Visit the children of its nested grid.
Definition: walker.hpp:40