15#include <Common/assertion.h>
22template<
typename Struct,
typename Owner>
24 std::string valueName,
25 std::vector<Struct> Owner::* const valuePtr)
30 "[S/" + getStructTypeName())
32 , m_valuePtr(valuePtr)
34 PH_ASSERT(m_valuePtr);
37template<
typename Struct,
typename Owner>
41 owner.*m_valuePtr = std::vector<Struct>{};
44template<
typename Struct,
typename Owner>
47 const std::vector<Struct>& structVector = owner.*m_valuePtr;
50 "[" + std::to_string(structVector.size()) +
" " +
51 getStructTypeName() +
" struct instances...]";
54template<
typename Struct,
typename Owner>
57 std::vector<const ISdlResource*>& out_resources)
const
64 const std::vector<Struct>& storedVector = getValueVec(owner);
65 for(
const Struct& storedObj : storedVector)
67 Struct::getSdlStruct()->referencedResources(&storedObj, out_resources);
71template<
typename Struct,
typename Owner>
74 std::vector<Struct>*
const structVec = &(owner.*m_valuePtr);
79 Struct*
const structVecData = structVec->data();
86 Struct*
const structPtr = &structVecData[elementIdx];
100template<
typename Struct,
typename Owner>
103 owner.*m_valuePtr = std::move(value);
106template<
typename Struct,
typename Owner>
109 return owner.*m_valuePtr;
112template<
typename Struct,
typename Owner>
120 setValueVec(owner, loadStructArray(clause, ctx));
124 throw_formatted<SdlLoadError>(
125 "on parsing struct array {} -> {}", valueToString(owner), e.whatStr());
129template<
typename Struct,
typename Owner>
135 const std::vector<Struct>& structVector = getValueVec(owner);
136 if(structVector.empty())
150 "requires named output clauses to save");
153 out_clause.
value =
'{';
154 for(
const Struct& obj : structVector)
157 Struct::getSdlStruct()->saveObject(&obj, objClauses, ctx);
162 out_clause.
value += generatedName;
163 out_clause.
value +=
' ';
165 out_clause.
value +=
'}';
169 throw_formatted<SdlSaveError>(
170 "unable to save struct array {} -> {}", valueToString(owner), e.whatStr());
174template<
typename Struct,
typename Owner>
179 static const Tokenizer tokenizer({
' ',
'\t',
'\n',
'\r'}, {{
'"',
'"'}});
184 "no target data packet group specified");
189 auto obj = loadStruct(clause.
value, ctx);
194 std::vector<std::string> tokens;
195 tokenizer.tokenize(clause.
value, tokens);
196 if(tokens.size() % 2 != 0)
198 throw SdlLoadError(
"syntax error: unexpected input format");
201 const auto numPacketNameTokens = tokens.size() / 2;
202 std::vector<Struct> structVector(numPacketNameTokens);
203 for(std::size_t i = 0; i < numPacketNameTokens; ++i)
205 const std::string packetNameToken = tokens[i * 2] + tokens[i * 2 + 1];
207 structVector[i] = loadStruct(packetName, ctx);
215 "bad data packet type (only cached target is supported)");
219template<
typename Struct,
typename Owner>
221 std::string_view packetName,
224 if(packetName.empty())
227 "packet name cannot be empty");
233 throw_formatted<SdlLoadError>(
234 "cannot find data packet with name <{}>", packetName);
243 Struct::getSdlStruct()->initObject(&obj, copiedPacket, ctx);
247template<
typename Struct,
typename Owner>
252 PH_ASSERT(Struct::getSdlStruct());
253 return std::string(Struct::getSdlStruct()->getTypeName());
261template<
typename Struct,
typename Owner>
265 this->setImportance(importance);
269template<
typename Struct,
typename Owner>
273 this->setDescription(std::move(descriptionStr));
277template<
typename Struct,
typename Owner>
284template<
typename Struct,
typename Owner>
291template<
typename Struct,
typename Owner>
virtual const SdlInputClauses * get(std::string_view packetName) const =0
General exception thrown on error related to SDL.
Definition sdl_exceptions.h:13
Data that SDL input process can rely on.
Definition SdlInputContext.h:19
const ISdlDataPacketGroup * getSrcDataPackets() const
Definition SdlInputContext.h:98
Error on the SDL input process.
Definition sdl_exceptions.h:22
void addOrUpdate(SdlOutputClauses clauses, std::string_view clausesName)
Add a named output clauses. Potentially update the existing one.
Definition SdlNamedOutputClauses.cpp:33
Definition SdlNativeData.h:88
std::size_t numElements
Hint for number of elements in this block of native data. For example, numElements would be 12 for an...
Definition SdlNativeData.h:99
void setDirectAccessor(AnyNonConstPtr accessor)
Definition SdlNativeData.ipp:267
static auto permissiveElementGetter(ElementType *elementPtr) -> SdlGetterVariant
Given a valid target element, get its value in a permissive way (with auto conversions).
Definition SdlNativeData.ipp:312
ESdlDataType elementType
Hint for the type of elements.
Definition SdlNativeData.h:113
ESdlDataFormat elementContainer
Hint for the type that encapsulates elements.
Definition SdlNativeData.h:109
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
bool isEmpty
If the clause carries no data and does not need to be written.
Definition SdlOutputClause.h:41
Definition SdlOutputClauses.h:14
Data that SDL output process can rely on.
Definition SdlOutputContext.h:19
SdlNamedOutputClauses * getNamedOutputClauses() const
Definition SdlOutputContext.h:97
Error on the SDL output process.
Definition sdl_exceptions.h:30
Definition SdlNativeData.h:24
References a SDL object. This is a lightweight utility for referencing SDL objects....
Definition TSdlAnyInstance.h:20
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
Definition Tokenizer.h:13
Whether T is a well-defined SDL struct.
Definition sdl_traits.h:36
constexpr char cached_specifier
Definition sdl_parser.h:10
std::string_view get_data_packet_name(std::string_view dataPacketNameToken)
Definition sdl_parser.cpp:136
The root for all renderer implementations.
Definition EEngineProject.h:6
TAnyPtr< false > AnyNonConstPtr
A type-safe, lightweight wrapper for any non-const raw pointer type.
Definition TAnyPtr.h:47
EFieldImportance
Definition EFieldImportance.h:7
@ General
Definition sdl_fwd.h:45
@ CachedTargetName
Definition sdl_fwd.h:51
Low-level helpers for SDL. Helpers are in an additional sdl namespace.