GlPortal Class Reference  0.1.1
Source code documentation of the free and open 3D action puzzle game.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Component.hpp
Go to the documentation of this file.
1 #ifndef RADIX_COMPONENT_HPP
2 #define RADIX_COMPONENT_HPP
3 
4 #include <cstddef>
5 #include <type_traits>
6 
7 #include <serine/Serializable.hpp>
8 
9 namespace radix {
10 
11 using ComponentTypeId = std::size_t;
12 
14 
16 template<typename T> struct _ComponentTypeId { static ComponentTypeId id; };
17 template<typename T> ComponentTypeId _ComponentTypeId<T>::id { getNewComponentTypeId() };
20 class Entity;
21 
25 class Component : public serine::Serializable {
26 private:
27  // Forbid any copy
28  Component(const Component&) = delete;
29  Component& operator=(const Component&) = delete;
30 
31 protected:
33 
34 public:
36  static constexpr TypeId MaxId = 32;
37 
41  template<typename T> inline static TypeId getTypeId() {
42  static_assert(std::is_base_of<Component, T>::value, "T must be a Component");
43  return _ComponentTypeId<typename std::remove_cv<T>::type>::id;
44  }
45 
46  inline Component(Entity &ent) noexcept :
47  entity(ent) {}
48 
49  virtual const char* getName() const = 0;
50  virtual TypeId getTypeId() const = 0;
51 
52  virtual ~Component() {}
53 };
54 
56  static ComponentTypeId lastId(0);
57  return lastId++;
58 }
59 
60 } /* namespace radix */
61 
62 #endif /* RADIX_COMPONENT_HPP */
std::size_t ComponentTypeId
Definition: Component.hpp:11
Definition: GameController.hpp:7
Component(const Component &)=delete
ECS entity, Component container It is created like this:
Definition: Entity.hpp:23
Component(Entity &ent) noexcept
Definition: Component.hpp:46
ComponentTypeId getNewComponentTypeId()
Definition: Component.hpp:55
Base class to create entity components.
Definition: Component.hpp:25
Entity & entity
Definition: Component.hpp:32
static TypeId getTypeId()
Gets a component's type ID.
Definition: Component.hpp:41
virtual ~Component()
Definition: Component.hpp:52
static constexpr TypeId MaxId
Definition: Component.hpp:36
ComponentTypeId TypeId
Definition: Component.hpp:35
Component & operator=(const Component &)=delete
virtual const char * getName() const =0