fpmas 1.6
Namespaces | Macros | Functions
serializer.h File Reference
#include "json_serializer.h"
#include "datapack_serializer.h"
#include "fpmas/io/json_datapack.h"
Include dependency graph for serializer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  fpmas
 

Macros

#define FPMAS_AGENT_PTR_DATAPACK_JSON_FALLBACK()
 
#define FPMAS_AGENT_PTR_JSON_DATAPACK_FALLBACK()
 
#define FPMAS_JSON_SET_UP(...)
 
#define FPMAS_DEFAULT_JSON_SET_UP()
 
#define FPMAS_DATAPACK_SET_UP(...)
 
#define FPMAS_DEFAULT_DATAPACK_SET_UP()
 
#define FPMAS_REGISTER_AGENT_TYPES(...)    fpmas::register_types<__VA_ARGS__ , void>();
 

Functions

template<typename _T , typename... T>
void fpmas::register_types ()
 
template<>
void fpmas::register_types< void > ()
 

Detailed Description

Agent serialization related objects.

Macro Definition Documentation

◆ FPMAS_AGENT_PTR_DATAPACK_JSON_FALLBACK

#define FPMAS_AGENT_PTR_DATAPACK_JSON_FALLBACK ( )
Value:
namespace fpmas { namespace io { namespace datapack {\
std::size_t Serializer<AgentPtr>::size(const ObjectPack& p, const AgentPtr& ptr) {\
}\
void Serializer<AgentPtr>::to_datapack(ObjectPack& p, const AgentPtr& ptr) {\
JsonSerializer<AgentPtr>::to_datapack(p, ptr);\
}\
}\
std::size_t LightSerializer<AgentPtr>::size(const LightObjectPack& p, const AgentPtr& ptr) {\
}\
LightJsonSerializer<AgentPtr>::to_datapack(p, ptr);\
}\
}\
}}}
BasicObjectPack< LightSerializer > LightObjectPack
Definition: datapack.h:1395
BasicObjectPack< Serializer > ObjectPack
Definition: datapack.h:1393
Definition: fpmas.cpp:3
static T from_datapack(const PackType &pack)
Definition: json_datapack.h:77
static std::size_t size(const PackType &, const T &)
Definition: json_datapack.h:46
static void to_datapack(LightObjectPack &pack, const T &item)
Definition: datapack.h:1438
static std::size_t size(const LightObjectPack &p)
Definition: datapack.h:1418
static T from_datapack(const LightObjectPack &pack)
Definition: datapack.h:1451
static void to_datapack(ObjectPack &pack, const AgentPtr &pointer)
static AgentPtr from_datapack(const ObjectPack &pack)
static std::size_t size(const ObjectPack &p, const AgentPtr &ptr)

Defines a json based implementation of AgentPtr fpmas::io::datapack::Serializer and fpmas::io::datapack::LightSerializer implementation, that can be used instead of definitions provided by FPMAS_BASE_DATAPACK_SET_UP().

This allows to use the object pack serialization for DistributedNodes for example, even if ObjectPack serialization rules are not provided for AgentPtr (i.e. FPMAS_BASE_DATAPACK_SET_UP() is not used).

◆ FPMAS_AGENT_PTR_JSON_DATAPACK_FALLBACK

#define FPMAS_AGENT_PTR_JSON_DATAPACK_FALLBACK ( )
Value:
namespace nlohmann {\
void adl_serializer<fpmas::api::model::AgentPtr>\
::to_json(json& j, const fpmas::api::model::AgentPtr& ptr) {\
fpmas::io::json::datapack_serializer<fpmas::api::model::AgentPtr>\
::to_json(j, ptr);\
}\
fpmas::api::model::AgentPtr adl_serializer<fpmas::api::model::AgentPtr>\
::from_json(const json& j) {\
}\
}\
namespace fpmas { namespace io { namespace json {\
void light_serializer<api::model::AgentPtr>\
::to_json(light_json& j, const api::model::AgentPtr& ptr) {\
fpmas::io::json::light_datapack_serializer<api::model::AgentPtr>\
::to_json(j, ptr);\
}\
api::model::AgentPtr light_serializer<api::model::AgentPtr>\
::from_json(const light_json& j) {\
}\
}}}
Definition: model.h:92
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
Definition: json_datapack.h:181

Defines an object pack based implementation of AgentPtr nlohmann::adl_serializer and fpmas::io::json::light_serializer implementation, that can be used instead of definitions provided by FPMAS_BASE_JSON_SET_UP().

This allows to use the json serialization for DistributedNodes for example, even if JSON serialization rules are not provided for AgentPtr (i.e. FPMAS_BASE_JSON_SET_UP() is not used).

◆ FPMAS_JSON_SET_UP

#define FPMAS_JSON_SET_UP (   ...)
Value:
FPMAS_BASE_JSON_SET_UP(__VA_ARGS__)\
FPMAS_AGENT_PTR_DATAPACK_JSON_FALLBACK()
#define FPMAS_BASE_JSON_SET_UP(...)
Definition: json_serializer.h:40

Sets up json based Agent serialization rules.

This macro must be invoked exactly once from a source file and should not be called together with FPMAS_DATAPACK_SET_UP().

It is possible to call the FPMAS_DEFAULT_JSON_SET_UP() macro to set up the JSON serialization without specifying any Agent.

The same set of Agent types must be registered at runtime using the FPMAS_REGISTER_AGENT_TYPES(...) macro at runtime.

Example
#define AGENT_TYPES Agent1, Agent2, OtherAgent
FPMAS_JSON_SET_UP(AGENT_TYPES)
int main(int argc, char** argv) {
fpmas::init(argc, argv);
...
}
void finalize()
Definition: fpmas.cpp:18
void init(int argc, char **argv)
Definition: fpmas.cpp:6
#define FPMAS_JSON_SET_UP(...)
Definition: serializer.h:122
#define FPMAS_REGISTER_AGENT_TYPES(...)
Definition: serializer.h:214

ObjectPack Agent serialization is set up so that Agent are serialized into JSON, stored in an ObjectPack field. To prevent this behavior, FPMAS_BASE_JSON_SET_UP() and FPMAS_BASE_DATAPACK_SET_UP() can be used together to enable both Agent serialization techniques.

Notice that all of this only affect AgentPtr serialization: serialization of any other object, with JSON or ObjectPack, is not altered by those macros.

See the nlohmann::adl_serializer<fpmas::api::utils::PtrWrapper<AgentType>> documentation to learn how to enable Agent datapack serialization.

◆ FPMAS_DEFAULT_JSON_SET_UP

#define FPMAS_DEFAULT_JSON_SET_UP ( )
Value:
FPMAS_BASE_DEFAULT_DATAPACK_SET_UP()
#define FPMAS_BASE_DEFAULT_JSON_SET_UP()
Definition: json_serializer.h:82

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

◆ FPMAS_DATAPACK_SET_UP

#define FPMAS_DATAPACK_SET_UP (   ...)
Value:
FPMAS_AGENT_PTR_JSON_DATAPACK_FALLBACK()
#define FPMAS_BASE_DATAPACK_SET_UP(...)
Definition: datapack_serializer.h:42

Sets up object pack based Agent serialization rules.

This macro must be invoked exactly once from a source file and should not be called together with FPMAS_JSON_SET_UP().

It is possible to call the FPMAS_DEFAULT_DATAPACK_SET_UP() macro to set up the object pack serialization without specifying any Agent.

The same set of Agent types must be registered at runtime using the FPMAS_REGISTER_AGENT_TYPES(...) macro at runtime.

Example
#define AGENT_TYPES Agent1, Agent2, OtherAgent
int main(int argc, char** argv) {
fpmas::init(argc, argv);
...
}
#define FPMAS_DATAPACK_SET_UP(...)
Definition: serializer.h:176

ObjectPack Agent serialization is set up so that Agent are serialized into JSON, stored in an ObjectPack field. To prevent this behavior, FPMAS_BASE_JSON_SET_UP() and FPMAS_BASE_DATAPACK_SET_UP() can be used together to enable both Agent serialization techniques.

Notice that all of this only affect AgentPtr serialization: serialization of any other object, with JSON or ObjectPack, is not altered by those macros.

See the fpmas::io::datapack::Serializer<api::utils::PtrWrapper<AgentType>> documentation to learn how to enable Agent datapack serialization.

◆ FPMAS_DEFAULT_DATAPACK_SET_UP

#define FPMAS_DEFAULT_DATAPACK_SET_UP ( )
Value:
FPMAS_BASE_DEFAULT_JSON_SET_UP()
#define FPMAS_BASE_DEFAULT_DATAPACK_SET_UP()
Definition: datapack_serializer.h:100

Can be used instead of FPMAS_DATAPACK_SET_UP() to set up object pack serialization without specifying any Agent type.

◆ FPMAS_REGISTER_AGENT_TYPES

#define FPMAS_REGISTER_AGENT_TYPES (   ...)     fpmas::register_types<__VA_ARGS__ , void>();

Registers the specified Agent types so that they can be serialized as JSON using the nlohmann library.

More particularly, registers Agents types so that their TypeId (i.e. their corresponding std::type_index) can be serialized. Serialization rules (to_json and from_json methods) for each type must still be specified.

This macro must be called at runtime, as soon as possible, before any Agent serialization occurs.

Example
...
int main(int argc, char** argv) {
fpmas::init(argc, argv);
FPMAS_REGISTER_AGENT_TYPES(Agent1, Agent2, OtherAgent);
...
}