Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSdlString.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6
7#include <string>
8
9namespace ph
10{
11
12template<typename Owner, typename SdlValueType = TSdlValue<std::string, Owner>>
13class TSdlString : public SdlValueType
14{
15 static_assert(std::is_base_of_v<TSdlAbstractValue<std::string, Owner>, SdlValueType>,
16 "SdlValueType should be a subclass of TSdlAbstractValue.");
17
18public:
19 template<typename ValueType>
20 TSdlString(std::string valueName, ValueType Owner::* const valuePtr) :
21 SdlValueType("string", std::move(valueName), valuePtr)
22 {}
23
24 std::string valueAsString(const std::string& str) const override
25 {
26 return str;
27 }
28
29 SdlNativeData ownedNativeData(Owner& owner) const override
30 {
31 std::string* const str = this->getValue(owner);
34 }
35
36protected:
38 Owner& owner,
39 const SdlInputClause& clause,
40 const SdlInputContext& ctx) const override
41 {
42 // Load value directly as it is already a string
43 this->setValue(owner, clause.value);
44 }
45
47 const Owner& owner,
48 SdlOutputClause& out_clause,
49 const SdlOutputContext& ctx) const override
50 {
51 // Not testing whether the string contains whitespaces--just add double quotes
52 out_clause.value = '"';
53
54 if(const std::string* str = this->getConstValue(owner); str)
55 {
56 // Append value directly as it is already a string
57 out_clause.value += *str;
58 }
59
60 out_clause.value += '"';
61 }
62};
63
64}// end namespace ph
Carries SDL representation of various data during the input process. Helps to read input data such as...
Definition SdlInputClause.h:15
std::string value
Loaded stringified data of a clause. All potential SDL value prefixes or suffixes (e....
Definition SdlInputClause.h:25
Data that SDL input process can rely on.
Definition SdlInputContext.h:19
Definition SdlNativeData.h:88
static SdlNativeData fromSingleElement(ElementType *elementPtr, ESdlDataFormat elementContainer, ESdlDataType elementType, bool canSet=false, bool canDirectAccess=false)
Creates native data for a single element pointer.
Definition SdlNativeData.ipp:86
Carries SDL representation of various data during the output process. Helps to write output data such...
Definition SdlOutputClause.h:14
std::string value
Stores stringified data of a clause. As the output clause generator knows best how its data look like...
Definition SdlOutputClause.h:29
Data that SDL output process can rely on.
Definition SdlOutputContext.h:19
Definition TSdlString.h:14
std::string valueAsString(const std::string &str) const override
Definition TSdlString.h:24
TSdlString(std::string valueName, ValueType Owner::*const valuePtr)
Definition TSdlString.h:20
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 TSdlString.h:46
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 TSdlString.h:37
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 TSdlString.h:29
void setValue(Owner &owner, T value) const override
Store a value.
Definition TSdlValue.ipp:38
const T * getConstValue(const Owner &owner) const override
Get a pointer to the stored value.
Definition TSdlValue.ipp:50
T * getValue(Owner &owner) const override
Get a pointer to the stored value.
Definition TSdlValue.ipp:44
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96