Nameless Engine
Loading...
Searching...
No Matches
ne::SerializableObjectFieldSerializer Class Reference

#include <SerializableObjectFieldSerializer.h>

Inheritance diagram for ne::SerializableObjectFieldSerializer:
ne::IFieldSerializer

Public Member Functions

virtual bool isFieldTypeSupported (const rfk::Field *pField) override
 
virtual std::optional< ErrorserializeField (toml::value *pTomlData, Serializable *pFieldOwner, const rfk::Field *pField, const std::string &sSectionName, const std::string &sEntityId, size_t &iSubEntityId, Serializable *pOriginalObject=nullptr) override
 
virtual std::optional< ErrordeserializeField (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
 
virtual std::optional< ErrorcloneField (Serializable *pFromInstance, const rfk::Field *pFromField, Serializable *pToInstance, const rfk::Field *pToField) override
 
virtual bool isFieldValueEqual (Serializable *pFieldAOwner, const rfk::Field *pFieldA, Serializable *pFieldBOwner, const rfk::Field *pFieldB) override
 
virtual bool isFieldTypeSupported (const rfk::Field *pField)=0
 
virtual std::optional< ErrorserializeField (toml::value *pTomlData, Serializable *pFieldOwner, const rfk::Field *pField, const std::string &sSectionName, const std::string &sEntityId, size_t &iSubEntityId, Serializable *pOriginalObject=nullptr)=0
 
virtual std::optional< ErrordeserializeField (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)=0
 
virtual std::optional< ErrorcloneField (Serializable *pFromInstance, const rfk::Field *pFromField, Serializable *pToInstance, const rfk::Field *pToField)=0
 
virtual bool isFieldValueEqual (Serializable *pFieldAOwner, const rfk::Field *pFieldA, Serializable *pFieldBOwner, const rfk::Field *pFieldB)=0
 

Static Public Member Functions

static std::optional< ErrorserializeFieldObject (Serializable *pObject, toml::value *pTomlData, const std::string &sFieldName, const std::string &sSectionName, const std::string &sEntityId, size_t &iSubEntityId, Serializable *pOriginalObject=nullptr)
 
static std::optional< ErrorcloneSerializableObject (Serializable *pFrom, Serializable *pTo, bool bNotifyAboutDeserialized)
 
static std::variant< std::unique_ptr< Serializable >, ErrordeserializeSerializableObject (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)
 
static bool isSerializableObjectValueEqual (Serializable *pObjectA, Serializable *pObjectB)
 
static bool isTypeDerivesFromSerializable (const std::string &sCanonicalTypeName)
 
static bool isFieldSerializable (rfk::Field const &field)
 
static bool isDerivedFromSerializable (rfk::Archetype const *pArchetype)
 

Static Private Member Functions

static bool isTypeDerivesFromSerializable (const std::string &sCanonicalTypeName, const rfk::Namespace *pNamespace)
 

Static Private Attributes

static const auto sSubEntityFieldNameKey = ".field_name"
 

Friends

class GameManager
 

Detailed Description

Serializer for field types that derive from Serializable class.

Member Function Documentation

◆ cloneField()

std::optional< Error > ne::SerializableObjectFieldSerializer::cloneField ( Serializable pFromInstance,
const rfk::Field *  pFromField,
Serializable pToInstance,
const rfk::Field *  pToField 
)
overridevirtual

Clones field's data from one object to another.

Parameters
pFromInstanceInstance to copy the field from.
pFromFieldField to copy.
pToInstanceInstance to copy to.
pToFieldField to copy to.
Returns
Error if something went wrong, empty otherwise.

Implements ne::IFieldSerializer.

◆ cloneSerializableObject()

std::optional< Error > ne::SerializableObjectFieldSerializer::cloneSerializableObject ( Serializable pFrom,
Serializable pTo,
bool  bNotifyAboutDeserialized 
)
static

Clones reflected serializable fields of one object to another.

Remarks
This function can be used by other serializers.
Parameters
pFromObject to clone fields from.
pToObject to clone fields to.
bNotifyAboutDeserializedWhether or not to notify the target object we cloned fields to about it being finally deserialized or not. This should be true if you are calling this function as the last step of your deserialize function or in some special cases for new objects that won't reach deserialize function (for ex. when copying data to new object), otherwise false.
Returns
Error if something went wrong.

◆ deserializeField()

std::optional< Error > ne::SerializableObjectFieldSerializer::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 
)
overridevirtual

Deserializes field from a TOML value.

Parameters
pTomlDocumentTOML document that contains a value to deserialize.
pTomlValueTOML value to deserialize the field from.
pFieldOwnerField's owner.
pFieldField to deserialize TOML value to.
sOwnerSectionNameName of the TOML section where is field was found.
sEntityIdCurrent ID string of the entity (field owner) that we are deserializing.
customAttributesPairs of values that were found with this object in TOML data. Only found when deserializing a field of type that derives from Serializable.
Returns
Error if something went wrong, empty otherwise.

Implements ne::IFieldSerializer.

◆ deserializeSerializableObject()

std::variant< std::unique_ptr< Serializable >, Error > ne::SerializableObjectFieldSerializer::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 
)
static

Deserializes field's object from a TOML value.

Remarks
This function can be used by other serializers.
Parameters
pTomlDocumentTOML document that contains a value to deserialize.
pTomlValueTOML value to deserialize the field from.
sFieldNameName of the field to deserialize to.
pTargetField's object to deserialize the value to.
sOwnerSectionNameName of the TOML section where is field was found.
sEntityIdCurrent ID string of the entity (field owner) that we are deserializing.
customAttributesPairs of values that were found with this object in TOML data. Only found when deserializing a field of type that derives from Serializable.
Returns
Error if something went wrong, otherwise deserialized object.

◆ isDerivedFromSerializable()

bool ne::SerializableObjectFieldSerializer::isDerivedFromSerializable ( rfk::Archetype const *  pArchetype)
static

Tests whether the specified archetype is Serializable or derives at some point from Serializable class.

Parameters
pArchetypeArchetype to test.
Returns
Whether the specified archetype is derived from Serializable or not.

◆ isFieldSerializable()

bool ne::SerializableObjectFieldSerializer::isFieldSerializable ( rfk::Field const &  field)
static

Returns whether the specified field can be serialized or not.

Parameters
fieldField to test.
Returns
Whether the field can be serialized or not.

◆ isFieldTypeSupported()

bool ne::SerializableObjectFieldSerializer::isFieldTypeSupported ( const rfk::Field *  pField)
overridevirtual

Tests if this serializer supports serialization/deserialization of this field.

Parameters
pFieldField to test for serialization/deserialization support.
Returns
true if this serializer can be used to serialize this field, false otherwise.

Implements ne::IFieldSerializer.

◆ isFieldValueEqual()

bool ne::SerializableObjectFieldSerializer::isFieldValueEqual ( Serializable pFieldAOwner,
const rfk::Field *  pFieldA,
Serializable pFieldBOwner,
const rfk::Field *  pFieldB 
)
overridevirtual

Checks if the specified fields' values are equal or not.

Parameters
pFieldAOwnerOwner of the field A.
pFieldAField A to compare.
pFieldBOwnerOwner of the field B.
pFieldBField B to compare.
Returns
false if some field is unsupported by this serializer or if fields' values are not equal, true otherwise.

Implements ne::IFieldSerializer.

◆ isSerializableObjectValueEqual()

bool ne::SerializableObjectFieldSerializer::isSerializableObjectValueEqual ( Serializable pObjectA,
Serializable pObjectB 
)
static

Checks if the specified fields' values are equal or not.

Remarks
Uses all registered field serializers to compare each field.
This function can be used by other serializers.
Parameters
pObjectAObject to compare with B.
pObjectBObject to compare with A.
Returns
false if some field is unsupported by this serializer or if fields' values are not equal, true otherwise.

◆ isTypeDerivesFromSerializable() [1/2]

bool ne::SerializableObjectFieldSerializer::isTypeDerivesFromSerializable ( const std::string &  sCanonicalTypeName)
static

Looks if the specified canonical type name derives from Serializable or not.

Parameters
sCanonicalTypeNameCanonical type name (not just type name, see rfk::Field::getCanonicalTypeName).
Returns
false if the specified type was not found to be derived from Serializable, otherwise true.

◆ isTypeDerivesFromSerializable() [2/2]

bool ne::SerializableObjectFieldSerializer::isTypeDerivesFromSerializable ( const std::string &  sCanonicalTypeName,
const rfk::Namespace *  pNamespace 
)
staticprivate

Looks if the specified canonical type name derives from Serializable.

Parameters
sCanonicalTypeNameCanonical type name without namespace in the name.
pNamespaceOptional. Namespace that the specified type resides in.
Returns
false if the specified type was not found to be derived from Serializable, otherwise true.

◆ serializeField()

std::optional< Error > ne::SerializableObjectFieldSerializer::serializeField ( toml::value *  pTomlData,
Serializable pFieldOwner,
const rfk::Field *  pField,
const std::string &  sSectionName,
const std::string &  sEntityId,
size_t &  iSubEntityId,
Serializable pOriginalObject = nullptr 
)
overridevirtual

Serializes field into a TOML value.

Parameters
pTomlDataTOML value to serialize the field to.
pFieldOwnerField's owner.
pFieldField to serialize.
sSectionNameName of the section (for TOML value) to use for this field.
sEntityIdCurrent ID string of the entity (field owner) that we are serializing. Only used when serializing a field of type that derives from Serializable.
iSubEntityIdCurrent ID of the sub entity (sub entity of the field owner). Only used when serializing a field of type that derives from Serializable.
pOriginalObjectOptional. Original object of the same type as the object being serialized, this object is a deserialized version of the object being serialized, used to compare serializable fields' values and only serialize changed values. Only used when serializing a field of type that derives from Serializable.
Returns
Error if something went wrong, empty otherwise.

Implements ne::IFieldSerializer.

◆ serializeFieldObject()

std::optional< Error > ne::SerializableObjectFieldSerializer::serializeFieldObject ( Serializable pObject,
toml::value *  pTomlData,
const std::string &  sFieldName,
const std::string &  sSectionName,
const std::string &  sEntityId,
size_t &  iSubEntityId,
Serializable pOriginalObject = nullptr 
)
static

Serializes field's object (serializable object wrapped into a container, such as gc) into a TOML value.

Remarks
This function can be used by other serializers.
Parameters
pObjectObject to serialize.
pTomlDataTOML value to serialize the field to.
sFieldNameName of the field to serialize.
sSectionNameName of the section (for TOML value) to use for this field.
sEntityIdCurrent ID string of the entity (field owner) that we are serializing. Only used when serializing a field of type that derives from Serializable.
iSubEntityIdCurrent ID of the sub entity (sub entity of the field owner). Only used when serializing a field of type that derives from Serializable.
pOriginalObjectOptional. Original object of the same type as the object being serialized, this object is a deserialized version of the object being serialized, used to compare serializable fields' values and only serialize changed values. Only used when serializing a field of type that derives from Serializable.
Returns
Error if something went wrong, empty otherwise.

Member Data Documentation

◆ sSubEntityFieldNameKey

const auto ne::SerializableObjectFieldSerializer::sSubEntityFieldNameKey = ".field_name"
inlinestaticprivate

Name of the key in which to store name of the field a section represents.


The documentation for this class was generated from the following files: