Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSdlValue.ipp
Go to the documentation of this file.
1#pragma once
2
4
5#include <utility>
6
7namespace ph
8{
9
10template<typename T, typename Owner>
12 std::string typeName,
13 std::string valueName,
14 T Owner::* valuePtr)
15
16 : TSdlValue(typeName, valueName, typeName, valuePtr)
17{}
18
19template<typename T, typename Owner>
21 std::string typeName,
22 std::string valueName,
23 std::string typeSignature,
24 T Owner::* valuePtr)
25
26 : TSdlAbstractValue<T, Owner>(
27 std::move(typeName),
28 std::move(valueName),
29 std::move(typeSignature))
30
31 , m_valuePtr(valuePtr)
32 , m_defaultValue(T{})
33{
34 PH_ASSERT(m_valuePtr);
35}
36
37template<typename T, typename Owner>
38inline void TSdlValue<T, Owner>::setValue(Owner& owner, T value) const
39{
40 owner.*m_valuePtr = std::move(value);
43template<typename T, typename Owner>
44inline T* TSdlValue<T, Owner>::getValue(Owner& owner) const
45{
46 return &(owner.*m_valuePtr);
47}
49template<typename T, typename Owner>
50inline const T* TSdlValue<T, Owner>::getConstValue(const Owner& owner) const
52 return &(owner.*m_valuePtr);
55template<typename T, typename Owner>
56inline void TSdlValue<T, Owner>::ownedValueToDefault(Owner& owner) const
57{
58 if(m_defaultValue.has_value())
59 {
60 setValue(owner, *m_defaultValue);
61 }
62}
63
64template<typename T, typename Owner>
66{
67 return m_defaultValue.has_value() ? &(*m_defaultValue) : nullptr;
69
70template<typename T, typename Owner>
71inline auto TSdlValue<T, Owner>::defaultTo(T defaultValue)
72-> TSdlValue&
73{
74 m_defaultValue = std::move(defaultValue);
75 return *this;
76}
77
78template<typename T, typename Owner>
80-> TSdlValue&
81{
82 m_defaultValue = std::nullopt;
83 return *this;
84}
85
86template<typename T, typename Owner>
88-> TSdlValue&
89{
90 this->setImportance(importance);
91 return *this;
92}
93
94template<typename T, typename Owner>
95inline auto TSdlValue<T, Owner>::description(std::string descriptionStr)
96-> TSdlValue&
97{
98 this->setDescription(std::move(descriptionStr));
99 return *this;
100}
101
102template<typename T, typename Owner>
104-> TSdlValue&
105{
106 return withImportance(EFieldImportance::Optional);
107}
108
109template<typename T, typename Owner>
111-> TSdlValue&
112{
113 return withImportance(EFieldImportance::NiceToHave);
114}
115
116template<typename T, typename Owner>
118-> TSdlValue&
119{
120 return withImportance(EFieldImportance::Required);
121}
122
123template<typename T, typename Owner>
124inline auto TSdlValue<T, Owner>::enableFallback(const bool isFallbackEnabled)
125-> TSdlValue&
126{
127 this->setEnableFallback(isFallbackEnabled);
128 return *this;
129}
130
131template<typename T, typename Owner>
132inline T& TSdlValue<T, Owner>::valueRef(Owner& owner) const
133{
134 return owner.*m_valuePtr;
135}
136
137}// end namespace ph
General concept of a SDL value type.
Definition TSdlAbstractValue.h:17
Abstractions for a SDL value type.
Definition TSdlValue.h:25
void setValue(Owner &owner, T value) const override
Store a value.
Definition TSdlValue.ipp:38
TSdlValue & description(std::string descriptionStr)
Definition TSdlValue.ipp:95
const T * getConstValue(const Owner &owner) const override
Get a pointer to the stored value.
Definition TSdlValue.ipp:50
TSdlValue(std::string typeName, std::string valueName, T Owner::*valuePtr)
Definition TSdlValue.ipp:11
const T * getDefaultValue() const
Definition TSdlValue.ipp:65
T * getValue(Owner &owner) const override
Get a pointer to the stored value.
Definition TSdlValue.ipp:44
TSdlValue & optional()
Definition TSdlValue.ipp:103
TSdlValue & defaultTo(T defaultValue)
Definition TSdlValue.ipp:71
T & valueRef(Owner &owner) const
Definition TSdlValue.ipp:132
TSdlValue & noDefault()
Definition TSdlValue.ipp:79
TSdlValue & enableFallback(bool isFallbackEnabled)
Definition TSdlValue.ipp:124
TSdlValue & withImportance(EFieldImportance importance)
Definition TSdlValue.ipp:87
void ownedValueToDefault(Owner &owner) const override
Set the value of the field to a default one. Since the field class is templatized by Owner type,...
Definition TSdlValue.ipp:56
TSdlValue & required()
Definition TSdlValue.ipp:117
TSdlValue & niceToHave()
Definition TSdlValue.ipp:110
The root for all renderer implementations.
Definition EEngineProject.h:6
EFieldImportance
Definition EFieldImportance.h:7
Definition TAABB2D.h:96