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