Skip to content

File include/brisk/core/Serialization.hpp


SerializationAction enum

enum class SerializationAction

Enum representing the action performed during serialization.

Load enumerator (SerializationAction::Load)

Load data during deserialization.

Save enumerator (SerializationAction::Save)

Save data during serialization.


SerializableInterface class

SerializableInterface

Interface for serializable objects.


Serialization class

Serialization

Handles serialization and deserialization of data to and from JSON.

The Serialization struct provides functionality to perform both loading (deserialization) and saving (serialization) of object data. It interacts with a Json object to store and retrieve values.

action variable (Serialization::action)

SerializationAction action

The current serialization action (load or save).

data variable (Serialization::data)

mutable Json data

The JSON data being processed.

callback variable (Serialization::callback)

function<void(Json &&)> callback

Optional callback invoked at destruction, useful for nested serialization contexts.

Serialization function (Serialization::Serialization)

Serialization() = default

Default constructor.

Serialization(const Serialization &) = default

Copy constructor.

Serialization(Serialization &&) = default

Move constructor.

~Serialization function (Serialization::~Serialization)

~Serialization()

Destructor, invokes the callback with the processed JSON data.

serializationError function (Serialization::serializationError)

void serializationError() const

Logs an error during serialization.

deserializationError function (Serialization::deserializationError)

void deserializationError() const

Logs an error during deserialization.

operator() function (Serialization::operator())

template <typename Type>
void operator()(const Value<Type> &prop,
                std::string_view name) const

Processes a property of a specific type for serialization or deserialization.

If the current action is loading, it tries to retrieve the value from the JSON. If saving, it stores the value into the JSON.
Template param Type The type of the property.
Param prop The property to process.
Param name The JSON key associated with the property.

template <typename Value, typename Setter>
void operator()(Value &value, Setter &&setter,
                std::string_view name) const

Processes a value with a setter function for serialization or deserialization.

Useful when custom setting logic is required during loading.
Template param Value The type of the value being processed.
Template param Setter The setter function to apply when loading data.
Param value The value to process.
Param setter The setter function for the value.
Param name The JSON key associated with the value.

template <typename Value>
void operator()(Value &value, std::string_view name) const

Processes a value for serialization or deserialization.

Handles simple types without the need for a property wrapper.
Template param Value The type of the value being processed.
Param value The value to process.
Param name The JSON key associated with the value.

void operator()(SerializableInterface &value,
                std::string_view name) const

Processes a serializable object.

Calls the serialize method on the object, allowing it to handle its own serialization.
Param value The serializable object to process.
Param name The JSON key associated with the object.

key function (Serialization::key)

Serialization key(std::string_view name) const

Returns a new Serialization context for a nested JSON object under a specific key.

Allows handling of nested serialization for objects contained within another object.
Param name The key for the nested object in the JSON data.
Returns A new Serialization object for the nested context.

index function (Serialization::index)

Serialization index(int idx) const

Returns a new Serialization context for a specific index in a JSON array.

Allows handling of nested serialization for arrays.
Param idx The index of the array to process.
Returns A new Serialization object for the nested array context.


SerializableInterface class

SerializableInterface

Interface for serializable objects.

serialize function (SerializableInterface::serialize)

virtual void serialize(const Serialization &serialization)

Virtual method to be overridden by derived classes for custom serialization.
Param serialization The Serialization object used for the process.

serializeTo function (SerializableInterface::serializeTo)

void serializeTo(Json &dest)

Serializes the object to the given Json object.
Param dest The destination JSON object where the serialized data will be stored.

deserializeFrom function (SerializableInterface::deserializeFrom)

void deserializeFrom(const Json &src)

Deserializes the object from the given Json object.
Param src The source JSON object to load the data from.

SerializableInterface function (SerializableInterface::SerializableInterface)

SerializableInterface() = default

Default constructor.


operator() function

inline void
Serialization::operator()(SerializableInterface &value,
                          std::string_view name) const

Processes a serializable object.

Calls the serialize method on the object, allowing it to handle its own serialization.
Param value The serializable object to process.
Param name The JSON key associated with the object.


Auto-generated from sources, Revision , https://github.com/brisklib/brisk/blob//include/brisk/