|
CeresEngine 0.2.0
A game development framework
|
A context that is shared between multiple serializer and deserializer instances. More...
#include <CeresEngine/Serialization/Serialization.hpp>
Classes | |
| struct | CustomSerialization |
| Holds data for custom serialization for a custom serializer/deserializer. More... | |
Public Member Functions | |
| SerializationContext () noexcept=default | |
| Creates a new root serialization context. | |
| SerializationContext (const SerializationContext &parent) | |
| Creates a new serialization sub-context with the given parent. | |
| template<typename T > | |
| void | addConstructor (Constructor &&constructor) |
Registers a new constructor for type T. | |
| Box | construct (SerializationState &state, const Type &type) const |
Constructs a new instance of the given type. | |
| template<typename T > | |
| Box | construct (SerializationState &state) const |
Constructs a new instance of the given type T. | |
| template<typename T > | |
| void | addPropertyMigration (const StringView propertyName, PropertyMigration &&migration) |
Adds a new property migration for the given propertyName for type T. | |
| template<typename T , typename CustomSerializer , typename CustomDeserializer > | |
| void | addCustomSerialization (CustomSerializer &&customSerializer, CustomDeserializer &&customDeserializer) |
Registers a new custom serializer for type T. | |
| template<typename T , typename CustomSerializer , typename CustomDeserializer > | |
| void | addCustomSerialization (const CustomSerializationOptions &options, CustomSerializer &&customSerializer, CustomDeserializer &&customDeserializer) |
Registers a new custom serializer for type T. | |
| void | addCustomSerialization (const Type &type, CustomSerializer &&customSerializer, CustomDeserializer &&customDeserializer) |
Registers a new custom serializer for type. | |
| void | addCustomSerialization (const Type &type, const CustomSerializationOptions &options, CustomSerializer &&customSerializer, CustomDeserializer &&customDeserializer) |
Registers a new custom serializer for type. | |
| const CustomSerializationOptions & | getCustomSerializationOptions (const Type &type) const |
| Gets a custom serializer/deserializer for the given type, if any exists. | |
| const CustomSerializer & | getCustomSerializer (const Type &type) const |
| Gets a custom serializer for the given type, if any exists. | |
| const CustomDeserializer & | getCustomDeserializer (const Type &type) const |
| Gets a custom deserializer for the given type, if any exists. | |
| void | willSerialize (const Box &object) const |
Fires the willSerialize callback for the given object. | |
| void | didSerialize (const Box &object) const |
Fires the didSerialize callback for the given object. | |
| void | willSerializeProperty (const Box &object, const ClassProperty &property) const |
Fires the willSerializeProperty callback for the given property of the object. | |
| void | didSerializeProperty (const Box &object, const ClassProperty &property) const |
Fires the didSerializeProperty callback for the given property of the object. | |
| void | willDeserialize (const Box &object) const |
Fires the willDeserialize callback for the given object. | |
| void | didDeserialize (const Box &object) const |
Fires the didDeserialize callback for the given object. | |
| void | willDeserializeProperty (const Box &object, const ClassProperty &property) const |
Fires the willDeserializeProperty callback for the given property of the object. | |
| void | didDeserializeProperty (const Box &object, const ClassProperty &property) const |
Fires the didDeserializeProperty callback for the given property of the object. | |
Static Public Member Functions | |
| static const SerializationContext & | getDefault () |
| Gets the default serialization context to be used in case the user doesn't provide one himself. | |
Private Types | |
| using | Constructor = DeserializerConstructor |
| A type that represents the constructor function. | |
| using | PropertyMigration = DeserializerPropertyMigrator |
| Represents the signature of the function that performs migration of an abandoned serialized property. | |
| template<typename Func > | |
| using | ForEachContextReturnType = std::invoke_result_t< Func, const SerializationContext & > |
Determines the return type for the forEachContext call. | |
Private Member Functions | |
| template<typename Func > | |
| ForEachContextReturnType< Func > | forEachContext (Func &&func, const ForEachContextReturnType< Func > &defaultValue={}) const |
Executes the given function on each context until there are no more parent contexts or func returns a truthy value. | |
| template<typename K , typename V , typename Hash , typename KeyEqual , typename RawAllocator > | |
| const V * | recursiveLookup (HashMap< K, V, Hash, KeyEqual, RawAllocator > SerializationContext::*ptr, const K &key) const |
| Recursively lookups the given hash map in this context and all parents until the root. | |
Private Attributes | |
| const SerializationContext * | mParent = nullptr |
| The parent context. | |
| HashMap< TypeID, Constructor > | mConstructors |
| A hash map that indexes constructors by type. | |
| HashMap< TypeID, HashMap< String, PropertyMigration > > | mPropertyMigrations |
| HashMap< TypeID, CustomSerialization > | mCustomSerialization |
| A map of registered custom serialization functions. | |
A context that is shared between multiple serializer and deserializer instances.
A type that represents the constructor function.
|
private |
Determines the return type for the forEachContext call.
Represents the signature of the function that performs migration of an abandoned serialized property.
|
explicitdefaultnoexcept |
Creates a new root serialization context.
|
inline |
Creates a new serialization sub-context with the given parent.
|
inline |
Registers a new constructor for type T.
| T | The type to register a constructor for. |
| constructor | A function to be called whenever a new instance of type T is required by the serializer. |
|
inline |
Registers a new custom serializer for type T.
| T | The type to register a new custom serializer/deserializer for. |
| options | A structure that contains options for the custom serializer. |
| customSerializer | The custom serializer function. |
| customDeserializer | The custom deserializer function. |
| void CeresEngine::SerializationContext::addCustomSerialization | ( | const Type & | type, |
| const CustomSerializationOptions & | options, | ||
| CustomSerializer && | customSerializer, | ||
| CustomDeserializer && | customDeserializer | ||
| ) |
Registers a new custom serializer for type.
| type | The type to register a new custom serializer/deserializer for. |
| options | A structure that contains options for the custom serializer. |
| customSerializer | The custom serializer function. |
| customDeserializer | The custom deserializer function. |
|
inline |
Registers a new custom serializer for type.
| type | The type to register a new custom serializer/deserializer for. |
| customSerializer | The custom serializer function. |
| customDeserializer | The custom deserializer function. |
|
inline |
Registers a new custom serializer for type T.
| T | The type to register a new custom serializer/deserializer for. |
| customSerializer | The custom serializer function. |
| customDeserializer | The custom deserializer function. |
|
inline |
Adds a new property migration for the given propertyName for type T.
| T | The type of the object to add a new migration for. |
| propertyName | The name of the property to execute the migration with. |
| migration | A function-like object that executes the migration for the property. |
|
inline |
Constructs a new instance of the given type T.
| Box CeresEngine::SerializationContext::construct | ( | SerializationState & | state, |
| const Type & | type | ||
| ) | const |
Constructs a new instance of the given type.
Fires the didDeserialize callback for the given object.
| void CeresEngine::SerializationContext::didDeserializeProperty | ( | const Box & | object, |
| const ClassProperty & | property | ||
| ) | const |
Fires the didDeserializeProperty callback for the given property of the object.
Fires the didSerialize callback for the given object.
| void CeresEngine::SerializationContext::didSerializeProperty | ( | const Box & | object, |
| const ClassProperty & | property | ||
| ) | const |
Fires the didSerializeProperty callback for the given property of the object.
|
private |
Executes the given function on each context until there are no more parent contexts or func returns a truthy value.
For most cases, func should return an Optional, but pointers or pointer-like objects are valid return types.
| func | The function to be called. |
| defaultValue | The default value to be returned if all calls to func() returned falsy values. |
defaultValue. | const CustomDeserializer & CeresEngine::SerializationContext::getCustomDeserializer | ( | const Type & | type | ) | const |
Gets a custom deserializer for the given type, if any exists.
If no custom deserializer exists, returns a nullptr callable.
| type | The type to get a custom deserializer for. |
| const CustomSerializationOptions & CeresEngine::SerializationContext::getCustomSerializationOptions | ( | const Type & | type | ) | const |
Gets a custom serializer/deserializer for the given type, if any exists.
If no custom serializer or deserializer exists, returns a default one.
| type | The type to get a custom serialization options for. |
| const CustomSerializer & CeresEngine::SerializationContext::getCustomSerializer | ( | const Type & | type | ) | const |
Gets a custom serializer for the given type, if any exists.
If no custom serializer exists, returns a nullptr callable.
| type | The type to get a custom serializer for. |
|
static |
Gets the default serialization context to be used in case the user doesn't provide one himself.
|
private |
Recursively lookups the given hash map in this context and all parents until the root.
If a match is found, returns a reference to it's value.
| ptr | A member pointer to the hash map to perform the lookup on. |
| key | The key value to be looked up. |
Fires the willDeserialize callback for the given object.
| void CeresEngine::SerializationContext::willDeserializeProperty | ( | const Box & | object, |
| const ClassProperty & | property | ||
| ) | const |
Fires the willDeserializeProperty callback for the given property of the object.
Fires the willSerialize callback for the given object.
| void CeresEngine::SerializationContext::willSerializeProperty | ( | const Box & | object, |
| const ClassProperty & | property | ||
| ) | const |
Fires the willSerializeProperty callback for the given property of the object.
|
private |
A hash map that indexes constructors by type.
|
private |
A map of registered custom serialization functions.
|
private |
The parent context.
Allows creating nested contexts that specialize from a common parent.
|
private |