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