os/ossrv/ossrv_pub/boost_apis/boost/serialization/vector.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
#ifndef  BOOST_SERIALIZATION_VECTOR_HPP
sl@0
     2
#define BOOST_SERIALIZATION_VECTOR_HPP
sl@0
     3
sl@0
     4
// MS compatible compilers support #pragma once
sl@0
     5
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
sl@0
     6
# pragma once
sl@0
     7
#endif
sl@0
     8
sl@0
     9
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
sl@0
    10
// vector.hpp: serialization for stl vector templates
sl@0
    11
sl@0
    12
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
sl@0
    13
// Use, modification and distribution is subject to the Boost Software
sl@0
    14
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
sl@0
    15
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
    16
sl@0
    17
//  See http://www.boost.org for updates, documentation, and revision history.
sl@0
    18
sl@0
    19
#include <vector>
sl@0
    20
sl@0
    21
#include <boost/config.hpp>
sl@0
    22
#include <boost/detail/workaround.hpp>
sl@0
    23
sl@0
    24
#include <boost/serialization/collections_save_imp.hpp>
sl@0
    25
#include <boost/serialization/collections_load_imp.hpp>
sl@0
    26
#include <boost/serialization/split_free.hpp>
sl@0
    27
sl@0
    28
namespace boost { 
sl@0
    29
namespace serialization {
sl@0
    30
sl@0
    31
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
sl@0
    32
// vector<T>
sl@0
    33
template<class Archive, class U, class Allocator>
sl@0
    34
inline void save(
sl@0
    35
    Archive & ar,
sl@0
    36
    const std::vector<U, Allocator> &t,
sl@0
    37
    const unsigned int /* file_version */
sl@0
    38
){
sl@0
    39
    boost::serialization::stl::save_collection<Archive, std::vector<U, Allocator> >(
sl@0
    40
        ar, t
sl@0
    41
    );
sl@0
    42
}
sl@0
    43
sl@0
    44
template<class Archive, class U, class Allocator>
sl@0
    45
inline void load(
sl@0
    46
    Archive & ar,
sl@0
    47
    std::vector<U, Allocator> &t,
sl@0
    48
    const unsigned int /* file_version */
sl@0
    49
){
sl@0
    50
    boost::serialization::stl::load_collection<
sl@0
    51
        Archive,
sl@0
    52
        std::vector<U, Allocator>,
sl@0
    53
        boost::serialization::stl::archive_input_seq<
sl@0
    54
            Archive, std::vector<U, Allocator> 
sl@0
    55
        >,
sl@0
    56
        boost::serialization::stl::reserve_imp<std::vector<U, Allocator> >
sl@0
    57
    >(ar, t);
sl@0
    58
}
sl@0
    59
sl@0
    60
// split non-intrusive serialization function member into separate
sl@0
    61
// non intrusive save/load member functions
sl@0
    62
template<class Archive, class U, class Allocator>
sl@0
    63
inline void serialize(
sl@0
    64
    Archive & ar,
sl@0
    65
    std::vector<U, Allocator> & t,
sl@0
    66
    const unsigned int file_version
sl@0
    67
){
sl@0
    68
    boost::serialization::split_free(ar, t, file_version);
sl@0
    69
}
sl@0
    70
sl@0
    71
#if ! BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
sl@0
    72
sl@0
    73
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
sl@0
    74
// vector<bool>
sl@0
    75
template<class Archive, class Allocator>
sl@0
    76
inline void save(
sl@0
    77
    Archive & ar,
sl@0
    78
    const std::vector<bool, Allocator> &t,
sl@0
    79
    const unsigned int /* file_version */
sl@0
    80
){
sl@0
    81
    // record number of elements
sl@0
    82
    unsigned int count = t.size();
sl@0
    83
    ar << BOOST_SERIALIZATION_NVP(count);
sl@0
    84
    std::vector<bool>::const_iterator it = t.begin();
sl@0
    85
    while(count-- > 0){
sl@0
    86
        bool tb = *it++;
sl@0
    87
        ar << boost::serialization::make_nvp("item", tb);
sl@0
    88
    }
sl@0
    89
}
sl@0
    90
sl@0
    91
template<class Archive, class Allocator>
sl@0
    92
inline void load(
sl@0
    93
    Archive & ar,
sl@0
    94
    std::vector<bool, Allocator> &t,
sl@0
    95
    const unsigned int /* file_version */
sl@0
    96
){
sl@0
    97
    // retrieve number of elements
sl@0
    98
    unsigned int count;
sl@0
    99
    ar >> BOOST_SERIALIZATION_NVP(count);
sl@0
   100
    t.clear();
sl@0
   101
    while(count-- > 0){
sl@0
   102
        bool i;
sl@0
   103
        ar >> boost::serialization::make_nvp("item", i);
sl@0
   104
        t.push_back(i);
sl@0
   105
    }
sl@0
   106
}
sl@0
   107
sl@0
   108
// split non-intrusive serialization function member into separate
sl@0
   109
// non intrusive save/load member functions
sl@0
   110
template<class Archive, class Allocator>
sl@0
   111
inline void serialize(
sl@0
   112
    Archive & ar,
sl@0
   113
    std::vector<bool, Allocator> & t,
sl@0
   114
    const unsigned int file_version
sl@0
   115
){
sl@0
   116
    boost::serialization::split_free(ar, t, file_version);
sl@0
   117
}
sl@0
   118
sl@0
   119
#endif // BOOST_WORKAROUND
sl@0
   120
sl@0
   121
} // serialization
sl@0
   122
} // namespace boost
sl@0
   123
sl@0
   124
#include <boost/serialization/collection_traits.hpp>
sl@0
   125
sl@0
   126
BOOST_SERIALIZATION_COLLECTION_TRAITS(std::vector)
sl@0
   127
sl@0
   128
#endif // BOOST_SERIALIZATION_VECTOR_HPP