24 #ifndef GRAPHLAB_SERIALIZE_VECTOR_HPP
25 #define GRAPHLAB_SERIALIZE_VECTOR_HPP
27 #include <graphlab/serialization/iarchive.hpp>
28 #include <graphlab/serialization/oarchive.hpp>
29 #include <graphlab/serialization/iterator.hpp>
33 namespace archive_detail {
38 template <
typename OutArcType,
typename ValueType,
bool IsPOD>
39 struct vector_serialize_impl {
40 static void exec(OutArcType& oarc,
const ValueType& vec) {
43 BOOST_STATIC_ASSERT(
sizeof(OutArcType) == 0);
51 template <
typename InArcType,
typename ValueType,
bool IsPOD>
52 struct vector_deserialize_impl {
53 static void exec(InArcType& iarc, ValueType& vec) {
56 BOOST_STATIC_ASSERT(
sizeof(InArcType) == 0);
62 template <
typename OutArcType,
typename ValueType>
63 struct vector_serialize_impl<OutArcType, ValueType, false > {
64 static void exec(OutArcType& oarc,
const std::vector<ValueType>& vec) {
65 oarc << size_t(vec.size());
71 template <
typename OutArcType,
typename ValueType>
72 struct vector_serialize_impl<OutArcType, ValueType, true > {
73 static void exec(OutArcType& oarc,
const std::vector<ValueType>& vec) {
74 oarc << size_t(vec.size());
75 serialize(oarc, &(vec[0]),
sizeof(ValueType)*vec.size());
80 template <
typename InArcType,
typename ValueType>
81 struct vector_deserialize_impl<InArcType, ValueType, false > {
82 static void exec(InArcType& iarc, std::vector<ValueType>& vec){
85 vec.clear(); vec.reserve(len);
86 deserialize_iterator<InArcType, ValueType>(iarc, std::inserter(vec, vec.end()));
91 template <
typename InArcType,
typename ValueType>
92 struct vector_deserialize_impl<InArcType, ValueType, true > {
93 static void exec(InArcType& iarc, std::vector<ValueType>& vec){
96 vec.clear(); vec.resize(len);
97 deserialize(iarc, &(vec[0]),
sizeof(ValueType)*vec.size());
105 template <
typename OutArcType,
typename ValueType>
106 struct serialize_impl<OutArcType, std::vector<ValueType>, false > {
107 static void exec(OutArcType& oarc,
const std::vector<ValueType>& vec) {
108 vector_serialize_impl<OutArcType, ValueType,
109 gl_is_pod_or_scaler<ValueType>::value >::exec(oarc, vec);
114 template <
typename InArcType,
typename ValueType>
115 struct deserialize_impl<InArcType, std::vector<ValueType>, false > {
116 static void exec(InArcType& iarc, std::vector<ValueType>& vec){
117 vector_deserialize_impl<InArcType, ValueType,
118 gl_is_pod_or_scaler<ValueType>::value >::exec(iarc, vec);