The Battle for Wesnoth  1.17.0-dev
policy_visit.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2021
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 
19 
20 #include <cstring>
21 
22 namespace gui2
23 {
24 
25 namespace iteration
26 {
27 
28 namespace policy
29 {
30 
31 namespace visit
32 {
33 
34 /**
35  * This policy skips the current level.
36  */
38 {
39 public:
40  /**
41  * Acts like @ref walker_base::next for the level where the policy is used.
42  */
44  {
45  return walker_base::fail;
46  }
47 
48  /**
49  * Acts like @ref walker_base::at_end for the level where the policy is used.
50  */
51  bool at_end(const walker_base&) const
52  {
53  return true;
54  }
55 
56  /**
57  * Acts like @ref walker_base::get for the level where the policy is used.
58  */
60  {
61  return nullptr;
62  }
63 };
64 
65 /**
66  * This policy tries to visit the current level.
67  *
68  * @tparam level The level to visit.
69  */
70 template <walker_base::level level>
72 {
73 public:
74  /**
75  * Acts like @ref walker_base::next for the level where the policy is used.
76  */
78  {
79  return visitor.next(level);
80  }
81 
82  /**
83  * Acts like @ref walker_base::at_end for the level where the policy is used.
84  */
85  bool at_end(const walker_base& visitor) const
86  {
87  return visitor.at_end(level);
88  }
89 
90  /**
91  * Acts like @ref walker_base::get for the level where the policy is used.
92  */
93  gui2::widget* get(walker_base& visitor)
94  {
95  return visitor.get(level);
96  }
97 };
98 
99 } // namespace visit
100 
101 /**
102  * Helper class to select to visit or skip a level.
103  *
104  * @tparam level The level to determine the policy for.
105  */
106 template <bool, walker_base::level level>
108 {
109 };
110 
111 /** Specialized to select the @ref visit::skip_level policy. */
112 template <walker_base::level level>
113 class visit_level<false, level> : public visit::skip_level
114 {
115 };
116 
117 /** Specialized to select the @ref visit::visit_level policy. */
118 template <walker_base::level level>
119 class visit_level<true, level> : public visit::visit_level<level>
120 {
121 };
122 
123 } // namespace policy
124 
125 } // namespace iteration
126 
127 } // 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:49
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: field-fwd.hpp:23
This policy tries to visit the current level.
state_t
The state of the walker.
Definition: walker.hpp:49
The walker abstract base class.
Definition: walker.hpp:27
virtual bool at_end(const level level) const =0
Returns whether the current widget is valid.
bool at_end(const walker_base &) const
Acts like walker_base::at_end for the level where the policy is used.
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.