template<typename AgentType>
struct fpmas::io::datapack::Serializer< api::utils::PtrWrapper< AgentType > >
Generic Agent pointer serialization.
This partial specialization can be used to easily define serialization rules directly from the Agent implementation, using the following static method definitions :
...
public:
...
const UserDefinedAgent* agent
);
);
...
};
Definition: datapack.h:275
static api::utils::PtrWrapper< AgentType > from_datapack(const PackType &pack)
Definition: datapack_serializer.h:399
static void to_datapack(PackType &pack, const api::utils::PtrWrapper< AgentType > &agent_ptr)
Definition: datapack_serializer.h:387
The from_datapack method is assumed to return an heap allocated agent (initialized with a new statement).
- Example
private:
int count;
std::string message;
public:
Agent1(int count, std::string message)
: count(count), message(message) {}
o.
allocate(pack_size<int>() + pack_size(agent->message));
}
int count;
std::string message;
return new Agent1(count, message);
}
};
void read(T &item) const
Definition: datapack.h:533
void allocate(std::size_t size)
Definition: datapack.h:444
void write(const T &item)
Definition: datapack.h:495
- Note
- Notice that its still possible to define adl_serializer specialization without using the internal to_json / from_json methods.
- Example
private:
int count;
std::string message;
public:
Agent1(int count, std::string message)
: count(count), message(message) {}
int getCount() const {return count;}
std::string getMessage() const {return message;}
};
namespace fpmas {
namespace io {
namespace datapack {
template<>
struct Serializer<
fpmas::api::utils::PtrWrapper<Agent1>> {
) {
o.allocate(pack_size<int>() + pack_size(agent->message));
o.write(agent->count);
o.write(agent->message);
}
) {
int count;
std::string message;
o.read(count);
o.read(message);
return new Agent1(count, message);
}
};
}}}
Definition: ptr_wrapper.h:21
BasicObjectPack< Serializer > ObjectPack
Definition: datapack.h:1364