Skip to content
Snippets Groups Projects
Commit 724c2b19 authored by Joan Solà Ortega's avatar Joan Solà Ortega
Browse files

Merge branch 'remove-serialization' into 'devel'

remove-serialization

See merge request !6
parents 4ef5653a dab2a40c
No related branches found
No related tags found
1 merge request!6remove-serialization
Showing
with 0 additions and 966 deletions
add_subdirectory(cereal)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
SET(HDRS_SERIALIZATION ${HDRS_SERIALIZATION}
${CMAKE_CURRENT_SOURCE_DIR}/serialization_eigen_core.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_eigen_geometry.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_eigen_sparse.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_local_parametrization_base.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_local_parametrization_homogeneous.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_local_parametrization_quaternion.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_node_base.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_sensor_intrinsic_base.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_sensor_odom2d_intrinsic.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_processor_params_base.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_processor_odom2d_params.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_processor_odom3d_params.h
${CMAKE_CURRENT_SOURCE_DIR}/serialization_time_stamp.h
${CMAKE_CURRENT_SOURCE_DIR}/archives.h
${CMAKE_CURRENT_SOURCE_DIR}/io.h
PARENT_SCOPE)
#ifndef _WOLF_IO_CEREAL_ARCHIVE_H_
#define _WOLF_IO_CEREAL_ARCHIVE_H_
#include <cereal/archives/binary.hpp>
#include <cereal/archives/json.hpp>
#include <cereal/archives/portable_binary.hpp>
#include <cereal/archives/xml.hpp>
#endif /* _WOLF_IO_CEREAL_ARCHIVE_H_ */
#ifndef _WOLF_SERIALIZATION_CEREAL_IO_H_
#define _WOLF_SERIALIZATION_CEREAL_IO_H_
#include <stdexcept>
#include "archives.h"
//#include <cereal/types/tuple.hpp>
namespace wolf {
namespace serialization {
/// @todo demangle typeid.name ?
template <typename T>
inline const std::string& type_name(const T&)
{
static const std::string typeid_name = typeid(T).name();
return typeid_name;
}
inline std::string extension(const std::string& file)
{
const std::size_t p = file.find_last_of(".");
return (p != std::string::npos) ? file.substr(p) : "";
}
//struct Extensions
//{
// constexpr static const char* bin = ".bin";
// constexpr static const char* json = ".json";
// constexpr static const char* xml = ".xml";
// constexpr static const char* fall_back = json;
//};
//enum class Extensions2 : std::size_t
//{
// BIN = 0,
//// CBIN,
// JSON,
//// TEXT,
// XML,
//};
//template <char... Chars>
//struct constexp_str
//{
// using type = constexp_str<Chars...>;
// virtual ~constexp_str() = default;
// constexpr static const char value[sizeof...(Chars)+1] = {Chars..., '\0'};
// constexpr static std::size_t size() { return sizeof...(Chars); }
// constexpr static const char* c_str() { return &value[0]; }
//// constexpr static bool comp(const std::string& s) { return s == value; }
// /*constexpr*/ bool operator == (const std::string& s) { return s == value; }
// constexpr /*static*/ operator const char* () { return c_str(); }
// constexpr /*static*/ operator std::string& () { return c_str(); }
//};
struct Extensions
{
// template <char... Chars>
// struct EXT : constexp_str<Chars...>
// {
// //
// };
// struct BIN : EXT<'.','b','i','n'> { };
// struct XML : EXT<'.','x','m','l'> { };
// struct JSON : EXT<'.','j','s','o','n'> { };
struct EXT { virtual ~EXT() = default; };
struct BIN : EXT
{
constexpr static const char* value = ".bin";
bool operator == (const std::string& s) { return value == s; }
};
struct XML : EXT
{
constexpr static const char* value = ".xml";
bool operator == (const std::string& s) { return value == s; }
};
struct JSON : EXT
{
constexpr static const char* value = ".json";
bool operator == (const std::string& s) { return value == s; }
};
};
template <typename Ar>
void serialize_pack(Ar&&)
{
// end of expansion
}
template <typename Ar, typename T, typename... Args>
void serialize_pack(Ar&& archive, T&& object, Args&&... args)
{
archive( cereal::make_nvp(type_name(object), std::forward<T>(object)) );
serialize_pack(archive, std::forward<Args>(args)...);
}
template <typename Ar, typename S, typename T, typename... Args>
void serialize(S& stream, T&& object, Args&&... args)
{
Ar archive(stream);
archive( cereal::make_nvp(type_name(object), std::forward<T>(object)) );
serialize_pack(archive, std::forward<Args>(args)...);
}
template <typename EXT, typename InAr, typename OutAr>
struct Serializer
{
template <typename S, typename... T>
static void serialize_in(S& stream, T&... object)
{
serialize<InAr>(stream, object...);
}
template <typename S, typename... T>
static void serialize_out(S& stream, T&&... object)
{
serialize<OutAr>(stream, std::forward<T>(object)...);
}
template <typename... T>
static void save(std::string filename, T&&... o)
{
const std::string ext = serialization::extension(filename);
if (ext != EXT::value) filename += EXT::value;
std::ofstream os(filename);
serialize_out(os, std::forward<T>(o)...);
}
template <typename... T>
static void load(std::string filename, T&... o)
{
const std::string ext = serialization::extension(filename);
if (ext != EXT::value) filename += EXT::value;
std::ifstream is(filename);
serialize_in(is, o...);
}
};
using SerializerBin = Serializer<Extensions::BIN,
cereal::BinaryInputArchive,
cereal::BinaryOutputArchive>;
using SerializerXML = Serializer<Extensions::XML,
cereal::XMLInputArchive,
cereal::XMLOutputArchive>;
using SerializerJSON = Serializer<Extensions::JSON,
cereal::JSONInputArchive,
cereal::JSONOutputArchive>;
} /* namespace serialization */
template <typename... T>
void save(const std::string& filename, T&&... o)
throw(std::runtime_error)
{
const std::string ext = serialization::extension(filename);
if (ext == serialization::Extensions::BIN::value)
{
serialization::SerializerBin::save(filename, std::forward<T>(o)...);
}
else if (ext == serialization::Extensions::JSON::value)
{
serialization::SerializerJSON::save(filename, std::forward<T>(o)...);
}
else if (ext == serialization::Extensions::XML::value)
{
serialization::SerializerXML::save(filename, std::forward<T>(o)...);
}
else if (ext == "") // falback is json
{
serialization::SerializerJSON::save(filename, std::forward<T>(o)...);
}
else
{
throw std::runtime_error("Unknown file extension : " + filename);
}
}
template <typename... T>
void load(const std::string& filename, T&... o)
{
const std::string ext = serialization::extension(filename);
if (ext == serialization::Extensions::BIN::value)
{
serialization::SerializerBin::load(filename, o...);
}
else if (ext == serialization::Extensions::XML::value)
{
serialization::SerializerXML::load(filename, o...);
}
else if (ext == serialization::Extensions::JSON::value)
{
serialization::SerializerJSON::load(filename, o...);
}
else if (ext == "") // falback is json
{
serialization::SerializerJSON::load(filename, o...);
}
else
{
throw std::runtime_error("Unknown file extension : " + filename);
}
}
} /* namespace wolf */
#endif /* _WOLF_SERIALIZATION_CEREAL_IO_H_ */
#ifndef _WOLF_IO_CEREAL_EIGEN_H_
#define _WOLF_IO_CEREAL_EIGEN_H_
// Wolf includes
#include <Eigen/Dense>
#include <cereal/cereal.hpp>
namespace cereal {
/**
* @brief Save Eigen::Matrix<...> to text based archives
*/
template<class Archive, typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
inline typename std::enable_if<!traits::is_output_serializable<BinaryData<_Scalar>, Archive>::value,
void>::type save(Archive& ar,
const Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& mat)
{
decltype(mat.rows()) rows = mat.rows();
decltype(mat.cols()) cols = mat.cols();
ar(cereal::make_nvp("rows", rows));
ar(cereal::make_nvp("cols", cols));
/// @todo find out something
std::cerr << "Saving Eigen type to text-based archive is NOT supported !\n";
}
/**
* @brief Save Eigen::Matrix<...> to binary based archives
*/
template<class Archive, typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
inline typename std::enable_if<traits::is_output_serializable<BinaryData<_Scalar>, Archive>::value,
void>::type save(Archive& ar,
const Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& mat)
{
decltype(mat.rows()) rows = mat.rows();
decltype(mat.cols()) cols = mat.cols();
ar(rows);
ar(cols);
ar(binary_data(mat.data(), static_cast<std::size_t>(rows * cols * sizeof(_Scalar))));
}
/**
* @brief Load compile-time sized Eigen::Matrix from text based archives
*/
template<class Archive, typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
inline typename std::enable_if<!traits::is_input_serializable<BinaryData<_Scalar>, Archive>::value and
_Rows != Eigen::Dynamic and _Cols != Eigen::Dynamic,
void>::type load(Archive& ar,
Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& mat)
{
decltype(mat.rows()) rows;
decltype(mat.cols()) cols;
ar(cereal::make_nvp("rows", rows));
ar(cereal::make_nvp("cols", cols));
/// @todo find out something
std::cerr << "Saving Eigen type to text-based archive is NOT supported !\n";
}
/**
* @brief Load dynamic sized Eigen::Matrix from text based archives
*/
template<class Archive, typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
inline typename std::enable_if<!traits::is_input_serializable<BinaryData<_Scalar>, Archive>::value and
(_Rows == Eigen::Dynamic or _Cols == Eigen::Dynamic),
void>::type load(Archive& ar,
Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& mat)
{
decltype(mat.rows()) rows;
decltype(mat.cols()) cols;
ar(cereal::make_nvp("rows", rows));
ar(cereal::make_nvp("cols", cols));
/// @todo find out something
std::cerr << "Saving Eigen type to text-based archive is NOT supported !\n";
//mat.resize(rows, cols);
}
/**
* @brief Load compile-time sized Eigen::Matrix from binary based archives
*/
template<class Archive, typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
inline typename std::enable_if<traits::is_input_serializable<BinaryData<_Scalar>, Archive>::value and
_Rows != Eigen::Dynamic and _Cols != Eigen::Dynamic,
void>::type load(Archive& ar,
Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& mat)
{
decltype(mat.rows()) rows;
decltype(mat.cols()) cols;
ar(rows);
ar(cols);
ar(binary_data(mat.data(), static_cast<std::size_t>(rows * cols * sizeof(_Scalar))));
}
/**
* @brief Load dynamic sized Eigen::Matrix from binary based archives
*/
template<class Archive, typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
inline typename std::enable_if<traits::is_input_serializable<BinaryData<_Scalar>, Archive>::value and
(_Rows == Eigen::Dynamic or _Cols == Eigen::Dynamic),
void>::type load(Archive& ar,
Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& mat)
{
decltype(mat.rows()) rows;
decltype(mat.cols()) cols;
ar(rows);
ar(cols);
mat.resize(rows, cols);
ar(binary_data(mat.data(), static_cast<std::size_t>(rows * cols * sizeof(_Scalar))));
}
} // namespace cereal
#endif /* _WOLF_IO_CEREAL_EIGEN_H_ */
#ifndef _WOLF_IO_CEREAL_EIGEN_GEOMETRY_H_
#define _WOLF_IO_CEREAL_EIGEN_GEOMETRY_H_
// Wolf includes
#include <Eigen/Geometry>
#include "serialization_eigen_core.h"
namespace cereal {
template<class Archive, typename _Scalar, int _Dim, int _Mode, int _Options>
inline void save(Archive& ar,
const Eigen::Transform<_Scalar, _Dim, _Mode, _Options>& t)
{
save(ar, t.matrix());
}
template<class Archive, typename _Scalar, int _Dim, int _Mode, int _Options>
inline void load(Archive& ar,
Eigen::Transform<_Scalar, _Dim, _Mode, _Options>& t)
{
load(ar, t.matrix());
}
template<class Archive, typename _Scalar>
void serialize(Archive & ar,
Eigen::Quaternion<_Scalar>& q,
const std::uint32_t /*version*/)
{
ar(cereal::make_nvp("w", q.w()));
ar(cereal::make_nvp("x", q.x()));
ar(cereal::make_nvp("y", q.y()));
ar(cereal::make_nvp("z", q.z()));
}
} // namespace cereal
#endif /* _WOLF_IO_CEREAL_EIGEN_GEOMETRY_H_ */
#ifndef _WOLF_IO_CEREAL_EIGEN_GEOMETRY_H_
#define _WOLF_IO_CEREAL_EIGEN_GEOMETRY_H_
// Wolf includes
#include <Eigen/Sparse>
#include "serialization_eigen_core.h"
#include <cereal/types/vector.hpp>
namespace cereal {
template<class Archive, typename Scalar, typename Index>
inline void save(Archive& ar,
const Eigen::Triplet<Scalar, Index>& t)
{
ar(cereal::make_nvp("row", t.row()));
ar(cereal::make_nvp("col", t.col()));
ar(cereal::make_nvp("value", t.value()));
}
template<class Archive, typename Scalar, typename Index>
inline void load(Archive& ar,
Eigen::Triplet<Scalar, Index>& t)
{
Index row, col;
Scalar value;
ar(cereal::make_nvp("row", row));
ar(cereal::make_nvp("col", col));
ar(cereal::make_nvp("value", value));
t = Eigen::Triplet<Scalar, Index>(row, col, value);
}
template <class Archive, typename _Scalar, int _Options, typename _Index>
void save(Archive& ar,
const Eigen::SparseMatrix<_Scalar, _Options, _Index>& m)
{
_Index inner_size = m.innerSize();
_Index outer_size = m.outerSize();
using Triplet = Eigen::Triplet<_Scalar>;
std::vector<Triplet> triplets;
for (_Index i=0; i < outer_size; ++i)
for (typename Eigen::SparseMatrix<_Scalar, _Options, _Index>::InnerIterator it(m,i); it; ++it)
triplets.emplace_back( it.row(), it.col(), it.value() );
ar(cereal::make_nvp("inner_size", inner_size));
ar(cereal::make_nvp("outer_size", outer_size));
ar(cereal::make_nvp("triplets", triplets));
}
template <class Archive, typename _Scalar, int _Options, typename _Index>
void load(Archive& ar,
Eigen::SparseMatrix<_Scalar, _Options, _Index>& m)
{
_Index inner_size;
_Index outer_size;
ar(cereal::make_nvp("inner_size", inner_size));
ar(cereal::make_nvp("outer_size", outer_size));
_Index rows = (m.IsRowMajor)? outer_size : inner_size;
_Index cols = (m.IsRowMajor)? inner_size : outer_size;
m.resize(rows, cols);
using Triplet = Eigen::Triplet<_Scalar>;
std::vector<Triplet> triplets;
ar(cereal::make_nvp("triplets", triplets));
m.setFromTriplets(triplets.begin(), triplets.end());
}
} // namespace cereal
#endif /* _WOLF_IO_CEREAL_EIGEN_GEOMETRY_H_ */
#ifndef _WOLF_IO_CEREAL_LOCAL_PARAMETRIZATION_BASE_H_
#define _WOLF_IO_CEREAL_LOCAL_PARAMETRIZATION_BASE_H_
#include "base/state_block/local_parametrization_base.h"
#include <cereal/cereal.hpp>
#include <cereal/types/polymorphic.hpp>
namespace cereal {
// Since classes deriving from LocalParametrizationBase
// have default constructor calling the non-default
// LocalParametrizationBase constructor with pre-defined
// arguments, there is nothing to save here.
template<class Archive>
inline void serialize(
Archive& /*ar*/,
wolf::LocalParametrizationBase& /*lpb*/,
std::uint32_t const /*file_version*/)
{
//
}
} //namespace cereal
#endif /* _WOLF_IO_CEREAL_LOCAL_PARAMETRIZATION_BASE_H_ */
#ifndef _WOLF_IO_CEREAL_LOCAL_PARAMETRIZATION_BASE_HOMOGENEOUS_H_
#define _WOLF_IO_CEREAL_LOCAL_PARAMETRIZATION_BASE_HOMOGENEOUS_H_
#include "core/local_parametrization_homogeneous.h"
#include "serialization_local_parametrization_base.h"
#include <cereal/cereal.hpp>
CEREAL_REGISTER_TYPE_WITH_NAME(wolf::LocalParametrizationHomogeneous,
"LocalParametrizationHomogeneous");
namespace cereal {
template<class Archive>
inline void serialize(
Archive& ar,
wolf::LocalParametrizationHomogeneous& lp,
std::uint32_t const /*file_version*/)
{
ar( cereal::make_nvp("LocalParametrizationBase",
cereal::base_class<wolf::LocalParametrizationBase>(&lp)) );
}
} //namespace cereal
#endif /* _WOLF_IO_CEREAL_LOCAL_PARAMETRIZATION_BASE_HOMOGENEOUS_H_ */
#ifndef WOLF_IO_SERIALIZATION_LOCAL_PARAMETRIZATION_QUATERNION_H_
#define WOLF_IO_SERIALIZATION_LOCAL_PARAMETRIZATION_QUATERNION_H_
#include "core/local_parametrization_quaternion.h"
#include "serialization_local_parametrization_base.h"
#include <cereal/cereal.hpp>
CEREAL_REGISTER_TYPE_WITH_NAME(wolf::LocalParametrizationQuaternion<wolf::DQ_LOCAL>,
"wolf_LocalParametrizationQuaternion_DQ_LOCAL")
CEREAL_REGISTER_TYPE_WITH_NAME(wolf::LocalParametrizationQuaternion<wolf::DQ_GLOBAL>,
"wolf_LocalParametrizationQuaternion_DQ_GLOBAL")
namespace cereal {
template<class Archive, unsigned int DeltaReference>
inline void serialize(
Archive &ar,
wolf::LocalParametrizationQuaternion<DeltaReference> &lp,
const unsigned int /*file_version*/)
{
ar( cereal::make_nvp("LocalParametrizationBase",
cereal::base_class<wolf::LocalParametrizationBase>(&lp)) );
}
} //namespace boost
#endif /* WOLF_IO_SERIALIZATION_LOCAL_PARAMETRIZATION_QUATERNION_H_ */
#ifndef _WOLF_IO_CEREAL_NODE_BASE_H_
#define _WOLF_IO_CEREAL_NODE_BASE_H_
// Wolf includes
#include "core/node_base.h"
#include <cereal/cereal.hpp>
#include <cereal/types/polymorphic.hpp>
namespace wolf {
struct NodeBase::Serializer {
template <class Archive>
static void serialize(Archive& ar, NodeBase& o, std::uint32_t const /*version*/)
{
ar( cereal::make_nvp("node_class_", o.node_category_) );
ar( cereal::make_nvp("node_type_", o.node_type_) );
ar( cereal::make_nvp("node_name_", o.node_name_) );
ar( cereal::make_nvp("node_id_", o.node_id_) );
// ar( cereal::make_nvp("problem_ptr_", o.problem_ptr_) );
// Not sure what to do with this guy ...
//ar( cereal::make_nvp("node_id_count_", o.node_id_count_) );
}
template <class Archive>
static void load_and_construct( Archive& ar, cereal::construct<wolf::NodeBase>& construct,
std::uint32_t const /*version*/ )
{
decltype(std::declval<wolf::NodeBase>().getCategory()) nb_class;
decltype(std::declval<wolf::NodeBase>().getType()) nb_type;
decltype(std::declval<wolf::NodeBase>().getName()) nb_name;
ar( cereal::make_nvp("node_class_", nb_class) );
ar( cereal::make_nvp("node_type_", nb_type) );
ar( cereal::make_nvp("node_name_", nb_name) );
construct( nb_class, nb_type, nb_name );
ar( cereal::make_nvp("node_id_", construct->node_id_) );
// ar( cereal::make_nvp("problem_ptr_", construct->problem_ptr_) );
// Not sure what to do with this guy ...
//ar( cereal::make_nvp("node_id_count_", construct->node_id_count_) );
}
};
} // namespace wolf
namespace cereal {
/// @note No default constructor thus the need
/// for these specializations
template <>
struct LoadAndConstruct<wolf::NodeBase>
{
template <class Archive>
static void load_and_construct( Archive& ar,
cereal::construct<wolf::NodeBase>& construct,
std::uint32_t const version )
{
wolf::NodeBase::Serializer::load_and_construct(ar, construct, version);
}
};
template <class Archive>
void serialize(Archive& ar, wolf::NodeBase& o, std::uint32_t const version)
{
wolf::NodeBase::Serializer::serialize(ar, o, version);
}
} // namespace cereal
#endif /* _WOLF_IO_CEREAL_NODE_BASE_H_ */
#ifndef _WOLF_SERIALIZATION_CEREAL_PROCESSOR_ODOM2D_PARAMS_H_
#define _WOLF_SERIALIZATION_CEREAL_PROCESSOR_ODOM2D_PARAMS_H_
// Wolf includes
#include "core/processor/processor_odom_2D.h"
#include "serialization_processor_params_base.h"
namespace cereal {
template <class Archive>
void serialize(Archive& ar, wolf::ProcessorParamsOdom2D& o,
std::uint32_t const /*version*/)
{
ar( cereal::make_nvp("ProcessorParamsBase",
cereal::base_class<wolf::ProcessorParamsBase>(&o)) );
ar( cereal::make_nvp("cov_det_th_", o.cov_det) );
ar( cereal::make_nvp("dist_traveled_th_", o.dist_traveled_th_) );
ar( cereal::make_nvp("elapsed_time_th_", o.elapsed_time_th_) );
ar( cereal::make_nvp("theta_traveled_th_", o.theta_traveled_th_) );
ar( cereal::make_nvp("unmeasured_perturbation_std_",
o.unmeasured_perturbation_std) );
}
} // namespace cereal
CEREAL_REGISTER_TYPE_WITH_NAME(wolf::ProcessorParamsOdom2D, "ProcessorParamsOdom2D")
#endif /* _WOLF_SERIALIZATION_CEREAL_PROCESSOR_ODOM3D_PARAMS_H_ */
#ifndef _WOLF_SERIALIZATION_CEREAL_PROCESSOR_ODOM3D_PARAMS_H_
#define _WOLF_SERIALIZATION_CEREAL_PROCESSOR_ODOM3D_PARAMS_H_
// Wolf includes
#include "core/processor/processor_odom_3D.h"
#include "serialization_processor_params_base.h"
namespace cereal {
template <class Archive>
void serialize(Archive& ar, wolf::ProcessorParamsOdom3D& o,
std::uint32_t const /*version*/)
{
ar( cereal::make_nvp("ProcessorParamsBase",
cereal::base_class<wolf::ProcessorParamsBase>(&o)) );
ar( cereal::make_nvp("angle_turned", o.angle_turned) );
ar( cereal::make_nvp("dist_traveled", o.dist_traveled) );
ar( cereal::make_nvp("max_buff_length", o.max_buff_length) );
ar( cereal::make_nvp("max_time_span", o.max_time_span) );
}
} // namespace cereal
CEREAL_REGISTER_TYPE_WITH_NAME(wolf::ProcessorParamsOdom3D, "ProcessorOdom3DParams")
#endif /* _WOLF_SERIALIZATION_CEREAL_PROCESSOR_ODOM3D_PARAMS_H_ */
#ifndef _WOLF_SERIALIZATION_CEREAL_PROCESSOR_PARAM_BASE_H_
#define _WOLF_SERIALIZATION_CEREAL_PROCESSOR_PARAM_BASE_H_
// Wolf includes
#include "core/processor/processor_base.h"
#include <cereal/cereal.hpp>
#include <cereal/types/polymorphic.hpp>
namespace cereal {
template <class Archive>
void serialize(Archive& ar, wolf::ProcessorParamsBase& o,
std::uint32_t const /*version*/)
{
ar( cereal::make_nvp("type", o.type) );
ar( cereal::make_nvp("name", o.name) );
}
} // namespace cereal
#endif /* _WOLF_SERIALIZATION_CEREAL_SENSOR_INTRINSIC_BASE_H_ */
#ifndef _WOLF_SERIALIZATION_CEREAL_SENSOR_INTRINSIC_BASE_H_
#define _WOLF_SERIALIZATION_CEREAL_SENSOR_INTRINSIC_BASE_H_
// Wolf includes
#include "core/sensor/sensor_base.h"
#include <cereal/cereal.hpp>
#include <cereal/types/polymorphic.hpp>
namespace cereal {
template <class Archive>
void serialize(Archive& ar, wolf::IntrinsicsBase& o,
std::uint32_t const /*version*/)
{
ar( cereal::make_nvp("type", o.type) );
ar( cereal::make_nvp("name", o.name) );
}
} // namespace cereal
// No need to register base
//CEREAL_REGISTER_TYPE_WITH_NAME(wolf::IntrinsicsBase, "IntrinsicsBase");
#endif /* _WOLF_SERIALIZATION_CEREAL_SENSOR_INTRINSIC_BASE_H_ */
#ifndef _WOLF_SERIALIZATION_CEREAL_SENSOR_ODOM2D_INTRINSIC_H_
#define _WOLF_SERIALIZATION_CEREAL_SENSOR_ODOM2D_INTRINSIC_H_
// Wolf includes
#include "core/sensor/sensor_odom_2D.h"
#include "serialization_sensor_intrinsic_base.h"
namespace cereal {
template <class Archive>
void serialize(Archive& ar, wolf::IntrinsicsOdom2D& o,
std::uint32_t const /*version*/)
{
ar( cereal::make_nvp("IntrinsicsBase",
cereal::base_class<wolf::IntrinsicsBase>(&o)) );
ar( cereal::make_nvp("k_disp_to_disp", o.k_disp_to_disp) );
ar( cereal::make_nvp("k_rot_to_rot", o.k_rot_to_rot) );
}
} // namespace cereal
CEREAL_REGISTER_TYPE_WITH_NAME(wolf::IntrinsicsOdom2D, "IntrinsicsOdom2D")
#endif /* _WOLF_SERIALIZATION_CEREAL_SENSOR_ODOM2D_INTRINSIC_H_ */
#ifndef _WOLF_IO_CEREAL_TIME_STAMP_H_
#define _WOLF_IO_CEREAL_TIME_STAMP_H_
// Wolf includes
#include "core/time_stamp.h"
#include <cereal/cereal.hpp>
namespace cereal {
/// @note serialization versionning raise
/// a compile error here...
template <class Archive>
void save(Archive& ar, const wolf::TimeStamp& o/*, std::uint32_t const version*/)
{
ar( cereal::make_nvp("value", o.get()) );
}
template <class Archive>
void load(Archive& ar, wolf::TimeStamp& o/*, std::uint32_t const version*/)
{
auto val = o.get();
ar( cereal::make_nvp("value", val) );
o.set(val);
}
} // namespace cereal
#endif /* _WOLF_IO_CEREAL_TIME_STAMP_H_ */
# cereal
IF(cereal_FOUND)
add_subdirectory(cereal)
ENDIF(cereal_FOUND)
# NodeBase serialization class test
wolf_add_gtest(gtest_cereal_serialization_node_base gtest_serialization_node_base.cpp)
target_link_libraries(gtest_cereal_serialization_node_base ${PROJECT_NAME})
wolf_add_gtest(gtest_cereal_serialization_local_parametrization
gtest_serialization_local_parametrization.cpp)
target_link_libraries(gtest_cereal_serialization_local_parametrization ${PROJECT_NAME})
wolf_add_gtest(gtest_cereal_serialization_sensor_intrinsic_base
gtest_serialization_sensor_intrinsic_base.cpp)
target_link_libraries(gtest_cereal_serialization_sensor_intrinsic_base ${PROJECT_NAME})
wolf_add_gtest(gtest_cereal_serialization_sensor_odom2d_intrinsic
gtest_serialization_sensor_odom2d_intrinsic.cpp)
target_link_libraries(gtest_cereal_serialization_sensor_odom2d_intrinsic ${PROJECT_NAME})
wolf_add_gtest(gtest_cereal_serialization_save_load
gtest_serialization_save_load.cpp)
target_link_libraries(gtest_cereal_serialization_save_load ${PROJECT_NAME})
wolf_add_gtest(gtest_cereal_serialization_processor_odom3d_params
gtest_serialization_processor_odom3d_params.cpp)
target_link_libraries(gtest_cereal_serialization_processor_odom3d_params ${PROJECT_NAME})
wolf_add_gtest(gtest_cereal_serialization_processor_odom2d_params
gtest_serialization_processor_odom2d_params.cpp)
target_link_libraries(gtest_cereal_serialization_processor_odom2d_params ${PROJECT_NAME})
wolf_add_gtest(gtest_cereal_serialization_time_stamp
gtest_serialization_time_stamp.cpp)
target_link_libraries(gtest_cereal_serialization_time_stamp ${PROJECT_NAME})
wolf_add_gtest(gtest_cereal_serialization_eigen_core
gtest_serialization_eigen_core.cpp)
target_link_libraries(gtest_cereal_serialization_eigen_core ${PROJECT_NAME})
wolf_add_gtest(gtest_cereal_serialization_eigen_geometry
gtest_serialization_eigen_geometry.cpp)
target_link_libraries(gtest_cereal_serialization_eigen_geometry ${PROJECT_NAME})
wolf_add_gtest(gtest_cereal_serialization_eigen_sparse
gtest_serialization_eigen_sparse.cpp)
target_link_libraries(gtest_cereal_serialization_eigen_sparse ${PROJECT_NAME})
/*
* gtest_intrinsics_odom2d_serialization.cpp
*
* Created on: Jul 16, 2017
* Author: Jeremie Deray
*/
#include "../../utils_gtest.h"
#include "../../../serialization/cereal/serialization_eigen_core.h"
#include "../../../serialization/cereal/io.h"
#include <cereal/types/memory.hpp>
#include <fstream>
class WolfTestCerealSerializationEigen : public testing::Test
{
public:
WolfTestCerealSerializationEigen()
{
nb_ = f_mat_t::Random();
dnb_ = d_mat_t::Random(10, 10);
}
const std::string path_to_io = "/tmp/";
const std::string filename = "serialization_eigen";
const std::vector<std::string> exts = {".bin"/*, ".xml", ".json"*/};
using f_mat_t = Eigen::Matrix<double, 5, 5>;
using d_mat_t = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>;
f_mat_t nb_;
d_mat_t dnb_;
};
TEST_F(WolfTestCerealSerializationEigen,
CerealSerializationEigenFixedMat)
{
for (const auto ext : exts)
{
const std::string full_path = path_to_io + filename + ext;
ASSERT_NO_THROW( wolf::save( full_path, nb_ ) )
<< "Failed on saving " << full_path;
WolfTestCerealSerializationEigen::f_mat_t nb_load;
ASSERT_NO_THROW( wolf::load( full_path, nb_load ) )
<< "Failed on loading " << full_path;
EXPECT_EQ(nb_load, nb_) << full_path;
}
PRINTF("All good at "
"WolfTestCerealSerializationEigen::"
"CerealSerializationEigenFixedMat !\n");
}
TEST_F(WolfTestCerealSerializationEigen,
CerealSerializationEigenDynamicMat)
{
for (const auto ext : exts)
{
const std::string full_path = path_to_io + filename + ext;
ASSERT_NO_THROW( wolf::save( full_path, dnb_ ) )
<< "Failed on saving " << full_path;
WolfTestCerealSerializationEigen::d_mat_t dnb_load;
ASSERT_NO_THROW( wolf::load( full_path, dnb_load ) )
<< "Failed on loading " << full_path;
EXPECT_EQ(dnb_load, dnb_) << full_path;
}
PRINTF("All good at "
"WolfTestCerealSerializationEigen::"
"CerealSerializationEigenDynamicMat !\n");
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment