Skip to content
Snippets Groups Projects

[WIP] LocalParametrization Serialization

Closed Jeremie Deray requested to merge local_param_seria into gtest
Files
10
#ifndef WOLF_IO_SERIALIZATION_LOCAL_PARAMETRIZATION_BASE_H_
#define WOLF_IO_SERIALIZATION_LOCAL_PARAMETRIZATION_BASE_H_
#include "../local_parametrization_base.h"
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/assume_abstract.hpp>
BOOST_SERIALIZATION_ASSUME_ABSTRACT(wolf::LocalParametrizationBase)
namespace boost {
namespace serialization {
// Since classes deriving from LocalParametrizationBase
// have default constructor calling the non-default
// LocalParametrizationBase constructor with pre-defined
// arguments, there is nothing to save here.
// The only necessary thing to do is to register this
// abstract class and define an empty serialize function.
template<class Archive>
inline void serialize(
Archive &/*ar*/,
wolf::LocalParametrizationBase &/*lpb*/,
const unsigned int /*file_version*/)
{
//
}
// Example of what might need to be the serialization
// in case LocalParametrizationBase was not pure abstract.
/*
template<class Archive>
inline void save(
Archive &ar,
const wolf::LocalParametrizationBase &lpb,
const unsigned int file_version )
{
unsigned int global_size = lpb.getGlobalSize();
unsigned int local_size = lpb.getLocalSize();
ar << BOOST_SERIALIZATION_NVP(global_size);
ar << BOOST_SERIALIZATION_NVP(local_size);
}
template<class Archive>
inline void load(
Archive &ar,
wolf::LocalParametrizationBase &lpb,
const unsigned int file_version )
{
unsigned int global_size(0);
unsigned int local_size(0);
ar >> BOOST_SERIALIZATION_NVP(global_size);
ar >> BOOST_SERIALIZATION_NVP(local_size);
// 'placement new'
// 1/ it assumes memory already allocated
// 2/ an instance of LocalParametrizationBase is constructed at
// the memory location
::new(&lpb)wolf::LocalParametrizationBase(global_size, local_size);
}
// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<class Archive>
inline void serialize(
Archive &ar,
wolf::LocalParametrizationBase &lpb,
const unsigned int file_version)
{
boost::serialization::split_free(ar, lpb, file_version);
}
// The two functions below allows for serialization of pointers
// (dynamic allocation)
template<class Archive>
inline void save_construct_data(
Archive &ar,
const wolf::LocalParametrizationBase *lpb,
const unsigned int file_version)
{
unsigned int global_size = lpb->getGlobalSize();
unsigned int local_size = lpb->getLocalSize();
ar << BOOST_SERIALIZATION_NVP(global_size);
ar << BOOST_SERIALIZATION_NVP(local_size);
}
template<class Archive>
inline void load_construct_data(
Archive &ar,
wolf::LocalParametrizationBase *lpb,
const unsigned int file_version)
{
unsigned int global_size(0);
unsigned int local_size(0);
ar >> BOOST_SERIALIZATION_NVP(global_size);
ar >> BOOST_SERIALIZATION_NVP(local_size);
::new(lpb)wolf::LocalParametrizationBase(global_size, local_size);
}
*/
} //namespace serialization
} //namespace boost
#endif /* WOLF_IO_SERIALIZATION_LOCAL_PARAMETRIZATION_BASE_H_ */
Loading