diff --git a/CMake/CMakeLists.txt b/CMake/CMakeLists.txt index d119f6f3..ddd016dd 100644 --- a/CMake/CMakeLists.txt +++ b/CMake/CMakeLists.txt @@ -342,12 +342,18 @@ archive_test(test_set_boost_unordered A) if(COMPILER_SUPPORTS_CXX11) archive_test(test_set_unordered A) else() - archive_test(test_set_hashed A) + CHECK_INCLUDE_FILE_CXX(hash_set HASH_SET_FOUND) + if(HASH_SET_FOUND) + archive_test(test_set_hashed A) + endif() endif() if(COMPILER_SUPPORTS_CXX11) archive_test(test_map_unordered A) else() - archive_test(test_map_hashed A) + CHECK_INCLUDE_FILE_CXX(hash_map HASH_MAP_FOUND) + if(HASH_MAP_FOUND) + archive_test(test_map_hashed A) + endif() endif() polymorphic_archive_test(test_polymorphic test_polymorphic_A A) diff --git a/include/boost/archive/basic_binary_iprimitive.hpp b/include/boost/archive/basic_binary_iprimitive.hpp index 40f45d9c..665d3e81 100644 --- a/include/boost/archive/basic_binary_iprimitive.hpp +++ b/include/boost/archive/basic_binary_iprimitive.hpp @@ -50,7 +50,7 @@ namespace std{ //#include #include -#include +#include #include #include diff --git a/include/boost/archive/basic_binary_oprimitive.hpp b/include/boost/archive/basic_binary_oprimitive.hpp index 4b7f454b..6dc770c6 100644 --- a/include/boost/archive/basic_binary_oprimitive.hpp +++ b/include/boost/archive/basic_binary_oprimitive.hpp @@ -45,7 +45,7 @@ namespace std{ //#include #include -#include +#include #include #include diff --git a/include/boost/archive/detail/iserializer.hpp b/include/boost/archive/detail/iserializer.hpp index d7420dd7..6e02eec7 100644 --- a/include/boost/archive/detail/iserializer.hpp +++ b/include/boost/archive/detail/iserializer.hpp @@ -77,10 +77,10 @@ namespace std{ #include #include #include -#include #include #include #include +#include // the following is need only for dynamic cast of polymorphic pointers #include diff --git a/include/boost/archive/detail/oserializer.hpp b/include/boost/archive/detail/oserializer.hpp index f5a9af87..c120ec55 100644 --- a/include/boost/archive/detail/oserializer.hpp +++ b/include/boost/archive/detail/oserializer.hpp @@ -56,8 +56,9 @@ #include #include #include -#include #include +#include + #include #include diff --git a/include/boost/serialization/array.hpp b/include/boost/serialization/array.hpp index f021f2ea..cf47ff2b 100644 --- a/include/boost/serialization/array.hpp +++ b/include/boost/serialization/array.hpp @@ -16,117 +16,11 @@ namespace std{ } // namespace std #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace boost { namespace serialization { - -// traits to specify whether to use an optimized array serialization - -template -struct use_array_optimization : boost::mpl::always {}; - -template -class array_wrapper : - public wrapper_traits > -{ -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 - friend const boost::serialization::array_wrapper 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 - 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 - void serialize_optimized(Archive &ar, const unsigned int version, mpl::true_ ) - { - boost::serialization::split_member(ar, *this, version); - } - - // default implementation - template - void save(Archive &ar, const unsigned int version) const - { - ar.save_array(*this,version); - } - - // default implementation - template - void load(Archive &ar, const unsigned int version) - { - ar.load_array(*this,version); - } - - // default implementation - template - void serialize(Archive &ar, const unsigned int version) - { - typedef typename - boost::serialization::use_array_optimization::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 -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 +#include + namespace boost { namespace serialization { -// implement serialization for std::array + template void serialize(Archive& ar, std::array& a, const unsigned int /* version */) { @@ -137,27 +31,6 @@ void serialize(Archive& ar, std::array& a, const unsigned int /* version */ } } } // end namespace boost::serialization -#endif -#include - -namespace boost { namespace serialization { -// implement serialization for boost::array -template -void serialize(Archive& ar, boost::array& 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 { \ - template \ - struct apply : boost::mpl::apply1::type \ - >::type {}; \ -}; }} #endif //BOOST_SERIALIZATION_ARRAY_HPP diff --git a/include/boost/serialization/array_optimization.hpp b/include/boost/serialization/array_optimization.hpp new file mode 100644 index 00000000..40dffba8 --- /dev/null +++ b/include/boost/serialization/array_optimization.hpp @@ -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 // msvc 6.0 needs this for warning suppression + +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::size_t; +} // namespace std +#endif + +#include +#include +#include + +namespace boost { namespace serialization { + +template +struct use_array_optimization : boost::mpl::always {}; + +} } // end namespace boost::serialization + +#define BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(Archive) \ +namespace boost { namespace serialization { \ +template <> struct use_array_optimization { \ + template \ + struct apply : boost::mpl::apply1::type \ + >::type {}; \ +}; }} + +#endif //BOOST_SERIALIZATION_ARRAY_OPTIMIZATON_HPP diff --git a/include/boost/serialization/array_wrapper.hpp b/include/boost/serialization/array_wrapper.hpp new file mode 100644 index 00000000..adf436e1 --- /dev/null +++ b/include/boost/serialization/array_wrapper.hpp @@ -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 + +#include // msvc 6.0 needs this for warning suppression + +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::size_t; +} // namespace std +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost { namespace serialization { + +template +class array_wrapper : + public wrapper_traits > +{ +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 + friend const boost::serialization::array_wrapper 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 + 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 + void serialize_optimized(Archive &ar, const unsigned int version, mpl::true_ ) + { + boost::serialization::split_member(ar, *this, version); + } + + // default implementation + template + void save(Archive &ar, const unsigned int version) const + { + ar.save_array(*this,version); + } + + // default implementation + template + void load(Archive &ar, const unsigned int version) + { + ar.load_array(*this,version); + } + + // default implementation + template + void serialize(Archive &ar, const unsigned int version) + { + typedef typename + boost::serialization::use_array_optimization::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 +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 diff --git a/include/boost/serialization/boost_array.hpp b/include/boost/serialization/boost_array.hpp new file mode 100644 index 00000000..d564ff15 --- /dev/null +++ b/include/boost/serialization/boost_array.hpp @@ -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 + +#include // msvc 6.0 needs this for warning suppression + +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::size_t; +} // namespace std +#endif + +#include +#include + +namespace boost { namespace serialization { +// implement serialization for boost::array +template +void serialize(Archive& ar, boost::array& a, const unsigned int /* version */) +{ + ar & boost::serialization::make_nvp("elems", a.elems); +} + +} } // end namespace boost::serialization + + +#endif //BOOST_SERIALIZATION_ARRAY_HPP diff --git a/include/boost/serialization/valarray.hpp b/include/boost/serialization/valarray.hpp index b5465100..a52d92e8 100644 --- a/include/boost/serialization/valarray.hpp +++ b/include/boost/serialization/valarray.hpp @@ -19,8 +19,8 @@ #include #include #include -#include #include +#include #include // function specializations must be defined in the appropriate diff --git a/include/boost/serialization/vector.hpp b/include/boost/serialization/vector.hpp index 7871a235..61257343 100644 --- a/include/boost/serialization/vector.hpp +++ b/include/boost/serialization/vector.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 31b385ff..8608e3bc 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -84,6 +84,7 @@ test-suite "serialization" : [ test-bsl-run_files test_list : A ] [ test-bsl-run_files test_list_ptrs : A ] [ test-bsl-run_files test_map : A ] + [ test-bsl-run_files test_map_hashed : A : : [ requires hash ] ] # BOOST_HAS_HASH [ test-bsl-run_files test_map_unordered : A : : [ requires cxx11_hdr_unordered_map ] ] # BOOST_NO_CXX11_HDR_UNORDERED_MAP [ test-bsl-run_files test_map_boost_unordered : A ] [ test-bsl-run_files test_mi ] diff --git a/test/test_boost_array.cpp b/test/test_boost_array.cpp index 6f8a8126..b691de8b 100644 --- a/test/test_boost_array.cpp +++ b/test/test_boost_array.cpp @@ -23,7 +23,7 @@ namespace std{ #include "test_tools.hpp" #include #include -#include +#include #include "A.hpp" #include "A.ipp" diff --git a/test/test_native_array.cpp b/test/test_native_array.cpp index 4bf3c874..49b9e6d2 100644 --- a/test/test_native_array.cpp +++ b/test/test_native_array.cpp @@ -23,7 +23,6 @@ namespace std{ #include "test_tools.hpp" #include #include -#include #include "A.hpp" #include "A.ipp" diff --git a/test/test_slist.cpp b/test/test_slist.cpp new file mode 100644 index 00000000..3cac92e2 --- /dev/null +++ b/test/test_slist.cpp @@ -0,0 +1,55 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_list.cpp + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// 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) + +// should pass compilation and execution + +#include // NULL +#include + +#include +#include // remove +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +#include +#include "test_tools.hpp" + +#include "A.hpp" +#include "A.ipp" + +#include +void test_slist(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_STD_EXTENSION_NAMESPACE::slist aslist; + aslist.push_front(A()); + aslist.push_front(A()); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("aslist", aslist); + } + BOOST_STD_EXTENSION_NAMESPACE::slist aslist1;{ + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("aslist", aslist1); + } + BOOST_CHECK(aslist == aslist1); + std::remove(testfile); +} + +int test_main( int /* argc */, char* /* argv */[] ) +{ + test_slist(); + return EXIT_SUCCESS; +} + +// EOF + diff --git a/test/test_slist_ptrs.cpp b/test/test_slist_ptrs.cpp new file mode 100644 index 00000000..aa038e0a --- /dev/null +++ b/test/test_slist_ptrs.cpp @@ -0,0 +1,88 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_list.cpp + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// 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) + +// should pass compilation and execution + +#include +#include + +#include +#include // remove +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +#include +#include +#include + +#include +#include "test_tools.hpp" + +#include + +#include "A.hpp" +#include "A.ipp" + +template +struct ptr_equal_to { + BOOST_STATIC_ASSERT(::boost::is_pointer< T >::value); + bool operator()(T const _Left, T const _Right) const + { + if(NULL == _Left && NULL == _Right) + return true; + if(typeid(*_Left) != typeid(*_Right)) + return false; + return *_Left == *_Right; + } +}; + +#include +void test_slist(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + std::list aslist; + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + aslist.push_back(new A); + aslist.push_back(new A); + oa << boost::serialization::make_nvp("aslist", aslist); + } + std::list aslist1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("aslist", aslist1); + BOOST_CHECK(aslist.size() == aslist1.size() && + std::equal(aslist.begin(),aslist.end(),aslist1.begin(),ptr_equal_to()) + ); + } + std::for_each( + aslist.begin(), + aslist.end(), + boost::checked_deleter() + ); + std::for_each( + aslist1.begin(), + aslist1.end(), + boost::checked_deleter() + ); + std::remove(testfile); +} + +int test_main( int /* argc */, char* /* argv */[] ) +{ + test_slist(); + return EXIT_SUCCESS; +} + +// EOF