Skip to content
Snippets Groups Projects
Commit 432b7e06 authored by Joseph Mirabel's avatar Joseph Mirabel
Browse files

Add serialization of ConstraintSet.

parent 2c5e3857
No related branches found
No related tags found
No related merge requests found
......@@ -95,6 +95,7 @@ SET(${PROJECT_NAME}_HEADERS
include/hpp/manipulation/steering-method/fwd.hh
include/hpp/manipulation/steering-method/graph.hh
include/hpp/manipulation/steering-method/end-effector-trajectory.hh
include/hpp/manipulation/serialization.hh
)
SET(${PROJECT_NAME}_SOURCES
......
......@@ -62,6 +62,9 @@ namespace hpp {
private:
graph::EdgePtr_t edge_;
ConstraintSetWkPtr_t weak_;
ConstraintSet() {}
HPP_SERIALIZABLE();
}; // class ConstraintSet
struct ConstraintAndComplement_t {
......
//
// Copyright (c) 2020 CNRS
// Author: Joseph Mirabel
//
// This file is part of hpp-manipulation
// hpp-manipulation 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-manipulation 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-manipulation If not, see
// <http://www.gnu.org/licenses/>.
#ifndef HPP_MANIPULATION_SERIALIZATION_HH
# define HPP_MANIPULATION_SERIALIZATION_HH
# include <boost/serialization/split_free.hpp>
# include <boost/serialization/shared_ptr.hpp>
# include <boost/serialization/weak_ptr.hpp>
# include <hpp/manipulation/fwd.hh>
namespace hpp {
namespace serialization {
struct archive_graph_wrapper {
manipulation::graph::GraphPtr_t graph;
virtual ~archive_graph_wrapper() {}
};
} // namespace manipulation
} // namespace hpp
namespace boost {
namespace serialization {
template<class Archive>
inline void serialize(Archive & ar, hpp::manipulation::graph::EdgePtr_t& e, const unsigned int /*version*/)
{
using hpp::serialization::archive_graph_wrapper;
using namespace hpp::manipulation::graph;
std::size_t id;
if (Archive::is_saving::value) id = e->id();
ar & BOOST_SERIALIZATION_NVP(id);
if (!Archive::is_saving::value) {
archive_graph_wrapper* agw = dynamic_cast<archive_graph_wrapper*>(&ar);
if (agw == NULL)
throw std::runtime_error("Cannot deserialize edges with a archive_graph_wrapper");
GraphComponentPtr_t gc = agw->graph->get(id).lock();
e = HPP_DYNAMIC_PTR_CAST(Edge, gc);
}
}
} // namespace serialization
} // namespace boost
#endif // HPP_MANIPULATION_SERIALIZATION_HH
......@@ -16,8 +16,11 @@
#include "hpp/manipulation/constraint-set.hh"
#include <hpp/util/serialization.hh>
#include "hpp/manipulation/device.hh"
#include "hpp/manipulation/graph/edge.hh"
#include "hpp/manipulation/serialization.hh"
namespace hpp {
namespace manipulation {
......@@ -75,5 +78,17 @@ namespace hpp {
if (edge_) os << iendl << "Built by edge " << edge_->name();
return os;
}
template<class Archive>
void ConstraintSet::serialize(Archive & ar, const unsigned int version)
{
using namespace boost::serialization;
(void) version;
ar & make_nvp("base", base_object<core::ConstraintSet>(*this));
ar & BOOST_SERIALIZATION_NVP(edge_);
ar & BOOST_SERIALIZATION_NVP(weak_);
}
HPP_SERIALIZATION_IMPLEMENT(ConstraintSet);
} // namespace manipulation
} // namespace hpp
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