EzGL
Component.hpp
Go to the documentation of this file.
1 /* EzGL/Component.hpp
2  *
3  * Copyright (c) 2018 Kirk Lange <github.com/kirklange>
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 
22 #ifndef EZGL_COMPONENT_HPP
23 #define EZGL_COMPONENT_HPP
24 
30 #include "EzGL/IComponent.hpp"
31 
32 
33 
34 namespace EzGL
35 {
36 
42 template <class T>
43 class Component : private IComponent
44 {
45 public:
46  virtual ~Component() = default;
47 
52  {
53  return ComponentPtr(new T());
54  }
55 
62  void IInit(Object &self, Object &main) override
63  {
64  static_cast<T*>(this)->init(self, main);
65  }
66 
73  void IUpdate(Object &self, Object &main) override
74  {
75  static_cast<T*>(this)->update(self, main);
76  }
77 
78 protected:
79  Component() = default;
80 };
81 
82 }; /* namespace EzGL */
83 
84 
85 
86 #endif /* EZGL_COMPONENT_HPP */
Object factory and Main game executor.
Definition: Object.hpp:46
The base class to inherit from for all components.
Definition: Component.hpp:43
void IUpdate(Object &self, Object &main) override
Initialize all components.
Definition: Component.hpp:73
void IInit(Object &self, Object &main) override
Initialize all components.
Definition: Component.hpp:62
Allows Component to utilize dynamic polymorphism.
Definition: IComponent.hpp:41
Allows Component to utilize dynamic polymorphism.
static ComponentPtr Create()
Automatically generated per-class component factory.
Definition: Component.hpp:51
Component enlister and smart pointer factory.
std::unique_ptr< class IComponent > ComponentPtr
Component smart pointer type.
Definition: ComponentFactory.hpp:53