Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Guilhem Saurel
hpp-util
Commits
65df636b
Commit
65df636b
authored
May 10, 2020
by
Joseph Mirabel
Browse files
Add serialization macros.
parent
8ec6b6b9
Changes
3
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
65df636b
...
...
@@ -29,7 +29,7 @@ COMPUTE_PROJECT_ARGS(PROJECT_ARGS LANGUAGES CXX C)
PROJECT
(
${
PROJECT_NAME
}
${
PROJECT_ARGS
}
)
# Search for Boost.
SET
(
BOOST_COMPONENTS filesystem system
)
SET
(
BOOST_COMPONENTS filesystem system
serialization
)
SEARCH_FOR_BOOST
()
SET
(
CMAKE_MODULE_PATH
${
PROJECT_SOURCE_DIR
}
/cmake/find-external/TinyXML
)
...
...
@@ -49,6 +49,8 @@ SET(${PROJECT_NAME}_HEADERS
include/hpp/util/parser.hh
include/hpp/util/factories/ignoretag.hh
include/hpp/util/factories/sequence.hh
include/hpp/util/serialization.hh
include/hpp/util/serialization-fwd.hh
)
SET
(
${
PROJECT_NAME
}
_SOURCES
...
...
include/hpp/util/serialization-fwd.hh
0 → 100644
View file @
65df636b
//
// Copyright (c) 2020 CNRS
// Authors: Joseph Mirabel
//
// This file is part of hpp-util
// hpp-util is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-util is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-util If not, see
// <http://www.gnu.org/licenses/>.
#ifndef HPP_UTIL_SERIALIZATION_FWD_HH
#define HPP_UTIL_SERIALIZATION_FWD_HH
#include
<boost/serialization/split_member.hpp>
namespace
boost
{
namespace
serialization
{
class
access
;
}
// namespace serialization
}
// namespace boost
/// Macro that should be put in a serializable class
/// It declares function \c serialize.
/// \note an empty constructor (that can leave the object unitialized) must exist.
#define HPP_SERIALIZABLE() \
friend class boost::serialization::access; \
/** Allow serialization of the class using \c boost::serialization. */
\
template<class Archive> \
void serialize(Archive & ar, const unsigned int version)
/// Macro that should be put in a serializable class
/// It declare a \c load and \c save function.
/// \note for the load function, an empty constructor (that can leave the object
/// unitialized) must exist.
#define HPP_SERIALIZABLE_SPLIT() \
BOOST_SERIALIZATION_SPLIT_MEMBER() \
friend class boost::serialization::access; \
/** Allow to save class using \c boost::serialization. */
\
template<class Archive> \
void save(Archive & ar, const unsigned int version) const; \
/** Allow to load class using \c boost::serialization. */
\
template<class Archive> \
void load(Archive & ar, const unsigned int version)
#endif // HPP_UTIL_SERIALIZATION_FWD_HH
include/hpp/util/serialization.hh
0 → 100644
View file @
65df636b
//
// Copyright (c) 2020 CNRS
// Authors: Joseph Mirabel
//
// This file is part of hpp-util
// hpp-util is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-util is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-util If not, see
// <http://www.gnu.org/licenses/>.
#ifndef HPP_UTIL_SERIALIZATION_HH
#define HPP_UTIL_SERIALIZATION_HH
#include
<boost/archive/binary_oarchive.hpp>
#include
<boost/archive/text_oarchive.hpp>
#include
<boost/archive/xml_oarchive.hpp>
#include
<boost/archive/binary_iarchive.hpp>
#include
<boost/archive/text_iarchive.hpp>
#include
<boost/archive/xml_iarchive.hpp>
#include
<boost/archive/polymorphic_oarchive.hpp>
#include
<boost/archive/polymorphic_iarchive.hpp>
#include
<boost/serialization/export.hpp>
#include
<boost/serialization/shared_ptr.hpp>
#include
<boost/serialization/nvp.hpp>
#define _HPP_SERIALIZATION_SPLIT_IMPLEMENT(type,archive) \
template void type::load<archive##_iarchive>(archive##_iarchive& ar, const unsigned int ver); \
template void type::save<archive##_oarchive>(archive##_oarchive& ar, const unsigned int ver) const
#define _HPP_SERIALIZATION_IMPLEMENT(type,archive) \
template void type::serialize<archive##_iarchive>(archive##_iarchive& ar, const unsigned int ver);\
template void type::serialize<archive##_oarchive>(archive##_oarchive& ar, const unsigned int ver)\
#define HPP_SERIALIZATION_SPLIT_IMPLEMENT(type) \
_HPP_SERIALIZATION_SPLIT_IMPLEMENT(type,boost::archive::polymorphic); \
_HPP_SERIALIZATION_SPLIT_IMPLEMENT(type,boost::archive::xml); \
_HPP_SERIALIZATION_SPLIT_IMPLEMENT(type,boost::archive::text); \
_HPP_SERIALIZATION_SPLIT_IMPLEMENT(type,boost::archive::binary)
#define HPP_SERIALIZATION_IMPLEMENT(type) \
_HPP_SERIALIZATION_IMPLEMENT(type,boost::archive::polymorphic); \
_HPP_SERIALIZATION_IMPLEMENT(type,boost::archive::xml); \
_HPP_SERIALIZATION_IMPLEMENT(type,boost::archive::text); \
_HPP_SERIALIZATION_IMPLEMENT(type,boost::archive::binary)
namespace
hpp
{
namespace
serialization
{
using
boost
::
serialization
::
make_nvp
;
}
// namespace util
}
// namespace hpp
#endif // HPP_UTIL_SERIALIZATION_HH
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment