diff options
Diffstat (limited to 'boost/serialization/collections_load_imp.hpp')
-rw-r--r-- | boost/serialization/collections_load_imp.hpp | 153 |
1 files changed, 46 insertions, 107 deletions
diff --git a/boost/serialization/collections_load_imp.hpp b/boost/serialization/collections_load_imp.hpp index 2291e74226..246b64ed65 100644 --- a/boost/serialization/collections_load_imp.hpp +++ b/boost/serialization/collections_load_imp.hpp @@ -38,6 +38,8 @@ namespace std{ #include <boost/serialization/detail/stack_constructor.hpp> #include <boost/serialization/collection_size_type.hpp> #include <boost/serialization/item_version_type.hpp> +#include <boost/serialization/detail/is_default_constructible.hpp> +#include <boost/utility/enable_if.hpp> namespace boost{ namespace serialization { @@ -47,116 +49,53 @@ namespace stl { // implementation of serialization for STL containers // -// sequential container input -template<class Archive, class Container> -struct archive_input_seq -{ - inline typename Container::iterator - operator()( - Archive &ar, - Container &s, - const unsigned int v, - typename Container::iterator hint - ){ - typedef typename Container::value_type type; - detail::stack_construct<Archive, type> t(ar, v); - // borland fails silently w/o full namespace - ar >> boost::serialization::make_nvp("item", t.reference()); - s.push_back(t.reference()); - ar.reset_object_address(& s.back() , & t.reference()); - return hint; - } -}; - -// map input -template<class Archive, class Container> -struct archive_input_map -{ - inline typename Container::iterator - operator()( - Archive &ar, - Container &s, - const unsigned int v, - typename Container::iterator hint - ){ - typedef typename Container::value_type type; - detail::stack_construct<Archive, type> t(ar, v); - // borland fails silently w/o full namespace - ar >> boost::serialization::make_nvp("item", t.reference()); - typename Container::iterator result = - s.insert(hint, t.reference()); - // note: the following presumes that the map::value_type was NOT tracked - // in the archive. This is the usual case, but here there is no way - // to determine that. - ar.reset_object_address( - & (result->second), - & t.reference().second - ); - return result; - } -}; - -// set input -template<class Archive, class Container> -struct archive_input_set -{ - inline typename Container::iterator - operator()( - Archive &ar, - Container &s, - const unsigned int v, - typename Container::iterator hint - ){ - typedef typename Container::value_type type; - detail::stack_construct<Archive, type> t(ar, v); - // borland fails silently w/o full namespace - ar >> boost::serialization::make_nvp("item", t.reference()); - typename Container::iterator result = - s.insert(hint, t.reference()); - ar.reset_object_address(& (* result), & t.reference()); - return result; - } -}; - -template<class Container> -class reserve_imp -{ -public: - void operator()(Container &s, std::size_t count) const { - s.reserve(count); - } -}; - -template<class Container> -class no_reserve_imp -{ -public: - void operator()(Container & /* s */, std::size_t /* count */) const{} -}; - -template<class Archive, class Container, class InputFunction, class R> -inline void load_collection(Archive & ar, Container &s) -{ - s.clear(); - const boost::archive::library_version_type library_version( - ar.get_library_version() - ); - // retrieve number of elements - item_version_type item_version(0); - collection_size_type count; - ar >> BOOST_SERIALIZATION_NVP(count); - if(boost::archive::library_version_type(3) < library_version){ - ar >> BOOST_SERIALIZATION_NVP(item_version); +template< + class Archive, + class T +> +typename boost::enable_if< + typename detail::is_default_constructible< + typename T::value_type + >, + void +>::type +collection_load_impl( + Archive & ar, + T & t, + collection_size_type count, + item_version_type item_version +){ + t.resize(count); + typename T::iterator hint; + hint = t.begin(); + while(count-- > 0){ + ar >> boost::serialization::make_nvp("item", *hint++); } +} - R rx; - rx(s, count); - InputFunction ifunc; - typename Container::iterator hint; - hint = s.begin(); +template< + class Archive, + class T +> +typename boost::disable_if< + typename detail::is_default_constructible< + typename T::value_type + >, + void +>::type +collection_load_impl( + Archive & ar, + T & t, + collection_size_type count, + item_version_type item_version +){ + t.clear(); while(count-- > 0){ - hint = ifunc(ar, s, item_version, hint); - } + detail::stack_construct<Archive, typename T::value_type> u(ar, item_version); + ar >> boost::serialization::make_nvp("item", u.reference()); + t.push_back(u.reference()); + ar.reset_object_address(& t.back() , & u.reference()); + } } } // namespace stl |