diff options
author | Kevin Smith <git@kismith.co.uk> | 2013-01-04 19:42:37 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2013-04-06 13:36:54 (GMT) |
commit | 3333ab69d62d1be7ae7dd7a4e56cc4bb608d3add (patch) | |
tree | 5ee630b666ae21dd4c4202703c158383de1faf91 /3rdParty/Boost/src/boost/serialization/array.hpp | |
parent | b9ef4566d31219d66a615b1eae042a01828c8b7d (diff) | |
download | swift-3333ab69d62d1be7ae7dd7a4e56cc4bb608d3add.zip swift-3333ab69d62d1be7ae7dd7a4e56cc4bb608d3add.tar.bz2 |
Add boost serialization library
We'll need it before too long
Change-Id: Ia34c7f26e1aedbc13a2fc10c980994cbcb7cb348
Diffstat (limited to '3rdParty/Boost/src/boost/serialization/array.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/serialization/array.hpp | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/3rdParty/Boost/src/boost/serialization/array.hpp b/3rdParty/Boost/src/boost/serialization/array.hpp new file mode 100644 index 0000000..3391a96 --- /dev/null +++ b/3rdParty/Boost/src/boost/serialization/array.hpp @@ -0,0 +1,153 @@ +#ifndef BOOST_SERIALIZATION_ARRAY_HPP +#define BOOST_SERIALIZATION_ARRAY_HPP + +// (C) Copyright 2005 Matthias Troyer and Dave Abrahams +// Use, modification and distribution is subject to 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) + +#include <iostream> +#include <cstddef> // std::size_t +#include <cstddef> +#include <boost/config.hpp> // msvc 6.0 needs this for warning suppression +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::size_t; +} // namespace std +#endif + +#include <boost/serialization/nvp.hpp> +#include <boost/serialization/split_member.hpp> +#include <boost/serialization/wrapper.hpp> +#include <boost/mpl/always.hpp> +#include <boost/mpl/apply.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/type_traits/remove_const.hpp> +#include <boost/array.hpp> + +namespace boost { namespace serialization { + +// traits to specify whether to use an optimized array serialization + +#ifdef __BORLANDC__ +// workaround for Borland compiler +template <class Archive> +struct use_array_optimization { + template <class T> struct apply : boost::mpl::false_ {}; +}; + +#else +template <class Archive> +struct use_array_optimization : boost::mpl::always<boost::mpl::false_> {}; +#endif + +template<class T> +class array : + public wrapper_traits<const array< T > > +{ +public: + typedef T value_type; + + array(value_type* t, std::size_t s) : + m_t(t), + m_element_count(s) + {} + array(const array & rhs) : + m_t(rhs.m_t), + m_element_count(rhs.m_element_count) + {} + array & operator=(const array & rhs){ + m_t = rhs.m_t; + m_element_count = rhs.m_element_count; + } + + // default implementation + template<class Archive> + void serialize_optimized(Archive &ar, const unsigned int, mpl::false_ ) const + { + // default implemention does the loop + std::size_t c = count(); + value_type * t = address(); + while(0 < c--) + ar & boost::serialization::make_nvp("item", *t++); + } + + // optimized implementation + template<class Archive> + void serialize_optimized(Archive &ar, const unsigned int version, mpl::true_ ) + { + boost::serialization::split_member(ar, *this, version); + } + + // default implementation + template<class Archive> + void save(Archive &ar, const unsigned int version) const + { + ar.save_array(*this,version); + } + + // default implementation + template<class Archive> + void load(Archive &ar, const unsigned int version) + { + ar.load_array(*this,version); + } + + // default implementation + template<class Archive> + void serialize(Archive &ar, const unsigned int version) + { + typedef BOOST_DEDUCED_TYPENAME + boost::serialization::use_array_optimization<Archive>::template apply< + BOOST_DEDUCED_TYPENAME remove_const< T >::type + >::type use_optimized; + serialize_optimized(ar,version,use_optimized()); + } + + value_type* address() const + { + return m_t; + } + + std::size_t count() const + { + return m_element_count; + } + +private: + value_type* m_t; + std::size_t m_element_count; +}; + +template<class T> +inline +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING +const +#endif +array< T > make_array( T* t, std::size_t s){ + return array< T >(t, s); +} + +template <class Archive, class T, std::size_t N> +void serialize(Archive& ar, boost::array<T,N>& a, const unsigned int /* version */) +{ + ar & boost::serialization::make_nvp("elems",a.elems); +} + +} } // end namespace boost::serialization + +#ifdef __BORLANDC__ +// ignore optimizations for Borland +#define BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(Archive) +#else +#define BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(Archive) \ +namespace boost { namespace serialization { \ +template <> struct use_array_optimization<Archive> { \ + template <class ValueType> \ + struct apply : boost::mpl::apply1<Archive::use_array_optimization \ + , BOOST_DEDUCED_TYPENAME boost::remove_const<ValueType>::type \ + >::type {}; \ +}; }} +#endif // __BORLANDC__ + +#endif //BOOST_SERIALIZATION_ARRAY_HPP |