Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSdlOptionalValue.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 std::optional<T> Owner::* valuePtr)
15
16 : TSdlOptionalValue(typeName, valueName, typeName, valuePtr)
17{}
18
19template<typename T, typename Owner>
21 std::string typeName,
22 std::string valueName,
23 std::string typeSignature,
24 std::optional<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{
33 PH_ASSERT(m_valuePtr);
34
36}
37
38template<typename T, typename Owner>
39inline auto TSdlOptionalValue<T, Owner>::description(std::string descriptionStr)
41{
42 this->setDescription(std::move(descriptionStr));
43 return *this;
44}
45
46template<typename T, typename Owner>
47inline void TSdlOptionalValue<T, Owner>::setValue(Owner& owner, T value) const
48{
49 owner.*m_valuePtr = std::move(value);
50}
51
52template<typename T, typename Owner>
53inline T* TSdlOptionalValue<T, Owner>::getValue(Owner& owner) const
54{
55 std::optional<T>& optValue = owner.*m_valuePtr;
56 return optValue.has_value() ? &optValue.value() : nullptr;
57}
58
59template<typename T, typename Owner>
60inline const T* TSdlOptionalValue<T, Owner>::getConstValue(const Owner& owner) const
61{
62 const std::optional<T>& optValue = owner.*m_valuePtr;
63 return optValue.has_value() ? &optValue.value() : nullptr;
64}
65
66template<typename T, typename Owner>
68{
69 owner.*m_valuePtr = std::nullopt;
70}
71
72template<typename T, typename Owner>
73inline std::optional<T>& TSdlOptionalValue<T, Owner>::valueRef(Owner& owner) const
74{
75 return owner.*m_valuePtr;
76}
77
78}// end namespace ph
SdlField & setImportance(EFieldImportance importance)
Sets the importance of the field. Different importance affect the underlying policy used during the i...
Definition SdlField.h:111
General concept of a SDL value type.
Definition TSdlAbstractValue.h:17
Abstractions for a SDL value type that can be empty.
Definition TSdlOptionalValue.h:22
TSdlOptionalValue(std::string typeName, std::string valueName, std::optional< T > Owner::*valuePtr)
Definition TSdlOptionalValue.ipp:11
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 TSdlOptionalValue.ipp:67
std::optional< T > & valueRef(Owner &owner) const
Definition TSdlOptionalValue.ipp:73
TSdlOptionalValue & description(std::string descriptionStr)
Definition TSdlOptionalValue.ipp:39
void setValue(Owner &owner, T value) const override
Store a value.
Definition TSdlOptionalValue.ipp:47
T * getValue(Owner &owner) const override
Get a pointer to the stored value.
Definition TSdlOptionalValue.ipp:53
const T * getConstValue(const Owner &owner) const override
Get a pointer to the stored value.
Definition TSdlOptionalValue.ipp:60
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96