5 #ifndef __pinocchio_serialization_vector_hpp__
6 #define __pinocchio_serialization_vector_hpp__
10 #include <boost/version.hpp>
11 #include <boost/serialization/nvp.hpp>
12 #include <boost/serialization/vector.hpp>
16 namespace serialization
20 #if BOOST_VERSION / 100 % 1000 == 58
26 public std::pair<const char *, T *>,
27 public wrapper_traits<const nvp< T > >
30 nvp(
const nvp & rhs) :
31 std::pair<const char *, T *>(rhs.first, rhs.second)
34 explicit nvp(
const char * name_, T & t) :
36 std::pair<const char *, T *>(name_, boost::addressof(t))
39 const char *
name()
const {
43 return *(this->second);
46 const T & const_value()
const {
47 return *(this->second);
50 template<
class Archive>
55 ar.operator<<(const_value());
57 template<
class Archive>
62 ar.operator>>(value());
64 BOOST_SERIALIZATION_SPLIT_MEMBER()
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> > >
74 nvp(
const nvp & rhs) :
75 std::pair<const char *, std::vector<T,Allocator> *>(rhs.first, rhs.second)
78 explicit nvp(
const char * name_, std::vector<T,Allocator> & t) :
80 std::pair<const char *, std::vector<T,Allocator> *>(name_, boost::addressof(t))
83 const char *
name()
const {
87 std::vector<T,Allocator> & value()
const {
88 return *(this->second);
91 const std::vector<T,Allocator> & const_value()
const {
92 return *(this->second);
95 template<
class Archive>
96 void save(Archive & ar,
100 const size_t count(const_value().size());
101 ar << BOOST_SERIALIZATION_NVP(count);
102 if (!const_value().empty())
104 for(
typename std::vector<T,Allocator>::const_iterator hint = const_value().begin();
105 hint != const_value().end(); ++hint)
107 ar & boost::serialization::make_nvp(
"item", *hint);
112 template<
class Archive>
113 void load(Archive & ar,
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)
123 ar >> boost::serialization::make_nvp(
"item", *hint);
127 BOOST_SERIALIZATION_SPLIT_MEMBER()
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)
137 return fixme::nvp< std::vector<T,Allocator> >(
name, t);
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)
144 return nvp< std::vector<T,Allocator> >(
name, t);
151 #endif // ifndef __pinocchio_serialization_vector_hpp__