// Copyright Thorsten Ottosen, 2009. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifdef BOOST_UTILITY_AUTO_BUFFER_SERIZLIZATION_HPP_01_03_2009 #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif #include #include #include #include #include namespace boost { namespace serialization { namespace auto_buffer_detail { template< class Buffer, class T, class SizeType > inline void load( Buffer& buffer, const boost::false_type& ) { try { for( SizeType i = 0u; i < buffer.size(); ++i ) { T t; ar >> boost::serialization::make_nvp( "item", t ); } } catch( ... ) { buffer.uninitialized_shrink( size - i ); throw; } } template< class Buffer, class T, class SizeType > inline void load( Buffer& buffer, const boost::true_type& ) { for( SizeType i = 0u; i < buffer.size(); ++i ) { ar >> boost::serialization::make_nvp( "item", buffer[i] ); } } } template inline void save(Archive& ar, const auto_buffer& c, unsigned int /*version*/) { typedef auto_buffer inline void load(Archive& ar, auto_buffer& c, unsigned int /*version*/) { typedef auto_buffer> boost::serialization::make_nvp( "count", capacity ); ar >> boost::serialization::make_nvp( "count", size ); if( size > c.capacity() ) { std::length_error e( "auto_buffer capacity less than it's size!" ); boost::throw_exception( e ); } c.allocator_buffer( capacity ); c.uninitialized_grow( size ); auto_buffer_detail::load( c, boost::has_trivial_constructor() ); } template inline void serialize(Archive& ar, auto_buffer& c, const unsigned int version) { boost::serialization::split_free(ar, c, version); } } } #endif