fpmas 1.6
Static Public Member Functions | List of all members
fpmas::io::json::AgentPtrSerializer< JsonType, Type, AgentTypes > Struct Template Reference

#include <json_serializer.h>

Static Public Member Functions

static void to_json (JsonType &j, const WeakAgentPtr &ptr)
 
static WeakAgentPtr from_json (const JsonType &j)
 

Detailed Description

template<typename JsonType, typename Type, typename... AgentTypes>
struct fpmas::io::json::AgentPtrSerializer< JsonType, Type, AgentTypes >

Generic AgentPtr serializer, that recursively deduces the final and concrete types of polymorphic AgentPtr instances.

Template Parameters
JsonTypetype of json used for serialization
Typetype currently inspected
AgentTypesagent types not inspected yet (must end with void)

Member Function Documentation

◆ to_json()

template<typename JsonType , typename Type , typename... AgentTypes>
static void fpmas::io::json::AgentPtrSerializer< JsonType, Type, AgentTypes >::to_json ( JsonType &  j,
const WeakAgentPtr &  ptr 
)
inlinestatic

Recursive to_json method used to serialize polymorphic Agent pointers as JSON.

Type corresponds to the currently examined Agent type. If this type id (i.e. Type::TYPE_ID) corresponds to the ptr Agent type (i.e. ptr->typedId()), the underlying agent is serialized using the specified JsonType.

Else, attempts to recursively serialize ptr with to_json<AgentTypes...>(j, ptr). Notice that the last value of AgentTypes must be void to reach the recursion base case (see to_json<void>).

Parameters
jjson
ptrpolymorphic agent pointer to serialize
See also
nlohmann::adl_serializer<std::type_index>::to_json (used to serialize the agent type id)

◆ from_json()

template<typename JsonType , typename Type , typename... AgentTypes>
static WeakAgentPtr fpmas::io::json::AgentPtrSerializer< JsonType, Type, AgentTypes >::from_json ( const JsonType &  j)
inlinestatic

Recursive from_json method used to unserialize polymorphic Agent pointers from JSON.

Type corresponds to the currently examined Agent type. If this type id (i.e. Type::TYPE_ID) corresponds to the JSON type id value (i.e. j.at("type").get<fpmas::api::model::TypeId>()), the JSON value is unserialized using the specified JsonType.

Else, attempts to recursively unserialize the JSON value with from_json<AgentTypes...>(j, ptr). Notice that the last value of AgentTypes must be void to reach the recursion base case (see from_json<void>).

Parameters
jjson
Returns
ptr unserialized polymorphic agent pointer
See also
nlohmann::adl_serializer<std::type_index>::from_json (used to unserialize the agent type id)

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