fpmas 1.5
Static Public Member Functions | List of all members
fpmas::io::json::light_serializer< fpmas::api::model::AgentPtr > Struct Reference

#include <model.h>

Static Public Member Functions

static void to_json (light_json &j, const fpmas::api::model::AgentPtr &pointer)
 
static fpmas::api::model::AgentPtr from_json (const light_json &j)
 

Detailed Description

fpmas::api::model::AgentPtr fpmas::io::json::light_json serialization rules declaration.

to_json and from_json methods must be defined by the user at compile time, depending on its own Agent types, using the FPMAS_JSON_SET_UP() macro, that must be called from a source file. Otherwise, linker errors will be thrown.

Member Function Documentation

◆ to_json()

static void fpmas::io::json::light_serializer< fpmas::api::model::AgentPtr >::to_json ( light_json j,
const fpmas::api::model::AgentPtr pointer 
)
static

Serializes the Agent represented by pointer to the specified light_json j.

Notice that since Agent is polymorphic, the actual to_json call that corresponds to the most derived type of the specified Agent is resolved at runtime.

The light_json version of the to_json() method attempts to serialize the agent with the less data possible, i.e. possibly nothing if the Agent is default constructible, and no user defined light_json serialization rules have been provided.

If Agent is not default constructible, the classic nlohmann::adl_serializer<PtrWrapper<AgentType>> is used, what might be inefficient.

See also
light_serializer<PtrWrapper<AgentType>>::to_json() (default constructible AgentType)
light_serializer<PtrWrapper<AgentType>>::to_json() (not default constructible AgentType)
Parameters
jjson output
pointerpointer to polymorphic Agent

◆ from_json()

Unserializes an Agent from the specified light_json j.

The built Agent is dynamically allocated, but is automatically managed by the fpmas::api::model::AgentPtr wrapper.

Since Agent is polymorphic, the concrete type that should be instantiated from the input light_json j is determined at runtime.

The light_json version of the from_json() method attempts to build the Agent using a default constructor, to bypass the classical json serialization process.

If Agent is not default constructible, the classic nlohmann::adl_serializer<PtrWrapper<AgentType>> is used, what might be inefficient.

See also
light_serializer<PtrWrapper<AgentType>>::from_json() (default constructible AgentType)
light_serializer<PtrWrapper<AgentType>>::from_json() (not default constructible AgentType)
Parameters
jinput json
Returns
dynamically allocated Agent, unserialized from j, wrapped in an fpmas::api::model::AgentPtr instance

The documentation for this struct was generated from the following file: