refactor various tests related to arrays and lists

This commit is contained in:
Robert Ramey
2016-11-14 23:39:14 -08:00
parent ec74c5a143
commit 6b33d1cd4e
16 changed files with 354 additions and 140 deletions

View File

@@ -50,7 +50,7 @@ namespace std{
//#include <boost/mpl/placeholders.hpp>
#include <boost/serialization/is_bitwise_serializable.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/array_wrapper.hpp>
#include <boost/archive/basic_streambuf_locale_saver.hpp>
#include <boost/archive/codecvt_null.hpp>

View File

@@ -45,7 +45,7 @@ namespace std{
//#include <boost/mpl/placeholders.hpp>
#include <boost/serialization/is_bitwise_serializable.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/array_wrapper.hpp>
#include <boost/archive/basic_streambuf_locale_saver.hpp>
#include <boost/archive/codecvt_null.hpp>

View File

@@ -77,10 +77,10 @@ namespace std{
#include <boost/serialization/type_info_implementation.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/void_cast.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/collection_size_type.hpp>
#include <boost/serialization/singleton.hpp>
#include <boost/serialization/wrapper.hpp>
#include <boost/serialization/array_wrapper.hpp>
// the following is need only for dynamic cast of polymorphic pointers
#include <boost/archive/archive_exception.hpp>

View File

@@ -56,8 +56,9 @@
#include <boost/serialization/type_info_implementation.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/void_cast.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/collection_size_type.hpp>
#include <boost/serialization/array_wrapper.hpp>
#include <boost/serialization/singleton.hpp>
#include <boost/archive/archive_exception.hpp>

View File

@@ -16,117 +16,11 @@ namespace std{
} // namespace std
#endif
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/wrapper.hpp>
#include <boost/serialization/collection_size_type.hpp>
#include <boost/mpl/always.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/bool_fwd.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/static_assert.hpp>
namespace boost { namespace serialization {
// traits to specify whether to use an optimized array serialization
template <class Archive>
struct use_array_optimization : boost::mpl::always<boost::mpl::false_> {};
template<class T>
class array_wrapper :
public wrapper_traits<const array_wrapper< T > >
{
private:
array_wrapper & operator=(const array_wrapper & rhs);
// note: I would like to make the copy constructor private but this breaks
// make_array. So I make make_array a friend
template<class Tx, class S>
friend const boost::serialization::array_wrapper<Tx> make_array(Tx * t, S s);
public:
array_wrapper(const array_wrapper & rhs) :
m_t(rhs.m_t),
m_element_count(rhs.m_element_count)
{}
public:
array_wrapper(T * t, std::size_t s) :
m_t(t),
m_element_count(s)
{}
// 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();
T * 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 typename
boost::serialization::use_array_optimization<Archive>::template apply<
typename remove_const< T >::type
>::type use_optimized;
serialize_optimized(ar,version,use_optimized());
}
T * address() const
{
return m_t;
}
std::size_t count() const
{
return m_element_count;
}
private:
T * const m_t;
const std::size_t m_element_count;
};
template<class T, class S>
inline
const array_wrapper< T > make_array(T* t, S s){
const array_wrapper< T > a(t, s);
return a;
}
} } // end namespace boost::serialization
#ifndef BOOST_NO_CXX11_HDR_ARRAY
#include <array>
#include <boost/serialization/nvp.hpp>
namespace boost { namespace serialization {
// implement serialization for std::array
template <class Archive, class T, std::size_t N>
void serialize(Archive& ar, std::array<T,N>& a, const unsigned int /* version */)
{
@@ -137,27 +31,6 @@ void serialize(Archive& ar, std::array<T,N>& a, const unsigned int /* version */
}
} } // end namespace boost::serialization
#endif
#include <boost/array.hpp>
namespace boost { namespace serialization {
// implement serialization for boost::array
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
#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 \
, typename boost::remove_const<ValueType>::type \
>::type {}; \
}; }}
#endif //BOOST_SERIALIZATION_ARRAY_HPP

View File

@@ -0,0 +1,37 @@
#ifndef BOOST_SERIALIZATION_ARRAY_OPTIMIZATON_HPP
#define BOOST_SERIALIZATION_ARRAY_OPTIMIZATON_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 <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/mpl/always.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/type_traits/remove_const.hpp>
namespace boost { namespace serialization {
template <class Archive>
struct use_array_optimization : boost::mpl::always<boost::mpl::false_> {};
} } // end namespace boost::serialization
#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 \
, typename boost::remove_const<ValueType>::type \
>::type {}; \
}; }}
#endif //BOOST_SERIALIZATION_ARRAY_OPTIMIZATON_HPP

View File

@@ -0,0 +1,121 @@
#ifndef BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP
#define BOOST_SERIALIZATION_ARRAY_WRAPPER_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 <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/serialization/collection_size_type.hpp>
#include <boost/serialization/array_optimization.hpp>
#include <boost/mpl/always.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/bool_fwd.hpp>
#include <boost/type_traits/remove_const.hpp>
namespace boost { namespace serialization {
template<class T>
class array_wrapper :
public wrapper_traits<const array_wrapper< T > >
{
private:
array_wrapper & operator=(const array_wrapper & rhs);
// note: I would like to make the copy constructor private but this breaks
// make_array. So I make make_array a friend
template<class Tx, class S>
friend const boost::serialization::array_wrapper<Tx> make_array(Tx * t, S s);
public:
array_wrapper(const array_wrapper & rhs) :
m_t(rhs.m_t),
m_element_count(rhs.m_element_count)
{}
public:
array_wrapper(T * t, std::size_t s) :
m_t(t),
m_element_count(s)
{}
// 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();
T * 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 typename
boost::serialization::use_array_optimization<Archive>::template apply<
typename remove_const< T >::type
>::type use_optimized;
serialize_optimized(ar,version,use_optimized());
}
T * address() const
{
return m_t;
}
std::size_t count() const
{
return m_element_count;
}
private:
T * const m_t;
const std::size_t m_element_count;
};
template<class T, class S>
inline
const array_wrapper< T > make_array(T* t, S s){
const array_wrapper< T > a(t, s);
return a;
}
} } // end namespace boost::serialization
#endif //BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP

View File

@@ -0,0 +1,33 @@
#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 <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/array.hpp>
namespace boost { namespace serialization {
// implement serialization for boost::array
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
#endif //BOOST_SERIALIZATION_ARRAY_HPP

View File

@@ -19,8 +19,8 @@
#include <valarray>
#include <boost/config.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/collection_size_type.hpp>
#include <boost/serialization/array_wrapper.hpp>
#include <boost/serialization/detail/get_data.hpp>
// function specializations must be defined in the appropriate

View File

@@ -31,7 +31,7 @@
#include <boost/serialization/collections_save_imp.hpp>
#include <boost/serialization/collections_load_imp.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/array_wrapper.hpp>
#include <boost/serialization/detail/get_data.hpp>
#include <boost/mpl/bool_fwd.hpp>
#include <boost/mpl/if.hpp>