pinocchio  2.6.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
vector.hpp
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 
21 #if BOOST_VERSION / 100 % 1000 == 58
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  public:
35  explicit nvp(const char * name_, T & t) :
36  // note: added _ to suppress useless gcc warning
37  std::pair<const char *, T *>(name_, boost::addressof(t))
38  {}
39 
40  const char * name() const {
41  return this->first;
42  }
43  T & value() const {
44  return *(this->second);
45  }
46 
47  const T & const_value() const {
48  return *(this->second);
49  }
50 
51  template<class Archive>
52  void save(
53  Archive & ar,
54  const unsigned int /* file_version */
55  ) const {
56  ar.operator<<(const_value());
57  }
58  template<class Archive>
59  void load(
60  Archive & ar,
61  const unsigned int /* file_version */
62  ){
63  ar.operator>>(value());
64  }
65  BOOST_SERIALIZATION_SPLIT_MEMBER()
66  };
67 
68 
69  template<class T, class Allocator>
70  struct nvp< std::vector<T,Allocator> > :
71  public std::pair<const char *, std::vector<T,Allocator> *>,
72  public wrapper_traits<const nvp< std::vector<T,Allocator> > >
73  {
74  //private:
75  nvp(const nvp & rhs) :
76  std::pair<const char *, std::vector<T,Allocator> *>(rhs.first, rhs.second)
77  {}
78  public:
79  explicit nvp(const char * name_, std::vector<T,Allocator> & t) :
80  // note: added _ to suppress useless gcc warning
81  std::pair<const char *, std::vector<T,Allocator> *>(name_, boost::addressof(t))
82  {}
83 
84  const char * name() const {
85  return this->first;
86  }
87 
88  std::vector<T,Allocator> & value() const {
89  return *(this->second);
90  }
91 
92  const std::vector<T,Allocator> & const_value() const {
93  return *(this->second);
94  }
95 
96  template<class Archive>
97  void save(Archive & ar,
98  const unsigned int /* file_version */
99  ) const
100  {
101  const size_t count(const_value().size());
102  ar << BOOST_SERIALIZATION_NVP(count);
103  if (!const_value().empty())
104  {
105  for(typename std::vector<T,Allocator>::const_iterator hint = const_value().begin();
106  hint != const_value().end(); ++hint)
107  {
108  ar & boost::serialization::make_nvp("item", *hint);
109  }
110  }
111  }
112 
113  template<class Archive>
114  void load(Archive & ar,
115  const unsigned int /* file_version */
116  )
117  {
118  std::size_t count;
119  ar >> BOOST_SERIALIZATION_NVP(count);
120  value().resize(count);
121  for(typename std::vector<T,Allocator>::iterator hint = value().begin();
122  hint != value().end(); ++hint)
123  {
124  ar >> boost::serialization::make_nvp("item", *hint);
125  }
126  }
127 
128  BOOST_SERIALIZATION_SPLIT_MEMBER()
129  };
130 
131 
132  }
133 
134  template<class T, class Allocator>
135  inline const fixme::nvp< std::vector<T,Allocator> >
136  make_nvp(const char * name, std::vector<T,Allocator> & t)
137  {
138  return fixme::nvp< std::vector<T,Allocator> >(name, t);
139  }
140 #else
141  template<class T, class Allocator>
142  inline const nvp< std::vector<T,Allocator> >
143  make_nvp(const char * name, std::vector<T,Allocator> & t)
144  {
145  return nvp< std::vector<T,Allocator> >(name, t);
146  }
147 #endif
148 
149  }
150 }
151 
152 #endif // ifndef __pinocchio_serialization_vector_hpp__
pinocchio::name
std::string name(const LieGroupGenericTpl< LieGroupCollection > &lg)
Visit a LieGroupVariant to get the name of it.