Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSdlStructArray.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <string>
6#include <string_view>
7#include <vector>
8#include <type_traits>
9
10namespace ph
11{
12
13template<typename Struct, typename Owner>
14class TSdlStructArray : public TSdlOwnedField<Owner>
15{
16 static_assert(!std::is_same_v<Struct, Owner>,
17 "`Struct` and `Owner` is not allowed to be the same type (for reducing the risk of "
18 "cyclic references and infinite recursion on initialization).");
19
20public:
21 TSdlStructArray(std::string valueName, std::vector<Struct> Owner::* const valuePtr);
22
25 void ownedValueToDefault(Owner& owner) const override;
26
27 std::string valueToString(const Owner& owner) const override;
28
29 void ownedResources(
30 const Owner& owner,
31 std::vector<const ISdlResource*>& out_resources) const override;
32
33 SdlNativeData ownedNativeData(Owner& owner) const override;
34
35 void setValueVec(Owner& owner, std::vector<Struct> value) const;
36 const std::vector<Struct>& getValueVec(const Owner& owner) const;
37
39 TSdlStructArray& description(std::string descriptionStr);
43
44protected:
45 void loadFromSdl(
46 Owner& owner,
47 const SdlInputClause& clause,
48 const SdlInputContext& ctx) const override;
49
50 void saveToSdl(
51 const Owner& owner,
52 SdlOutputClause& out_clause,
53 const SdlOutputContext& ctx) const override;
54
55 static std::vector<Struct> loadStructArray(
56 const SdlInputClause& clause,
57 const SdlInputContext& ctx);
58
59 static Struct loadStruct(
60 std::string_view packetName,
61 const SdlInputContext& ctx);
62
63private:
64 static std::string getStructTypeName();
65
66 std::vector<Struct> Owner::* m_valuePtr;
67};
68
69}// end namespace ph
70
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
Definition TSdlStructArray.h:15
static Struct loadStruct(std::string_view packetName, const SdlInputContext &ctx)
Definition TSdlStructArray.ipp:220
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 TSdlStructArray.ipp:130
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 TSdlStructArray.ipp:113
void ownedValueToDefault(Owner &owner) const override
By default, default value of the array is empty.
Definition TSdlStructArray.ipp:38
TSdlStructArray(std::string valueName, std::vector< Struct > Owner::*const valuePtr)
Definition TSdlStructArray.ipp:23
const std::vector< Struct > & getValueVec(const Owner &owner) const
Definition TSdlStructArray.ipp:107
TSdlStructArray & niceToHave()
Definition TSdlStructArray.ipp:285
TSdlStructArray & required()
Definition TSdlStructArray.ipp:292
TSdlStructArray & optional()
Definition TSdlStructArray.ipp:278
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 TSdlStructArray.ipp:72
static std::vector< Struct > loadStructArray(const SdlInputClause &clause, const SdlInputContext &ctx)
Definition TSdlStructArray.ipp:175
TSdlStructArray & withImportance(EFieldImportance importance)
Definition TSdlStructArray.ipp:262
std::string valueToString(const Owner &owner) const override
Convert the value of the field to human-readable string.
Definition TSdlStructArray.ipp:45
TSdlStructArray & description(std::string descriptionStr)
Definition TSdlStructArray.ipp:270
void setValueVec(Owner &owner, std::vector< Struct > value) const
Definition TSdlStructArray.ipp:101
void ownedResources(const Owner &owner, std::vector< const ISdlResource * > &out_resources) const override
Get all SDL resources associated by owner.
Definition TSdlStructArray.ipp:55
The root for all renderer implementations.
Definition EEngineProject.h:6
EFieldImportance
Definition EFieldImportance.h:7