Nameless Engine
Loading...
Searching...
No Matches
SerializableObjectFieldSerializer.h
1#pragma once
2
3// Standard.
4#include <variant>
5
6// Custom.
7#include "io/serializers/IFieldSerializer.hpp"
8
9namespace rfk {
10 class Struct;
11 class Field;
12 class Archetype;
13} // namespace rfk
14
15namespace ne {
20 // Checks GUIDs uniqueness in debug builds.
21 friend class GameManager;
22
23 public:
25 virtual ~SerializableObjectFieldSerializer() override = default;
26
48 [[nodiscard]] static std::optional<Error> serializeFieldObject(
49 Serializable* pObject,
50 toml::value* pTomlData,
51 const std::string& sFieldName,
52 const std::string& sSectionName,
53 const std::string& sEntityId,
54 size_t& iSubEntityId,
55 Serializable* pOriginalObject = nullptr);
56
72 [[nodiscard]] static std::optional<Error>
73 cloneSerializableObject(Serializable* pFrom, Serializable* pTo, bool bNotifyAboutDeserialized);
74
92 static std::variant<std::unique_ptr<Serializable>, Error> deserializeSerializableObject(
93 const toml::value* pTomlDocument,
94 const toml::value* pTomlValue,
95 const std::string& sFieldName,
96 Serializable* pTarget,
97 const std::string& sOwnerSectionName,
98 const std::string& sEntityId,
99 std::unordered_map<std::string, std::string>& customAttributes);
100
114 static bool isSerializableObjectValueEqual(Serializable* pObjectA, Serializable* pObjectB);
115
125 static bool isTypeDerivesFromSerializable(const std::string& sCanonicalTypeName);
126
134 static bool isFieldSerializable(rfk::Field const& field);
135
144 static bool isDerivedFromSerializable(rfk::Archetype const* pArchetype);
145
153 virtual bool isFieldTypeSupported(const rfk::Field* pField) override;
154
173 [[nodiscard]] virtual std::optional<Error> serializeField(
174 toml::value* pTomlData,
175 Serializable* pFieldOwner,
176 const rfk::Field* pField,
177 const std::string& sSectionName,
178 const std::string& sEntityId,
179 size_t& iSubEntityId,
180 Serializable* pOriginalObject = nullptr) override;
181
197 [[nodiscard]] virtual std::optional<Error> deserializeField(
198 const toml::value* pTomlDocument,
199 const toml::value* pTomlValue,
200 Serializable* pFieldOwner,
201 const rfk::Field* pField,
202 const std::string& sOwnerSectionName,
203 const std::string& sEntityId,
204 std::unordered_map<std::string, std::string>& customAttributes) override;
205
216 [[nodiscard]] virtual std::optional<Error> cloneField(
217 Serializable* pFromInstance,
218 const rfk::Field* pFromField,
219 Serializable* pToInstance,
220 const rfk::Field* pToField) override;
221
233 virtual bool isFieldValueEqual(
234 Serializable* pFieldAOwner,
235 const rfk::Field* pFieldA,
236 Serializable* pFieldBOwner,
237 const rfk::Field* pFieldB) override;
238
239 private:
240#if defined(DEBUG)
247 static void checkGuidUniqueness();
248
255 static void collectGuids(
256 const rfk::Struct* pArchetypeToAnalyze, std::unordered_map<std::string, std::string>& vAllGuids);
257#endif
258
269 const std::string& sCanonicalTypeName, const rfk::Namespace* pNamespace);
270
272 static inline const auto sSubEntityFieldNameKey = ".field_name";
273 };
274} // namespace ne
Definition: Error.h:27
Definition: GameManager.h:34
Definition: IFieldSerializer.hpp:33
Definition: SerializableObjectFieldSerializer.h:19
static bool isFieldSerializable(rfk::Field const &field)
Definition: SerializableObjectFieldSerializer.cpp:393
static bool isDerivedFromSerializable(rfk::Archetype const *pArchetype)
Definition: SerializableObjectFieldSerializer.cpp:410
virtual bool isFieldValueEqual(Serializable *pFieldAOwner, const rfk::Field *pFieldA, Serializable *pFieldBOwner, const rfk::Field *pFieldB) override
Definition: SerializableObjectFieldSerializer.cpp:541
virtual bool isFieldTypeSupported(const rfk::Field *pField) override
Definition: SerializableObjectFieldSerializer.cpp:14
virtual std::optional< Error > serializeField(toml::value *pTomlData, Serializable *pFieldOwner, const rfk::Field *pField, const std::string &sSectionName, const std::string &sEntityId, size_t &iSubEntityId, Serializable *pOriginalObject=nullptr) override
Definition: SerializableObjectFieldSerializer.cpp:19
static std::optional< Error > cloneSerializableObject(Serializable *pFrom, Serializable *pTo, bool bNotifyAboutDeserialized)
Definition: SerializableObjectFieldSerializer.cpp:52
static const auto sSubEntityFieldNameKey
Definition: SerializableObjectFieldSerializer.h:272
static bool isTypeDerivesFromSerializable(const std::string &sCanonicalTypeName)
Definition: SerializableObjectFieldSerializer.cpp:335
static std::optional< Error > serializeFieldObject(Serializable *pObject, toml::value *pTomlData, const std::string &sFieldName, const std::string &sSectionName, const std::string &sEntityId, size_t &iSubEntityId, Serializable *pOriginalObject=nullptr)
Definition: SerializableObjectFieldSerializer.cpp:635
static std::variant< std::unique_ptr< Serializable >, Error > deserializeSerializableObject(const toml::value *pTomlDocument, const toml::value *pTomlValue, const std::string &sFieldName, Serializable *pTarget, const std::string &sOwnerSectionName, const std::string &sEntityId, std::unordered_map< std::string, std::string > &customAttributes)
Definition: SerializableObjectFieldSerializer.cpp:140
virtual std::optional< Error > cloneField(Serializable *pFromInstance, const rfk::Field *pFromField, Serializable *pToInstance, const rfk::Field *pToField) override
Definition: SerializableObjectFieldSerializer.cpp:513
virtual std::optional< Error > deserializeField(const toml::value *pTomlDocument, const toml::value *pTomlValue, Serializable *pFieldOwner, const rfk::Field *pField, const std::string &sOwnerSectionName, const std::string &sEntityId, std::unordered_map< std::string, std::string > &customAttributes) override
Definition: SerializableObjectFieldSerializer.cpp:472
static bool isSerializableObjectValueEqual(Serializable *pObjectA, Serializable *pObjectB)
Definition: SerializableObjectFieldSerializer.cpp:262
Definition: Serializable.h:113