vector.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2021 INRIA
3 //
4 
5 #ifndef __pinocchio_serialization_vector_hpp__
6 #define __pinocchio_serialization_vector_hpp__
7 
8 #include <vector>
9 
10 #include <boost/version.hpp>
11 #include <boost/core/addressof.hpp>
12 #include <boost/serialization/nvp.hpp>
13 #include <boost/serialization/vector.hpp>
14 
15 namespace boost
16 {
17  namespace serialization
18  {
19 
20 #if BOOST_VERSION / 100 % 1000 == 58
21 
22  namespace fixme
23  {
24 
25  template<class T>
26  struct nvp
27  : public std::pair<const char *, T *>
28  , public wrapper_traits<const nvp<T>>
29  {
30  // private:
31  nvp(const nvp & rhs)
32  : std::pair<const char *, T *>(rhs.first, rhs.second)
33  {
34  }
35 
36  public:
37  explicit nvp(const char * name_, T & t)
38  : // note: added _ to suppress useless gcc warning
39  std::pair<const char *, T *>(name_, boost::addressof(t))
40  {
41  }
42 
43  const char * name() const
44  {
45  return this->first;
46  }
47  T & value() const
48  {
49  return *(this->second);
50  }
51 
52  const T & const_value() const
53  {
54  return *(this->second);
55  }
56 
57  template<class Archive>
58  void save(
59  Archive & ar, const unsigned int /* file_version */
60  ) const
61  {
62  ar.operator<<(const_value());
63  }
64  template<class Archive>
65  void load(
66  Archive & ar, const unsigned int /* file_version */
67  )
68  {
69  ar.operator>>(value());
70  }
71  BOOST_SERIALIZATION_SPLIT_MEMBER()
72  };
73 
74  template<class T, class Allocator>
75  struct nvp<std::vector<T, Allocator>>
76  : public std::pair<const char *, std::vector<T, Allocator> *>
77  , public wrapper_traits<const nvp<std::vector<T, Allocator>>>
78  {
79  // private:
80  nvp(const nvp & rhs)
81  : std::pair<const char *, std::vector<T, Allocator> *>(rhs.first, rhs.second)
82  {
83  }
84 
85  typedef typename std::vector<T, Allocator>::const_iterator const_iterator;
86  typedef typename std::vector<T, Allocator>::iterator iterator;
87 
88  public:
89  explicit nvp(const char * name_, std::vector<T, Allocator> & t)
90  : // note: added _ to suppress useless gcc warning
91  std::pair<const char *, std::vector<T, Allocator> *>(name_, boost::addressof(t))
92  {
93  }
94 
95  const char * name() const
96  {
97  return this->first;
98  }
99 
100  std::vector<T, Allocator> & value() const
101  {
102  return *(this->second);
103  }
104 
105  const std::vector<T, Allocator> & const_value() const
106  {
107  return *(this->second);
108  }
109 
110  template<class Archive>
111  void save(
112  Archive & ar, const unsigned int /* file_version */
113  ) const
114  {
115  const size_t count(const_value().size());
116  ar << BOOST_SERIALIZATION_NVP(count);
117  if (!const_value().empty())
118  {
119  for (const_iterator hint = const_value().begin(); hint != const_value().end(); ++hint)
120  {
121  ar & boost::serialization::make_nvp("item", *hint);
122  }
123  }
124  }
125 
126  template<class Archive>
127  void load(
128  Archive & ar, const unsigned int /* file_version */
129  )
130  {
131  std::size_t count;
132  ar >> BOOST_SERIALIZATION_NVP(count);
133  value().resize(count);
134  for (iterator hint = value().begin(); hint != value().end(); ++hint)
135  {
136  ar >> boost::serialization::make_nvp("item", *hint);
137  }
138  }
139 
140  BOOST_SERIALIZATION_SPLIT_MEMBER()
141  };
142 
143  template<typename Allocator>
144  struct nvp<std::vector<bool, Allocator>>
145  : public std::pair<const char *, std::vector<bool, Allocator> *>
146  , public wrapper_traits<const nvp<std::vector<bool, Allocator>>>
147  {
148  // private:
149  nvp(const nvp & rhs)
150  : std::pair<const char *, std::vector<bool, Allocator> *>(rhs.first, rhs.second)
151  {
152  }
153 
154  typedef typename std::vector<bool, Allocator>::const_iterator const_iterator;
155  typedef typename std::vector<bool, Allocator>::iterator iterator;
156 
157  public:
158  explicit nvp(const char * name_, std::vector<bool, Allocator> & t)
159  : // note: added _ to suppress useless gcc warning
160  std::pair<const char *, std::vector<bool, Allocator> *>(name_, boost::addressof(t))
161  {
162  }
163 
164  const char * name() const
165  {
166  return this->first;
167  }
168 
169  std::vector<bool, Allocator> & value() const
170  {
171  return *(this->second);
172  }
173 
174  const std::vector<bool, Allocator> & const_value() const
175  {
176  return *(this->second);
177  }
178 
179  template<class Archive>
180  void save(
181  Archive & ar, const unsigned int /* file_version */
182  ) const
183  {
184  const size_t count(const_value().size());
185  ar << BOOST_SERIALIZATION_NVP(count);
186  if (!const_value().empty())
187  {
188  for (const_iterator hint = const_value().begin(); hint != const_value().end(); ++hint)
189  {
190  bool v = *hint;
191  ar & boost::serialization::make_nvp("item", v);
192  }
193  }
194  }
195 
196  template<class Archive>
197  void load(
198  Archive & ar, const unsigned int /* file_version */
199  )
200  {
201  std::size_t count;
202  ar >> BOOST_SERIALIZATION_NVP(count);
203  value().resize(count);
204  for (iterator hint = value().begin(); hint != value().end(); ++hint)
205  {
206  bool v;
207  ar >> boost::serialization::make_nvp("item", v);
208  *hint = v;
209  }
210  }
211 
212  BOOST_SERIALIZATION_SPLIT_MEMBER()
213  };
214 
215  } // namespace fixme
216 
217  template<class T, class Allocator>
218  inline const fixme::nvp<std::vector<T, Allocator>>
219  make_nvp(const char * name, std::vector<T, Allocator> & t)
220  {
221  return fixme::nvp<std::vector<T, Allocator>>(name, t);
222  }
223 #else
224  template<class T, class Allocator>
225  inline const nvp<std::vector<T, Allocator>>
226  make_nvp(const char * name, std::vector<T, Allocator> & t)
227  {
228  return nvp<std::vector<T, Allocator>>(name, t);
229  }
230 #endif
231 
232  } // namespace serialization
233 } // namespace boost
234 
235 #endif // ifndef __pinocchio_serialization_vector_hpp__
simulation-contact-dynamics.T
int T
Definition: simulation-contact-dynamics.py:89
boost::serialization::save
void save(Archive &ar, const Eigen::Map< PlainObjectBase, MapOptions, StrideType > &m, const unsigned int)
Definition: serialization/eigen.hpp:192
boost
boost::serialization::load
void load(Archive &ar, Eigen::Map< PlainObjectBase, MapOptions, StrideType > &m, const unsigned int)
Definition: serialization/eigen.hpp:206
boost::serialization::make_nvp
const nvp< pinocchio::container::aligned_vector< T > > make_nvp(const char *name, pinocchio::container::aligned_vector< T > &t)
Definition: serialization/aligned-vector.hpp:37
count
unsigned char const & count() const
cartpole.v
v
Definition: cartpole.py:153
size
FCL_REAL size() const
value
float value
setup.name
name
Definition: cmake/cython/setup.in.py:179
std
Definition: autodiff/casadi/utils/static-if.hpp:64
serialization
Definition: serialization.py:1
t
Transform3f t
simulation-closed-kinematic-chains.rhs
rhs
Definition: simulation-closed-kinematic-chains.py:138


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:49