Skylicht Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
Components
CComponentCategory.h
1
/*
2
!@
3
MIT License
4
5
Copyright (c) 2021 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
29
namespace
Skylicht
30
{
31
// Warning:
32
// if this code don't run on SkylichtEditor
33
// please register at CEngineEditor.cpp (Projects/Editor/Source/Editor/Components)
34
#define CATEGORY_COMPONENT(component, name, path) int component##_category = CComponentCategory::createGetInstance()->addToCategory(#component, name, path);
35
36
class
SKYLICHT_API CComponentCategory
37
{
38
public
:
39
DECLARE_SINGLETON
(CComponentCategory)
40
41
public
:
42
struct
SComponent
43
{
44
std::string ComponentName;
45
std::string Name;
46
std::string Path;
47
};
48
49
struct
SCategory
50
{
51
std::string Name;
52
std::vector<SComponent*> Components;
53
std::vector<SCategory*> Childs;
54
SCategory* Parent;
55
56
SCategory()
57
{
58
Parent = NULL;
59
}
60
61
~SCategory()
62
{
63
for
(
SComponent
* c : Components)
64
delete
c;
65
66
for
(SCategory* child : Childs)
67
delete
child;
68
}
69
70
SCategory* getChild(
const
char
* name)
const
71
{
72
for
(SCategory* child : Childs)
73
{
74
if
(child->Name == name)
75
return
child;
76
}
77
78
return
NULL;
79
}
80
81
SCategory* addChild(
const
char
* name)
82
{
83
SCategory* child =
new
SCategory();
84
child->Name = name;
85
child->Parent =
this
;
86
Childs.push_back(child);
87
std::sort(Childs.begin(), Childs.end(), [](
const
SCategory* a,
const
SCategory* b) {return a->Name < b->Name; });
88
return
child;
89
}
90
91
SComponent
* add(
const
char
* component,
const
char
* name,
const
char
* path)
92
{
93
SComponent
* s =
new
SComponent
();
94
s->ComponentName = component;
95
s->Name = name;
96
s->Path = path;
97
98
Components.push_back(s);
99
return
s;
100
}
101
};
102
103
SCategory
* m_category;
104
std::vector<SComponent*> m_components;
105
106
public
:
107
CComponentCategory();
108
109
virtual
~CComponentCategory();
110
111
int
addToCategory(
const
char
* componentName,
const
char
* name,
const
char
* path);
112
113
const
SCategory
* getCategory()
114
{
115
return
m_category;
116
}
117
118
const
std::vector<SComponent*>& getAllComponents()
119
{
120
return
m_components;
121
}
122
};
123
}
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::CComponentCategory::SCategory
Definition
CComponentCategory.h:50
Skylicht::CComponentCategory::SComponent
Definition
CComponentCategory.h:43
Generated by
1.17.0