Medial Code Documentation
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
SerializableObject.h File Reference

An Abstract class that can be serialized and written/read from file. More...

#include <Logger/Logger/Logger.h>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/crc.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/regex.hpp>
#include <cstring>
#include <string>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <typeinfo>
#include <map>
#include <vector>
#include <regex>
#include "SerializableObject_imp.h"

Go to the source code of this file.

Data Structures

class  SerializableObject
 

Macros

#define SRL_LOG(...)   global_logger.log(LOG_SRL, LOG_DEF_LEVEL, __VA_ARGS__)
 
#define SRL_LOG_D(...)   global_logger.log(LOG_SRL, DEBUG_LOG_LEVEL, __VA_ARGS__)
 
#define SRL_ERR(...)   global_logger.log(LOG_SRL, MAX_LOG_LEVEL, __VA_ARGS__)
 
#define MEDSERIALIZE_SUPPORT(Type)
 
#define ADD_SERIALIZATION_FUNCS(...)
 
#define ADD_SERIALIZATION_HEADERS()
 
#define ADD_SERIALIZATION_FUNCS_CPP(ClassName, ...)
 
#define ADD_CLASS_NAME(Type)   string my_class_name() const {return string(#Type);}
 
#define CONDITIONAL_NEW_CLASS(s, c)    if (s == string(#c)) return new c;
 

Functions

template<class T >
void copy_serializable_object (T &source, T &dst)
 
float med_stof (const string &_Str)
 
int med_stoi (const string &_Str)
 

Detailed Description

An Abstract class that can be serialized and written/read from file.

Macro Definition Documentation

◆ ADD_SERIALIZATION_FUNCS

#define ADD_SERIALIZATION_FUNCS (   ...)
Value:
virtual size_t get_size() { pre_serialization(); return MedSerialize::get_size_top(#__VA_ARGS__, __VA_ARGS__); } \
virtual size_t serialize(unsigned char *blob) { pre_serialization(); return MedSerialize::serialize_top(blob, #__VA_ARGS__, __VA_ARGS__); } \
virtual size_t deserialize(unsigned char *blob) { size_t size = MedSerialize::deserialize_top(blob, #__VA_ARGS__, __VA_ARGS__); post_deserialization(); return size;} \
virtual void serialized_fields_name(vector<string> &field_names) const { MedSerialize::get_list_names(#__VA_ARGS__, field_names); } \
virtual string object_json() const { return MedSerialize::object_json_start(my_class_name(), this->version(), #__VA_ARGS__, __VA_ARGS__); }

To add automatic serialization to your class you can use the following macro with the list of the
variables to serialize inside your class. They all should be MedSerialize supported

◆ ADD_SERIALIZATION_FUNCS_CPP

#define ADD_SERIALIZATION_FUNCS_CPP (   ClassName,
  ... 
)
Value:
size_t ClassName::get_size() { pre_serialization(); return MedSerialize::get_size_top(#__VA_ARGS__, __VA_ARGS__); } \
size_t ClassName::serialize(unsigned char *blob) { pre_serialization(); return MedSerialize::serialize_top(blob, #__VA_ARGS__, __VA_ARGS__); } \
size_t ClassName::deserialize(unsigned char *blob) { return MedSerialize::deserialize_top(blob, #__VA_ARGS__, __VA_ARGS__); post_deserialization();} \
void ClassName::serialized_fields_name(vector<string> &field_names) const { MedSerialize::get_list_names(#__VA_ARGS__, field_names); } \
string ClassName::object_json() const { return MedSerialize::object_json_start(my_class_name(), this->version(), #__VA_ARGS__, __VA_ARGS__); }

◆ ADD_SERIALIZATION_HEADERS

#define ADD_SERIALIZATION_HEADERS ( )
Value:
virtual size_t get_size(); \
virtual size_t serialize(unsigned char *blob); \
virtual size_t deserialize(unsigned char *blob); \
virtual void serialized_fields_name(vector<string> &field_names) const; \
virtual string object_json() const;

◆ MEDSERIALIZE_SUPPORT

#define MEDSERIALIZE_SUPPORT (   Type)
Value:
namespace MedSerialize { \
template<> inline size_t get_size<Type>(Type &elem) { return elem.get_size(); } \
template<> inline size_t serialize<Type>(unsigned char *blob, Type &elem) { return elem.serialize(blob); } \
template<> inline size_t deserialize<Type>(unsigned char *blob, Type &elem) { return elem.deserialize(blob); } \
template<> inline string object_json<const Type>(const Type &elem) { return elem.object_json(); } \
}

To Join the MedSerialize Wagon :
(1) include this h file, in your h file
(2) implement the get_size, serialize and deserialize functions for your class, you can use MedSerialize functions for that
(3) add the following macro for your class