Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/serialization/collections_load_imp.hpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 4.0 KB
Line 
1#ifndef  BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
2#define BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
3
4// MS compatible compilers support #pragma once
5#if defined(_MSC_VER) && (_MSC_VER >= 1020)
6# pragma once
7#endif
8
9#if defined(_MSC_VER) && (_MSC_VER <= 1020)
10#  pragma warning (disable : 4786) // too long name, harmless warning
11#endif
12
13/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
14// collections_load_imp.hpp: serialization for loading stl collections
15
16// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
17// Use, modification and distribution is subject to the Boost Software
18// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
19// http://www.boost.org/LICENSE_1_0.txt)
20
21//  See http://www.boost.org for updates, documentation, and revision history.
22
23// helper function templates for serialization of collections
24
25#include <cassert>
26#include <boost/config.hpp>
27#include <boost/detail/workaround.hpp>
28
29#include <boost/aligned_storage.hpp>
30
31#include <boost/serialization/access.hpp>
32#include <boost/serialization/nvp.hpp>
33#include <boost/serialization/detail/stack_constructor.hpp>
34
35namespace boost{
36namespace serialization {
37namespace stl {
38
39//////////////////////////////////////////////////////////////////////
40// implementation of serialization for STL containers
41//
42
43// sequential container input
44template<class Archive, class Container>
45struct archive_input_seq
46{
47    inline void operator()(
48        Archive &ar, 
49        Container &s, 
50        const unsigned int v
51    ){
52        typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
53        detail::stack_construct<Archive, type> t(ar, v);
54        // borland fails silently w/o full namespace
55        ar >> boost::serialization::make_nvp("item", t.reference());
56        s.push_back(t.reference());
57        ar.reset_object_address(& s.back() , & t.reference());
58    }
59};
60
61// map and set input
62template<class Archive, class Container>
63struct archive_input_unique
64{
65    inline void operator()(
66        Archive &ar, 
67        Container &s, 
68        const unsigned int v
69    ){
70        typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
71        detail::stack_construct<Archive, type>t(ar, v);
72        // borland fails silently w/o full namespace
73        ar >> boost::serialization::make_nvp("item", t.reference());
74        std::pair<BOOST_DEDUCED_TYPENAME Container::const_iterator, bool> result = 
75            s.insert(t.reference());
76        if(result.second)
77            ar.reset_object_address(& (* result.first), & t.reference());
78    }
79};
80
81// multiset and multimap input
82template<class Archive, class Container>
83struct archive_input_multi
84{
85    inline void operator()(
86        Archive &ar, 
87        Container &s, 
88        const unsigned int v
89    ){
90        typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
91        detail::stack_construct<Archive, type> t(ar, v);
92        // borland fails silently w/o full namespace
93        ar >> boost::serialization::make_nvp("item", t.reference());
94        BOOST_DEDUCED_TYPENAME Container::const_iterator result
95            = s.insert(t.reference());
96        ar.reset_object_address(& (* result), & t.reference());
97    }
98};
99
100template<class Container>
101class reserve_imp
102{
103public:
104    void operator()(Container &s, unsigned int count) const {
105        s.reserve(count);
106    }
107};
108
109template<class Container>
110class no_reserve_imp
111{
112public:
113    void operator()(Container & /* s */, unsigned int /* count */) const{}
114};
115
116template<class Archive, class Container, class InputFunction, class R>
117inline void load_collection(Archive & ar, Container &s)
118{
119    s.clear();
120    // retrieve number of elements
121    unsigned int count;
122    unsigned int item_version(0);
123    ar >> BOOST_SERIALIZATION_NVP(count);
124    if(3 < ar.get_library_version()){
125        ar >> BOOST_SERIALIZATION_NVP(item_version);
126    }
127    R rx;
128    rx(s, count);
129    InputFunction ifunc;
130    while(count-- > 0){
131        ifunc(ar, s, item_version);
132    }
133}
134
135} // namespace stl
136} // namespace serialization
137} // namespace boost
138
139#endif //BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
Note: See TracBrowser for help on using the repository browser.