The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
policy_visit.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 
18 
19 #include <cstring>
20 
21 namespace gui2
22 {
23 
24 namespace iteration
25 {
26 
27 namespace policy
28 {
29 
30 namespace visit
31 {
32 
33 /**
34  * This policy skips the current level.
35  */
37 {
38 public:
39  /**
40  * Acts like @ref walker_base::next for the level where the policy is used.
41  */
43  {
44  return walker_base::fail;
45  }
46 
47  /**
48  * Acts like @ref walker_base::at_end for the level where the policy is used.
49  */
50  bool at_end(const walker_base&) const
51  {
52  return true;
53  }
54 
55  /**
56  * Acts like @ref walker_base::get for the level where the policy is used.
57  */
59  {
60  return nullptr;
61  }
62 };
63 
64 /**
65  * This policy tries to visit the current level.
66  *
67  * @tparam level The level to visit.
68  */
69 template <walker_base::level level>
71 {
72 public:
73  /**
74  * Acts like @ref walker_base::next for the level where the policy is used.
75  */
77  {
78  return visitor.next(level);
79  }
80 
81  /**
82  * Acts like @ref walker_base::at_end for the level where the policy is used.
83  */
84  bool at_end(const walker_base& visitor) const
85  {
86  return visitor.at_end(level);
87  }
88 
89  /**
90  * Acts like @ref walker_base::get for the level where the policy is used.
91  */
92  gui2::widget* get(walker_base& visitor)
93  {
94  return visitor.get(level);
95  }
96 };
97 
98 } // namespace visit
99 
100 /**
101  * Helper class to select to visit or skip a level.
102  *
103  * @tparam level The level to determine the policy for.
104  */
105 template <bool, walker_base::level level>
107 {
108 };
109 
110 /** Specialized to select the @ref visit::skip_level policy. */
111 template <walker_base::level level>
112 class visit_level<false, level> : public visit::skip_level
113 {
114 };
115 
116 /** Specialized to select the @ref visit::visit_level policy. */
117 template <walker_base::level level>
118 class visit_level<true, level> : public visit::visit_level<level>
119 {
120 };
121 
122 } // namespace policy
123 
124 } // namespace iteration
125 
126 } // namespace gui2
walker_base::state_t next(walker_base &)
Acts like walker_base::next for the level where the policy is used.
Helper class to select to visit or skip a level.
Base class for all widgets.
Definition: widget.hpp:48
virtual state_t next(const level level)=0
Make the next widget the current one.
This policy skips the current level.
Generic file dialog.
Definition: text.hpp:37
This policy tries to visit the current level.
state_t
The state of the walker.
Definition: walker.hpp:48
The walker abstract base class.
Definition: walker.hpp:26
bool at_end(const walker_base &) const
Acts like walker_base::at_end for the level where the policy is used.
virtual bool at_end(const level level) const =0
Returns whether the current widget is valid.
walker_base::state_t next(walker_base &visitor)
Acts like walker_base::next for the level where the policy is used.
bool at_end(const walker_base &visitor) const
Acts like walker_base::at_end for the level where the policy is used.