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 
21 #if BOOST_VERSION / 100 % 1000 == 58
22 
23  namespace fixme
24  {
25 
26  template<class T>
27  struct nvp :
28  public std::pair<const char *, T *>,
29  public wrapper_traits<const nvp< T > >
30  {
31  //private:
32  nvp(const nvp & rhs) :
33  std::pair<const char *, T *>(rhs.first, rhs.second)
34  {}
35  public:
36  explicit nvp(const char * name_, T & t) :
37  // note: added _ to suppress useless gcc warning
38  std::pair<const char *, T *>(name_, boost::addressof(t))
39  {}
40 
41  const char * name() const {
42  return this->first;
43  }
44  T & value() const {
45  return *(this->second);
46  }
47 
48  const T & const_value() const {
49  return *(this->second);
50  }
51 
52  template<class Archive>
53  void save(
54  Archive & ar,
55  const unsigned int /* file_version */
56  ) const {
57  ar.operator<<(const_value());
58  }
59  template<class Archive>
60  void load(
61  Archive & ar,
62  const unsigned int /* file_version */
63  ){
64  ar.operator>>(value());
65  }
66  BOOST_SERIALIZATION_SPLIT_MEMBER()
67  };
68 
69 
70  template<class T, class Allocator>
71  struct nvp< std::vector<T,Allocator> > :
72  public std::pair<const char *, std::vector<T,Allocator> *>,
73  public wrapper_traits<const nvp< std::vector<T,Allocator> > >
74  {
75  //private:
76  nvp(const nvp & rhs) :
77  std::pair<const char *, std::vector<T,Allocator> *>(rhs.first, rhs.second)
78  {}
79 
80  typedef typename std::vector<T,Allocator>::const_iterator const_iterator;
81  typedef typename std::vector<T,Allocator>::iterator iterator;
82 
83  public:
84  explicit nvp(const char * name_, std::vector<T,Allocator> & t) :
85  // note: added _ to suppress useless gcc warning
86  std::pair<const char *, std::vector<T,Allocator> *>(name_, boost::addressof(t))
87  {}
88 
89  const char * name() const {
90  return this->first;
91  }
92 
93  std::vector<T,Allocator> & value() const {
94  return *(this->second);
95  }
96 
97  const std::vector<T,Allocator> & const_value() const {
98  return *(this->second);
99  }
100 
101  template<class Archive>
102  void save(Archive & ar,
103  const unsigned int /* file_version */
104  ) const
105  {
106  const size_t count(const_value().size());
107  ar << BOOST_SERIALIZATION_NVP(count);
108  if (!const_value().empty())
109  {
110  for(const_iterator hint = const_value().begin();
111  hint != const_value().end(); ++hint)
112  {
113  ar & boost::serialization::make_nvp("item", *hint);
114  }
115  }
116  }
117 
118  template<class Archive>
119  void load(Archive & ar,
120  const unsigned int /* file_version */
121  )
122  {
123  std::size_t count;
124  ar >> BOOST_SERIALIZATION_NVP(count);
125  value().resize(count);
126  for(iterator hint = value().begin();
127  hint != value().end(); ++hint)
128  {
129  ar >> boost::serialization::make_nvp("item", *hint);
130  }
131  }
132 
133  BOOST_SERIALIZATION_SPLIT_MEMBER()
134  };
135 
136  template<typename Allocator>
137  struct nvp< std::vector<bool,Allocator> > :
138  public std::pair<const char *, std::vector<bool,Allocator> *>,
139  public wrapper_traits<const nvp< std::vector<bool,Allocator> > >
140  {
141  //private:
142  nvp(const nvp & rhs) :
143  std::pair<const char *, std::vector<bool,Allocator> *>(rhs.first, rhs.second)
144  {}
145 
146  typedef typename std::vector<bool,Allocator>::const_iterator const_iterator;
147  typedef typename std::vector<bool,Allocator>::iterator iterator;
148 
149  public:
150  explicit nvp(const char * name_, std::vector<bool,Allocator> & t) :
151  // note: added _ to suppress useless gcc warning
152  std::pair<const char *, std::vector<bool,Allocator> *>(name_, boost::addressof(t))
153  {}
154 
155  const char * name() const {
156  return this->first;
157  }
158 
159  std::vector<bool,Allocator> & value() const {
160  return *(this->second);
161  }
162 
163  const std::vector<bool,Allocator> & const_value() const {
164  return *(this->second);
165  }
166 
167  template<class Archive>
168  void save(Archive & ar,
169  const unsigned int /* file_version */
170  ) const
171  {
172  const size_t count(const_value().size());
173  ar << BOOST_SERIALIZATION_NVP(count);
174  if (!const_value().empty())
175  {
176  for(const_iterator hint = const_value().begin();
177  hint != const_value().end(); ++hint)
178  {
179  bool v = *hint;
180  ar & boost::serialization::make_nvp("item", v);
181  }
182  }
183  }
184 
185  template<class Archive>
186  void load(Archive & ar,
187  const unsigned int /* file_version */
188  )
189  {
190  std::size_t count;
191  ar >> BOOST_SERIALIZATION_NVP(count);
192  value().resize(count);
193  for(iterator hint = value().begin();
194  hint != value().end(); ++hint)
195  {
196  bool v;
197  ar >> boost::serialization::make_nvp("item", v);
198  *hint = v;
199  }
200  }
201 
202  BOOST_SERIALIZATION_SPLIT_MEMBER()
203  };
204 
205 
206  }
207 
208  template<class T, class Allocator>
209  inline const fixme::nvp< std::vector<T,Allocator> >
210  make_nvp(const char * name, std::vector<T,Allocator> & t)
211  {
212  return fixme::nvp< std::vector<T,Allocator> >(name, t);
213  }
214 #else
215  template<class T, class Allocator>
216  inline const nvp< std::vector<T,Allocator> >
217  make_nvp(const char * name, std::vector<T,Allocator> & t)
218  {
219  return nvp< std::vector<T,Allocator> >(name, t);
220  }
221 #endif
222 
223  }
224 }
225 
226 #endif // ifndef __pinocchio_serialization_vector_hpp__
void save(Archive &ar, const Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &m, const unsigned int)
std::size_t size(custom_string const &s)
v
const nvp< typename pinocchio::container::aligned_vector< T >::vector_base > make_nvp(const char *name, pinocchio::container::aligned_vector< T > &t)
void load(Archive &ar, Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &m, const unsigned int)
int value


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:05