| 1 | #ifndef BOOST_SERIALIZATION_HASH_COLLECTIONS_SAVE_IMP_HPP |
|---|
| 2 | #define BOOST_SERIALIZATION_HASH_COLLECTIONS_SAVE_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 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
|---|
| 10 | // hash_collections_save_imp.hpp: serialization for stl collections |
|---|
| 11 | |
|---|
| 12 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
|---|
| 13 | // Use, modification and distribution is subject to the Boost Software |
|---|
| 14 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 15 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 16 | |
|---|
| 17 | // See http://www.boost.org for updates, documentation, and revision history. |
|---|
| 18 | |
|---|
| 19 | // helper function templates for serialization of collections |
|---|
| 20 | |
|---|
| 21 | #include <boost/config.hpp> |
|---|
| 22 | #include <boost/serialization/nvp.hpp> |
|---|
| 23 | #include <boost/serialization/serialization.hpp> |
|---|
| 24 | #include <boost/serialization/version.hpp> |
|---|
| 25 | |
|---|
| 26 | namespace boost{ |
|---|
| 27 | namespace serialization { |
|---|
| 28 | namespace stl { |
|---|
| 29 | |
|---|
| 30 | ////////////////////////////////////////////////////////////////////// |
|---|
| 31 | // implementation of serialization for STL containers |
|---|
| 32 | // |
|---|
| 33 | |
|---|
| 34 | template<class Archive, class Container> |
|---|
| 35 | inline void save_hash_collection(Archive & ar, const Container &s) |
|---|
| 36 | { |
|---|
| 37 | // record number of elements |
|---|
| 38 | unsigned int count = s.size(); |
|---|
| 39 | ar << BOOST_SERIALIZATION_NVP(count); |
|---|
| 40 | // make sure the target type is registered so we can retrieve |
|---|
| 41 | // the version when we load |
|---|
| 42 | if(3 < ar.get_library_version()){ |
|---|
| 43 | const unsigned int bucket_count = s.bucket_count(); |
|---|
| 44 | ar << BOOST_SERIALIZATION_NVP(bucket_count); |
|---|
| 45 | const unsigned int item_version = version<BOOST_DEDUCED_TYPENAME Container::value_type>::value; |
|---|
| 46 | ar << BOOST_SERIALIZATION_NVP(item_version); |
|---|
| 47 | } |
|---|
| 48 | BOOST_DEDUCED_TYPENAME Container::const_iterator it = s.begin(); |
|---|
| 49 | while(count-- > 0){ |
|---|
| 50 | // note borland emits a no-op without the explicit namespace |
|---|
| 51 | boost::serialization::save_construct_data_adl( |
|---|
| 52 | ar, |
|---|
| 53 | &(*it), |
|---|
| 54 | boost::serialization::version< |
|---|
| 55 | BOOST_DEDUCED_TYPENAME Container::value_type |
|---|
| 56 | >::value |
|---|
| 57 | ); |
|---|
| 58 | ar << boost::serialization::make_nvp("item", *it++); |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | } // namespace stl |
|---|
| 63 | } // namespace serialization |
|---|
| 64 | } // namespace boost |
|---|
| 65 | |
|---|
| 66 | #endif //BOOST_SERIALIZATION_HASH_COLLECTIONS_SAVE_IMP_HPP |
|---|