The Battle for Wesnoth  1.13.4+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 - 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 #ifndef GUI_WIDGETS_AUXILIARY_ITERATOR_POLICY_VISIT_HPP_INCLUDED
16 #define GUI_WIDGETS_AUXILIARY_ITERATOR_POLICY_VISIT_HPP_INCLUDED
17 
19 
20 #include <cstring>
21 
22 namespace gui2
23 {
24 
25 namespace iterator
26 {
27 
28 namespace policy
29 {
30 
31 namespace visit
32 {
33 
34 /**
35  * This policy skips the current level.
36  */
37 class tskip
38 {
39 public:
40  /**
41  * Acts like @ref twalker_::next for the level where the policy is used.
42  */
44  {
45  return twalker_::fail;
46  }
47 
48  /**
49  * Acts like @ref twalker_::at_end for the level where the policy is used.
50  */
51  bool at_end(const twalker_&) const
52  {
53  return true;
54  }
55 
56  /**
57  * Acts like @ref twalker_::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 <twalker_::tlevel level>
71 class tvisit
72 {
73 public:
74  /**
75  * Acts like @ref twalker_::next for the level where the policy is used.
76  */
78  {
79  return visitor.next(level);
80  }
81 
82  /**
83  * Acts like @ref twalker_::at_end for the level where the policy is used.
84  */
85  bool at_end(const twalker_& visitor) const
86  {
87  return visitor.at_end(level);
88  }
89 
90  /**
91  * Acts like @ref twalker_::get for the level where the policy is used.
92  */
93  gui2::twidget* get(twalker_& 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, twalker_::tlevel level>
107 class tvisit
108 {
109 };
110 
111 /** Specialized to select the @ref visit::tskip policy. */
112 template <twalker_::tlevel level>
113 class tvisit<false, level> : public visit::tskip
114 {
115 };
116 
117 /** Specialized to select the @ref visit::tvisit policy. */
118 template <twalker_::tlevel level>
119 class tvisit<true, level> : public visit::tvisit<level>
120 {
121 };
122 
123 } // namespace policy
124 
125 } // namespace iterator
126 
127 } // namespace gui2
128 
129 #endif
bool at_end(const twalker_ &) const
Acts like twalker_::at_end for the level where the policy is used.
virtual tstate next(const tlevel level)=0
Make the next widget the current one.
GLint level
Definition: glew.h:1220
Helper class to select to visit or skip a level.
This policy skips the current level.
tstate
The state of the walker.
Definition: walker.hpp:51
bool at_end(const twalker_ &visitor) const
Acts like twalker_::at_end for the level where the policy is used.
virtual bool at_end(const tlevel level) const =0
Returns whether the current widget is valid.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
twalker_::tstate next(twalker_ &)
Acts like twalker_::next for the level where the policy is used.
twalker_::tstate next(twalker_ &visitor)
Acts like twalker_::next for the level where the policy is used.
This policy tries to visit the current level.
Base class for all widgets.
Definition: widget.hpp:49
The walker abstract base class.
Definition: walker.hpp:27
std::string::const_iterator iterator
Definition: tokenizer.hpp:21