hx3d  1
2D/3D Simple Game Framework
component.hpp
1 /*
2  Entity Component System: Component.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_ECS_COMPONENT
22 #define HX3D_ECS_COMPONENT
23 
24 #include "hx3d/utils/bitset.hpp"
25 
26 #include <map>
27 #include <typeindex>
28 
29 namespace hx3d {
30 namespace ecs {
31 
35 class Component {
36 public:
37  Component();
38  virtual ~Component();
39 };
40 
45 public:
53  template <class T>
54  static unsigned int get(typename std::enable_if<std::is_base_of<Component, T>::value>::type* test = nullptr);
55 
61  template <class... Types>
62  static unsigned int getFamily();
63 
64 private:
66  static std::map<std::type_index, unsigned int> _componentBits;
68  static unsigned int _currentBit;
69 
75  template <class T, class... Types>
76  static Bitset getFamilyInternal();
77  template <class... Types>
78  static Bitset getFamilyInternal(typename std::enable_if<sizeof...(Types) == 0>::type* test = nullptr);
79 };
80 
81 #include "hx3d/ecs/_inline/component.inl.hpp"
82 
83 } /* ecs */
84 } /* hx3d */
85 
86 #endif
hx3d framework namespace
Definition: audio.hpp:26
Base entity component.
Definition: component.hpp:35
Bitset helper in an unsigned int.
Definition: bitset.hpp:32
Unique bit attribution for each component.
Definition: component.hpp:44