template<typename AgentType>
struct fpmas::io::json::light_serializer< fpmas::api::utils::PtrWrapper< AgentType >, typename std::enable_if< std::is_base_of< fpmas::api::model::Agent, AgentType >::value &&!std::is_default_constructible< AgentType >::value &&std::is_same< AgentType, typename AgentType::FinalAgentType >::value >::type >
A default light_serializer specialization for Agent types, when no default constructor is available. In this case, to_json() and from_json() methods falls back to the classic nlohmann::json serialization rules, what might be inefficient. A warning is also printed at runtime.
To avoid this inefficient behaviors, two things can be performed:
- Defining a default constructor for
AgentType. Notice that the default constructed AgentType will never be used by FPMAS (since AgentType transmitted in a light_json are completely passive, a complete DistributedNode transfer is always performed when the Agent data is required).
- Specializing the light_serializer with
AgentType: namespace fpmas {
namespace io {
namespace json {
template<>
struct light_serializer<
fpmas::api::utils::PtrWrapper<CustomAgentType>> {
...
}
...
return new CustomAgentType(...);
}
};
}}}
Definition: ptr_wrapper.h:21
nlohmann::basic_json< std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, light_serializer > light_json
Definition: json.h:14
static fpmas::api::utils::PtrWrapper< AgentType > from_json(const light_json &j)
Definition: json_serializer.h:419
static void to_json(light_json &j, const fpmas::api::utils::PtrWrapper< AgentType > &agent)
Definition: json_serializer.h:395
- Template Parameters
-
| AgentType | concrete type of Agent to serialize |