The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
walker_tree_node.cpp
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 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include <cassert>
20 
21 namespace gui2
22 {
23 
24 namespace iteration
25 {
26 
28  : children_(children), widget_(&node), itor_(children.begin())
29 {
30 }
31 
33 {
34  if(at_end(level)) {
35  return fail;
36  }
37 
38  switch(level) {
39  case self:
40  if(widget_) {
41  widget_ = nullptr;
42  return invalid;
43  }
44  FALLTHROUGH;
45  case internal:
46  assert(false);
47  return fail;
48  case child:
49  if(itor_ != children_.end()) {
50  ++itor_;
51  return itor_ == children_.end() ? invalid : valid;
52  }
53  }
54 
55  assert(false);
56  return fail;
57 }
58 
59 bool tree_node::at_end(const level level) const
60 {
61  switch(level) {
62  case self:
63  return widget_ == nullptr;
64  case internal:
65  return true;
66  case child:
67  return (itor_ == children_.end());
68  }
69 
70  assert(false);
71  return true;
72 }
73 
75 {
76  switch(level) {
77  case self:
78  return widget_;
79  case internal:
80  return nullptr;
81  case child:
82  if(itor_ == children_.end()) {
83  return nullptr;
84  } else {
85  return itor_.operator->()->get();
86  }
87  }
88 
89  assert(false);
90  return nullptr;
91 }
92 
93 } // namespace iteration
94 
95 } // namespace gui2
std::vector< std::unique_ptr< tree_view_node >> node_children_vector
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 gui2::widget * get(const level level)
Inherited from gui2::iteration::walker_base.
tree_node(gui2::tree_view_node &node, tree_view_node::node_children_vector &children)
Constructor.
Generic file dialog.
Definition: text.hpp:37
gui2::widget * widget_
The node which the walker is attached to.
state_t
The state of the walker.
Definition: walker.hpp:48
virtual state_t next(const level level)
Inherited from gui2::iteration::walker_base.
virtual bool at_end(const level level) const
Inherited from gui2::iteration::walker_base.
tree_view_node::node_children_vector & children_
The children of the node which the walker is attached to.
Visit the children of its nested grid.
Definition: walker.hpp:40
tree_view_node::node_children_vector::iterator itor_
The iterator to the children of node_.