Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
SdlClass.h
Go to the documentation of this file.
1#pragma once
2
4#include "SDL/sdl_fwd.h"
8
9#include <Common/primitive_type.h>
10#include <Common/logging.h>
11
12#include <vector>
13#include <cstddef>
14#include <string>
15#include <string_view>
16#include <type_traits>
17#include <memory>
18
19namespace ph
20{
21
23
25{
26public:
27 SdlClass(ESdlTypeCategory category, const std::string& typeName);
28
29 virtual std::shared_ptr<ISdlResource> createResource() const = 0;
30
34 virtual void initResource(
35 ISdlResource& resource,
36 SdlInputClauses& clauses,
37 const SdlInputContext& ctx) const = 0;
38
42 virtual void initDefaultResource(ISdlResource& resource) const = 0;
43
44 virtual void saveResource(
45 const ISdlResource& resource,
46 SdlOutputClauses& clauses,
47 const SdlOutputContext& ctx) const = 0;
48
49 virtual void call(
50 std::string_view funcName,
51 ISdlResource* resource,
52 SdlInputClauses& clauses,
53 const SdlInputContext& ctx) const = 0;
54
60 virtual void referencedResources(
61 const ISdlResource* targetResource,
62 std::vector<const ISdlResource*>& out_resources) const = 0;
63
68 virtual std::size_t numFunctions() const = 0;
69
70 virtual const SdlFunction* getFunction(std::size_t index) const = 0;
71
76 std::size_t numFields() const override = 0;
77
78 const SdlField* getField(std::size_t index) const override = 0;
79
80 std::string_view getTypeName() const override;
81 std::string_view getDescription() const override;
82
87 bool isBlueprint() const;
88
95
96 std::string genPrettyName() const;
97 std::string genCategoryName() const;
99
100 std::string_view getDocName() const;
101 const SdlClass* getBase() const;
102 bool isDerived() const;
103 bool hasField() const;
104 bool hasFunction() const;
105
106protected:
107 SdlClass& setDescription(std::string description);
108
109 SdlClass& setDocName(std::string docName);
110
115 template<typename SdlResourceType>
116 SdlClass& setBase();
117
120
121private:
122 ESdlTypeCategory m_category;
123 std::string m_typeName;
124 std::string m_docName;
125 std::string m_description;
126 const SdlClass* m_base;
127 uint32 m_isBlueprint : 1;
128 uint32 m_allowCreateFromClass : 1;
129};
130
131// In-header Implementation:
132
133inline bool SdlClass::isBlueprint() const
134{
135 return m_isBlueprint;
136}
137
139{
140 return m_allowCreateFromClass;
141}
142
144{
145 return m_category;
146}
147
148inline std::string_view SdlClass::getTypeName() const
149{
150 return m_typeName;
151}
152
153inline std::string_view SdlClass::getDocName() const
154{
155 return m_docName;
156}
157
158inline std::string_view SdlClass::getDescription() const
159{
160 return m_description;
161}
162
163inline const SdlClass* SdlClass::getBase() const
164{
165 return m_base;
166}
167
168inline bool SdlClass::isDerived() const
169{
170 return getBase() != nullptr;
171}
172
173inline bool SdlClass::hasField() const
174{
175 return numFields() != 0;
176}
177
178inline bool SdlClass::hasFunction() const
179{
180 return numFunctions() != 0;
181}
182
183template<typename SdlResourceType>
185{
186 static_assert(std::is_base_of_v<ISdlResource, SdlResourceType>,
187 "Input type must be a SDL resource.");
188
189 m_base = SdlResourceType::getSdlClass();
190 return *this;
191}
192
193}// end namespace ph
Definition ISdlInstantiable.h:12
Interface for all SDL resource.
Definition ISdlResource.h:22
Definition SdlClass.h:25
SdlClass & setDescription(std::string description)
Definition SdlClass.cpp:37
SdlClass & setIsBlueprint(bool isBlueprint)
Definition SdlClass.cpp:49
std::string genPrettyName() const
Definition SdlClass.cpp:27
bool hasField() const
Definition SdlClass.h:173
bool hasFunction() const
Definition SdlClass.h:178
virtual const SdlFunction * getFunction(std::size_t index) const =0
ESdlTypeCategory getCategory() const
Definition SdlClass.h:143
virtual std::shared_ptr< ISdlResource > createResource() const =0
SdlClass(ESdlTypeCategory category, const std::string &typeName)
Definition SdlClass.cpp:11
bool allowCreateFromClass() const
Whether a resource can be created by calling createResource(). This attribute is useful to decide whe...
Definition SdlClass.h:138
virtual void call(std::string_view funcName, ISdlResource *resource, SdlInputClauses &clauses, const SdlInputContext &ctx) const =0
virtual std::size_t numFunctions() const =0
bool isDerived() const
Definition SdlClass.h:168
virtual void initResource(ISdlResource &resource, SdlInputClauses &clauses, const SdlInputContext &ctx) const =0
Initialize a resource from value clauses. How the resource will be initialized depends on the resourc...
bool isBlueprint() const
Whether the class is for building other classes only. A blueprint class cannot be instantiated as a S...
Definition SdlClass.h:133
SdlClass & setDocName(std::string docName)
Definition SdlClass.cpp:43
virtual void referencedResources(const ISdlResource *targetResource, std::vector< const ISdlResource * > &out_resources) const =0
Get all SDL resources referenced by targetResource.
std::string genCategoryName() const
Definition SdlClass.cpp:32
virtual void saveResource(const ISdlResource &resource, SdlOutputClauses &clauses, const SdlOutputContext &ctx) const =0
std::size_t numFields() const override=0
SdlClass & setAllowCreateFromClass(bool allowCreateFromClass)
Definition SdlClass.cpp:55
const SdlClass * getBase() const
Definition SdlClass.h:163
virtual void initDefaultResource(ISdlResource &resource) const =0
Initialize a resource to default values. Default values are defined by the resource class's SDL defin...
SdlClass & setBase()
Set another SDL class as the base of this class.
Definition SdlClass.h:184
std::string_view getDocName() const
Definition SdlClass.h:153
const SdlField * getField(std::size_t index) const override=0
std::string_view getDescription() const override
Definition SdlClass.h:158
std::string_view getTypeName() const override
Definition SdlClass.h:148
Definition SdlField.h:19
Definition SdlFunction.h:18
Container for input clauses.
Definition SdlInputClauses.h:18
Data that SDL input process can rely on.
Definition SdlInputContext.h:19
Definition SdlOutputClauses.h:14
Data that SDL output process can rely on.
Definition SdlOutputContext.h:19
The root for all renderer implementations.
Definition EEngineProject.h:6
ESdlTypeCategory
Definition ESdlTypeCategory.h:15
PH_DEFINE_EXTERNAL_LOG_GROUP(ApiDatabase, Core)