Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSdlReference.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <string>
7#include <memory>
8#include <type_traits>
9
10namespace ph
11{
12
13class ISdlResource;
14
19template<typename T, typename Owner>
20class TSdlReference : public TSdlOwnedField<Owner>
21{
22public:
23 TSdlReference(std::string valueName, std::shared_ptr<T> Owner::* valuePtr);
24
27 void ownedValueToDefault(Owner& owner) const override;
28
29 std::string valueToString(const Owner& owner) const override;
30
31 void ownedResources(
32 const Owner& owner,
33 std::vector<const ISdlResource*>& out_resources) const override;
34
35 SdlNativeData ownedNativeData(Owner& owner) const override;
36
37 void setValueRef(Owner& owner, std::shared_ptr<T> value) const;
38 const std::shared_ptr<T>& getValueRef(const Owner& owner) const;
39
41 TSdlReference& description(std::string descriptionStr);
45
46 template<typename ResourceType = T>
47 static std::shared_ptr<ResourceType> loadReference(
48 const SdlInputClause& clause,
49 const SdlInputContext& ctx);
50
51 template<typename ResourceType = T>
52 static std::shared_ptr<ResourceType> loadReference(
53 std::string_view referenceName,
54 const SdlInputContext& ctx);
55
56protected:
57 void loadFromSdl(
58 Owner& owner,
59 const SdlInputClause& clause,
60 const SdlInputContext& ctx) const override;
61
62 void saveToSdl(
63 const Owner& owner,
64 SdlOutputClause& out_clause,
65 const SdlOutputContext& ctx) const override;
66
67private:
68 std::shared_ptr<T> Owner::* m_valuePtr;
69};
70
71}// end namespace ph
72
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
Abstraction for a value that is owned by some owner type. Governs how a field should be initialized o...
Definition TSdlOwnedField.h:15
A value that points to a SDL resource.
Definition TSdlReference.h:21
TSdlReference & optional()
Definition TSdlReference.ipp:214
void ownedValueToDefault(Owner &owner) const override
By default, default value of a SDL reference is empty.
Definition TSdlReference.ipp:36
static std::shared_ptr< ResourceType > loadReference(const SdlInputClause &clause, const SdlInputContext &ctx)
Definition TSdlReference.ipp:155
void loadFromSdl(Owner &owner, 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 TSdlReference.ipp:96
TSdlReference & required()
Definition TSdlReference.ipp:228
SdlNativeData ownedNativeData(Owner &owner) const override
Direct access to the field memory of an owner. Short-lived owner objects such as function parameter s...
Definition TSdlReference.ipp:63
std::string valueToString(const Owner &owner) const override
Convert the value of the field to human-readable string.
Definition TSdlReference.ipp:43
const std::shared_ptr< T > & getValueRef(const Owner &owner) const
Definition TSdlReference.ipp:90
TSdlReference(std::string valueName, std::shared_ptr< T > Owner::*valuePtr)
Definition TSdlReference.ipp:19
TSdlReference & description(std::string descriptionStr)
Definition TSdlReference.ipp:206
TSdlReference & niceToHave()
Definition TSdlReference.ipp:221
TSdlReference & withImportance(EFieldImportance importance)
Definition TSdlReference.ipp:198
void ownedResources(const Owner &owner, std::vector< const ISdlResource * > &out_resources) const override
Get all SDL resources associated by owner.
Definition TSdlReference.ipp:51
void setValueRef(Owner &owner, std::shared_ptr< T > value) const
Definition TSdlReference.ipp:84
void saveToSdl(const Owner &owner, 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 TSdlReference.ipp:113
The root for all renderer implementations.
Definition EEngineProject.h:6
EFieldImportance
Definition EFieldImportance.h:7