fpmas 1.6
Classes | Namespaces | Macros
json_serializer.h File Reference
#include "serializer_set_up.h"
#include "fpmas/api/model/model.h"
#include "fpmas/io/json.h"
#include "fpmas/model/model.h"
Include dependency graph for json_serializer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  nlohmann::adl_serializer< std::type_index >
 
struct  nlohmann::adl_serializer< fpmas::api::utils::PtrWrapper< 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 >
 
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 >
 
struct  fpmas::io::json::AgentPtrSerializer< JsonType, void >
 
struct  fpmas::io::json::AgentPtrSerializer< JsonType, Type, AgentTypes >
 

Namespaces

namespace  nlohmann
 
namespace  fpmas
 
namespace  fpmas::io
 
namespace  fpmas::io::json
 

Macros

#define FPMAS_BASE_JSON_SET_UP(...)
 
#define FPMAS_BASE_DEFAULT_JSON_SET_UP()
 
#define FPMAS_DEFAULT_JSON(AGENT)
 

Detailed Description

Agent JSON serialization related objects.

Macro Definition Documentation

◆ FPMAS_BASE_JSON_SET_UP

#define FPMAS_BASE_JSON_SET_UP (   ...)

Defines the nlohmann specializations required to handle the JSON serialization of the specified set of Agent types.

Notice that this is only the definitions of the to_json and from_json methods, that are declared (but not defined) in src/fpmas/model/model.h.

In consequence, this macro must be invoked exaclty once from a source file, at the global definition level, in any C++ target using FPMAS.

This macro does not define any rule for AgentPtr ObjectPack serialization, so using only this macro will produce compile time errors.

Two solutions are available:

  • calling FPMAS_BASE_JSON_SET_UP() and FPMAS_BASE_DATAPACK_SET_UP(). This enable both AgentPtr serialization techniques, but to_datapack() and from_datapack() methods must be specified for all agents, in addition to the to_json() and from_json() methods.
  • just calling FPMAS_JSON_SET_UP(), instead of FPMAS_BASE_JSON_SET_UP(). This also enable both serialization techniques, but object pack serialization falls back to json serialization. This might be inefficient, but only requires to_json() and from_json() definitions.
See also
FPMAS_BASE_DATAPACK_SET_UP()
FPMAS_JSON_SET_UP()
FPMAS_DATAPACK_SET_UP()

◆ FPMAS_BASE_DEFAULT_JSON_SET_UP

#define FPMAS_BASE_DEFAULT_JSON_SET_UP ( )

Can be used instead of FPMAS_BASE_JSON_SET_UP() to set up json serialization without specifying any Agent type.

◆ FPMAS_DEFAULT_JSON

#define FPMAS_DEFAULT_JSON (   AGENT)
Value:
namespace nlohmann {\
template<>\\
struct adl_serializer<fpmas::api::utils::PtrWrapper<AGENT>> {\\
template<typename JsonType>\
static void to_json(JsonType& j, const fpmas::api::utils::PtrWrapper<AGENT>&) {\
j = json::object();\
}\
\\
template<typename JsonType>\
static void from_json(const JsonType&, fpmas::api::utils::PtrWrapper<AGENT>& ptr) {\
}\
};\
}
Definition: ptr_wrapper.h:21

Helper macro to easily define JSON serialization rules for DefaultConstructible Agents.

Parameters
AGENTDefaultConstructible Agent type