hpp-manipulation 6.0.0
Classes for manipulation planning.
Loading...
Searching...
No Matches
serialization.hh
Go to the documentation of this file.
1//
2// Copyright (c) 2020 CNRS
3// Author: Joseph Mirabel
4//
5
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
9//
10// 1. Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12//
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28// DAMAGE.
29
30#ifndef HPP_MANIPULATION_SERIALIZATION_HH
31#define HPP_MANIPULATION_SERIALIZATION_HH
32
33#include <boost/serialization/shared_ptr.hpp>
34#include <boost/serialization/split_free.hpp>
35#include <boost/serialization/weak_ptr.hpp>
40#include <hpp/pinocchio/serialization.hh>
41#include <hpp/util/serialization.hh>
42
43namespace hpp {
44namespace serialization {
45template <typename Archive>
47 const std::string& name) {
48 auto* har = hpp::serialization::cast(&ar);
49 if (!har || !har->contains(name))
50 throw std::runtime_error(
51 "Cannot deserialize edges with a provided graph with correct name.");
52 return har->template get<manipulation::graph::Graph>(name, true)->self();
53}
54
55template <class Archive, class GraphCompT>
56inline void serializeGraphComponent(Archive& ar, shared_ptr<GraphCompT>& c,
57 const unsigned int version) {
58 (void)version;
59
60 std::size_t id;
61 std::string name;
62 if (Archive::is_saving::value) {
63 id = (c ? c->id() : -1);
64 if (c && c->parentGraph()) name = c->parentGraph()->name();
65 }
66 ar& BOOST_SERIALIZATION_NVP(id);
67 ar& BOOST_SERIALIZATION_NVP(name);
68 if (!Archive::is_saving::value) {
69 auto graph = getGraphFromArchive(ar, name);
70 c = HPP_DYNAMIC_PTR_CAST(GraphCompT, graph->get(id).lock());
71 }
72}
73} // namespace serialization
74} // namespace hpp
75
76BOOST_CLASS_EXPORT_KEY(hpp::manipulation::RoadmapNode)
77BOOST_CLASS_EXPORT_KEY(hpp::manipulation::ConnectedComponent)
79BOOST_CLASS_EXPORT_KEY(hpp::manipulation::Roadmap)
80
81namespace boost {
82namespace serialization {
83template <class Archive>
85 const unsigned int version) {
87 (void)version;
88
89 std::string name;
90 if (Archive::is_saving::value) name = g->name();
91 ar& BOOST_SERIALIZATION_NVP(name);
92 if (!Archive::is_saving::value) g = getGraphFromArchive(ar, name);
93}
94
95template <class Archive>
97 const unsigned int version) {
99}
100
101template <class Archive>
103 const unsigned int version) {
105}
106
107template <class Archive>
108inline void serialize(Archive& ar, hpp::manipulation::graph::EdgeWkPtr_t& e,
109 const unsigned int version) {
110 auto e_ = e.lock();
111 serialize(ar, e_, version);
112 e = e_;
113}
114
115template <class Archive>
116inline void serialize(Archive& ar, hpp::manipulation::graph::StateWkPtr_t& s,
117 const unsigned int version) {
118 auto s_ = s.lock();
119 serialize(ar, s_, version);
120 s = s_;
121}
122
123template <class Archive>
124inline void load(Archive& ar, hpp::manipulation::DevicePtr_t& d,
125 const unsigned int version) {
126 load<Archive, hpp::manipulation::Device>(ar, d, version);
127 auto* har = hpp::serialization::cast(&ar);
128 if (d && har && har->contains(d->name()))
129 d = har->template getChildClass<hpp::pinocchio::Device,
130 hpp::manipulation::Device>(d->name(), true)
131 ->self();
132}
133
134template <class Archive>
135inline void load(Archive& ar, hpp::manipulation::DeviceWkPtr_t& d,
136 const unsigned int version) {
137 load<Archive, hpp::manipulation::Device>(ar, d, version);
138 auto* har = hpp::serialization::cast(&ar);
139 auto dd = d.lock();
140 if (!dd) return;
141 if (har && har->contains(dd->name()))
142 d = har->template getChildClass<hpp::pinocchio::Device,
143 hpp::manipulation::Device>(dd->name(), true)
144 ->self();
145}
146} // namespace serialization
147} // namespace boost
148
149#endif // HPP_MANIPULATION_SERIALIZATION_HH
Definition connected-component.hh:44
Definition device.hh:50
Definition roadmap-node.hh:42
Definition roadmap.hh:47
Definition leaf-connected-comp.hh:110
void serialize(Archive &ar, hpp::manipulation::graph::GraphPtr_t &g, const unsigned int version)
Definition serialization.hh:84
void load(Archive &ar, hpp::manipulation::DevicePtr_t &d, const unsigned int version)
Definition serialization.hh:124
Definition serialization.hh:81
shared_ptr< Edge > EdgePtr_t
Definition fwd.hh:49
shared_ptr< State > StatePtr_t
Definition fwd.hh:48
shared_ptr< Graph > GraphPtr_t
Definition fwd.hh:47
shared_ptr< Device > DevicePtr_t
Definition fwd.hh:40
manipulation::graph::GraphPtr_t getGraphFromArchive(Archive &ar, const std::string &name)
Definition serialization.hh:46
void serializeGraphComponent(Archive &ar, shared_ptr< GraphCompT > &c, const unsigned int version)
Definition serialization.hh:56
Definition main.hh:1