Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSdlValue.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6
7#include <string_view>
8#include <optional>
9
10namespace ph
11{
12
23template<typename T, typename Owner>
24class TSdlValue : public TSdlAbstractValue<T, Owner>
25{
26public:
28 std::string typeName,
29 std::string valueName,
30 T Owner::* valuePtr);
31
33 std::string typeName,
34 std::string valueName,
35 std::string typeSignature,
36 T Owner::* valuePtr);
37
38 std::string valueAsString(const T& value) const override = 0;
39 SdlNativeData ownedNativeData(Owner& owner) const override = 0;
40
41 void setValue(Owner& owner, T value) const override;
42 T* getValue(Owner& owner) const override;
43 const T* getConstValue(const Owner& owner) const override;
44 void ownedValueToDefault(Owner& owner) const override;
45
46 const T* getDefaultValue() const;
47
48 TSdlValue& defaultTo(T defaultValue);
51 TSdlValue& description(std::string descriptionStr);
56
57protected:
59 Owner& owner,
60 const SdlInputClause& clause,
61 const SdlInputContext& ctx) const override = 0;
62
64 const Owner& owner,
65 SdlOutputClause& out_clause,
66 const SdlOutputContext& ctx) const override = 0;
67
68 T& valueRef(Owner& owner) const;
69
70private:
71 T Owner::* m_valuePtr;
72 std::optional<T> m_defaultValue;
73};
74
75}// end namespace ph
76
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
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
General concept of a SDL value type.
Definition TSdlAbstractValue.h:17
Abstractions for a SDL value type.
Definition TSdlValue.h:25
void loadFromSdl(Owner &owner, const SdlInputClause &clause, const SdlInputContext &ctx) const override=0
Load SDL value to actual value and store it in the owner's field. Implementations are highly encourag...
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
std::string valueAsString(const T &value) const override=0
Human-readable representation of the value.
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
void saveToSdl(const Owner &owner, SdlOutputClause &out_clause, const SdlOutputContext &ctx) const override=0
Convert actual value back to SDL value. Saving a loaded value as SDL value should rarely fail–as load...
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
SdlNativeData ownedNativeData(Owner &owner) const override=0
Direct access to the field memory of an owner. Short-lived owner objects such as function parameter s...
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