Skylicht Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
Utils
CActivator.h
1
/*
2
!@
3
MIT License
4
5
Copyright (c) 2020 Skylicht Technology CO., LTD
6
7
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10
subject to the following conditions:
11
12
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20
This file is part of the "Skylicht Engine".
21
https://github.com/skylicht-lab/skylicht-engine
22
!#
23
*/
24
25
#pragma once
26
27
#include "Utils/CSingleton.h"
28
37
#define ACTIVATOR_REGISTER(type) \
38
IActivatorObject* type##CreateFunc() { return new type(); } \
39
bool type##_activator = CActivator::createGetInstance()->registerType(#type, &type##CreateFunc)
40
45
#define DECLARE_GETTYPENAME(type) \
46
virtual const char* getTypeName() {return #type;}
47
48
namespace
Skylicht
49
{
54
class
SKYLICHT_API
IActivatorObject
55
{
56
public
:
60
virtual
~IActivatorObject
()
61
{
62
63
}
64
};
65
70
typedef
IActivatorObject
* (*ActivatorCreateInstance)();
71
76
class
SKYLICHT_API
CActivator
77
{
78
public
:
79
DECLARE_SINGLETON
(
CActivator
)
80
81
protected
:
82
std::map<std::string, int> m_factoryName;
83
std::vector<ActivatorCreateInstance> m_factoryFunc;
84
85
public
:
92
bool
registerType
(
const
char
* type,
ActivatorCreateInstance
func);
93
99
IActivatorObject
*
createInstance
(
const
char
* type);
100
};
101
}
Skylicht::CActivator
Runtime factory that creates registered objects by type name.
Definition
CActivator.h:77
Skylicht::CActivator::createInstance
IActivatorObject * createInstance(const char *type)
Create an instance of a registered type.
Skylicht::CActivator::registerType
bool registerType(const char *type, ActivatorCreateInstance func)
Register a type name and constructor callback.
Skylicht::IActivatorObject
Base interface for objects created by CActivator.
Definition
CActivator.h:55
Skylicht::IActivatorObject::~IActivatorObject
virtual ~IActivatorObject()
Virtual destructor for polymorphic activator objects.
Definition
CActivator.h:60
DECLARE_SINGLETON
#define DECLARE_SINGLETON(className)
Declare the standard singleton accessors for a class.
Definition
CSingleton.h:36
Skylicht
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition
AudioDebugLog.h:29
Skylicht::ActivatorCreateInstance
IActivatorObject *(* ActivatorCreateInstance)()
Function pointer used to construct an activator object.
Definition
CActivator.h:70
Generated by
1.17.0