Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSdlNestedField.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <Common/assertion.h>
7#include <Common/primitive_type.h>
8
9#include <type_traits>
10#include <string>
11#include <exception>
12#include <vector>
13
14namespace ph
15{
16
23template<typename OuterType, typename InnerType>
24class TSdlNestedField : public TSdlOwnedField<OuterType>
25{
26public:
28 InnerType OuterType::* innerObjPtr,
29 const TSdlOwnedField<InnerType>* innerObjField);
30
31 void ownedValueToDefault(OuterType& outerObj) const override;
32 std::string valueToString(const OuterType& outerObj) const override;
33
34 void ownedResources(
35 const OuterType& outerObj,
36 std::vector<const ISdlResource*>& out_resources) const override;
37
38 SdlNativeData ownedNativeData(OuterType& outerObj) const override;
39
40protected:
41 void loadFromSdl(
42 OuterType& outerObj,
43 const SdlInputClause& clause,
44 const SdlInputContext& ctx) const override;
45
46 void saveToSdl(
47 const OuterType& outerObj,
48 SdlOutputClause& out_clause,
49 const SdlOutputContext& ctx) const override;
50
51private:
52 InnerType OuterType::* m_innerObjPtr;
53 const TSdlOwnedField<InnerType>* m_innerObjField;
54};
55
56// In-header Implementations:
57
58template<typename OuterType, typename InnerType>
60 InnerType OuterType::* const innerObjPtr,
61 const TSdlOwnedField<InnerType>* const innerObjField) :
62
63 TSdlOwnedField<OuterType>(
64 std::string(innerObjField ? innerObjField->getTypeName() : "unavailable"),
65 std::string(innerObjField ? innerObjField->getFieldName() : "unavailable")),
66
67 m_innerObjPtr (innerObjPtr),
68 m_innerObjField(innerObjField)
69{
70 PH_ASSERT(m_innerObjPtr);
71 PH_ASSERT(m_innerObjField);
72
73 PH_ASSERT_MSG(static_cast<const SdlField*>(m_innerObjField) != this,
74 "setting self as inner field is forbidden (will result in infinite recursive calls)");
75
76 this->setDescription(std::string(m_innerObjField->getDescription()));
77 this->setEnableFallback(m_innerObjField->isFallbackEnabled());
78 this->setImportance(m_innerObjField->getImportance());
79}
80
81template<typename OuterType, typename InnerType>
83{
84 m_innerObjField->ownedValueToDefault(outerObj.*m_innerObjPtr);
85}
86
87template<typename OuterType, typename InnerType>
88inline std::string TSdlNestedField<OuterType, InnerType>::valueToString(const OuterType& outerObj) const
89{
90 return m_innerObjField->valueToString(outerObj.*m_innerObjPtr);
91}
92
93template<typename OuterType, typename InnerType>
95 const OuterType& outerObj,
96 std::vector<const ISdlResource*>& out_resources) const
97{
98 m_innerObjField->ownedResources(outerObj.*m_innerObjPtr, out_resources);
99}
100
101template<typename OuterType, typename InnerType>
103{
104 return m_innerObjField->ownedNativeData(outerObj.*m_innerObjPtr);
105}
106
107template<typename OuterType, typename InnerType>
109 OuterType& outerObj,
110 const SdlInputClause& clause,
111 const SdlInputContext& ctx) const
112{
113 m_innerObjField->loadFromSdl(
114 outerObj.*m_innerObjPtr,
115 clause,
116 ctx);
117}
118
119template<typename OuterType, typename InnerType>
121 const OuterType& outerObj,
122 SdlOutputClause& out_clause,
123 const SdlOutputContext& ctx) const
124{
125 m_innerObjField->saveToSdl(
126 outerObj.*m_innerObjPtr,
127 out_clause,
128 ctx);
129}
130
131}// end namespace ph
Definition SdlField.h:19
SdlField & setEnableFallback(bool isFallbackEnabled)
Definition SdlField.h:118
bool isFallbackEnabled() const
Whether the field want to use built-in mechanism to handle I/O problems. An example of this is defaul...
Definition SdlField.h:99
std::string_view getDescription() const
Definition SdlField.h:84
SdlField & setImportance(EFieldImportance importance)
Sets the importance of the field. Different importance affect the underlying policy used during the i...
Definition SdlField.h:111
SdlField & setDescription(std::string descriptionStr)
Definition SdlField.h:104
EFieldImportance getImportance() const
Definition SdlField.h:94
Carries SDL representation of various data during the input process. Helps to read input data such as...
Definition SdlInputClause.h:15
Data that SDL input process can rely on.
Definition SdlInputContext.h:19
Definition SdlNativeData.h:88
Carries SDL representation of various data during the output process. Helps to write output data such...
Definition SdlOutputClause.h:14
Data that SDL output process can rely on.
Definition SdlOutputContext.h:19
A field that lives within an inner object.
Definition TSdlNestedField.h:25
void saveToSdl(const OuterType &outerObj, SdlOutputClause &out_clause, const SdlOutputContext &ctx) const override
Convert actual value back to SDL value. Saving a loaded value as SDL value should rarely fail–as load...
Definition TSdlNestedField.h:120
void loadFromSdl(OuterType &outerObj, const SdlInputClause &clause, const SdlInputContext &ctx) const override
Load SDL value to actual value and store it in the owner's field. Implementations are highly encourag...
Definition TSdlNestedField.h:108
SdlNativeData ownedNativeData(OuterType &outerObj) const override
Direct access to the field memory of an owner. Short-lived owner objects such as function parameter s...
Definition TSdlNestedField.h:102
void ownedValueToDefault(OuterType &outerObj) const override
Set the value of the field to a default one. Since the field class is templatized by Owner type,...
Definition TSdlNestedField.h:82
void ownedResources(const OuterType &outerObj, std::vector< const ISdlResource * > &out_resources) const override
Get all SDL resources associated by owner.
Definition TSdlNestedField.h:94
std::string valueToString(const OuterType &outerObj) const override
Convert the value of the field to human-readable string.
Definition TSdlNestedField.h:88
Abstraction for a value that is owned by some owner type. Governs how a field should be initialized o...
Definition TSdlOwnedField.h:15
friend class TSdlNestedField
Definition TSdlOwnedField.h:107
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96