entity
Entity/Component System for C++
window.hpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // entity/for_each.h
3 //
4 // Algorithm to call a functor for an entity with the supplied component
5 // types. If the entity does not have all of the supplied compnent types
6 // f is not called.
7 //
8 // Copyright Chris Glover 2014-2015
9 //
10 // Distributed under the Boost Software License, Version 1.0.
11 // See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt
13 //
14 // ****************************************************************************
15 #ifndef _ENTITY_FUNCTIONAL_WINDOW_H_INCLUDED_
16 #define _ENTITY_FUNCTIONAL_WINDOW_H_INCLUDED_
17 
18 #include "entity/config.hpp" // IWYU pragma: keep
19 #include "entity/entity.hpp"
20 
21 // ----------------------------------------------------------------------------
22 //
23 namespace entity { namespace functional
24 {
25  // ------------------------------------------------------------------------
26  //
27  struct get_window
28  {
29  template<typename ComponentPool>
30  typename ComponentPool::window operator()(ComponentPool& p) const
31  {
32  return p.view();
33  }
34  };
35 
37  {
38  template<typename ComponentPoolWindow>
39  typename ComponentPoolWindow::value_type& operator()(ComponentPoolWindow view) const
40  {
41  return view.get();
42  }
43  };
44 
46  {
48  : target_(target)
49  {}
50 
51  template<typename ComponentPoolWindow>
52  bool operator()(bool result, ComponentPoolWindow& view) const
53  {
54  return view.increment(target_) && result;
55  }
56 
58  };
59 
61  {
63  : target_(target)
64  {}
65 
66  template<typename ComponentPoolWindow>
67  bool operator()(bool result, ComponentPoolWindow& view) const
68  {
69  return view.increment(target_) && result;
70  }
71 
73  };
74 
75  struct is_entity
76  {
77  is_entity(entity target)
78  : target_(target)
79  {}
80 
81  template<typename ComponentPoolWindow>
82  bool operator()(ComponentPoolWindow const& view) const
83  {
84  return view.is_entity(target_);
85  }
86 
88  };
89 
90  struct is_end
91  {
92  template<typename ComponentPoolWindow>
93  bool operator()(ComponentPoolWindow const& view) const
94  {
95  return view.is_end();
96  }
97  };
98 }}
99 
100 #endif // _ENTITY_FUNCTIONAL_WINDOW_H_INCLUDED_
bool operator()(ComponentPoolWindow const &view) const
Definition: window.hpp:82
is_entity(entity target)
Definition: window.hpp:77
bool operator()(bool result, ComponentPoolWindow &view) const
Definition: window.hpp:52
ComponentPool::window operator()(ComponentPool &p) const
Definition: window.hpp:30
bool operator()(ComponentPoolWindow const &view) const
Definition: window.hpp:93
ComponentPoolWindow::value_type & operator()(ComponentPoolWindow view) const
Definition: window.hpp:39
bool operator()(bool result, ComponentPoolWindow &view) const
Definition: window.hpp:67