diff options
Diffstat (limited to 'libs/serialization')
104 files changed, 2659 insertions, 1356 deletions
diff --git a/libs/serialization/CMake/CMakeLists.txt b/libs/serialization/CMake/CMakeLists.txt index 3a252dde0f..4fb1a41114 100644 --- a/libs/serialization/CMake/CMakeLists.txt +++ b/libs/serialization/CMake/CMakeLists.txt @@ -2,6 +2,13 @@ cmake_minimum_required(VERSION 3.0) +if (POLICY CMP0054) + cmake_policy (SET CMP0054 NEW) +endif (POLICY CMP0054) + +if (POLICY CMP0063) + cmake_policy (SET CMP0063 NEW) +endif (POLICY CMP0063) if(Boost_USE_STATIC_LIBS) project("Serialization-Static") @@ -20,9 +27,11 @@ if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" ) # we use gcc to test for C++03 compatibility add_definitions( std=c++03 ) message(STATUS "compiler is g++ c++03") + set(COMPILER_SUPPORTS_CXX11 FALSE) elseif( CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" ) add_definitions( /wd4996 ) message(STATUS "compiler is MSVC") + set(COMPILER_SUPPORTS_CXX11 TRUE) elseif( CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=300") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98") @@ -30,6 +39,7 @@ elseif( CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" ) set(CMAKE_CXX_FLAGS_DEBUG "-g -O0" ) set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3" ) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -dead_strip") + set(COMPILER_SUPPORTS_CXX11 TRUE) endif() # @@ -111,15 +121,22 @@ elseif() endif() if(Boost_USE_STATIC_LIBS) - set(BUILD_SHARED_LIBRARIES OFF) + message(STATUS "Building static libraries") + set(LINK_TYPE "STATIC") else() - set(BUILD_SHARED_LIBRARIES ON) + message(STATUS "Building shared libraries") + set(LINK_TYPE "SHARED") + add_definitions( "-DBOOST_ALL_DYN_LINK=1") + add_definitions( "-DBOOST_ALL_NO_LIB=1") + add_definitions( "-DBOOST_LIB_DIAGNOSTICS=1") endif() +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(VISIBILITY_INLINES_HIDDEN) ########################### # library builds -add_library(serialization +add_library(serialization ${LINK_TYPE} ../src/archive_exception.cpp ../src/basic_archive.cpp ../src/basic_iarchive.cpp @@ -134,38 +151,40 @@ add_library(serialization ../src/basic_xml_archive.cpp ../src/binary_iarchive.cpp ../src/binary_oarchive.cpp - ../src/codecvt_null.cpp ../src/extended_type_info_no_rtti.cpp ../src/extended_type_info_typeid.cpp ../src/extended_type_info.cpp ../src/polymorphic_iarchive.cpp ../src/polymorphic_oarchive.cpp + ../src/singleton.cpp ../src/stl_port.cpp ../src/text_iarchive.cpp ../src/text_oarchive.cpp - ../src/text_wiarchive.cpp - ../src/text_woarchive.cpp - ../src/utf8_codecvt_facet.cpp ../src/void_cast.cpp ../src/xml_archive_exception.cpp ../src/xml_iarchive.cpp ../src/xml_oarchive.cpp ../src/xml_grammar.cpp - # ../src/basic_xml_grammar.ipp # doesn't show up in "Source Files" in Xcode"' + ../src/utf8_codecvt_facet.cpp + ../src/basic_xml_grammar.ipp # doesn't show up in "Source Files" in Xcode"' ) -add_library(wserialization +# target_compile_options(serialization PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden ) + +add_library(wserialization ${LINK_TYPE} + ../src/codecvt_null.cpp ../src/basic_text_wiprimitive.cpp ../src/basic_text_woprimitive.cpp ../src/text_wiarchive.cpp ../src/text_woarchive.cpp - ../src/utf8_codecvt_facet.cpp ../src/xml_wiarchive.cpp ../src/xml_woarchive.cpp - ../src/codecvt_null.cpp ../src/xml_wgrammar.cpp + ../src/basic_xml_grammar.ipp # doesn't show up in "Source Files" in Xcode"' ) +#target_compile_options(wserialization PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden ) + # end library build ########################### @@ -242,10 +261,14 @@ serialization_test(test_iterators) serialization_test(test_iterators_base64) serialization_test(test_inclusion) serialization_test(test_smart_cast) -serialization_test(test_utf8_codecvt ../src/utf8_codecvt_facet) +serialization_test(test_utf8_codecvt ) serialization_test(test_codecvt_null ../src/codecvt_null) -archive_test(test_array A) +archive_test(test_native_array A) +archive_test(test_boost_array A) +if(COMPILER_SUPPORTS_CXX11) + archive_test(test_array A) +endif() archive_test(test_binary) archive_test(test_bitset) archive_test(test_class_info_save) @@ -260,11 +283,14 @@ archive_test(test_derived_class A) archive_test(test_diamond) archive_test(test_diamond_complex) archive_test(test_exported polymorphic_base) +archive_test(test_forward_list A) +archive_test(test_forward_list_ptrs A) archive_test(test_helper_support) archive_test(test_interrupts) archive_test(test_list A) archive_test(test_list_ptrs A) archive_test(test_map A) +archive_test(test_map_boost_unordered A) archive_test(test_mi) archive_test(test_multiple_ptrs A) archive_test(test_multiple_inheritance) @@ -279,11 +305,11 @@ archive_test(test_object) archive_test(test_optional) archive_test(test_primitive) archive_test(test_priority_queue A) -# archive_test(test_private_base) +archive_test(test_private_base) +archive_test(test_private_base2) archive_test(test_queue A) archive_test(test_recursion A) archive_test(test_registered) -archive_test(test_set A) archive_test(test_shared_ptr) archive_test(test_shared_ptr_multi_base) archive_test(test_shared_ptr_132) @@ -297,9 +323,22 @@ archive_test(test_unique_ptr) archive_test(test_valarray) archive_test(test_variant A) archive_test(test_vector A) +archive_test(test_set A) +archive_test(test_set_boost_unordered A) +if(COMPILER_SUPPORTS_CXX11) + archive_test(test_set_unordered A) +elseif() + archive_test(test_set_hashed A) +endif() +if(COMPILER_SUPPORTS_CXX11) + archive_test(test_map_unordered A) +elseif() + archive_test(test_map_hashed A) +endif() -polymorphic_archive_test(test_polymorphic test_polymorphic_A A ) +polymorphic_archive_test(test_polymorphic test_polymorphic_A A) polymorphic_archive_test(test_polymorphic2 test_polymorphic2imp) +polymorphic_archive_test(test_polymorphic_helper) # end test targets #################### @@ -357,8 +396,7 @@ file(GLOB x RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/*_w*.hpp" ) - -add_custom_target(wserialization_headers SOURCES ${x} "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/codecvt_null.hpp") +add_custom_target(wserialization_headers SOURCES ${x}) set_property(TARGET wserialization_headers PROPERTY FOLDER "wserialization") # end headers in IDE diff --git a/libs/serialization/build/Jamfile.v2 b/libs/serialization/build/Jamfile.v2 index e3950a4c51..8fd92e6480 100644 --- a/libs/serialization/build/Jamfile.v2 +++ b/libs/serialization/build/Jamfile.v2 @@ -80,6 +80,9 @@ SOURCES = xml_iarchive xml_oarchive xml_archive_exception + codecvt_null + utf8_codecvt_facet + singleton ; WSOURCES = @@ -87,19 +90,22 @@ WSOURCES = basic_text_woprimitive text_wiarchive text_woarchive - utf8_codecvt_facet xml_wgrammar xml_wiarchive xml_woarchive - codecvt_null ; - lib boost_serialization : $(SOURCES).cpp : <toolset>msvc:<cxxflags>/Gy - #<toolset>gcc:<cxxflags>"-fvisibility=hidden" + <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS + <toolset>clang:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden" + <toolset>gcc:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden" + <toolset>darwin:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden" + <toolset>gcc:<cxxflags>"-ftemplate-depth-255" + <toolset>clang:<cxxflags>"-ftemplate-depth-255" + <toolset>darwin:<cxxflags>"-ftemplate-depth-255" <link>shared:<define>BOOST_SERIALIZATION_DYN_LINK=1 ; @@ -107,7 +113,13 @@ lib boost_wserialization : $(WSOURCES).cpp boost_serialization : <toolset>msvc:<cxxflags>/Gy - #<toolset>gcc:<cxxflags>"-fvisibility=hidden" + <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS + <toolset>clang:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden" + <toolset>gcc:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden" + <toolset>darwin:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden" + <toolset>gcc:<cxxflags>"-ftemplate-depth-255" + <toolset>clang:<cxxflags>"-ftemplate-depth-255" + <toolset>darwin:<cxxflags>"-ftemplate-depth-255" <link>shared:<define>BOOST_SERIALIZATION_DYN_LINK=1 ; diff --git a/libs/serialization/doc/contents.html b/libs/serialization/doc/contents.html index 721abe0e8a..f5308ad7ad 100644 --- a/libs/serialization/doc/contents.html +++ b/libs/serialization/doc/contents.html @@ -269,6 +269,7 @@ function initialize() { <dt><img style="display:none" src="dot.gif"><a target="detail" href="shared_ptr.html">Template serialization - <code>shared_ptr<class T></code></a> <dt><img style="display:none" src="dot.gif"><a target="detail" href="shared_ptr2.html"><code>shared_ptr<class T></code>Revisited</a> <dt><img style="display:none" src="dot.gif"><a target="detail" href="pimpl.html">PIMPL</a> + <dt><img style="display:none" src="dot.gif"><a target="detail" href="private_base.html">Private Base Classes</a> <dt><img style="display:none" src="dot.gif"><a target="detail" href="simple_log.html">A Simple Logging Archive Class</a> <dt><img style="display:none" src="dot.gif"><a target="detail" href="derivation.html">Derivation from an Existing Archive Class</a> </dl></div></dd> diff --git a/libs/serialization/doc/implementation.html b/libs/serialization/doc/implementation.html index 839bc45cc4..08e9974b03 100644 --- a/libs/serialization/doc/implementation.html +++ b/libs/serialization/doc/implementation.html @@ -26,20 +26,13 @@ http://www.boost.org/LICENSE_1_0.txt) </table> <hr> <dl class="page-index"> - <dt><a href="#functiontemplateordering">Partial Function Template Ordering</a> <dt><a href="#charencoding">Character Encoding</a> - <dt><a href="#tempatesyntax">Template Invocation syntax</a> - <dt><a href="#partialtemplatespecialization">Partial Template Specialization</a> <dt><a href="#othercompilerissues">Specific Compiler/Library Issues</a> <dl class="page-index"> - <dt><a href="#gcc3x">GCC 3.X, 4.X</a> - <dt><a href="#gcc295">GCC 2.95</a> + <dt><a href="#gcc4x">44.X</a> <dt><a href="#intel80">Intel 8.0</a> <dt><a href="#vc80">Visual C++ 8.0</a> <dt><a href="#vc71">Visual C++ 7.1</a> - <dt><a href="#vc70">Visual C++ 7.0</a> - <dt><a href="#vc6">Visual C++ 6.0</a> - <dt><a href="#borland">Borland 5.64 and 5.51</a> <dt><a href="#comeau">Comeau 4.3.3</a> <dt><a href="#codewarrior9">Code Warrior 9.x</a> <dt><a href="#codewarrior">Code Warrior 8.3</a> @@ -49,81 +42,6 @@ http://www.boost.org/LICENSE_1_0.txt) </dl> </dl> -<h3><a name="functiontemplateordering">Partial Function Template Ordering</a></h3> -Not all C++ compilers correctly support partial function template ordering (PFTO). -For these compilers, the following code will fail to compile: -<pre><code> -template<class Archive, class T> -void serialize( - Archive & ar, - T & t, - const unsigned int file_version -){ - ... -} - -template<class Archive, class T> -void serialize( - Archive & ar, - my_template<T> & t, - const unsigned int file_version -){ - ... -} -</pre></code> -The serialization library works around this issue by using a different -default definition of the first template: -<pre><code> -template<class Archive, class T> -void serialize( - Archive & ar, - T & t, - const unsigned long int file_version // Note: change to long -){ - ... -} -</pre></code> -Now, the second template is not matched with the first one so there -is no PFTO and no compile error. When the serialization library invokes -<pre><code> -serialize(ar, t, 0); -</pre></code> -the function declaration is first matched against templates with -an integer for the third argument. If there is a match, the matching -template is instantiated and later invoked. If there is no match, -an attempt is made to match other templates by converting arguments to other types. -In this case the third argument can be converted to long to match -the first template - which is the default. So in this case, the first -template will be instantiated and later invoked. We have managed to -use function overloading to achieve the same effect as PFTO -were it correctly implemented. -<p> -This depends upon undefined behavior of a compiler already -determined to be non-conforming. In other words, there is no -guarantee that this will work on all compilers. If a compiler does not -correctly support PFTO and this method cannot be used to workaround -it, non-intrusive serialization cannot be supported for that compiler. -As of this writing, such a compiler has not been encountered. -<p> -It turns out that using this "trick" can create problems with -compilers that DO correctly support PFTO. For this reason we -define a macro <code style="white-space: normal">BOOST_PTFO</code> which -is defined to be <code style="white-space: normal">long</code> -for non-conforming compilers and nothing for conforming ones. So -the default definition is really: -The serialization library works around this issue by using a different -default definition of the first template: -<pre><code> -template<class Archive, class T> -void serialize( - Archive & ar, - T & t, - const unsigned BOOST_PFTO int file_version // Note: change to BOOST_PFTO -){ - ... -} -</pre></code> - <h3><a name="charencoding">Character Encoding</a></h3> The whole question of character encoding combined with wide characters is much more complicated than it would seem to be. The current library @@ -175,31 +93,8 @@ do the following. <li>Create the archive with the flag <code style="white-space: normal">no_codecvt</code>. </ul> Naturally, the input process has to be symmetrical. -<h3><a name="partialtemplatespecialization">Partial Template Specialization</a></h3> -Compilers which fail to support partial template specialization will fail to compile -the following code. To make this compile, the <code style="white-space: normal">const</code> has to be removed. -<pre><code> -void f(A const* a, text_oarchive& oa) -{ - oa << a; -} -</code></pre> -<h3><a name="tempatesyntax">Template Invocation syntax</a></h3> -Some compilers may not recognize the syntax: -<pre><code> -ar.template register_type<T>(); -</code></pre> -for "registering" derived pointers of polymorphic classes. The actual -function prototype is: -<pre><code> -template<T> -void register_type(T * t = NULL); -</code></pre> -so that one may write <code style="white-space: normal">ar.register_type(static_cast<T *>(NULL))</code> instead of -the syntax described above. -</ul> <h3><a name="othercompilerissues">Specific Compiler/Library Issues</a></h3> -<h4><a name="gcc3x">GCC 3.X, 4.X</a></h4> +<h4><a name="gcc4x">GCC 4.X</a></h4> <ul> <li>GCC versions for Cygwin and MinGW fail to support wide character I/O. So all tests using wide char I/O fail. Note that if wide character I/O support @@ -219,17 +114,6 @@ the syntax described above. -Wno-ctor-dtor-privacy </code></pre> </ul> -<h4><a name="gcc295">GCC 2.95</a></h4> -All of the above plus:<br> -<ul> - <li>The serialization library depends on the templated stream - implementation to function properly. - So STLPort must be used to build the library. - <li>Polymorphic archive tests fail. - <li>XML serialization only works with version 1.6x of spirit. In order to build - and use this library with this compiler, one must use version 1.6x rather than the - latest version shipped with boost. See <a href="release.html">Release Notes</a>. -</ul> <h4><a name="intel80">Intel C++ 8.0</a></h4> No known issues. All tests compile and run in debug and release modes. @@ -311,77 +195,6 @@ decide to use these configurations. in sync with those included here. </ul> -<h4><a name="vc70">Visual C++ 7.0</a></h4> -<ul> - <li>The "pimpl" demo fails to link. Cause and workaround for this is unknown - <li>XML serialization only works with version 1.6x of spirit. In order to build and use this - library with this compiler, one must use version 1.6x rather than the latest version - shipped with boost. See <a href="release.html">Release Notes</a>. - <li>This compiler does not support partial template specialization. - The implementation of the new <code>shared_ptr</code> serialization depends upon - compiler support for partial template specialization. This compiler doesn't implement this - feature. In order to serialize <code style="white-space: normal">shared_ptr<A></code>, - invoke the macro <code style="white-space: normal">BOOST_SERIALIZATION_SHARED_PTR(A)</code> - in the header code. - <li>Lack of support for partial template specialization also creates problems for - serialization of <code style="white-space: normal">std::map</code>. In order to serialize - instances of this type include the invocation of BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION - for the key type of the map. -</ul> -<h4><a name="vc6">Visual C++ 6.5</a></h4> -all the above issues for Visual C++ 7.0 plus: -<ul> - <li>Out of line template definitions are not recognized and fail with a confusing - error message. To function save/load/serialize member function templates must be defined - within the class definition. This feature is essential to <code style="white-space: normal">demo_pimpl</code>. Hence, - this program will fail to compile. In this case the problem can't be worked around and - still demonstrate this facility. - <li>This compiler does not support <code style="white-space: normal">wchar_t</code> as a separate type. It defines - <code style="white-space: normal">wchar_t</code> as an alias for <code style="white-space: normal">short int</code>. In general things will still - function. However certain customizations, such as overloading archive operators for - saving/loading wide character arrays would produce surprises in this environment. - <li>Under certain circumstances, a program will fail to link with the message: - LIN1179 - "invalid or corrupt file: duplicate comdat". According - to <a href="http://groups.google.com/groups?th=8a05c82c4ffee280"> - http://groups.google.com/groups?th=8a05c82c4ffee280 - </a> (look for P78) - A LNK1179 error occurs when: - <ul> - <li>The template class takes at least two arguments. - <li>The template is used at least two times with identical first - and different second arguments. - <li>The static member variable is of an object type with at least one - base class. (In another scenario it also occurred using a member - without a base class.) - </ul> - Working around this in the implementation of the library for this compiler - entailed a ridiculous amount of effort. Even so, the effort wasn't entirely successful. - With this compiler, this message will still appear under the following conditions: - <ul> - <li>When serializing a class with multiple base classes. This problem causes two - failure in the test suite. I have been unable to devise a way to work around this. - <li>Using more than one kind of archive in the same code module. This should be easy - to work around in practice. - </ul> - <li>Code modules exceeding some undetermined size that use the library will fail with - <i>fatal error C1204: compiler limit : internal structure overflow</i>. This can be addressed - by dividing the module into smaller ones. -</ul> -<h4><a name="borland">Borland 5.64 and 5.51</a></h4> -<ul> - <li><code style="white-space: normal">enum</code> data members cannot be serialized. - Conversion to/from integers will work around the problem. - <li>If class serialize functions are not accessible either by making them public or by - including <code style="white-space: normal">friend</code> declarations as described in - <a href="serialization.html#member">Class Serialization - Member Function</a>, the code - will compile but fail at runtime. - <li>Tests using custom extended type which doesn't use RTTI fails. (5.64 only !). - <li>Tests built in release mode fail. This seems to be an issue with the boost test system - with this compiler. - <li>XML serialization only works with version 1.6x of spirit. In order to build - and use this library with this compiler, one must use version 1.6x rather than the - latest version shipped with boost. See <a href="release.html">Release Notes</a>. -</ul> <h4><a name="comeau">Comeau 4.3.3</a></h4> <ul> <li>This compiler fails to make a DLL with export under windows. @@ -434,7 +247,7 @@ These platforms have several issues: <hr> <p>Revised 1 November, 2004 -<p><i>© Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2002-2004. +<p><i>© Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2002-2015. 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) </i></p> diff --git a/libs/serialization/doc/private_base.html b/libs/serialization/doc/private_base.html new file mode 100644 index 0000000000..f41791dbe6 --- /dev/null +++ b/libs/serialization/doc/private_base.html @@ -0,0 +1,170 @@ +<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<!-- +(C) Copyright 2002-4 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) +--> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<link rel="stylesheet" type="text/css" href="../../../boost.css"> +<link rel="stylesheet" type="text/css" href="style.css"> +<title>Serialization - Private Base Classes</title> +</head> +<body link="#0000ff" vlink="#800080"> +<table border="0" cellpadding="7" cellspacing="0" width="100%" summary="header"> + <tr> + <td valign="top" width="300"> + <h3><a href="../../../index.htm"><img height="86" width="277" alt="C++ Boost" src="../../../boost.png" border="0"></a></h3> + </td> + <td valign="top"> + <h1 align="center">Serialization</h1> + <h2 align="center">Private Base Classes</h2> + </td> + </tr> +</table> +<hr> +In many cases, serialization of private or protected base classes present no special problems. +This is true for both simple classes and types as well as pointers to those +classes and types. That is, the following program compiles and runs exactly as one would expect. +<pre><code> +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_private_base.cpp + +// (C) Copyright 2009 Eric Moyer - 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) + +#include <fstream> +#include <boost/config.hpp> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +#include <boost/serialization/access.hpp> +#include <boost/serialization/base_object.hpp> +#include <boost/serialization/export.hpp> + +class Base { + friend class boost::serialization::access; + int m_i; + template<class Archive> + void serialize(Archive & ar, const unsigned int version){ + ar & BOOST_SERIALIZATION_NVP(m_i); + } +protected: + bool equals(const Base &rhs) const { + return m_i == rhs.m_i; + } + Base(int i = 0) : + m_i(i) + {} +}; + +class Derived : private Base { + friend class boost::serialization::access; +private: + Base & base_cast(){ + return static_cast<Base &>(*this); + } + template<class Archive> + void serialize(Archive & ar, const unsigned int version){ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base); + } +public: + bool operator==(const Derived &rhs) const { + return Base::equals(static_cast<const Base &>(rhs)); + } + Derived(int i = 0) : + Base(i) + {} +}; + +int +main( int /* argc */, char* /* argv */[] ) +{ + const char * testfile = boost::archive::tmpnam(NULL); + + // serialize Derived and Base + Derived a(1), a1(2); + { + test_ostream os(testfile); + test_oarchive oa(os); + oa << boost::serialization::make_nvp("a", a); + } + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("a", a1); + } + std::remove(testfile); + + if(a != a1) + return 1; + + // serialize Derived and Base + Derived *ta = &a; + Derived *ta1 = NULL; + { + test_ostream os(testfile); + test_oarchive oa(os); + oa << boost::serialization::make_nvp("ta", ta); + } + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("ta", ta1); + } + std::remove(testfile); + if(*ta != *ta1) + return 1; + + return 0; +} +</code></pre> +Difficulties start to occur when the base class is made polymorphic by the designation +of one or more functions as "virtual". If a class is polymorphic, the library +presumes that one will want the ability to serialize a derived class through +a pointer to the base class. Included in the macro +<code> +BOOST_SERIALIZATION_BASE_OBJECT_NVP +</code> +is code which links derived and base class definitions in tables used to serialize +derived classes through pointers to a polymorphinc base class. This code requires +the ability to invoke +<code> +static_cast<Base &>(Derived &) +</code> +which C++ will only permit from within the derived class if the base class is +private or protected. The program will fail to compile with an error message +indicating invalid cast. +<p> +In order for this +code compiler the following alteration must be made: +<pre><code> + template<class Archive> + void serialize(Archive & ar, const unsigned int version){ + //ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base); + ar & boost::serialization::make_nvp( + "Base", + static_cast<Base &>(*this) + ); + } +</code></pre> +With this change the program will now compile. +<p> +If we made one of the functions of <code>Base></code> <code>virtual</code> +in order to use the "export" functionality of the serialization library and permit serialization through +a pointer the the base class, we'll be disappointed. Without the ability to +cast to the base class, we can't use the functionality. +<hr> +<p><i>© Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2015. +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) +</i></p> +</body> +</html> diff --git a/libs/serialization/doc/release.html b/libs/serialization/doc/release.html index eb785438da..714752644a 100644 --- a/libs/serialization/doc/release.html +++ b/libs/serialization/doc/release.html @@ -29,6 +29,8 @@ http://www.boost.org/LICENSE_1_0.txt) </table> <hr> <dl class="index"> + <dt><a href="#differences_1_59">Differences from version 1.58</a></dt> + <dt><a href="#differences_1_58">Differences from version 1.48</a></dt> <dt><a href="#differences_1_45">Differences from version 1.45</a></dt> <dt><a href="#differences_1_43">Differences from version 1.43</a></dt> <dt><a href="#differences_1_42">Differences from version 1.42</a></dt> @@ -39,12 +41,28 @@ http://www.boost.org/LICENSE_1_0.txt) <dt><a href="#differences_1_35">Differences from version 1.35</a></dt> <dt><a href="#differences_1_34">Differences from version 1.34</a></dt> <dt><a href="#differences_1_33">Differences from version 1.33</a></dt> - <dt><a href="#differences_1_32">Differences from version 1.32</a></dt> + <dt><a href="#differences_1_32">Differences from version 1.32</a></dt> <dt><a href="#todo">Pending Issues</a></dt> </dl> As of this writing, there are no known bugs. However, due to compiler/library quirks and or bugs, some tests fail with some combinations of compilers and libraries. +<h2><a name="differences_1_59"></a>Differences from Boost 1.58</h2> +<ul> +<li>Eliminated support for Borland compilers and Microsoft compilers prior to version +7.1. +<li>Eliminated support for compilers which do not support Partial Function Template +Ordering (pfto). +<li>Added support for "visibility hidden" for GCC compilers. Shared libraries +will only expose symbols actually needed rather than all sympols in the library. This +should result in smaller shared libraries which are faster to load. +</ul> +<h2><a name="differences_1_58"></a>Differences from Boost 1.48</h2> +<ul> +<li>Added support for C++11 types such as std::shared_ptr, std::array, and others. +<li>Implemented the concept of a "Helper" which can be used to implement serialization of types which are otherwise not serializable." +<li>Made library compatible with C++11, Compatibility with C++03 has been maintained. +</ul> <h2><a name="differences_1_45"></a>Differences from Boost 1.45</h2> Since the release of version 1.42, it has been discovered that binary archives created by versions 1.42-1.44 cannot always be read by the diff --git a/libs/serialization/doc/serialization.html b/libs/serialization/doc/serialization.html index 3378c28861..8252930986 100644 --- a/libs/serialization/doc/serialization.html +++ b/libs/serialization/doc/serialization.html @@ -792,7 +792,7 @@ class derived : public base { ar & boost::serialization::base_object<base>(*this); // method 2 : explicitly register base/derived relationship boost::serialization::void_cast_register<derived, base>( - static_cast<derived *>=NULL), + static_cast<derived *>(NULL), static_cast<base *>(NULL) ) } diff --git a/libs/serialization/example/Jamfile.v2 b/libs/serialization/example/Jamfile.v2 index ab4d258d40..cce6ee65fc 100644 --- a/libs/serialization/example/Jamfile.v2 +++ b/libs/serialization/example/Jamfile.v2 @@ -11,47 +11,32 @@ project libs/serialization/example : requirements <library>../build//boost_serialization ; -rule demo_bsl_run ( demo-name : othersources * : requirements * ) -{ - return [ run - # sources - $(demo-name).cpp - $(othersources).cpp - : # command - : # input files - : # requirements - # toolset suppress-warnings - <toolset>gcc:<cxxflags>"-Wno-non-virtual-dtor -Wno-ctor-dtor-privacy" - <toolset>msvc-8.0:<cxxflags>"-wd4996" - <toolset>borland:<cxxflags>"-w-8080 -w-8071 -w-8057 -w-8062 -w-8008 -w-0018 -w-8066" - # toolset optimizations - <toolset>gcc:<cxxflags>"-ftemplate-depth-255" - <toolset>msvc:<cxxflags>"-Gy" - # toolset shared library support - <toolset>como,<runtime-link>shared:<build>no - <toolset>msvc,<stdlib>stlport,<runtime-link>shared:<build>no - <toolset>cw,<runtime-link>static:<build>no - $(requirements) - : # test name - $(demo-name) - ] - ; -} +import ../util/test : + run-template + run-invoke + run-winvoke + test-bsl-run-no-lib + test-bsl-run + test-bsl-run_archive + test-bsl-run_files + test-bsl-run_polymorphic_archive +; test-suite "demo-suite" : # demos - [ demo_bsl_run demo ] - [ demo_bsl_run demo_auto_ptr ] - [ demo_bsl_run demo_exception ] - [ demo_bsl_run demo_log : log_archive ] - [ demo_bsl_run demo_pimpl : demo_pimpl_A ] - [ demo_bsl_run demo_polymorphic : demo_polymorphic_A ] - [ demo_bsl_run demo_portable_archive : portable_binary_iarchive portable_binary_oarchive ] - [ demo_bsl_run demo_shared_ptr ] - [ demo_bsl_run demo_simple_log ] - [ demo_bsl_run demo_trivial_archive ] - [ demo_bsl_run demo_xml ] - [ demo_bsl_run demo_xml_save ] - [ demo_bsl_run demo_xml_load : : <dependency>demo_xml_save ] + [ test-bsl-run demo ] + [ test-bsl-run demo_auto_ptr ] + [ test-bsl-run demo_exception ] + [ test-bsl-run demo_fast_archive ] + [ test-bsl-run demo_log : log_archive ] + [ test-bsl-run demo_pimpl : demo_pimpl_A ] + [ test-bsl-run demo_polymorphic : demo_polymorphic_A ] + [ test-bsl-run demo_portable_archive : portable_binary_iarchive portable_binary_oarchive ] + [ test-bsl-run demo_shared_ptr ] + [ test-bsl-run demo_simple_log ] + [ test-bsl-run demo_trivial_archive ] + [ test-bsl-run demo_xml ] + [ test-bsl-run demo_xml_save ] + [ test-bsl-run demo_xml_load : : : <dependency>demo_xml_save ] ; diff --git a/libs/serialization/example/demo_fast_archive.cpp b/libs/serialization/example/demo_fast_archive.cpp index 0f28ef7baa..8e12fd3ce3 100644 --- a/libs/serialization/example/demo_fast_archive.cpp +++ b/libs/serialization/example/demo_fast_archive.cpp @@ -11,7 +11,6 @@ #include <boost/static_assert.hpp> #include <boost/type_traits/is_array.hpp> -#include <boost/serialization/pfto.hpp> #define BOOST_ARCHIVE_SOURCE #include <boost/archive/binary_oarchive_impl.hpp> @@ -61,26 +60,26 @@ public: // binary_oarchive_impl<derived_t>::load_override; // so we use the sure-fire method below. This failed to work as well template<class T> - void save_override(T & t, BOOST_PFTO int){ - base_t::save_override(t, 0); + void save_override(T & t){ + base_t::save_override(t); // verify that this program is in fact working by making sure // that arrays are getting passed here BOOST_STATIC_ASSERT(! (boost::is_array<T>::value) ); } template<int N> - void save_override(const int (& t)[N] , int){ + void save_override(const int (& t)[N]){ save_binary(t, sizeof(t)); } template<int N> - void save_override(const unsigned int (& t)[N], int){ + void save_override(const unsigned int (& t)[N]){ save_binary(t, sizeof(t)); } template<int N> - void save_override(const long (& t)[N], int){ + void save_override(const long (& t)[N]){ save_binary(t, sizeof(t)); } template<int N> - void save_override(const unsigned long (& t)[N], int){ + void save_override(const unsigned long (& t)[N]){ save_binary(t, sizeof(t)); } public: @@ -129,24 +128,24 @@ public: // binary_oarchive_impl<derived_t>::load_override; // so we use the sure-fire method below. This failed to work as well template<class T> - void load_override(T & t, BOOST_PFTO int){ - base_t::load_override(t, 0); + void load_override(T & t){ + base_t::load_override(t); BOOST_STATIC_ASSERT(! (boost::is_array<T>::value) ); } template<int N> - void load_override(int (& t)[N], int){ + void load_override(int (& t)[N]){ load_binary(t, sizeof(t)); } template<int N> - void load_override(unsigned int (& t)[N], int){ + void load_override(unsigned int (& t)[N]){ load_binary(t, sizeof(t)); } template<int N> - void load_override(long (& t)[N], int){ + void load_override(long (& t)[N]){ load_binary(t, sizeof(t)); } template<int N> - void load_override(unsigned long (& t)[N], int){ + void load_override(unsigned long (& t)[N]){ load_binary(t, sizeof(t)); } public: diff --git a/libs/serialization/example/demo_log.cpp b/libs/serialization/example/demo_log.cpp index 55fc53513e..eef40ec810 100644 --- a/libs/serialization/example/demo_log.cpp +++ b/libs/serialization/example/demo_log.cpp @@ -13,8 +13,7 @@ #include "demo_gps.hpp" #include "log_archive.hpp" -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]){ // make the schedule bus_schedule schedule; @@ -65,7 +64,7 @@ int main(int argc, char *argv[]) // display the complete schedule log_archive oa(std::cout); - //oa << BOOST_SERIALIZATION_NVP(schedule); + oa << BOOST_SERIALIZATION_NVP(schedule); oa << schedule; delete bs0; @@ -74,3 +73,4 @@ int main(int argc, char *argv[]) delete bs3; return 0; } + diff --git a/libs/serialization/example/log_archive.hpp b/libs/serialization/example/log_archive.hpp index f032bb2803..039f0b3edb 100644 --- a/libs/serialization/example/log_archive.hpp +++ b/libs/serialization/example/log_archive.hpp @@ -19,11 +19,12 @@ #include <boost/archive/xml_oarchive.hpp> namespace boost { -namespace archive { - namespace detail { - template<class Archive> class interface_oarchive; - } // namespace detail -} // namespace archive + namespace archive { + namespace detail { + template<class Archive> class interface_oarchive; + } // namespace detail + } // namespace archive +} // boost ///////////////////////////////////////////////////////////////////////// // log data to an output stream. This illustrates a simpler implemenation @@ -43,34 +44,31 @@ class log_archive : // Override functions defined in basic_xml_oarchive // Anything not an attribute and not a name-value pair is an - // error and should be trapped here. Note the usage of - // function argument matching (BOOST_PFTO) to permit usage - // with compilers which fail to properly support - // function template ordering + // error and should be trapped here. template<class T> - void save_override(T & t, BOOST_PFTO int){ + void save_override(T & t){ // make it a name-value pair and pass it on. // this permits this to be used even with data types which // are not wrapped with the name - base::save_override(boost::serialization::make_nvp(NULL, t), 0); + base::save_override(boost::serialization::make_nvp(NULL, t)); } template<class T> - void save_override(const boost::serialization::nvp< T > & t, int){ + void save_override(const boost::serialization::nvp< T > & t){ // this is here to remove the "const" requirement. Since // this class is to be used only for output, it's not required. - base::save_override(t, 0); + base::save_override(t); } // specific overrides for attributes - not name value pairs so we // want to trap them before the above "fall through" // since we don't want to see these in the output - make them no-ops. - void save_override(const boost::archive::object_id_type & t, int){} - void save_override(const boost::archive::object_reference_type & t, int){} - void save_override(const boost::archive::version_type & t, int){} - void save_override(const boost::archive::class_id_type & t, int){} - void save_override(const boost::archive::class_id_optional_type & t, int){} - void save_override(const boost::archive::class_id_reference_type & t, int){} - void save_override(const boost::archive::class_name_type & t, int){} - void save_override(const boost::archive::tracking_type & t, int){} + void save_override(const boost::archive::object_id_type & t){} + void save_override(const boost::archive::object_reference_type & t){} + void save_override(const boost::archive::version_type & t){} + void save_override(const boost::archive::class_id_type & t){} + void save_override(const boost::archive::class_id_optional_type & t){} + void save_override(const boost::archive::class_id_reference_type & t){} + void save_override(const boost::archive::class_name_type & t){} + void save_override(const boost::archive::tracking_type & t){} public: log_archive(std::ostream & os, unsigned int flags = 0) : boost::archive::xml_oarchive_impl<log_archive>( diff --git a/libs/serialization/example/portable_binary_archive.hpp b/libs/serialization/example/portable_binary_archive.hpp index b64a7f33de..eecd9508b4 100644 --- a/libs/serialization/example/portable_binary_archive.hpp +++ b/libs/serialization/example/portable_binary_archive.hpp @@ -13,7 +13,6 @@ #include <boost/config.hpp> #include <boost/cstdint.hpp> -#include <boost/serialization/pfto.hpp> #include <boost/static_assert.hpp> #include <climits> diff --git a/libs/serialization/example/portable_binary_iarchive.cpp b/libs/serialization/example/portable_binary_iarchive.cpp index 6b8d7ccd5c..a0b61d52f9 100644 --- a/libs/serialization/example/portable_binary_iarchive.cpp +++ b/libs/serialization/example/portable_binary_iarchive.cpp @@ -47,7 +47,7 @@ portable_binary_iarchive::load_impl(boost::intmax_t & l, char maxsize){ #else if(m_flags & endian_big) #endif - reverse_bytes(size, cptr); + reverse_bytes(size, cptr); if(negative) l = -l; @@ -55,11 +55,11 @@ portable_binary_iarchive::load_impl(boost::intmax_t & l, char maxsize){ void portable_binary_iarchive::load_override( - boost::archive::class_name_type & t, int + boost::archive::class_name_type & t ){ std::string cn; cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE); - load_override(cn, 0); + load_override(cn); if(cn.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE - 1)) boost::serialization::throw_exception( boost::archive::archive_exception( diff --git a/libs/serialization/example/portable_binary_iarchive.hpp b/libs/serialization/example/portable_binary_iarchive.hpp index e381df3e65..3730660c9b 100644 --- a/libs/serialization/example/portable_binary_iarchive.hpp +++ b/libs/serialization/example/portable_binary_iarchive.hpp @@ -148,21 +148,15 @@ protected: void load(unsigned char & t){ this->primitive_base_t::load(t); } - // intermediate level to support override of operators - // fot templates in the absence of partial function - // template ordering typedef boost::archive::detail::common_iarchive<portable_binary_iarchive> detail_common_iarchive; template<class T> - void load_override(T & t, BOOST_PFTO int){ - this->detail_common_iarchive::load_override(t, 0); + void load_override(T & t){ + this->detail_common_iarchive::load_override(t); } - void load_override(boost::archive::class_name_type & t, int); + void load_override(boost::archive::class_name_type & t); // binary files don't include the optional information - void load_override( - boost::archive::class_id_optional_type & /* t */, - int - ){} + void load_override(boost::archive::class_id_optional_type &){} void init(unsigned int flags); public: diff --git a/libs/serialization/example/portable_binary_oarchive.hpp b/libs/serialization/example/portable_binary_oarchive.hpp index 639e10aa3e..317aa1d7cb 100644 --- a/libs/serialization/example/portable_binary_oarchive.hpp +++ b/libs/serialization/example/portable_binary_oarchive.hpp @@ -131,18 +131,17 @@ protected: typedef boost::archive::detail::common_oarchive<portable_binary_oarchive> detail_common_oarchive; template<class T> - void save_override(T & t, BOOST_PFTO int){ - this->detail_common_oarchive::save_override(t, 0); + void save_override(T & t){ + this->detail_common_oarchive::save_override(t); } // explicitly convert to char * to avoid compile ambiguities - void save_override(const boost::archive::class_name_type & t, int){ + void save_override(const boost::archive::class_name_type & t){ const std::string s(t); * this << s; } // binary files don't include the optional information void save_override( - const boost::archive::class_id_optional_type & /* t */, - int + const boost::archive::class_id_optional_type & /* t */ ){} void init(unsigned int flags); diff --git a/libs/serialization/src/archive_exception.cpp b/libs/serialization/src/archive_exception.cpp index d06303f670..8fcc6eeb08 100644 --- a/libs/serialization/src/archive_exception.cpp +++ b/libs/serialization/src/archive_exception.cpp @@ -13,15 +13,17 @@ #endif #include <exception> -//#include <boost/assert.hpp> #include <string> +#include <cstring> #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/archive_exception.hpp> namespace boost { namespace archive { +BOOST_ARCHIVE_DECL unsigned int archive_exception::append(unsigned int l, const char * a){ while(l < (sizeof(m_buffer) - 1)){ @@ -34,12 +36,12 @@ archive_exception::append(unsigned int l, const char * a){ return l; } -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL archive_exception::archive_exception( exception_code c, const char * e1, const char * e2 -) : +) BOOST_NOEXCEPT : code(c) { unsigned int length = 0; @@ -110,17 +112,26 @@ archive_exception::archive_exception( break; } } -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) -archive_exception::~archive_exception() throw() {} -BOOST_ARCHIVE_DECL(const char *) -archive_exception::what( ) const throw() +BOOST_ARCHIVE_DECL +archive_exception::archive_exception(archive_exception const & oth) BOOST_NOEXCEPT : + std::exception(oth), + code(oth.code) { + std::memcpy(m_buffer,oth.m_buffer,sizeof m_buffer); +} + +BOOST_ARCHIVE_DECL +archive_exception::~archive_exception() BOOST_NOEXCEPT_OR_NOTHROW {} + +BOOST_ARCHIVE_DECL const char * +archive_exception::what() const BOOST_NOEXCEPT_OR_NOTHROW { return m_buffer; } -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) -archive_exception::archive_exception() : - code(no_exception) + +BOOST_ARCHIVE_DECL +archive_exception::archive_exception() BOOST_NOEXCEPT : + code(no_exception) {} } // archive diff --git a/libs/serialization/src/basic_archive.cpp b/libs/serialization/src/basic_archive.cpp index 3f6c3e353d..5391021a50 100644 --- a/libs/serialization/src/basic_archive.cpp +++ b/libs/serialization/src/basic_archive.cpp @@ -32,6 +32,7 @@ // * required only for pointers - optional for objects #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/basic_archive.hpp> namespace boost { @@ -41,7 +42,7 @@ namespace archive { // constants used in archive signature //This should never ever change. note that is not an std::string // string. -BOOST_ARCHIVE_DECL(const char *) +BOOST_SYMBOL_VISIBLE const char * BOOST_ARCHIVE_SIGNATURE(){ return "serialization::archive"; } @@ -73,10 +74,12 @@ BOOST_ARCHIVE_SIGNATURE(){ // 10- fixed base64 output/input. // 11- not changes // 12- improved serialization of collections +// 13- simplified visibility, removed Borland, removed pfto +// 14- improved visibility, refactor map/set -BOOST_ARCHIVE_DECL(library_version_type) +BOOST_SYMBOL_VISIBLE library_version_type BOOST_ARCHIVE_VERSION(){ - return library_version_type(12); + return library_version_type(14); } } // namespace archive diff --git a/libs/serialization/src/basic_iarchive.cpp b/libs/serialization/src/basic_iarchive.cpp index 9e25092ae9..841fefdd5e 100644 --- a/libs/serialization/src/basic_iarchive.cpp +++ b/libs/serialization/src/basic_iarchive.cpp @@ -24,17 +24,18 @@ namespace std{ #endif #include <boost/integer_traits.hpp> -#include <boost/serialization/state_saver.hpp> -#include <boost/serialization/throw_exception.hpp> -#include <boost/serialization/tracking.hpp> #define BOOST_ARCHIVE_SOURCE // include this to prevent linker errors when the // same modules are marked export and import. #define BOOST_SERIALIZATION_SOURCE +#include <boost/serialization/config.hpp> -#include <boost/archive/archive_exception.hpp> +#include <boost/serialization/state_saver.hpp> +#include <boost/serialization/throw_exception.hpp> +#include <boost/serialization/tracking.hpp> +#include <boost/archive/archive_exception.hpp> #include <boost/archive/detail/decl.hpp> #include <boost/archive/basic_archive.hpp> #include <boost/archive/detail/basic_iserializer.hpp> @@ -518,26 +519,26 @@ namespace boost { namespace archive { namespace detail { -BOOST_ARCHIVE_DECL(void) +BOOST_ARCHIVE_DECL void basic_iarchive::next_object_pointer(void *t){ pimpl->next_object_pointer(t); } -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_iarchive::basic_iarchive(unsigned int flags) : pimpl(new basic_iarchive_impl(flags)) {} -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_iarchive::~basic_iarchive() {} -BOOST_ARCHIVE_DECL(void) +BOOST_ARCHIVE_DECL void basic_iarchive::set_library_version(library_version_type archive_library_version){ pimpl->set_library_version(archive_library_version); } -BOOST_ARCHIVE_DECL(void) +BOOST_ARCHIVE_DECL void basic_iarchive::reset_object_address( const void * new_address, const void * old_address @@ -545,7 +546,7 @@ basic_iarchive::reset_object_address( pimpl->reset_object_address(new_address, old_address); } -BOOST_ARCHIVE_DECL(void) +BOOST_ARCHIVE_DECL void basic_iarchive::load_object( void *t, const basic_iserializer & bis @@ -554,7 +555,7 @@ basic_iarchive::load_object( } // load a pointer object -BOOST_ARCHIVE_DECL(const basic_pointer_iserializer *) +BOOST_ARCHIVE_DECL const basic_pointer_iserializer * basic_iarchive::load_pointer( void * &t, const basic_pointer_iserializer * bpis_ptr, @@ -566,23 +567,23 @@ basic_iarchive::load_pointer( return pimpl->load_pointer(*this, t, bpis_ptr, finder); } -BOOST_ARCHIVE_DECL(void) +BOOST_ARCHIVE_DECL void basic_iarchive::register_basic_serializer(const basic_iserializer & bis){ pimpl->register_type(bis); } -BOOST_ARCHIVE_DECL(void) +BOOST_ARCHIVE_DECL void basic_iarchive::delete_created_pointers() { pimpl->delete_created_pointers(); } -BOOST_ARCHIVE_DECL(boost::archive::library_version_type) +BOOST_ARCHIVE_DECL boost::archive::library_version_type basic_iarchive::get_library_version() const{ return pimpl->m_archive_library_version; } -BOOST_ARCHIVE_DECL(unsigned int) +BOOST_ARCHIVE_DECL unsigned int basic_iarchive::get_flags() const{ return pimpl->m_flags; } diff --git a/libs/serialization/src/basic_iserializer.cpp b/libs/serialization/src/basic_iserializer.cpp index e18e16fe50..3898a6a723 100644 --- a/libs/serialization/src/basic_iserializer.cpp +++ b/libs/serialization/src/basic_iserializer.cpp @@ -11,13 +11,14 @@ #include <cstddef> // NULL #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/detail/basic_iserializer.hpp> namespace boost { namespace archive { namespace detail { -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_iserializer::basic_iserializer( const boost::serialization::extended_type_info & eti ) : @@ -25,7 +26,7 @@ basic_iserializer::basic_iserializer( m_bpis(NULL) {} -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_iserializer::~basic_iserializer(){} } // namespace detail diff --git a/libs/serialization/src/basic_oarchive.cpp b/libs/serialization/src/basic_oarchive.cpp index 2ce98c6d55..538be310a0 100644 --- a/libs/serialization/src/basic_oarchive.cpp +++ b/libs/serialization/src/basic_oarchive.cpp @@ -15,8 +15,6 @@ #include <cstddef> // NULL #include <boost/limits.hpp> -#include <boost/serialization/state_saver.hpp> -#include <boost/serialization/throw_exception.hpp> // including this here to work around an ICC in intel 7.0 // normally this would be part of basic_oarchive.hpp below. @@ -24,6 +22,10 @@ // include this to prevent linker errors when the // same modules are marked export and import. #define BOOST_SERIALIZATION_SOURCE +#include <boost/serialization/config.hpp> +#include <boost/serialization/state_saver.hpp> +#include <boost/serialization/throw_exception.hpp> +#include <boost/serialization/extended_type_info.hpp> #include <boost/archive/detail/decl.hpp> #include <boost/archive/basic_archive.hpp> @@ -31,7 +33,6 @@ #include <boost/archive/detail/basic_pointer_oserializer.hpp> #include <boost/archive/detail/basic_oarchive.hpp> #include <boost/archive/archive_exception.hpp> -#include <boost/serialization/extended_type_info.hpp> #ifdef BOOST_MSVC # pragma warning(push) @@ -410,16 +411,16 @@ namespace boost { namespace archive { namespace detail { -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_oarchive::basic_oarchive(unsigned int flags) : pimpl(new basic_oarchive_impl(flags)) {} -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_oarchive::~basic_oarchive() {} -BOOST_ARCHIVE_DECL(void) +BOOST_ARCHIVE_DECL void basic_oarchive::save_object( const void *x, const basic_oserializer & bos @@ -427,7 +428,7 @@ basic_oarchive::save_object( pimpl->save_object(*this, x, bos); } -BOOST_ARCHIVE_DECL(void) +BOOST_ARCHIVE_DECL void basic_oarchive::save_pointer( const void * t, const basic_pointer_oserializer * bpos_ptr @@ -435,25 +436,30 @@ basic_oarchive::save_pointer( pimpl->save_pointer(*this, t, bpos_ptr); } -BOOST_ARCHIVE_DECL(void) +BOOST_ARCHIVE_DECL void basic_oarchive::register_basic_serializer(const basic_oserializer & bos){ pimpl->register_type(bos); } -BOOST_ARCHIVE_DECL(library_version_type) +BOOST_ARCHIVE_DECL library_version_type basic_oarchive::get_library_version() const{ return BOOST_ARCHIVE_VERSION(); } -BOOST_ARCHIVE_DECL(unsigned int) +BOOST_ARCHIVE_DECL unsigned int basic_oarchive::get_flags() const{ return pimpl->m_flags; } -BOOST_ARCHIVE_DECL(void) +BOOST_ARCHIVE_DECL void basic_oarchive::end_preamble(){ } +BOOST_ARCHIVE_DECL helper_collection & +basic_oarchive::get_helper_collection(){ + return *this; +} + } // namespace detail } // namespace archive } // namespace boost diff --git a/libs/serialization/src/basic_oserializer.cpp b/libs/serialization/src/basic_oserializer.cpp index 0e21806454..afe08c4bb8 100644 --- a/libs/serialization/src/basic_oserializer.cpp +++ b/libs/serialization/src/basic_oserializer.cpp @@ -11,13 +11,14 @@ #include <cstddef> // NULL #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/detail/basic_oserializer.hpp> namespace boost { namespace archive { namespace detail { -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_oserializer::basic_oserializer( const boost::serialization::extended_type_info & eti ) : @@ -25,7 +26,7 @@ basic_oserializer::basic_oserializer( m_bpos(NULL) {} -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_oserializer::~basic_oserializer(){} } // namespace detail diff --git a/libs/serialization/src/basic_pointer_iserializer.cpp b/libs/serialization/src/basic_pointer_iserializer.cpp index fac766fdef..7cf63f306e 100644 --- a/libs/serialization/src/basic_pointer_iserializer.cpp +++ b/libs/serialization/src/basic_pointer_iserializer.cpp @@ -9,20 +9,21 @@ // See http://www.boost.org for updates, documentation, and revision history. #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/detail/basic_pointer_iserializer.hpp> namespace boost { namespace archive { namespace detail { -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_pointer_iserializer::basic_pointer_iserializer( const boost::serialization::extended_type_info & eti ) : basic_serializer(eti) {} -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_pointer_iserializer::~basic_pointer_iserializer() {} } // namespace detail diff --git a/libs/serialization/src/basic_pointer_oserializer.cpp b/libs/serialization/src/basic_pointer_oserializer.cpp index 9e9f1dd15f..e86f7b78ed 100644 --- a/libs/serialization/src/basic_pointer_oserializer.cpp +++ b/libs/serialization/src/basic_pointer_oserializer.cpp @@ -9,20 +9,21 @@ // See http://www.boost.org for updates, documentation, and revision history. #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/detail/basic_pointer_oserializer.hpp> namespace boost { namespace archive { namespace detail { -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_pointer_oserializer::basic_pointer_oserializer( const boost::serialization::extended_type_info & eti ) : basic_serializer(eti) {} -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL basic_pointer_oserializer::~basic_pointer_oserializer() {} } // namespace detail diff --git a/libs/serialization/src/basic_serializer_map.cpp b/libs/serialization/src/basic_serializer_map.cpp index 7df0b3ddc3..5b79107728 100644 --- a/libs/serialization/src/basic_serializer_map.cpp +++ b/libs/serialization/src/basic_serializer_map.cpp @@ -19,10 +19,10 @@ // include this to prevent linker errors when the // same modules are marked export and import. #define BOOST_SERIALIZATION_SOURCE - -#include <boost/archive/archive_exception.hpp> +#include <boost/serialization/config.hpp> #include <boost/serialization/throw_exception.hpp> +#include <boost/archive/archive_exception.hpp> #include <boost/archive/detail/basic_serializer.hpp> #include <boost/archive/detail/basic_serializer_map.hpp> @@ -40,7 +40,7 @@ basic_serializer_map::type_info_pointer_compare::operator()( return *lhs < *rhs; } -BOOST_ARCHIVE_DECL(bool) +BOOST_ARCHIVE_DECL bool basic_serializer_map::insert(const basic_serializer * bs){ // attempt to insert serializer into it's map // the following is commented out - rather than being just @@ -72,7 +72,7 @@ basic_serializer_map::insert(const basic_serializer * bs){ return true; } -BOOST_ARCHIVE_DECL(void) +BOOST_ARCHIVE_DECL void basic_serializer_map::erase(const basic_serializer * bs){ map_type::iterator it = m_map.begin(); map_type::iterator it_end = m_map.end(); @@ -92,7 +92,7 @@ basic_serializer_map::erase(const basic_serializer * bs){ //if(*it == bs) // m_map.erase(it); } -BOOST_ARCHIVE_DECL(const basic_serializer *) +BOOST_ARCHIVE_DECL const basic_serializer * basic_serializer_map::find( const boost::serialization::extended_type_info & eti ) const { diff --git a/libs/serialization/src/basic_text_iprimitive.cpp b/libs/serialization/src/basic_text_iprimitive.cpp index c67a9420ba..c0b7f76682 100644 --- a/libs/serialization/src/basic_text_iprimitive.cpp +++ b/libs/serialization/src/basic_text_iprimitive.cpp @@ -15,6 +15,7 @@ #include <istream> #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/detail/auto_link_archive.hpp> #include <boost/archive/impl/basic_text_iprimitive.ipp> diff --git a/libs/serialization/src/basic_text_oprimitive.cpp b/libs/serialization/src/basic_text_oprimitive.cpp index d8d98d6977..601662294e 100644 --- a/libs/serialization/src/basic_text_oprimitive.cpp +++ b/libs/serialization/src/basic_text_oprimitive.cpp @@ -15,6 +15,7 @@ #include <ostream> #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/detail/auto_link_archive.hpp> #include <boost/archive/impl/basic_text_oprimitive.ipp> diff --git a/libs/serialization/src/basic_text_wiprimitive.cpp b/libs/serialization/src/basic_text_wiprimitive.cpp index 4797485b0d..28250007bd 100644 --- a/libs/serialization/src/basic_text_wiprimitive.cpp +++ b/libs/serialization/src/basic_text_wiprimitive.cpp @@ -8,6 +8,8 @@ // See http://www.boost.org for updates, documentation, and revision history. +#include <istream> + #include <boost/config.hpp> #ifdef BOOST_NO_STD_WSTREAMBUF @@ -18,9 +20,8 @@ # pragma warning (disable : 4786) // too long name, harmless warning #endif -#include <istream> - #define BOOST_WARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/detail/auto_link_warchive.hpp> #include <boost/archive/impl/basic_text_iprimitive.ipp> diff --git a/libs/serialization/src/basic_text_woprimitive.cpp b/libs/serialization/src/basic_text_woprimitive.cpp index e13294e70c..6c0caa9793 100644 --- a/libs/serialization/src/basic_text_woprimitive.cpp +++ b/libs/serialization/src/basic_text_woprimitive.cpp @@ -8,6 +8,8 @@ // See http://www.boost.org for updates, documentation, and revision history. +#include <ostream> + #include <boost/config.hpp> #ifdef BOOST_NO_STD_WSTREAMBUF @@ -18,9 +20,8 @@ # pragma warning (disable : 4786) // too long name, harmless warning #endif -#include <ostream> - #define BOOST_WARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/detail/auto_link_warchive.hpp> #include <boost/archive/impl/basic_text_oprimitive.ipp> diff --git a/libs/serialization/src/basic_xml_archive.cpp b/libs/serialization/src/basic_xml_archive.cpp index e71aaef39c..23ab1819d1 100644 --- a/libs/serialization/src/basic_xml_archive.cpp +++ b/libs/serialization/src/basic_xml_archive.cpp @@ -9,40 +9,41 @@ // See http://www.boost.org for updates, documentation, and revision history. #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/basic_xml_archive.hpp> namespace boost { namespace archive { -BOOST_ARCHIVE_DECL(const char *) +BOOST_SYMBOL_VISIBLE const char * BOOST_ARCHIVE_XML_OBJECT_ID(){ return "object_id"; } -BOOST_ARCHIVE_DECL(const char *) +BOOST_SYMBOL_VISIBLE const char * BOOST_ARCHIVE_XML_OBJECT_REFERENCE(){ return "object_id_reference"; } -BOOST_ARCHIVE_DECL(const char *) +BOOST_SYMBOL_VISIBLE const char * BOOST_ARCHIVE_XML_CLASS_ID(){ return "class_id"; } -BOOST_ARCHIVE_DECL(const char *) +BOOST_SYMBOL_VISIBLE const char * BOOST_ARCHIVE_XML_CLASS_ID_REFERENCE(){ return "class_id_reference"; } -BOOST_ARCHIVE_DECL(const char *) +BOOST_SYMBOL_VISIBLE const char * BOOST_ARCHIVE_XML_CLASS_NAME(){ return "class_name"; } -BOOST_ARCHIVE_DECL(const char *) +BOOST_SYMBOL_VISIBLE const char * BOOST_ARCHIVE_XML_TRACKING(){ return "tracking_level"; } -BOOST_ARCHIVE_DECL(const char *) +BOOST_SYMBOL_VISIBLE const char * BOOST_ARCHIVE_XML_VERSION(){ return "version"; } -BOOST_ARCHIVE_DECL(const char *) +BOOST_SYMBOL_VISIBLE const char * BOOST_ARCHIVE_XML_SIGNATURE(){ return "signature"; } diff --git a/libs/serialization/src/basic_xml_grammar.ipp b/libs/serialization/src/basic_xml_grammar.ipp index 28be525ca3..6dc6b58cd5 100644 --- a/libs/serialization/src/basic_xml_grammar.ipp +++ b/libs/serialization/src/basic_xml_grammar.ipp @@ -14,11 +14,11 @@ #include <istream> #include <algorithm> -#include <boost/config.hpp> // BOOST_DEDUCED_TYPENAME +#include <boost/config.hpp> // typename #ifdef BOOST_MSVC # pragma warning(push) -# pragma warning(disable : 4511 4512) +# pragma warning(disable : 4244 4511 4512) #endif // spirit stuff @@ -33,7 +33,6 @@ // for head_iterator test //#include <boost/bind.hpp> #include <boost/function.hpp> -#include <boost/serialization/pfto.hpp> #include <boost/io/ios_state.hpp> #include <boost/serialization/throw_exception.hpp> @@ -146,7 +145,7 @@ template<class String> struct append_char { String & contents; void operator()(const unsigned int char_value) const { - const BOOST_DEDUCED_TYPENAME String::value_type z = char_value; + const typename String::value_type z = char_value; contents += z; } append_char(String & contents_) @@ -159,7 +158,7 @@ struct append_lit { String & contents; template<class X, class Y> void operator()(const X & /*x*/, const Y & /*y*/) const { - const BOOST_DEDUCED_TYPENAME String::value_type z = c; + const typename String::value_type z = c; contents += z; } append_lit(String & contents_) @@ -175,14 +174,12 @@ struct append_lit { template<class CharType> bool basic_xml_grammar<CharType>::my_parse( - BOOST_DEDUCED_TYPENAME basic_xml_grammar<CharType>::IStream & is, + typename basic_xml_grammar<CharType>::IStream & is, const rule_t & rule_, CharType delimiter ) const { if(is.fail()){ - boost::serialization::throw_exception( - archive_exception(archive_exception::input_stream_error) - ); + return false; } boost::io::ios_flags_saver ifs(is); @@ -192,7 +189,7 @@ bool basic_xml_grammar<CharType>::my_parse( CharType val; do{ - BOOST_DEDUCED_TYPENAME basic_xml_grammar<CharType>::IStream::int_type + typename basic_xml_grammar<CharType>::IStream::int_type result = is.get(); if(is.fail()) return false; @@ -206,14 +203,14 @@ bool basic_xml_grammar<CharType>::my_parse( // is terminated. This will permit the archive to be used for debug // and transaction data logging in the standard way. - parse_info<BOOST_DEDUCED_TYPENAME std::basic_string<CharType>::iterator> + parse_info<typename std::basic_string<CharType>::iterator> result = boost::spirit::classic::parse(arg.begin(), arg.end(), rule_); return result.hit; } template<class CharType> bool basic_xml_grammar<CharType>::parse_start_tag( - BOOST_DEDUCED_TYPENAME basic_xml_grammar<CharType>::IStream & is + typename basic_xml_grammar<CharType>::IStream & is ){ rv.class_name.resize(0); return my_parse(is, STag); @@ -283,7 +280,7 @@ basic_xml_grammar<CharType>::basic_xml_grammar(){ CharDataChars [ xml::append_string< StringType, - BOOST_DEDUCED_TYPENAME std::basic_string<CharType>::const_iterator + typename std::basic_string<CharType>::const_iterator >(rv.contents) ] ; @@ -456,12 +453,8 @@ void basic_xml_grammar<CharType>::init(IStream & is){ } template<class CharType> -void basic_xml_grammar<CharType>::windup(IStream & is){ - if(is.fail() || is.eof()) - return; - // uh-oh - don't throw exception from code called by a destructor ! - // so just ignore any failure. - my_parse(is, ETag); +bool basic_xml_grammar<CharType>::windup(IStream & is) { + return my_parse(is, ETag); } } // namespace archive diff --git a/libs/serialization/src/binary_iarchive.cpp b/libs/serialization/src/binary_iarchive.cpp index c1117e9ee1..41aad8413e 100644 --- a/libs/serialization/src/binary_iarchive.cpp +++ b/libs/serialization/src/binary_iarchive.cpp @@ -11,6 +11,7 @@ #include <istream> #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/binary_iarchive.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> diff --git a/libs/serialization/src/binary_oarchive.cpp b/libs/serialization/src/binary_oarchive.cpp index e7ab9040ef..8b86d2cb38 100644 --- a/libs/serialization/src/binary_oarchive.cpp +++ b/libs/serialization/src/binary_oarchive.cpp @@ -11,6 +11,7 @@ #include <ostream> #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/binary_oarchive.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> diff --git a/libs/serialization/src/codecvt_null.cpp b/libs/serialization/src/codecvt_null.cpp index 80ba2a3327..2f0115bf25 100644 --- a/libs/serialization/src/codecvt_null.cpp +++ b/libs/serialization/src/codecvt_null.cpp @@ -8,6 +8,7 @@ // http://www.boost.org/LICENSE_1_0.txt) #define BOOST_WARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/codecvt_null.hpp> // codecvt implementation for passing wchar_t objects to char output @@ -17,7 +18,7 @@ namespace boost { namespace archive { -BOOST_WARCHIVE_DECL(std::codecvt_base::result) +BOOST_WARCHIVE_DECL std::codecvt_base::result codecvt_null<wchar_t>::do_out( std::mbstate_t & /*state*/, const wchar_t * first1, @@ -45,7 +46,7 @@ codecvt_null<wchar_t>::do_out( return std::codecvt_base::ok; } -BOOST_WARCHIVE_DECL(std::codecvt_base::result) +BOOST_WARCHIVE_DECL std::codecvt_base::result codecvt_null<wchar_t>::do_in( std::mbstate_t & /*state*/, const char * first1, diff --git a/libs/serialization/src/extended_type_info.cpp b/libs/serialization/src/extended_type_info.cpp index 48bbc56273..13a60c3e77 100644 --- a/libs/serialization/src/extended_type_info.cpp +++ b/libs/serialization/src/extended_type_info.cpp @@ -18,18 +18,22 @@ #include <boost/assert.hpp> #include <cstddef> // NULL -#include <boost/config.hpp> // msvc needs this to suppress warning - #include <cstring> #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ using ::strcmp; } #endif +#include <boost/config.hpp> // msvc needs this to suppress warning + #include <boost/core/no_exceptions_support.hpp> -#include <boost/serialization/singleton.hpp> -#include <boost/serialization/force_include.hpp> +// it marks our code with proper attributes as being exported when +// we're compiling it while marking it import when just the headers +// is being included. #define BOOST_SERIALIZATION_SOURCE +#include <boost/serialization/config.hpp> +#include <boost/serialization/singleton.hpp> +#include <boost/serialization/force_include.hpp> #include <boost/serialization/extended_type_info.hpp> #ifdef BOOST_MSVC @@ -110,14 +114,14 @@ public: } // namespace detail -BOOST_SERIALIZATION_DECL(void) +BOOST_SERIALIZATION_DECL void extended_type_info::key_register() const{ if(NULL == get_key()) return; singleton<detail::ktmap>::get_mutable_instance().insert(this); } -BOOST_SERIALIZATION_DECL(void) +BOOST_SERIALIZATION_DECL void extended_type_info::key_unregister() const{ if(NULL == get_key()) return; @@ -135,7 +139,7 @@ extended_type_info::key_unregister() const{ } } -BOOST_SERIALIZATION_DECL(const extended_type_info *) +BOOST_SERIALIZATION_DECL const extended_type_info * extended_type_info::find(const char *key) { BOOST_ASSERT(NULL != key); const detail::ktmap & k = singleton<detail::ktmap>::get_const_instance(); @@ -146,7 +150,7 @@ extended_type_info::find(const char *key) { return *(it); } -BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) +BOOST_SERIALIZATION_DECL extended_type_info::extended_type_info( const unsigned int type_info_key, const char * key @@ -156,11 +160,11 @@ extended_type_info::extended_type_info( { } -BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) +BOOST_SERIALIZATION_DECL extended_type_info::~extended_type_info(){ } -BOOST_SERIALIZATION_DECL(bool) +BOOST_SERIALIZATION_DECL bool extended_type_info::operator<(const extended_type_info &rhs) const { // short cut for a common cases if(this == & rhs) @@ -173,7 +177,7 @@ extended_type_info::operator<(const extended_type_info &rhs) const { return false; } -BOOST_SERIALIZATION_DECL(bool) +BOOST_SERIALIZATION_DECL bool extended_type_info::operator==(const extended_type_info &rhs) const { // short cut for a common cases if(this == & rhs) diff --git a/libs/serialization/src/extended_type_info_no_rtti.cpp b/libs/serialization/src/extended_type_info_no_rtti.cpp index 3b2a888459..0a8d2a078c 100644 --- a/libs/serialization/src/extended_type_info_no_rtti.cpp +++ b/libs/serialization/src/extended_type_info_no_rtti.cpp @@ -18,7 +18,11 @@ namespace std{ using ::strcmp; } #endif +// it marks our code with proper attributes as being exported when +// we're compiling it while marking it import when just the headers +// is being included. #define BOOST_SERIALIZATION_SOURCE +#include <boost/serialization/config.hpp> #include <boost/serialization/extended_type_info_no_rtti.hpp> #define EXTENDED_TYPE_INFO_NO_RTTI_KEY 2 @@ -27,14 +31,14 @@ namespace boost { namespace serialization { namespace no_rtti_system { -BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) +BOOST_SERIALIZATION_DECL extended_type_info_no_rtti_0::extended_type_info_no_rtti_0( const char * key ) : extended_type_info(EXTENDED_TYPE_INFO_NO_RTTI_KEY, key) {} -BOOST_SERIALIZATION_DECL(bool) +BOOST_SERIALIZATION_DECL bool extended_type_info_no_rtti_0::is_less_than( const boost::serialization::extended_type_info &rhs) const { @@ -57,7 +61,7 @@ extended_type_info_no_rtti_0::is_less_than( return std::strcmp(l, r) < 0; } -BOOST_SERIALIZATION_DECL(bool) +BOOST_SERIALIZATION_DECL bool extended_type_info_no_rtti_0::is_equal( const boost::serialization::extended_type_info &rhs) const { @@ -76,7 +80,7 @@ extended_type_info_no_rtti_0::is_equal( return 0 == std::strcmp(l, r); } -BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) +BOOST_SERIALIZATION_DECL extended_type_info_no_rtti_0::~extended_type_info_no_rtti_0() {} diff --git a/libs/serialization/src/extended_type_info_typeid.cpp b/libs/serialization/src/extended_type_info_typeid.cpp index 8d970309e4..5669dfa772 100644 --- a/libs/serialization/src/extended_type_info_typeid.cpp +++ b/libs/serialization/src/extended_type_info_typeid.cpp @@ -17,9 +17,12 @@ #include <boost/core/no_exceptions_support.hpp> -#include <boost/serialization/singleton.hpp> - +// it marks our code with proper attributes as being exported when +// we're compiling it while marking it import when just the headers +// is being included. #define BOOST_SERIALIZATION_SOURCE +#include <boost/serialization/config.hpp> +#include <boost/serialization/singleton.hpp> #include <boost/serialization/extended_type_info_typeid.hpp> namespace boost { @@ -44,7 +47,7 @@ typedef std::multiset< type_compare > tkmap; -BOOST_SERIALIZATION_DECL(bool) +BOOST_SERIALIZATION_DECL bool extended_type_info_typeid_0::is_less_than( const boost::serialization::extended_type_info & rhs ) const { @@ -56,7 +59,7 @@ extended_type_info_typeid_0::is_less_than( ); } -BOOST_SERIALIZATION_DECL(bool) +BOOST_SERIALIZATION_DECL bool extended_type_info_typeid_0::is_equal( const boost::serialization::extended_type_info & rhs ) const { @@ -70,7 +73,7 @@ extended_type_info_typeid_0::is_equal( ; } -BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) +BOOST_SERIALIZATION_DECL extended_type_info_typeid_0::extended_type_info_typeid_0( const char * key ) : @@ -78,17 +81,17 @@ extended_type_info_typeid_0::extended_type_info_typeid_0( m_ti(NULL) {} -BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) +BOOST_SERIALIZATION_DECL extended_type_info_typeid_0::~extended_type_info_typeid_0() {} -BOOST_SERIALIZATION_DECL(void) +BOOST_SERIALIZATION_DECL void extended_type_info_typeid_0::type_register(const std::type_info & ti){ m_ti = & ti; singleton<tkmap>::get_mutable_instance().insert(this); } -BOOST_SERIALIZATION_DECL(void) +BOOST_SERIALIZATION_DECL void extended_type_info_typeid_0::type_unregister() { if(NULL != m_ti){ @@ -144,7 +147,7 @@ public: # pragma warning(pop) #endif -BOOST_SERIALIZATION_DECL(const extended_type_info *) +BOOST_SERIALIZATION_DECL const extended_type_info * extended_type_info_typeid_0::get_extended_type_info( const std::type_info & ti ) const { diff --git a/libs/serialization/src/polymorphic_iarchive.cpp b/libs/serialization/src/polymorphic_iarchive.cpp index 5e8c986783..249363b8ea 100644 --- a/libs/serialization/src/polymorphic_iarchive.cpp +++ b/libs/serialization/src/polymorphic_iarchive.cpp @@ -13,6 +13,7 @@ #endif #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> #include <boost/archive/impl/archive_serializer_map.ipp> diff --git a/libs/serialization/src/polymorphic_oarchive.cpp b/libs/serialization/src/polymorphic_oarchive.cpp index b85895e260..f63296be5b 100644 --- a/libs/serialization/src/polymorphic_oarchive.cpp +++ b/libs/serialization/src/polymorphic_oarchive.cpp @@ -13,6 +13,7 @@ #endif #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> #include <boost/archive/impl/archive_serializer_map.ipp> diff --git a/libs/serialization/src/shared_ptr_helper.cpp b/libs/serialization/src/shared_ptr_helper.cpp deleted file mode 100644 index 15102e2f3a..0000000000 --- a/libs/serialization/src/shared_ptr_helper.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// shared_ptr_helper.hpp: serialization for boost shared pointern - -// (C) Copyright 2004-2009 Robert Ramey, Martin Ecker and Takatoshi Kondo -// 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) - -// See http://www.boost.org for updates, documentation, and revision history. - -#include <map> -#include <list> -#include <utility> -#include <cstddef> // NULL -#include <cassert> - -#define BOOST_ARCHIVE_SOURCE -// include this to prevent linker errors when the -// same modules are marked export and import. -#define BOOST_SERIALIZATION_SOURCE - -#include <boost/serialization/throw_exception.hpp> -#include <boost/serialization/void_cast.hpp> -#include <boost/serialization/extended_type_info.hpp> -#include <boost/serialization/shared_ptr_helper.hpp> -#include <boost/archive/archive_exception.hpp> - -namespace boost { -namespace serialization { - -/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// a common class for holding various types of shared pointers - -// #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP -BOOST_ARCHIVE_DECL(void) -shared_ptr_helper_base::append(const boost_132::shared_ptr<const void> & t){ - if(NULL == m_pointers_132) - m_pointers_132 = new std::list<boost_132::shared_ptr<const void> >; - m_pointers_132->push_back(t); -} -// #endif - -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) -shared_ptr_helper_base::shared_ptr_helper_base() : - m_o_sp(NULL) - #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP - , m_pointers_132(NULL) - #endif -{} - -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) -shared_ptr_helper_base::~shared_ptr_helper_base(){ - if(NULL != m_o_sp) - delete m_o_sp; - #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP - if(NULL != m_pointers_132) - delete m_pointers_132; - #endif -} - -} // namespace serialization -} // namespace boost - diff --git a/libs/serialization/src/singleton.cpp b/libs/serialization/src/singleton.cpp new file mode 100644 index 0000000000..b8078c1bec --- /dev/null +++ b/libs/serialization/src/singleton.cpp @@ -0,0 +1,36 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// singleton.cpp +// +// Copyright (c) 201 5 Robert Ramey, Indiana University (garcia@osl.iu.edu) +// 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) +// + +// it marks our code with proper attributes as being exported when +// we're compiling it while marking it import when just the headers +// is being included. +#define BOOST_SERIALIZATION_SOURCE +#include <boost/serialization/config.hpp> +#include <boost/serialization/singleton.hpp> + +namespace boost { +namespace serialization { + +bool & singleton_module::get_lock(){ + static bool lock = false; + return lock; +} + +BOOST_SERIALIZATION_DECL void singleton_module::lock(){ + get_lock() = true; +} +BOOST_SERIALIZATION_DECL void singleton_module::unlock(){ + get_lock() = false; +} +BOOST_SERIALIZATION_DECL bool singleton_module::is_locked() { + return get_lock(); +} + +} // namespace serialization +} // namespace boost diff --git a/libs/serialization/src/stl_port.cpp b/libs/serialization/src/stl_port.cpp index e5378bca4b..343faa6d16 100644 --- a/libs/serialization/src/stl_port.cpp +++ b/libs/serialization/src/stl_port.cpp @@ -13,8 +13,7 @@ #endif // this befuddles the msvc 6 compiler so we can't use it -#if ! ((defined _MSC_VER) && (_MSC_VER <= 1300)) \ -&& ! defined(__BORLANDC__) +#if ! ((defined _MSC_VER) && (_MSC_VER <= 1300)) #include <boost/config.hpp> diff --git a/libs/serialization/src/text_iarchive.cpp b/libs/serialization/src/text_iarchive.cpp index 9520ca2598..dfcff4e149 100644 --- a/libs/serialization/src/text_iarchive.cpp +++ b/libs/serialization/src/text_iarchive.cpp @@ -13,6 +13,7 @@ #endif #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> diff --git a/libs/serialization/src/text_oarchive.cpp b/libs/serialization/src/text_oarchive.cpp index 19165d62de..ae24a0bf74 100644 --- a/libs/serialization/src/text_oarchive.cpp +++ b/libs/serialization/src/text_oarchive.cpp @@ -13,6 +13,7 @@ #endif #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> diff --git a/libs/serialization/src/text_wiarchive.cpp b/libs/serialization/src/text_wiarchive.cpp index a0c68a8e3d..6b6e592f74 100644 --- a/libs/serialization/src/text_wiarchive.cpp +++ b/libs/serialization/src/text_wiarchive.cpp @@ -15,6 +15,7 @@ #else #define BOOST_WARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/text_wiarchive.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> diff --git a/libs/serialization/src/text_woarchive.cpp b/libs/serialization/src/text_woarchive.cpp index 54b4a0df58..46441694ef 100644 --- a/libs/serialization/src/text_woarchive.cpp +++ b/libs/serialization/src/text_woarchive.cpp @@ -14,6 +14,7 @@ #else #define BOOST_WARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/text_woarchive.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> diff --git a/libs/serialization/src/utf8_codecvt_facet.cpp b/libs/serialization/src/utf8_codecvt_facet.cpp index 07deada139..c0a64f2912 100644 --- a/libs/serialization/src/utf8_codecvt_facet.cpp +++ b/libs/serialization/src/utf8_codecvt_facet.cpp @@ -7,10 +7,13 @@ #ifdef BOOST_NO_STD_WSTREAMBUF #error "wide char i/o not supported on this platform" #else - #ifdef BOOST_NO_CXX11_HDR_CODECVT +// #ifdef BOOST_NO_CXX11_HDR_CODECVT + #if 1 + # define BOOST_ARCHIVE_SOURCE + #include <boost/archive/detail/decl.hpp> #define BOOST_UTF8_BEGIN_NAMESPACE \ namespace boost { namespace archive { namespace detail { - #define BOOST_UTF8_DECL + #define BOOST_UTF8_DECL BOOST_ARCHIVE_DECL #define BOOST_UTF8_END_NAMESPACE }}} #include <boost/detail/utf8_codecvt_facet.ipp> #undef BOOST_UTF8_END_NAMESPACE diff --git a/libs/serialization/src/void_cast.cpp b/libs/serialization/src/void_cast.cpp index df31235f41..9009993326 100644 --- a/libs/serialization/src/void_cast.cpp +++ b/libs/serialization/src/void_cast.cpp @@ -13,20 +13,24 @@ # pragma warning (disable : 4786) // too long name, harmless warning #endif -#include <boost/assert.hpp> +// STL +#include <set> +#include <functional> +#include <algorithm> #include <cstddef> // NULL #ifdef BOOST_SERIALIZATION_LOG #include <iostream> #endif -// STL -#include <set> -#include <functional> -#include <algorithm> +// BOOST +#include <boost/config.hpp> #include <boost/assert.hpp> -// BOOST #define BOOST_SERIALIZATION_SOURCE +#include <boost/serialization/config.hpp> +// it marks our code with proper attributes as being exported when +// we're compiling it while marking it import when just the headers +// is being included. #include <boost/serialization/singleton.hpp> #include <boost/serialization/extended_type_info.hpp> #include <boost/serialization/void_cast.hpp> @@ -212,7 +216,7 @@ public: #endif // implementation of void caster base class -BOOST_SERIALIZATION_DECL(void) +BOOST_SERIALIZATION_DECL void void_caster::recursive_register(bool includes_virtual_base) const { void_cast_detail::set_type & s = void_cast_detail::void_caster_registry::get_mutable_instance(); @@ -270,7 +274,7 @@ void_caster::recursive_register(bool includes_virtual_base) const { } } -BOOST_SERIALIZATION_DECL(void) +BOOST_SERIALIZATION_DECL void void_caster::recursive_unregister() const { if(void_caster_registry::is_destroyed()) return; @@ -306,11 +310,18 @@ void_caster::recursive_unregister() const { } // namespace void_cast_detail +BOOST_SYMBOL_VISIBLE void const * +void_upcast( + extended_type_info const & derived, + extended_type_info const & base, + void const * const t +); + // Given a void *, assume that it really points to an instance of one type // and alter it so that it would point to an instance of a related type. // Return the altered pointer. If there exists no sequence of casts that // can transform from_type to to_type, return a NULL. -BOOST_SERIALIZATION_DECL(void const *) +BOOST_SERIALIZATION_DECL void const * void_upcast( extended_type_info const & derived, extended_type_info const & base, @@ -333,7 +344,14 @@ void_upcast( return NULL; } -BOOST_SERIALIZATION_DECL(void const *) +BOOST_SYMBOL_VISIBLE void const * +void_downcast( + extended_type_info const & derived, + extended_type_info const & base, + void const * const t +); + +BOOST_SERIALIZATION_DECL void const * void_downcast( extended_type_info const & derived, extended_type_info const & base, diff --git a/libs/serialization/src/xml_archive_exception.cpp b/libs/serialization/src/xml_archive_exception.cpp index 41d33fdaba..f4ca98c086 100644 --- a/libs/serialization/src/xml_archive_exception.cpp +++ b/libs/serialization/src/xml_archive_exception.cpp @@ -14,16 +14,18 @@ #include <exception> -#include <boost/assert.hpp> #include <string> +#include <boost/assert.hpp> + #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/xml_archive_exception.hpp> namespace boost { namespace archive { -BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) +BOOST_ARCHIVE_DECL xml_archive_exception::xml_archive_exception( exception_code c, const char * e1, @@ -35,13 +37,15 @@ xml_archive_exception::xml_archive_exception( case xml_archive_parsing_error: archive_exception::append(0, "unrecognized XML syntax"); break; - case xml_archive_tag_mismatch: - archive_exception::append(0, "XML start/end tag mismatch"); + case xml_archive_tag_mismatch:{ + unsigned int l; + l = archive_exception::append(0, "XML start/end tag mismatch"); if(NULL != e1){ - archive_exception::append(0, " - "); - archive_exception::append(0, e1); + l = archive_exception::append(l, " - "); + archive_exception::append(l, e1); } break; + } case xml_archive_tag_name_error: archive_exception::append(0, "Invalid XML tag name"); break; @@ -51,6 +55,14 @@ xml_archive_exception::xml_archive_exception( break; } } + +BOOST_ARCHIVE_DECL +xml_archive_exception::xml_archive_exception(xml_archive_exception const & oth) : + archive_exception(oth) + { + } + +BOOST_ARCHIVE_DECL xml_archive_exception::~xml_archive_exception() BOOST_NOEXCEPT_OR_NOTHROW {} } // archive } // boost diff --git a/libs/serialization/src/xml_grammar.cpp b/libs/serialization/src/xml_grammar.cpp index 05904f42f3..ae48f70dec 100644 --- a/libs/serialization/src/xml_grammar.cpp +++ b/libs/serialization/src/xml_grammar.cpp @@ -12,13 +12,14 @@ # pragma warning (disable : 4786) // too long name, harmless warning #endif +#include <boost/config.hpp> + #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/impl/basic_xml_grammar.hpp> using namespace boost::spirit::classic; -#include <boost/config.hpp> - // fixup for borland // The following code will be put into Boost.Config in a later revision #if ! defined(__SGI_STL_PORT) \ diff --git a/libs/serialization/src/xml_iarchive.cpp b/libs/serialization/src/xml_iarchive.cpp index 4311893553..0a19a8e8e6 100644 --- a/libs/serialization/src/xml_iarchive.cpp +++ b/libs/serialization/src/xml_iarchive.cpp @@ -13,16 +13,7 @@ #endif #define BOOST_ARCHIVE_SOURCE - -// the following works around an issue between spirit 1.61 and borland. -// it turns out the the certain spirit stuff must be defined before -// certain parts of mpl. including this here makes sure that happens -#include <boost/config.hpp> -#include <boost/detail/workaround.hpp> -#if BOOST_WORKAROUND(__BORLANDC__, <= 0x560 ) -#include <boost/archive/impl/basic_xml_grammar.hpp> -#endif - +#include <boost/serialization/config.hpp> #include <boost/archive/xml_iarchive.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> diff --git a/libs/serialization/src/xml_oarchive.cpp b/libs/serialization/src/xml_oarchive.cpp index 88bcdd652b..c238845d63 100644 --- a/libs/serialization/src/xml_oarchive.cpp +++ b/libs/serialization/src/xml_oarchive.cpp @@ -13,6 +13,7 @@ #endif #define BOOST_ARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/xml_oarchive.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> diff --git a/libs/serialization/src/xml_wgrammar.cpp b/libs/serialization/src/xml_wgrammar.cpp index d3dd844d53..7c053e8098 100644 --- a/libs/serialization/src/xml_wgrammar.cpp +++ b/libs/serialization/src/xml_wgrammar.cpp @@ -15,12 +15,12 @@ #else #define BOOST_WARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/impl/basic_xml_grammar.hpp> using namespace boost::spirit::classic; // fixup for RogueWave -#include <boost/config.hpp> #if ! defined(__SGI_STL_PORT) \ && defined(BOOST_RWSTD_VER) && BOOST_RWSTD_VER<=0x020101 #include <string> diff --git a/libs/serialization/src/xml_wiarchive.cpp b/libs/serialization/src/xml_wiarchive.cpp index 02665488ab..8c60abf733 100644 --- a/libs/serialization/src/xml_wiarchive.cpp +++ b/libs/serialization/src/xml_wiarchive.cpp @@ -8,26 +8,17 @@ // See http://www.boost.org for updates, documentation, and revision history. +#if (defined _MSC_VER) && (_MSC_VER == 1200) +# pragma warning (disable : 4786) // too long name, harmless warning +#endif + #include <boost/config.hpp> #ifdef BOOST_NO_STD_WSTREAMBUF #error "wide char i/o not supported on this platform" #else -#include <boost/detail/workaround.hpp> - -#if (defined _MSC_VER) && (_MSC_VER == 1200) -# pragma warning (disable : 4786) // too long name, harmless warning -#endif - #define BOOST_WARCHIVE_SOURCE - -// the following works around an issue between spirit 1.61 and borland. -// it turns out the the certain spirit stuff must be defined before -// certain parts of mpl. including this here makes sure that happens -#if BOOST_WORKAROUND(__BORLANDC__, <= 0x560 ) -#include <boost/archive/impl/basic_xml_grammar.hpp> -#endif - +#include <boost/serialization/config.hpp> #include <boost/archive/xml_wiarchive.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> diff --git a/libs/serialization/src/xml_woarchive.cpp b/libs/serialization/src/xml_woarchive.cpp index e71daaf6fd..f9b6ba389e 100644 --- a/libs/serialization/src/xml_woarchive.cpp +++ b/libs/serialization/src/xml_woarchive.cpp @@ -8,12 +8,17 @@ // See http://www.boost.org for updates, documentation, and revision history. +#if (defined _MSC_VER) && (_MSC_VER == 1200) +# pragma warning (disable : 4786) // too long name, harmless warning +#endif + #include <boost/config.hpp> #ifdef BOOST_NO_STD_WSTREAMBUF #error "wide char i/o not supported on this platform" #else #define BOOST_WARCHIVE_SOURCE +#include <boost/serialization/config.hpp> #include <boost/archive/xml_woarchive.hpp> #include <boost/archive/detail/archive_serializer_map.hpp> diff --git a/libs/serialization/test/A.hpp b/libs/serialization/test/A.hpp index 6ba98fa7ae..84e1419c98 100644 --- a/libs/serialization/test/A.hpp +++ b/libs/serialization/test/A.hpp @@ -44,17 +44,15 @@ namespace std{ #include <boost/preprocessor/facilities/empty.hpp> -#include "test_decl.hpp" - #if defined(A_IMPORT) - #define DLL_DECL IMPORT_DECL + #define DLL_DECL BOOST_SYMBOL_IMPORT #elif defined(A_EXPORT) - #define DLL_DECL EXPORT_DECL + #define DLL_DECL BOOST_SYMBOL_EXPORT #else - #define DLL_DECL(x) + #define DLL_DECL #endif -class DLL_DECL(BOOST_PP_EMPTY()) A +class DLL_DECL A { private: friend class boost::serialization::access; diff --git a/libs/serialization/test/Jamfile.v2 b/libs/serialization/test/Jamfile.v2 index c993a0f7f0..08fde1f169 100644 --- a/libs/serialization/test/Jamfile.v2 +++ b/libs/serialization/test/Jamfile.v2 @@ -11,6 +11,9 @@ project libs/serialization/test : requirements <source>/boost/filesystem ; +# import rules for testing conditional on config file variables +import ../../config/checks/config : requires ; + # import rules from the boost serialization test # import ../util/test : test-bsl-run-no-lib ; import ../util/test : @@ -56,10 +59,12 @@ lib dll_polymorphic_derived2_lib ; test-suite "serialization" : - [ test-bsl-run_files test_array : A ] + [ test-bsl-run_files test_array : A : : [ requires cxx11_hdr_array ] ] # BOOST_NO_CXX11_HDR_ARRAY + [ test-bsl-run_files test_boost_array : A ] + [ test-bsl-run_files test_native_array : A ] [ test-bsl-run_files test_binary ] - [ test-bsl-run_files test_class_info_load ] [ test-bsl-run_files test_class_info_save ] + [ test-bsl-run_files test_class_info_load ] [ test-bsl-run_files test_bitset ] [ test-bsl-run_files test_complex ] [ test-bsl-run_files test_contained_class : A ] @@ -72,11 +77,15 @@ test-suite "serialization" : [ test-bsl-run_files test_diamond ] [ test-bsl-run_files test_diamond_complex ] [ test-bsl-run_files test_exported : polymorphic_base ] + [ test-bsl-run_files test_forward_list : A : : [ requires cxx11_hdr_forward_list ] ] # BOOST_NO_CXX11_HDR_FORWARD_LIST + [ test-bsl-run_files test_forward_list_ptrs : A : : [ requires cxx11_hdr_forward_list ] ] # BOOST_NO_CXX11_HDR_FORWARD_LIST [ test-bsl-run_files test_helper_support ] [ test-bsl-run_files test_interrupts ] [ 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_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 ] [ test-bsl-run_files test_multiple_ptrs : A ] [ test-bsl-run_files test_multiple_inheritance ] @@ -93,6 +102,9 @@ test-suite "serialization" : [ test-bsl-run_files test_recursion : A ] [ test-bsl-run_files test_registered ] [ test-bsl-run_files test_set : A ] + [ test-bsl-run_files test_set_hashed : A : : [ requires hash ] ] # BOOST_HAS_HASH + [ test-bsl-run_files test_set_unordered : A : : [ requires cxx11_hdr_unordered_set ] ] # BOOST_NO_CXX11_HDR_UNORDERED_SET + [ test-bsl-run_files test_set_boost_unordered : A ] [ test-bsl-run_files test_simple_class : A ] [ test-bsl-run_files test_simple_class_ptr : A ] [ test-bsl-run_files test_split ] @@ -110,10 +122,12 @@ test-suite "serialization" : [ test-bsl-run_files test_shared_ptr_132 ] [ test-bsl-run_polymorphic_archive test_polymorphic : test_polymorphic_A A ] [ test-bsl-run_polymorphic_archive test_polymorphic2 : test_polymorphic2imp ] + [ test-bsl-run_polymorphic_archive test_polymorphic_helper ] ; if ! $(BOOST_ARCHIVE_LIST) { test-suite "serialization2" : + [ test-bsl-run-no-lib test_inclusion ] [ test-bsl-run test_dll_exported : : dll_polymorphic_derived2_lib ] [ test-bsl-run test_dll_simple : : dll_a_lib ] [ compile test_dll_plugin.cpp ] @@ -124,22 +138,21 @@ if ! $(BOOST_ARCHIVE_LIST) { [ test-bsl-run test_reset_object_address : A ] [ test-bsl-run test_void_cast ] [ test-bsl-run test_mult_archive_types ] - - [ test-bsl-run-no-lib test_iterators ] - [ test-bsl-run-no-lib test_iterators_base64 ] - [ test-bsl-run-no-lib test_inclusion ] - [ test-bsl-run-no-lib test_smart_cast ] - - [ test-bsl-run-no-lib test_utf8_codecvt - : ../src/utf8_codecvt_facet + [ test-bsl-run test_iterators ] + [ test-bsl-run test_iterators_base64 ] + [ test-bsl-run test_smart_cast ] + [ test-bsl-run test_utf8_codecvt + : + : : <dependency>../../config/test/all//BOOST_NO_STD_WSTREAMBUF ] - [ test-bsl-run-no-lib test_codecvt_null - : ../src/codecvt_null + [ test-bsl-run test_codecvt_null + : ../src/codecvt_null + : : <dependency>../../config/test/all//BOOST_NO_STD_WSTREAMBUF ] - - [ test-bsl-run-no-lib test_z ] + + #[ test-bsl-run test_z ] # should fail compilation [ compile-fail test_not_serializable.cpp ] diff --git a/libs/serialization/test/base.hpp b/libs/serialization/test/base.hpp index c27d989f2a..853bbc1873 100644 --- a/libs/serialization/test/base.hpp +++ b/libs/serialization/test/base.hpp @@ -16,21 +16,21 @@ // See http://www.boost.org for updates, documentation, and revision history. +#include <boost/config.hpp> + #include <boost/serialization/access.hpp> #include <boost/serialization/assume_abstract.hpp> #include <boost/preprocessor/facilities/empty.hpp> -#include "test_decl.hpp" - #if defined(BASE_IMPORT) - #define DLL_DECL IMPORT_DECL + #define DLL_DECL BOOST_SYMBOL_IMPORT #elif defined(BASE_EXPORT) - #define DLL_DECL EXPORT_DECL + #define DLL_DECL BOOST_SYMBOL_EXPORT #else - #define DLL_DECL(x) + #define DLL_DECL #endif -class DLL_DECL(BOOST_PP_EMPTY()) base +class DLL_DECL base { friend class boost::serialization::access; template<class Archive> diff --git a/libs/serialization/test/derived2.hpp b/libs/serialization/test/derived2.hpp index d16f2571aa..4be59166db 100644 --- a/libs/serialization/test/derived2.hpp +++ b/libs/serialization/test/derived2.hpp @@ -16,23 +16,23 @@ // See http://www.boost.org for updates, documentation, and revision history. +#include <boost/config.hpp> + #include <boost/serialization/export.hpp> #include <boost/serialization/access.hpp> #define BASE_IMPORT #include "base.hpp" -#include "test_decl.hpp" - #if defined(DERIVED2_IMPORT) - #define DLL_DECL IMPORT_DECL + #define DLL_DECL BOOST_SYMBOL_IMPORT #elif defined(DERIVED2_EXPORT) - #define DLL_DECL EXPORT_DECL + #define DLL_DECL BOOST_SYMBOL_EXPORT #else - #define DLL_DECL(x) + #define DLL_DECL #endif -class DLL_DECL(BOOST_PP_EMPTY()) derived2 : +class DLL_DECL derived2 : public base { friend class boost::serialization::access; diff --git a/libs/serialization/test/dll_a.cpp b/libs/serialization/test/dll_a.cpp index 33c6dc3b09..3bc71955da 100644 --- a/libs/serialization/test/dll_a.cpp +++ b/libs/serialization/test/dll_a.cpp @@ -20,12 +20,12 @@ #include <boost/archive/text_iarchive.hpp> template -EXPORT_DECL(void) A::serialize( +BOOST_SYMBOL_EXPORT void A::serialize( boost::archive::text_oarchive &ar, const unsigned int /* file_version */ ); template -EXPORT_DECL(void) A::serialize( +BOOST_SYMBOL_EXPORT void A::serialize( boost::archive::text_iarchive &ar, const unsigned int /* file_version */ ); @@ -36,12 +36,12 @@ EXPORT_DECL(void) A::serialize( #include <boost/archive/polymorphic_iarchive.hpp> template -EXPORT_DECL(void) A::serialize( +BOOST_SYMBOL_EXPORT void A::serialize( boost::archive::polymorphic_oarchive &ar, const unsigned int /* file_version */ ); template -EXPORT_DECL(void) A::serialize( +BOOST_SYMBOL_EXPORT void A::serialize( boost::archive::polymorphic_iarchive &ar, const unsigned int /* file_version */ ); diff --git a/libs/serialization/test/dll_base.cpp b/libs/serialization/test/dll_base.cpp index e33fa5dee5..87645b4d01 100644 --- a/libs/serialization/test/dll_base.cpp +++ b/libs/serialization/test/dll_base.cpp @@ -37,19 +37,19 @@ void base::serialize( // explicit instantiation in this case. //BOOST_CLASS_EXPORT(polymorphic_base) -template EXPORT_DECL(void) base::serialize( +template BOOST_SYMBOL_EXPORT void base::serialize( boost::archive::text_oarchive & ar, const unsigned int version ); -template EXPORT_DECL(void) base::serialize( +template BOOST_SYMBOL_EXPORT void base::serialize( boost::archive::text_iarchive & ar, const unsigned int version ); -template EXPORT_DECL(void) base::serialize( +template BOOST_SYMBOL_EXPORT void base::serialize( boost::archive::polymorphic_oarchive & ar, const unsigned int version ); -template EXPORT_DECL(void) base::serialize( +template BOOST_SYMBOL_EXPORT void base::serialize( boost::archive::polymorphic_iarchive & ar, const unsigned int version ); diff --git a/libs/serialization/test/dll_derived2.cpp b/libs/serialization/test/dll_derived2.cpp index 4065c3d234..e5757b3f33 100644 --- a/libs/serialization/test/dll_derived2.cpp +++ b/libs/serialization/test/dll_derived2.cpp @@ -9,6 +9,8 @@ // Build a dll which contains the serialization for a class A // used in testing distribution of serialization code in DLLS +#include <boost/config.hpp> + #include <boost/serialization/nvp.hpp> #define DERIVED2_EXPORT @@ -26,11 +28,11 @@ void derived2::serialize( #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> -template EXPORT_DECL(void) derived2::serialize( +template BOOST_SYMBOL_EXPORT void derived2::serialize( boost::archive::text_oarchive & ar, const unsigned int version ); -template EXPORT_DECL(void) derived2::serialize( +template BOOST_SYMBOL_EXPORT void derived2::serialize( boost::archive::text_iarchive & ar, const unsigned int version ); @@ -38,11 +40,11 @@ template EXPORT_DECL(void) derived2::serialize( #include <boost/archive/polymorphic_oarchive.hpp> #include <boost/archive/polymorphic_iarchive.hpp> -template EXPORT_DECL(void) derived2::serialize( +template BOOST_SYMBOL_EXPORT void derived2::serialize( boost::archive::polymorphic_oarchive & ar, const unsigned int version ); -template EXPORT_DECL(void) derived2::serialize( +template BOOST_SYMBOL_EXPORT void derived2::serialize( boost::archive::polymorphic_iarchive & ar, const unsigned int version ); diff --git a/libs/serialization/test/polymorphic_base.cpp b/libs/serialization/test/polymorphic_base.cpp index ffe8b16b93..3dfd89ce4f 100644 --- a/libs/serialization/test/polymorphic_base.cpp +++ b/libs/serialization/test/polymorphic_base.cpp @@ -9,6 +9,8 @@ // See http://www.boost.org for updates, documentation, and revision history. #include <boost/serialization/export.hpp> + +#define POLYMORPHIC_BASE_EXPORT #include "polymorphic_base.hpp" BOOST_CLASS_EXPORT_IMPLEMENT(polymorphic_base) diff --git a/libs/serialization/test/polymorphic_base.hpp b/libs/serialization/test/polymorphic_base.hpp index 4e3b833559..187c2157bf 100644 --- a/libs/serialization/test/polymorphic_base.hpp +++ b/libs/serialization/test/polymorphic_base.hpp @@ -16,23 +16,23 @@ // See http://www.boost.org for updates, documentation, and revision history. +#include <boost/config.hpp> + #include <boost/serialization/access.hpp> #include <boost/serialization/assume_abstract.hpp> #include <boost/serialization/export.hpp> #include <boost/serialization/type_info_implementation.hpp> #include <boost/serialization/extended_type_info_no_rtti.hpp> -#include "test_decl.hpp" - -#if defined(POLYMORPHIC_DERIVED_IMPORT) - #define DLL_DECL IMPORT_DECL -#elif defined(POLYMORPHIC_DERIVED_EXPORT) - #define DLL_DECL EXPORT_DECL +#if defined(POLYMORPHIC_BASE_IMPORT) + #define DLL_DECL BOOST_SYMBOL_IMPORT +#elif defined(POLYMORPHIC_BASE_EXPORT) + #define DLL_DECL BOOST_SYMBOL_EXPORT #else - #define DLL_DECL(x) + #define DLL_DECL #endif -class DLL_DECL(BOOST_PP_EMPTY()) polymorphic_base +class BOOST_SYMBOL_VISIBLE polymorphic_base { friend class boost::serialization::access; template<class Archive> @@ -48,6 +48,8 @@ public: virtual ~polymorphic_base(){}; }; +#undef DLL_DECL + BOOST_SERIALIZATION_ASSUME_ABSTRACT(polymorphic_base) // the no_rtti system requires this !!! diff --git a/libs/serialization/test/polymorphic_derived2.cpp b/libs/serialization/test/polymorphic_derived2.cpp index e7c6a15b61..4919b16faa 100644 --- a/libs/serialization/test/polymorphic_derived2.cpp +++ b/libs/serialization/test/polymorphic_derived2.cpp @@ -27,11 +27,11 @@ void polymorphic_derived2::serialize( #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> -template EXPORT_DECL(void) polymorphic_derived2::serialize( +template BOOST_SYMBOL_EXPORT void polymorphic_derived2::serialize( boost::archive::text_oarchive & ar, const unsigned int version ); -template EXPORT_DECL(void) polymorphic_derived2::serialize( +template BOOST_SYMBOL_EXPORT void polymorphic_derived2::serialize( boost::archive::text_iarchive & ar, const unsigned int version ); @@ -40,11 +40,11 @@ template EXPORT_DECL(void) polymorphic_derived2::serialize( #include <boost/archive/polymorphic_iarchive.hpp> #include <boost/archive/polymorphic_oarchive.hpp> -template EXPORT_DECL(void) polymorphic_derived2::serialize( +template BOOST_SYMBOL_EXPORT void polymorphic_derived2::serialize( boost::archive::polymorphic_oarchive & ar, const unsigned int version ); -template EXPORT_DECL(void) polymorphic_derived2::serialize( +template BOOST_SYMBOL_EXPORT void polymorphic_derived2::serialize( boost::archive::polymorphic_iarchive & ar, const unsigned int version ); @@ -60,6 +60,6 @@ BOOST_CLASS_EXPORT_IMPLEMENT(polymorphic_derived2) BOOST_SERIALIZATION_FACTORY_0(polymorphic_derived2) template -EXPORT_DECL(polymorphic_derived2 *) +BOOST_SYMBOL_EXPORT void polymorphic_derived2 * boost::serialization::factory<polymorphic_derived2, 0>(std::va_list ap); #endif diff --git a/libs/serialization/test/polymorphic_derived2.hpp b/libs/serialization/test/polymorphic_derived2.hpp index 28f020e935..01979c6052 100644 --- a/libs/serialization/test/polymorphic_derived2.hpp +++ b/libs/serialization/test/polymorphic_derived2.hpp @@ -16,6 +16,8 @@ // See http://www.boost.org for updates, documentation, and revision history. +#include <boost/config.hpp> + #include <boost/serialization/access.hpp> #include <boost/serialization/nvp.hpp> #include <boost/serialization/base_object.hpp> @@ -26,7 +28,15 @@ #include "polymorphic_base.hpp" -class DLL_DECL(BOOST_PP_EMPTY()) polymorphic_derived2 : +#if defined(POLYMORPHIC_DERIVED2_IMPORT) + #define DLL_DECL BOOST_SYMBOL_IMPORT +#elif defined(POLYMORPHIC_DERIVED2_EXPORT) + #define DLL_DECL BOOST_SYMBOL_EXPORT +#else + #define DLL_DECL +#endif + +class DLL_DECL polymorphic_derived2 : public polymorphic_base { friend class boost::serialization::access; diff --git a/libs/serialization/test/test.dat b/libs/serialization/test/test.dat deleted file mode 100644 index 3f09ecb3a5..0000000000 --- a/libs/serialization/test/test.dat +++ /dev/null @@ -1 +0,0 @@ -߿ࠀ𐀀
\ No newline at end of file diff --git a/libs/serialization/test/test2.dat b/libs/serialization/test/test2.dat deleted file mode 100644 index 3f09ecb3a5..0000000000 --- a/libs/serialization/test/test2.dat +++ /dev/null @@ -1 +0,0 @@ -߿ࠀ𐀀
\ No newline at end of file diff --git a/libs/serialization/test/test_array.cpp b/libs/serialization/test/test_array.cpp index 9179fd02fd..d0941d922f 100644 --- a/libs/serialization/test/test_array.cpp +++ b/libs/serialization/test/test_array.cpp @@ -20,132 +20,15 @@ namespace std{ using ::remove; } #endif -#include <boost/foreach.hpp> #include "test_tools.hpp" +#include <boost/serialization/array.hpp> #include <boost/core/no_exceptions_support.hpp> #include <boost/archive/archive_exception.hpp> -#include <boost/array.hpp> #include "A.hpp" #include "A.ipp" template <class T> -int test_native_array(){ - const char * testfile = boost::archive::tmpnam(NULL); - BOOST_REQUIRE(NULL != testfile); - - // test array of objects - const T a_array[10]={T(),T(),T(),T(),T(),T(),T(),T(),T(),T()}; - const T b_array[2][3]={{T(),T(),T()},{T(),T(),T()}}; - { - test_ostream os(testfile, TEST_STREAM_FLAGS); - { - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << boost::serialization::make_nvp("a_array", a_array); - oa << boost::serialization::make_nvp("b_array", b_array); - } - os.close(); - } - { - T a_array1[10]; - T b_array1[2][3]; - test_istream is(testfile, TEST_STREAM_FLAGS); - { - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("a_array", a_array1); - ia >> boost::serialization::make_nvp("b_array", b_array1); - } - is.close(); - BOOST_CHECK(std::equal(& a_array[0], & a_array[10], & a_array1[0])); - BOOST_CHECK(b_array[0][0] == b_array1[0][0]); - BOOST_CHECK(b_array[1][0] == b_array1[1][0]); - } - { - T a_array1[9]; - T b_array1[2][3]; - test_istream is(testfile, TEST_STREAM_FLAGS); - { - BOOST_TRY { - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - bool exception_invoked = false; - BOOST_TRY { - ia >> boost::serialization::make_nvp("a_array", a_array1); - ia >> boost::serialization::make_nvp("b_array", b_array1); - } - BOOST_CATCH (boost::archive::archive_exception ae){ - BOOST_CHECK( - boost::archive::archive_exception::array_size_too_short - == ae.code - ); - exception_invoked = true; - } - BOOST_CATCH_END - BOOST_CHECK(exception_invoked); - } - BOOST_CATCH (boost::archive::archive_exception ae){} - BOOST_CATCH_END - } - is.close(); - } - std::remove(testfile); - return EXIT_SUCCESS; -} - -template <class T> -int test_boost_array(){ - const char * testfile = boost::archive::tmpnam(NULL); - BOOST_REQUIRE(NULL != testfile); - - // test array of objects - const boost::array<T,10> a_array = {{T(),T(),T(),T(),T(),T(),T(),T(),T(),T()}}; - { - test_ostream os(testfile, TEST_STREAM_FLAGS); - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << boost::serialization::make_nvp("a_array", a_array); - } - { - boost::array<T,10> a_array1; - test_istream is(testfile, TEST_STREAM_FLAGS); - { - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("a_array", a_array1); - } - is.close(); - BOOST_CHECK(std::equal(a_array.begin(), a_array.end(), a_array1.begin())); - } - { - boost::array<T, 9> a_array1; - test_istream is(testfile, TEST_STREAM_FLAGS); - { - BOOST_TRY { - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - bool exception_invoked = false; - BOOST_TRY { - ia >> boost::serialization::make_nvp("a_array", a_array1); - } - BOOST_CATCH (boost::archive::archive_exception ae){ - BOOST_CHECK( - boost::archive::archive_exception::array_size_too_short - == ae.code - ); - exception_invoked = true; - } - BOOST_CATCH_END - BOOST_CHECK(exception_invoked); - } - BOOST_CATCH (boost::archive::archive_exception ae){} - BOOST_CATCH_END - } - is.close(); - } - std::remove(testfile); - return EXIT_SUCCESS; -} - -#ifndef BOOST_NO_CXX11_HDR_ARRAY -#include <array> - -template <class T> int test_std_array(){ const char * testfile = boost::archive::tmpnam(NULL); BOOST_REQUIRE(NULL != testfile); @@ -170,55 +53,31 @@ int test_std_array(){ std::array<T, 9> a_array1; test_istream is(testfile, TEST_STREAM_FLAGS); { + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + bool exception_invoked = false; BOOST_TRY { - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - bool exception_invoked = false; - BOOST_TRY { - ia >> boost::serialization::make_nvp("a_array", a_array1); - } - BOOST_CATCH (boost::archive::archive_exception ae){ - BOOST_CHECK( - boost::archive::archive_exception::array_size_too_short - == ae.code - ); - exception_invoked = true; - } - BOOST_CATCH_END - BOOST_CHECK(exception_invoked); + ia >> boost::serialization::make_nvp("a_array", a_array1); + } + BOOST_CATCH (boost::archive::archive_exception ae){ + BOOST_CHECK( + boost::archive::archive_exception::array_size_too_short + == ae.code + ); + exception_invoked = true; } - BOOST_CATCH (boost::archive::archive_exception ae){} BOOST_CATCH_END + BOOST_CHECK(exception_invoked); } is.close(); } std::remove(testfile); return EXIT_SUCCESS; } -#endif -int test_main( int /* argc */, char* /* argv */[] ) -{ +int test_main( int /* argc */, char* /* argv */[] ){ int res; - // native array - res = test_native_array<A>(); - if (res != EXIT_SUCCESS) - return EXIT_FAILURE; - // test an int array for which optimized versions should be available - res = test_native_array<int>(); - if (res != EXIT_SUCCESS) - return EXIT_FAILURE; - - // boost array - res = test_boost_array<A>(); - if (res != EXIT_SUCCESS) - return EXIT_FAILURE; - // test an int array for which optimized versions should be available - res = test_boost_array<int>(); - if (res != EXIT_SUCCESS) - return EXIT_FAILURE; // std array - #ifndef BOOST_NO_CXX11_HDR_ARRAY res = test_std_array<A>(); if (res != EXIT_SUCCESS) return EXIT_FAILURE; @@ -226,7 +85,7 @@ int test_main( int /* argc */, char* /* argv */[] ) res = test_std_array<int>(); if (res != EXIT_SUCCESS) return EXIT_FAILURE; - #endif + return EXIT_SUCCESS; } diff --git a/libs/serialization/test/test_boost_array.cpp b/libs/serialization/test/test_boost_array.cpp new file mode 100644 index 0000000000..6f8a812657 --- /dev/null +++ b/libs/serialization/test/test_boost_array.cpp @@ -0,0 +1,93 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_array.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 <stdlib.h> + +#include <boost/config.hpp> +#include <cstddef> +#include <fstream> +#include <algorithm> // equal +#include <cstdio> // remove +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif +#include "test_tools.hpp" +#include <boost/core/no_exceptions_support.hpp> +#include <boost/archive/archive_exception.hpp> +#include <boost/array.hpp> + +#include "A.hpp" +#include "A.ipp" + +template <class T> +int test_boost_array(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + // test array of objects + const boost::array<T,10> a_array = {{T(),T(),T(),T(),T(),T(),T(),T(),T(),T()}}; + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("a_array", a_array); + } + { + boost::array<T,10> a_array1; + test_istream is(testfile, TEST_STREAM_FLAGS); + { + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("a_array", a_array1); + } + is.close(); + BOOST_CHECK(std::equal(a_array.begin(), a_array.end(), a_array1.begin())); + } + { + boost::array<T, 9> a_array1; + test_istream is(testfile, TEST_STREAM_FLAGS); + { + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + bool exception_invoked = false; + BOOST_TRY { + ia >> boost::serialization::make_nvp("a_array", a_array1); + } + BOOST_CATCH (boost::archive::archive_exception ae){ + BOOST_CHECK( + boost::archive::archive_exception::array_size_too_short + == ae.code + ); + exception_invoked = true; + } + BOOST_CATCH_END + BOOST_CHECK(exception_invoked); + } + is.close(); + } + std::remove(testfile); + return EXIT_SUCCESS; +} + +int test_main( int /* argc */, char* /* argv */[] ){ + int res; + + // boost array + res = test_boost_array<A>(); + if (res != EXIT_SUCCESS) + return EXIT_FAILURE; + // test an int array for which optimized versions should be available + res = test_boost_array<int>(); + if (res != EXIT_SUCCESS) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +// EOF diff --git a/libs/serialization/test/test_codecvt_null.cpp b/libs/serialization/test/test_codecvt_null.cpp index 40abd8885a..5c78380b1a 100644 --- a/libs/serialization/test/test_codecvt_null.cpp +++ b/libs/serialization/test/test_codecvt_null.cpp @@ -28,7 +28,6 @@ namespace std{ #include "test_tools.hpp" -#include <boost/archive/add_facet.hpp> #include <boost/archive/codecvt_null.hpp> #include <boost/archive/iterators/ostream_iterator.hpp> #include <boost/archive/iterators/istream_iterator.hpp> @@ -73,40 +72,30 @@ int test_main( int /* argc */, char* /* argv */[] ) { BOOST_REQUIRE(NULL != testfile); std::locale old_loc; - std::locale * null_locale = - boost::archive::add_facet(old_loc, new boost::archive::codecvt_null<wchar_t>); + std::locale null_locale = std::locale( + old_loc, + new boost::archive::codecvt_null<wchar_t> + ); typedef test_data<sizeof(wchar_t)> td; { std::wofstream ofs; - ofs.imbue(*null_locale); + ofs.imbue(null_locale); ofs.open(testfile, std::ios::binary); std::copy( td::wchar_encoding, - #if ! defined(__BORLANDC__) - // borland 5.60 complains about this - td::wchar_encoding + sizeof(td::wchar_encoding)/sizeof(wchar_t), - #else - // so use this instead - td::wchar_encoding + 6, - #endif + td::wchar_encoding + sizeof(td::wchar_encoding)/sizeof(wchar_t), boost::archive::iterators::ostream_iterator<wchar_t>(ofs) ); } bool ok = false; { std::wifstream ifs; - ifs.imbue(*null_locale); + ifs.imbue(null_locale); ifs.open(testfile, std::ios::binary); ok = std::equal( td::wchar_encoding, - #if ! defined(__BORLANDC__) - // borland 5.60 complains about this - td::wchar_encoding + sizeof(td::wchar_encoding)/sizeof(wchar_t), - #else - // so use this instead - td::wchar_encoding + 6, - #endif + td::wchar_encoding + sizeof(td::wchar_encoding)/sizeof(wchar_t), boost::archive::iterators::istream_iterator<wchar_t>(ifs) ); } @@ -114,13 +103,13 @@ int test_main( int /* argc */, char* /* argv */[] ) { BOOST_CHECK(ok); { std::wofstream ofs("testfile2"); - ofs.imbue(*null_locale); + ofs.imbue(null_locale); int i = 10; ofs << i; ofs.close(); std::wifstream ifs("testfile2"); - ifs.imbue(*null_locale); + ifs.imbue(null_locale); int i2; ifs >> i2; std::cout << "i=" << i << std::endl; @@ -129,7 +118,6 @@ int test_main( int /* argc */, char* /* argv */[] ) { ifs.close(); } - delete null_locale; std::remove(testfile); return EXIT_SUCCESS; } diff --git a/libs/serialization/test/test_decl.hpp b/libs/serialization/test/test_decl.hpp deleted file mode 100644 index 53ac12cf11..0000000000 --- a/libs/serialization/test/test_decl.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef BOOST_TEST_DECL_HPP -#define BOOST_TEST_DECL_HPP - -// MS compatible compilers support #pragma once -#if defined(_MSC_VER) -# pragma once -#endif - -/////////1/////////2///////// 3/////////4/////////5/////////6/////////7/////////8 -// test_decl.hpp -// -// (c) Copyright Robert Ramey 2004 -// 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) -// -// See library home page at http://www.boost.org/libs/serialization -// export if this is our own source, otherwise import: - -// usage: -// -// class header declarations should look something like: -// -// #include "test_decl.hpp" -// #if defined(A_CPP) -// #define DLL_DECL IMPORT_DECL(BOOST_PP_EMPTY()) -// #else -// #define DLL_DECL EXPORT_DECL(BOOST_PP_EMPTY()) -// #endif -// -// class DLL_DECL A { -// ... -// }; -// -// #undef DLL_DECL -// -// code which includes such headers should look something like: -// -// #include "A.hpp" -// -// code which builds dll should like like -// -// #define A_CPP -// #include "A.hpp" -// -// A::A(){ -// ... -// } -// ... -// - -#include <boost/config.hpp> - -#ifdef BOOST_HAS_DECLSPEC // defined in config system - #if ! defined(EXPORT_DECL) - #if defined(__BORLANDC__) - #define EXPORT_DECL(T) T __export - #else - #define EXPORT_DECL(T) __declspec(dllexport) T - #endif - #endif - #if ! defined(IMPORT_DECL) - #if defined(__BORLANDC__) - #define IMPORT_DECL(T) T __import - #else - #define IMPORT_DECL(T) __declspec(dllimport) T - #endif - #endif -#else - #define IMPORT_DECL(T) T - #define EXPORT_DECL(T) T -#endif // BOOST_HAS_DECLSPEC - -#endif // BOOST_TEST_DECL_HPP diff --git a/libs/serialization/test/test_derived.cpp b/libs/serialization/test/test_derived.cpp index 6a9aee874a..4c3697b179 100644 --- a/libs/serialization/test/test_derived.cpp +++ b/libs/serialization/test/test_derived.cpp @@ -31,7 +31,7 @@ class base template<class Archive> void serialize(Archive & /* ar */, const unsigned int /* file_version */){ } -protected: +public: virtual ~base(){}; }; diff --git a/libs/serialization/test/test_dll_exported.cpp b/libs/serialization/test/test_dll_exported.cpp index 41a2b2adb5..03095ab1de 100644 --- a/libs/serialization/test/test_dll_exported.cpp +++ b/libs/serialization/test/test_dll_exported.cpp @@ -45,6 +45,7 @@ namespace std{ #include <boost/serialization/export.hpp> #include <boost/serialization/access.hpp> +#define POLYMORPHIC_BASE_IMPORT #include "polymorphic_base.hpp" class polymorphic_derived1 : public polymorphic_base diff --git a/libs/serialization/test/test_exported.cpp b/libs/serialization/test/test_exported.cpp index 7db68c2104..63a8ac6ef1 100644 --- a/libs/serialization/test/test_exported.cpp +++ b/libs/serialization/test/test_exported.cpp @@ -66,11 +66,11 @@ void polymorphic_derived2::serialize( BOOST_CLASS_EXPORT_IMPLEMENT(polymorphic_derived2) -template EXPORT_DECL(void) polymorphic_derived2::serialize( +template BOOST_SYMBOL_EXPORT void polymorphic_derived2::serialize( test_oarchive & ar, const unsigned int version ); -template EXPORT_DECL(void) polymorphic_derived2::serialize( +template BOOST_SYMBOL_EXPORT void polymorphic_derived2::serialize( test_iarchive & ar, const unsigned int version ); diff --git a/libs/serialization/example/demo_dll.cpp b/libs/serialization/test/test_forward_list.cpp index 31556e7cdb..5a162a5813 100644 --- a/libs/serialization/example/demo_dll.cpp +++ b/libs/serialization/test/test_forward_list.cpp @@ -1,5 +1,5 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// test_derived_class.cpp +// test_list.cpp // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . // Use, modification and distribution is subject to the Boost Software @@ -10,41 +10,45 @@ #include <cstddef> // NULL #include <fstream> - #include <cstdio> // remove -#include <boost/config.hpp> #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ using ::remove; } #endif +#include <boost/config.hpp> +#ifdef BOOST_NO_CXX11_HDR_FORWARD_LIST +#error this test presumes support for forward_list.hpp +#endif +#include <boost/serialization/forward_list.hpp> + +#include <boost/archive/archive_exception.hpp> #include "test_tools.hpp" -#include "B.hpp" +#include "A.hpp" #include "A.ipp" -int test_main( int argc, char* argv[] ) +int test_main( int /* argc */, char* /* argv */[] ) { - const char * testfile = boost::archive::tmpnam(NULL); - - BOOST_REQUIRE(NULL != testfile); - - B b, b1; - + const char * testfile = boost::archive::tmpnam(NULL); + std::forward_list<A> 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("b", b); + oa << boost::serialization::make_nvp("aslist", aslist); } - { + std::forward_list<A> aslist1;{ test_istream is(testfile, TEST_STREAM_FLAGS); test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("b1", b1); + ia >> boost::serialization::make_nvp("aslist", aslist1); } - BOOST_CHECK(b == b1); + BOOST_CHECK(aslist == aslist1); std::remove(testfile); return EXIT_SUCCESS; } // EOF + diff --git a/libs/serialization/test/test_forward_list_ptrs.cpp b/libs/serialization/test/test_forward_list_ptrs.cpp new file mode 100644 index 0000000000..3899461235 --- /dev/null +++ b/libs/serialization/test/test_forward_list_ptrs.cpp @@ -0,0 +1,182 @@ +/////////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 <cstddef> +#include <fstream> + +#include <boost/config.hpp> +#include <cstdio> // remove +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +#include <boost/type_traits/is_pointer.hpp> +#include <boost/static_assert.hpp> +#include <boost/checked_delete.hpp> + +#include <boost/archive/archive_exception.hpp> +#include "test_tools.hpp" + +#include <boost/serialization/nvp.hpp> + +#include "A.hpp" +#include "A.ipp" + +template<class T> +struct ptr_equal_to : public std::binary_function<T, T, bool> +{ + 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 <boost/serialization/list.hpp> +void test_list(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + std::list<A *> alist; + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + A * free_a_ptr = new A; + alist.push_back(free_a_ptr); + alist.push_back(new A); + // verify that first element is the same as the free pointer + BOOST_CHECK((*alist.begin()) == free_a_ptr); + oa << boost::serialization::make_nvp("alist", alist); + oa << boost::serialization::make_nvp("free_a_ptr", free_a_ptr); + } + std::list<A *> alist1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + A * free_a_ptr1; + ia >> boost::serialization::make_nvp("alist", alist1); + ia >> boost::serialization::make_nvp("free_a_ptr", free_a_ptr1); + BOOST_CHECK( + alist.size() == alist1.size() + && std::equal(alist.begin(),alist.end(),alist1.begin(),ptr_equal_to<A *>()) + ); + // verify that first element is the same as the free pointer + BOOST_CHECK((*alist1.begin()) == free_a_ptr1); + } + + std::for_each( + alist.begin(), + alist.end(), + boost::checked_deleter<A>() + ); + std::for_each( + alist1.begin(), + alist1.end(), + boost::checked_deleter<A>() + ); + std::remove(testfile); +} + +#ifdef BOOST_HAS_SLIST +#include <boost/serialization/slist.hpp> +void test_slist(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + std::list<A *> 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<A *> 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<A *>()) + ); + } + std::for_each( + aslist.begin(), + aslist.end(), + boost::checked_deleter<A>() + ); + std::for_each( + aslist1.begin(), + aslist1.end(), + boost::checked_deleter<A>() + ); + std::remove(testfile); +} +#endif + +#ifndef BOOST_NO_CXX11_HDR_FORWARD_LIST +#include <boost/serialization/forward_list.hpp> +void test_forward_list(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + std::forward_list<A *> aslist; + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + aslist.push_front(new A); + aslist.push_front(new A); + oa << boost::serialization::make_nvp("aslist", aslist); + } + std::forward_list<A *> aslist1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("aslist", aslist1); + BOOST_CHECK( + std::equal(aslist.begin(),aslist.end(),aslist1.begin(),ptr_equal_to<A *>()) + ); + } + std::for_each( + aslist.begin(), + aslist.end(), + boost::checked_deleter<A>() + ); + std::for_each( + aslist1.begin(), + aslist1.end(), + boost::checked_deleter<A>() + ); + std::remove(testfile); +} +#endif + +int test_main( int /* argc */, char* /* argv */[] ) +{ + test_list(); + + #ifdef BOOST_HAS_SLIST + test_slist(); + #endif + + #ifndef BOOST_NO_CXX11_HDR_FORWARD_LIST + test_forward_list(); + #endif + + return EXIT_SUCCESS; +} + +// EOF diff --git a/libs/serialization/test/test_interrupts.cpp b/libs/serialization/test/test_interrupts.cpp index c1c3239b2f..cb81712a66 100644 --- a/libs/serialization/test/test_interrupts.cpp +++ b/libs/serialization/test/test_interrupts.cpp @@ -29,7 +29,7 @@ namespace std{ struct test_dummy_out { template<class Archive> - void save(Archive & ar, const unsigned int version) const { + void save(Archive & ar, const unsigned int /*version*/) const { throw boost::archive::archive_exception( boost::archive::archive_exception::other_exception ); @@ -77,10 +77,10 @@ int test_out(){ struct test_dummy_in { template<class Archive> - void save(Archive & ar, const unsigned int version) const { + void save(Archive & ar, const unsigned int /*version*/) const { } template<class Archive> - void load(Archive & ar, const unsigned int version){ + void load(Archive & ar, const unsigned int /*version*/){ throw boost::archive::archive_exception( boost::archive::archive_exception::other_exception ); diff --git a/libs/serialization/test/test_iterators.cpp b/libs/serialization/test/test_iterators.cpp index ef0ac424ef..048c7949d0 100644 --- a/libs/serialization/test/test_iterators.cpp +++ b/libs/serialization/test/test_iterators.cpp @@ -6,11 +6,14 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include <algorithm> // std::copy +//#include <algorithm> // std::copy, std::equal #include <vector> #include <cstdlib> // for rand #include <functional> #include <sstream> // used to test stream iterators +#include <clocale> +#include <iterator> // begin +#include <locale> // setlocale #include <boost/config.hpp> #ifdef BOOST_NO_STDC_NAMESPACE @@ -42,8 +45,8 @@ void test_wchar_from_mb(const wchar_t *la, const char * a, const unsigned int si typedef boost::archive::iterators::wchar_from_mb<const char *> translator; BOOST_CHECK(( std::equal( - translator(BOOST_MAKE_PFTO_WRAPPER(a)), - translator(BOOST_MAKE_PFTO_WRAPPER(a + size)), + translator(a), + translator(a + size), la ) )); @@ -53,13 +56,39 @@ void test_mb_from_wchar(const char * a, const wchar_t *la, const unsigned int si typedef boost::archive::iterators::mb_from_wchar<const wchar_t *> translator; BOOST_CHECK( std::equal( - translator(BOOST_MAKE_PFTO_WRAPPER(la)), - translator(BOOST_MAKE_PFTO_WRAPPER(la + size)), + translator(la), + translator(la + size), a ) ); } +void test_roundtrip(const wchar_t * la){ + std::size_t s = std::wcslen(la); + std::vector<char> a; + { + typedef boost::archive::iterators::mb_from_wchar<const wchar_t *> translator; + std::copy( + translator(la), + translator(la + s), + std::back_inserter(a) + ); + // note: wchar_from_mb NEEDS a termination null in order to function! + a.push_back(static_cast<char>(0)); + } + BOOST_CHECK(a.size() > 0); + std::vector<wchar_t> la2; + { + typedef boost::archive::iterators::wchar_from_mb<std::vector<char>::const_iterator> translator; + std::copy( + translator(a.begin()), + translator(), + std::back_inserter(la2) + ); + } + BOOST_CHECK(la2.size() == s); + BOOST_CHECK(std::equal(la, la + s, la2.begin())); +} #endif template<class CharType> @@ -72,8 +101,8 @@ void test_xml_escape( BOOST_CHECK( std::equal( - translator(BOOST_MAKE_PFTO_WRAPPER(xml)), - translator(BOOST_MAKE_PFTO_WRAPPER(xml + size)), + translator(xml), + translator(xml + size), xml_escaped ) ); @@ -91,8 +120,8 @@ void test_xml_unescape( BOOST_CHECK( std::equal( - translator(BOOST_MAKE_PFTO_WRAPPER(xml_escaped)), - translator(BOOST_MAKE_PFTO_WRAPPER(xml_escaped + size)), + translator(xml_escaped), + translator(xml_escaped + size), xml ) ); @@ -115,8 +144,8 @@ void test_transform_width(unsigned int size){ std::vector<char> vout; std::copy( - translator1(BOOST_MAKE_PFTO_WRAPPER(static_cast<char *>(rawdata))), - translator1(BOOST_MAKE_PFTO_WRAPPER(rawdata + size)), + translator1(static_cast<char *>(rawdata)), + translator1(rawdata + size), std::back_inserter(vout) ); @@ -132,8 +161,8 @@ void test_transform_width(unsigned int size){ std::vector<char> vin; std::copy( - translator2(BOOST_MAKE_PFTO_WRAPPER(vout.begin())), - translator2(BOOST_MAKE_PFTO_WRAPPER(vout.end())), + translator2(vout.begin()), + translator2(vout.end()), std::back_inserter(vin) ); @@ -182,7 +211,6 @@ test_main(int /* argc */, char* /* argv */ [] ) sizeof(xml_escaped) / sizeof(char) - 1 ); - const char a[] = "abcdefghijklmnopqrstuvwxyz"; #ifndef BOOST_NO_CWCHAR const wchar_t wxml[] = L"<+>+&+\"+'"; @@ -198,10 +226,17 @@ test_main(int /* argc */, char* /* argv */ [] ) sizeof(wxml_escaped) / sizeof(wchar_t) - 1 ); - const wchar_t la[] = L"abcdefghijklmnopqrstuvwxyz"; + const char b[] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; + const wchar_t lb[] = L"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; + test_mb_from_wchar(b, lb, sizeof(lb) / sizeof(wchar_t) - 1); + test_wchar_from_mb(lb, b, sizeof(b) / sizeof(char) - 1); - test_wchar_from_mb(la, a, sizeof(a) / sizeof(char) - 1); + const char a[] = "abcdefghijklmnopqrstuvwxyz"; + const wchar_t la[] = L"abcdefghijklmnopqrstuvwxyz"; test_mb_from_wchar(a, la, sizeof(la) / sizeof(wchar_t) - 1); + test_wchar_from_mb(la, a, sizeof(a) / sizeof(char) - 1); + + test_roundtrip(L"z\u00df\u6c34\U0001f34c"); test_stream_iterators<wchar_t>(la, sizeof(la)/sizeof(wchar_t) - 1); #endif diff --git a/libs/serialization/test/test_iterators_base64.cpp b/libs/serialization/test/test_iterators_base64.cpp index ebddf85d5e..cdfeabcec9 100644 --- a/libs/serialization/test/test_iterators_base64.cpp +++ b/libs/serialization/test/test_iterators_base64.cpp @@ -24,8 +24,6 @@ namespace std{ } #endif -#include <boost/serialization/pfto.hpp> - #include <boost/archive/iterators/binary_from_base64.hpp> #include <boost/archive/iterators/base64_from_binary.hpp> #include <boost/archive/iterators/insert_linebreaks.hpp> @@ -61,8 +59,8 @@ void test_base64(unsigned int size){ translate_out; std::copy( - translate_out(BOOST_MAKE_PFTO_WRAPPER(static_cast<CharType *>(rawdata))), - translate_out(BOOST_MAKE_PFTO_WRAPPER(rawdata + size)), + translate_out(static_cast<CharType *>(rawdata)), + translate_out(rawdata + size), std::back_inserter(text_base64) ); @@ -82,7 +80,7 @@ void test_base64(unsigned int size){ std::equal( rawdata, rawdata + size, - translate_in(BOOST_MAKE_PFTO_WRAPPER(text_base64.begin())) + translate_in(text_base64.begin()) ) ); diff --git a/libs/serialization/test/test_map.cpp b/libs/serialization/test/test_map.cpp index fa2ab226e9..66e6f885da 100644 --- a/libs/serialization/test/test_map.cpp +++ b/libs/serialization/test/test_map.cpp @@ -139,176 +139,11 @@ test_multimap(){ std::remove(testfile); } -#ifdef BOOST_HAS_HASH -#include <boost/serialization/hash_map.hpp> - -namespace BOOST_STD_EXTENSION_NAMESPACE { - template<> - struct hash<random_key>{ - std::size_t operator()(const random_key& r) const { - return static_cast<std::size_t>(r); - } - }; -} // namespace BOOST_STD_EXTENSION_NAMESPACE - -void -test_hash_map(){ - const char * testfile = boost::archive::tmpnam(NULL); - BOOST_REQUIRE(NULL != testfile); - - BOOST_CHECKPOINT("hash_map"); - // test hash_map of objects - BOOST_STD_EXTENSION_NAMESPACE::hash_map<random_key, A> ahash_map; - ahash_map.insert(std::make_pair(random_key(), A())); - ahash_map.insert(std::make_pair(random_key(), A())); - { - test_ostream os(testfile, TEST_STREAM_FLAGS); - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << boost::serialization::make_nvp("ahashmap",ahash_map); - } - BOOST_STD_EXTENSION_NAMESPACE::hash_map<random_key, A> ahash_map1; - { - test_istream is(testfile, TEST_STREAM_FLAGS); - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("ahashmap",ahash_map1); - } - - std::vector< std::pair<random_key, A> > tvec, tvec1; - std::copy(ahash_map.begin(), ahash_map.end(), std::back_inserter(tvec)); - std::sort(tvec.begin(), tvec.end()); - std::copy(ahash_map1.begin(), ahash_map1.end(), std::back_inserter(tvec1)); - std::sort(tvec1.begin(), tvec1.end()); - BOOST_CHECK(tvec == tvec1); - - std::remove(testfile); -} - -void -test_hash_multimap(){ - const char * testfile = boost::archive::tmpnam(NULL); - BOOST_REQUIRE(NULL != testfile); - - BOOST_CHECKPOINT("hash_multimap"); - BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<random_key, A> ahash_multimap; - ahash_multimap.insert(std::make_pair(random_key(), A())); - ahash_multimap.insert(std::make_pair(random_key(), A())); - { - test_ostream os(testfile, TEST_STREAM_FLAGS); - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << boost::serialization::make_nvp("ahash_multimap", ahash_multimap); - } - BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<random_key, A> ahash_multimap1; - { - test_istream is(testfile, TEST_STREAM_FLAGS); - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("ahash_multimap", ahash_multimap1); - } - std::vector< std::pair<random_key, A> > tvec, tvec1; - tvec.clear(); - tvec1.clear(); - std::copy(ahash_multimap.begin(), ahash_multimap.end(), std::back_inserter(tvec)); - std::sort(tvec.begin(), tvec.end()); - std::copy(ahash_multimap1.begin(), ahash_multimap1.end(), std::back_inserter(tvec1)); - std::sort(tvec1.begin(), tvec1.end()); - BOOST_CHECK(tvec == tvec1); - std::remove(testfile); -} -#endif - -#ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP - -#include <boost/serialization/unordered_map.hpp> -#include <functional> // requires changeset [69520]; Ticket #5254 - -namespace std { - template<> - struct hash<random_key>{ - std::size_t operator()(const random_key& r) const { - return static_cast<std::size_t>(r); - } - }; -} // namespace std - -void -test_unordered_map(){ - const char * testfile = boost::archive::tmpnam(NULL); - BOOST_REQUIRE(NULL != testfile); - - BOOST_CHECKPOINT("unordered_map"); - // test unordered_map of objects - std::unordered_map<random_key, A> anunordered_map; - anunordered_map.insert(std::make_pair(random_key(), A())); - anunordered_map.insert(std::make_pair(random_key(), A())); - { - test_ostream os(testfile, TEST_STREAM_FLAGS); - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << boost::serialization::make_nvp("anunorderedmap",anunordered_map); - } - std::unordered_map<random_key, A> anunordered_map1; - { - test_istream is(testfile, TEST_STREAM_FLAGS); - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("anunorderedmap",anunordered_map1); - } - - std::vector< std::pair<random_key, A> > tvec, tvec1; - std::copy(anunordered_map.begin(), anunordered_map.end(), std::back_inserter(tvec)); - std::sort(tvec.begin(), tvec.end()); - std::copy(anunordered_map1.begin(), anunordered_map1.end(), std::back_inserter(tvec1)); - std::sort(tvec1.begin(), tvec1.end()); - BOOST_CHECK(tvec == tvec1); - - std::remove(testfile); -} - -void -test_unordered_multimap(){ - const char * testfile = boost::archive::tmpnam(NULL); - BOOST_REQUIRE(NULL != testfile); - - BOOST_CHECKPOINT("unordered_multimap"); - std::unordered_multimap<random_key, A> anunordered_multimap; - anunordered_multimap.insert(std::make_pair(random_key(), A())); - anunordered_multimap.insert(std::make_pair(random_key(), A())); - { - test_ostream os(testfile, TEST_STREAM_FLAGS); - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap); - } - std::unordered_multimap<random_key, A> anunordered_multimap1; - { - test_istream is(testfile, TEST_STREAM_FLAGS); - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap1); - } - std::vector< std::pair<random_key, A> > tvec, tvec1; - tvec.clear(); - tvec1.clear(); - std::copy(anunordered_multimap.begin(), anunordered_multimap.end(), std::back_inserter(tvec)); - std::sort(tvec.begin(), tvec.end()); - std::copy(anunordered_multimap1.begin(), anunordered_multimap1.end(), std::back_inserter(tvec1)); - std::sort(tvec1.begin(), tvec1.end()); - BOOST_CHECK(tvec == tvec1); - std::remove(testfile); -} - -#endif - int test_main( int /* argc */, char* /* argv */[] ) { test_map(); test_map_2(); test_multimap(); - #ifdef BOOST_HAS_HASH - test_hash_map(); - test_hash_multimap(); - #endif - - #ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP - test_unordered_map(); - test_unordered_multimap(); - #endif - return EXIT_SUCCESS; } diff --git a/libs/serialization/test/test_map_boost_unordered.cpp b/libs/serialization/test/test_map_boost_unordered.cpp new file mode 100644 index 0000000000..5af31e1608 --- /dev/null +++ b/libs/serialization/test/test_map_boost_unordered.cpp @@ -0,0 +1,142 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_map.cpp + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// (C) Copyright 2014 Jim Bell +// 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 <algorithm> // std::copy +#include <vector> +#include <fstream> +#include <cstddef> // size_t, NULL + +#include <boost/config.hpp> +#include <boost/detail/workaround.hpp> + +#include <cstdio> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::rand; + using ::size_t; +} +#endif + +#include "test_tools.hpp" + +#include <boost/serialization/nvp.hpp> +#include <boost/serialization/map.hpp> + +#include "A.hpp" +#include "A.ipp" + +/////////////////////////////////////////////////////// +// a key value initialized with a random value for use +// in testing STL map serialization +struct random_key { + friend class boost::serialization::access; + template<class Archive> + void serialize( + Archive & ar, + const unsigned int /* file_version */ + ){ + ar & boost::serialization::make_nvp("random_key", m_i); + } + int m_i; + random_key() : m_i(std::rand()){}; + bool operator<(const random_key &rhs) const { + return m_i < rhs.m_i; + } + bool operator==(const random_key &rhs) const { + return m_i == rhs.m_i; + } + operator std::size_t () const { // required by hash_map + return m_i; + } +}; + +#include <boost/serialization/boost_unordered_map.hpp> +#include <functional> // requires changeset [69520]; Ticket #5254 + +namespace boost { + template<> + struct hash<random_key>{ + std::size_t operator()(const random_key& r) const { + return static_cast<std::size_t>(r); + } + }; +} // namespace std + +void +test_unordered_map(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + BOOST_CHECKPOINT("unordered_map"); + // test unordered_map of objects + boost::unordered_map<random_key, A> anunordered_map; + anunordered_map.insert(std::make_pair(random_key(), A())); + anunordered_map.insert(std::make_pair(random_key(), A())); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunorderedmap",anunordered_map); + } + boost::unordered_map<random_key, A> anunordered_map1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunorderedmap",anunordered_map1); + } + + std::vector< std::pair<random_key, A> > tvec, tvec1; + std::copy(anunordered_map.begin(), anunordered_map.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_map1.begin(), anunordered_map1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + + std::remove(testfile); +} + +void +test_unordered_multimap(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + BOOST_CHECKPOINT("unordered_multimap"); + boost::unordered_multimap<random_key, A> anunordered_multimap; + anunordered_multimap.insert(std::make_pair(random_key(), A())); + anunordered_multimap.insert(std::make_pair(random_key(), A())); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap); + } + boost::unordered_multimap<random_key, A> anunordered_multimap1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap1); + } + std::vector< std::pair<random_key, A> > tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(anunordered_multimap.begin(), anunordered_multimap.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_multimap1.begin(), anunordered_multimap1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + std::remove(testfile); +} + +int test_main( int /* argc */, char* /* argv */[] ) +{ + test_unordered_map(); + test_unordered_multimap(); + + return EXIT_SUCCESS; +} diff --git a/libs/serialization/test/test_map_hashed.cpp b/libs/serialization/test/test_map_hashed.cpp new file mode 100644 index 0000000000..3fcb902c67 --- /dev/null +++ b/libs/serialization/test/test_map_hashed.cpp @@ -0,0 +1,139 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_map.cpp + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// (C) Copyright 2014 Jim Bell +// 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 <algorithm> // std::copy +#include <vector> +#include <fstream> +#include <cstddef> // size_t, NULL + +#include <boost/config.hpp> +#include <boost/detail/workaround.hpp> + +#include <cstdio> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::rand; + using ::size_t; +} +#endif + +#include "test_tools.hpp" + +#include <boost/serialization/nvp.hpp> +#include <boost/serialization/map.hpp> + +#include "A.hpp" +#include "A.ipp" + +/////////////////////////////////////////////////////// +// a key value initialized with a random value for use +// in testing STL map serialization +struct random_key { + friend class boost::serialization::access; + template<class Archive> + void serialize( + Archive & ar, + const unsigned int /* file_version */ + ){ + ar & boost::serialization::make_nvp("random_key", m_i); + } + int m_i; + random_key() : m_i(std::rand()){}; + bool operator<(const random_key &rhs) const { + return m_i < rhs.m_i; + } + bool operator==(const random_key &rhs) const { + return m_i == rhs.m_i; + } + operator std::size_t () const { // required by hash_map + return m_i; + } +}; + +#include <boost/serialization/hash_map.hpp> + +namespace BOOST_STD_EXTENSION_NAMESPACE { + template<> + struct hash<random_key>{ + std::size_t operator()(const random_key& r) const { + return static_cast<std::size_t>(r); + } + }; +} // namespace BOOST_STD_EXTENSION_NAMESPACE + +void +test_hash_map(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + BOOST_CHECKPOINT("hash_map"); + // test hash_map of objects + BOOST_STD_EXTENSION_NAMESPACE::hash_map<random_key, A> ahash_map; + ahash_map.insert(std::make_pair(random_key(), A())); + ahash_map.insert(std::make_pair(random_key(), A())); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("ahashmap",ahash_map); + } + BOOST_STD_EXTENSION_NAMESPACE::hash_map<random_key, A> ahash_map1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("ahashmap",ahash_map1); + } + + std::vector< std::pair<random_key, A> > tvec, tvec1; + std::copy(ahash_map.begin(), ahash_map.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(ahash_map1.begin(), ahash_map1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + + std::remove(testfile); +} + +void +test_hash_multimap(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + BOOST_CHECKPOINT("hash_multimap"); + BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<random_key, A> ahash_multimap; + ahash_multimap.insert(std::make_pair(random_key(), A())); + ahash_multimap.insert(std::make_pair(random_key(), A())); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("ahash_multimap", ahash_multimap); + } + BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<random_key, A> ahash_multimap1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("ahash_multimap", ahash_multimap1); + } + std::vector< std::pair<random_key, A> > tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(ahash_multimap.begin(), ahash_multimap.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(ahash_multimap1.begin(), ahash_multimap1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + std::remove(testfile); +} +int test_main( int /* argc */, char* /* argv */[] ) +{ + test_hash_map(); + test_hash_multimap(); + return EXIT_SUCCESS; +} diff --git a/libs/serialization/test/test_map_unordered.cpp b/libs/serialization/test/test_map_unordered.cpp new file mode 100644 index 0000000000..488e928aa2 --- /dev/null +++ b/libs/serialization/test/test_map_unordered.cpp @@ -0,0 +1,142 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_map.cpp + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// (C) Copyright 2014 Jim Bell +// 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 <algorithm> // std::copy +#include <vector> +#include <fstream> +#include <cstddef> // size_t, NULL + +#include <boost/config.hpp> +#include <boost/detail/workaround.hpp> + +#include <cstdio> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::rand; + using ::size_t; +} +#endif + +#include "test_tools.hpp" + +#include <boost/serialization/nvp.hpp> +#include <boost/serialization/map.hpp> + +#include "A.hpp" +#include "A.ipp" + +/////////////////////////////////////////////////////// +// a key value initialized with a random value for use +// in testing STL map serialization +struct random_key { + friend class boost::serialization::access; + template<class Archive> + void serialize( + Archive & ar, + const unsigned int /* file_version */ + ){ + ar & boost::serialization::make_nvp("random_key", m_i); + } + int m_i; + random_key() : m_i(std::rand()){}; + bool operator<(const random_key &rhs) const { + return m_i < rhs.m_i; + } + bool operator==(const random_key &rhs) const { + return m_i == rhs.m_i; + } + operator std::size_t () const { // required by hash_map + return m_i; + } +}; + +#include <boost/serialization/unordered_map.hpp> +#include <functional> // requires changeset [69520]; Ticket #5254 + +namespace std { + template<> + struct hash<random_key>{ + std::size_t operator()(const random_key& r) const { + return static_cast<std::size_t>(r); + } + }; +} // namespace std + +void +test_unordered_map(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + BOOST_CHECKPOINT("unordered_map"); + // test unordered_map of objects + std::unordered_map<random_key, A> anunordered_map; + anunordered_map.insert(std::make_pair(random_key(), A())); + anunordered_map.insert(std::make_pair(random_key(), A())); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunorderedmap",anunordered_map); + } + std::unordered_map<random_key, A> anunordered_map1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunorderedmap",anunordered_map1); + } + + std::vector< std::pair<random_key, A> > tvec, tvec1; + std::copy(anunordered_map.begin(), anunordered_map.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_map1.begin(), anunordered_map1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + + std::remove(testfile); +} + +void +test_unordered_multimap(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + BOOST_CHECKPOINT("unordered_multimap"); + std::unordered_multimap<random_key, A> anunordered_multimap; + anunordered_multimap.insert(std::make_pair(random_key(), A())); + anunordered_multimap.insert(std::make_pair(random_key(), A())); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap); + } + std::unordered_multimap<random_key, A> anunordered_multimap1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap1); + } + std::vector< std::pair<random_key, A> > tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(anunordered_multimap.begin(), anunordered_multimap.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_multimap1.begin(), anunordered_multimap1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + std::remove(testfile); +} + +int test_main( int /* argc */, char* /* argv */[] ) +{ + test_unordered_map(); + test_unordered_multimap(); + + return EXIT_SUCCESS; +} diff --git a/libs/serialization/test/test_native_array.cpp b/libs/serialization/test/test_native_array.cpp new file mode 100644 index 0000000000..4bf3c87411 --- /dev/null +++ b/libs/serialization/test/test_native_array.cpp @@ -0,0 +1,104 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_array.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 <stdlib.h> + +#include <boost/config.hpp> +#include <cstddef> +#include <fstream> +#include <algorithm> // equal +#include <cstdio> // remove +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif +#include "test_tools.hpp" +#include <boost/core/no_exceptions_support.hpp> +#include <boost/archive/archive_exception.hpp> +#include <boost/array.hpp> + +#include "A.hpp" +#include "A.ipp" + +template <class T> +int test_native_array(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + // test array of objects + const T a_array[10]={T(),T(),T(),T(),T(),T(),T(),T(),T(),T()}; + const T b_array[2][3]={{T(),T(),T()},{T(),T(),T()}}; + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + { + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("a_array", a_array); + oa << boost::serialization::make_nvp("b_array", b_array); + } + os.close(); + } + { + T a_array1[10]; + T b_array1[2][3]; + test_istream is(testfile, TEST_STREAM_FLAGS); + { + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("a_array", a_array1); + ia >> boost::serialization::make_nvp("b_array", b_array1); + } + is.close(); + BOOST_CHECK(std::equal(& a_array[0], & a_array[10], & a_array1[0])); + BOOST_CHECK(b_array[0][0] == b_array1[0][0]); + BOOST_CHECK(b_array[1][0] == b_array1[1][0]); + } + { + T a_array1[9]; + T b_array1[2][3]; + test_istream is(testfile, TEST_STREAM_FLAGS); + { + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + bool exception_invoked = false; + BOOST_TRY { + ia >> boost::serialization::make_nvp("a_array", a_array1); + ia >> boost::serialization::make_nvp("b_array", b_array1); + } + BOOST_CATCH (boost::archive::archive_exception ae){ + BOOST_CHECK( + boost::archive::archive_exception::array_size_too_short + == ae.code + ); + exception_invoked = true; + } + BOOST_CATCH_END + BOOST_CHECK(exception_invoked); + } + is.close(); + } + std::remove(testfile); + return EXIT_SUCCESS; +} + +int test_main( int /* argc */, char* /* argv */[] ){ + int res; + + // native array + res = test_native_array<A>(); + if (res != EXIT_SUCCESS) + return EXIT_FAILURE; + // test an int array for which optimized versions should be available + res = test_native_array<int>(); + if (res != EXIT_SUCCESS) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +// EOF diff --git a/libs/serialization/test/test_new_operator.cpp b/libs/serialization/test/test_new_operator.cpp index c356b02a78..b6931216b0 100644 --- a/libs/serialization/test/test_new_operator.cpp +++ b/libs/serialization/test/test_new_operator.cpp @@ -43,27 +43,72 @@ public: ++m_new_calls; return ::operator new(s); } - static void operator delete(void *p, std::size_t /*s*/){ + static void operator delete(void *p, std::size_t){ ++m_delete_calls; ::operator delete(p); } }; - unsigned int ANew::m_new_calls = 0; unsigned int ANew::m_delete_calls = 0; -int test_main( int /* argc */, char* /* argv */[] ) -{ +class ANew1 : public A { + friend class boost::serialization::access; + template<class Archive> + void serialize(Archive & ar, const unsigned /*file_version*/){ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A); + } +public: + static unsigned int m_new_calls; + static unsigned int m_delete_calls; + // implement class specific new/delete in terms standard + // implementation - we're testing serialization + // not "new" here. + static void * operator new(size_t s){ + ++m_new_calls; + return ::operator new(s); + } + static void operator delete(void *p){ + ++m_delete_calls; + ::operator delete(p); + } +}; +unsigned int ANew1::m_new_calls = 0; +unsigned int ANew1::m_delete_calls = 0; + + +class ANew2 : public A { + friend class boost::serialization::access; + template<class Archive> + void serialize(Archive & ar, const unsigned /*file_version*/){ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A); + } +public: + static unsigned int m_new_calls; + static unsigned int m_delete_calls; + // implement class specific new/delete in terms standard + // implementation - we're testing serialization + // not "new" here. + static void * operator new(size_t s){ + ++m_new_calls; + return ::operator new(s); + } +}; +unsigned int ANew2::m_new_calls = 0; +unsigned int ANew2::m_delete_calls = 0; + +template<typename T> +int test(){ const char * testfile = boost::archive::tmpnam(NULL); BOOST_REQUIRE(NULL != testfile); - ANew *ta = new ANew(); - BOOST_CHECK(1 == ANew::m_new_calls); - BOOST_CHECK(0 == ANew::m_delete_calls); + T *ta = new T(); + + BOOST_CHECK(1 == T::m_new_calls); + BOOST_CHECK(0 == T::m_delete_calls); - ANew *ta1 = NULL; + T *ta1 = NULL; { test_ostream os(testfile, TEST_STREAM_FLAGS); @@ -78,18 +123,32 @@ int test_main( int /* argc */, char* /* argv */[] ) BOOST_CHECK(ta != ta1); BOOST_CHECK(*ta == *ta1); - BOOST_CHECK(2 == ANew::m_new_calls); - BOOST_CHECK(0 == ANew::m_delete_calls); + BOOST_CHECK(2 == T::m_new_calls); + BOOST_CHECK(0 == T::m_delete_calls); std::remove(testfile); delete ta; delete ta1; - BOOST_CHECK(2 == ANew::m_new_calls); - BOOST_CHECK(2 == ANew::m_delete_calls); + BOOST_CHECK(2 == T::m_new_calls); + BOOST_CHECK(2 == T::m_delete_calls); return EXIT_SUCCESS; } +int test_main( int /* argc */, char* /* argv */[] ){ + if(EXIT_SUCCESS != test<ANew>()) + return EXIT_FAILURE; + if(EXIT_SUCCESS != test<ANew1>()) + return EXIT_FAILURE; + // Note the following test fails. To see why this is, look into the file + // iserializer line # 247. Feel free to send a patch to detect the absense + // of a class specific delete. + /* + if(EXIT_SUCCESS != test<ANew2>()) + return EXIT_FAILURE; + */ + return EXIT_SUCCESS; +} // EOF diff --git a/libs/serialization/test/test_non_default_ctor.cpp b/libs/serialization/test/test_non_default_ctor.cpp index 76b16c2c90..9a656f1811 100644 --- a/libs/serialization/test/test_non_default_ctor.cpp +++ b/libs/serialization/test/test_non_default_ctor.cpp @@ -128,7 +128,7 @@ template<class Archive> inline void save_construct_data( Archive & ar, const A * a, - const BOOST_PFTO unsigned int /* file_version */ + const unsigned int /* file_version */ ){ // variable used for construction ar << boost::serialization::make_nvp("i", a->get_i()); diff --git a/libs/serialization/test/test_non_default_ctor2.cpp b/libs/serialization/test/test_non_default_ctor2.cpp index ed718382e7..392bb52a44 100644 --- a/libs/serialization/test/test_non_default_ctor2.cpp +++ b/libs/serialization/test/test_non_default_ctor2.cpp @@ -99,7 +99,7 @@ template <class ArchiveT> void save_construct_data( ArchiveT& archive, const A* p, - const BOOST_PFTO unsigned int /*version*/ + const unsigned int /*version*/ ){ archive & boost::serialization::make_nvp("initialValue", p->value); } diff --git a/libs/serialization/test/test_optional.cpp b/libs/serialization/test/test_optional.cpp index 0beb750dca..bee2c6b415 100644 --- a/libs/serialization/test/test_optional.cpp +++ b/libs/serialization/test/test_optional.cpp @@ -20,7 +20,6 @@ namespace std{ } #endif - #include <boost/archive/archive_exception.hpp> #include "test_tools.hpp" @@ -36,16 +35,14 @@ int test_main( int /* argc */, char* /* argv */[] ) const boost::optional<int> aoptional1; const boost::optional<int> aoptional2(123); - { + { test_ostream os(testfile, TEST_STREAM_FLAGS); test_oarchive oa(os, TEST_ARCHIVE_FLAGS); oa << boost::serialization::make_nvp("aoptional1",aoptional1); oa << boost::serialization::make_nvp("aoptional2",aoptional2); } - boost::optional<int> aoptional1a(999); boost::optional<int> aoptional2a; - { test_istream is(testfile, TEST_STREAM_FLAGS); test_iarchive ia(is, TEST_ARCHIVE_FLAGS); @@ -54,7 +51,7 @@ int test_main( int /* argc */, char* /* argv */[] ) } BOOST_CHECK(aoptional1 == aoptional1a); BOOST_CHECK(aoptional2 == aoptional2a); - + std::remove(testfile); return EXIT_SUCCESS; } diff --git a/libs/serialization/test/test_polymorphic.cpp b/libs/serialization/test/test_polymorphic.cpp index 1e501c6819..33957e1c7f 100644 --- a/libs/serialization/test/test_polymorphic.cpp +++ b/libs/serialization/test/test_polymorphic.cpp @@ -73,7 +73,7 @@ int test_main(int /* argc */, char * /* argv */ []) BOOST_CHECK(d == d1); std::remove(testfile); - // test using using polymorphic implementation. + // test using using polymorphic interface. { test_ostream os(testfile, TEST_STREAM_FLAGS); boost::archive::polymorphic_oarchive * oa_implementation diff --git a/libs/serialization/test/test_polymorphic_helper.cpp b/libs/serialization/test/test_polymorphic_helper.cpp new file mode 100644 index 0000000000..0d68588e49 --- /dev/null +++ b/libs/serialization/test/test_polymorphic_helper.cpp @@ -0,0 +1,160 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_polymorphic.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 <cstddef> // NULL +#include <cstdio> // remove +#include <fstream> + +#include <boost/config.hpp> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +// the following is to ensure that when one of the libraries changes +// BJAM rebuilds and relinks the test. +/* +#include "polymorphic_text_archive.hpp" +#include "polymorphic_text_warchive.hpp" +#include "polymorphic_binary_archive.hpp" +#include "polymorphic_xml_archive.hpp" +#include "polymorphic_xml_warchive.hpp" +*/ + +#include <string> +#include <vector> + +#include "test_tools.hpp" +#include <boost/lexical_cast.hpp> +#include <boost/serialization/split_free.hpp> +#include <boost/serialization/vector.hpp> +#include <boost/serialization/nvp.hpp> +// this test uses a special string (my_string) whose contents are shared +// and hence saved in the archive only once. We need a helper in order +// to convert my_string into a serializable type + +class my_string:public std::string +{ + typedef std::string super; + +public: + my_string(){} + my_string(const super & str): super(str){} + my_string & operator=(const super& rhs) { + super::operator=(rhs); + return *this; + } +}; + +struct my_string_helper +{ + typedef std::vector<my_string> table; + table m_t; +}; + +BOOST_SERIALIZATION_SPLIT_FREE(my_string) + +namespace boost { +namespace serialization { + +template<class Archive> +void save(Archive & ar, const my_string & str, const unsigned int /* version */) +{ + void (* const idx)(Archive &, const my_string &, const unsigned int) = & save; + void * const id = reinterpret_cast<void * const>(idx); + my_string_helper & msh = ar.template get_helper<my_string_helper>(id); + + my_string_helper::table t = msh.m_t; + my_string_helper::table::iterator it = std::find(t.begin(), t.end(), str); + if(it == t.end()){ + my_string_helper::table::size_type s = t.size(); + ar << make_nvp("index", s); + t.push_back(str); + ar << make_nvp("string", static_cast<const std::string &>(str)); + } + else{ + my_string_helper::table::size_type s = it - t.begin(); + ar << make_nvp("index", s); + } +} + +template<class Archive> +void load(Archive & ar, my_string & str, const unsigned int /* version */) +{ + void (* const idx)(Archive &, my_string &, const unsigned int) = & load; + void * const id = reinterpret_cast<void * const>(idx); + my_string_helper & msh = ar.template get_helper<my_string_helper>(id); + + my_string_helper::table t = msh.m_t; + + my_string_helper::table::size_type s; + ar >> make_nvp("index", s); + t.reserve(s); + if(s >= t.size()){ + std::string tmp; + ar >> make_nvp("string", tmp); + str = tmp; + t.push_back(str); + } + else{ + str = t[s]; + } +} + +} // namespace serialization +} // namespace boost +#include <boost/archive/polymorphic_oarchive.hpp> +#include <boost/archive/polymorphic_iarchive.hpp> + +int test_main(int /* argc */, char * /* argv */ []) +{ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + std::vector<my_string> v1; + for(int i=0; i<1000; ++i){ + v1.push_back(my_string(boost::lexical_cast<std::string>(i % 100))); + } + + // test using using polymorphic implementation. + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa_implementation(os, TEST_ARCHIVE_FLAGS); + oa_implementation << boost::serialization::make_nvp("vector", v1); + } + { + std::vector<my_string> v2; + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia_implementation(is, TEST_ARCHIVE_FLAGS); + ia_implementation >> boost::serialization::make_nvp("vector", v2); + BOOST_CHECK(v1 == v2); + } + std::remove(testfile); + + // test using using polymorphic interface. + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa_implementation(os, TEST_ARCHIVE_FLAGS); + boost::archive::polymorphic_oarchive & oa_interface = oa_implementation; + oa_interface << boost::serialization::make_nvp("vector", v1); + } + { + std::vector<my_string> v2; + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia_implementation(is, TEST_ARCHIVE_FLAGS); + boost::archive::polymorphic_iarchive & ia_interface = ia_implementation; + ia_interface >> boost::serialization::make_nvp("vector", v2); + BOOST_CHECK(v1 == v2); + } + std::remove(testfile); + std::remove(testfile); + return EXIT_SUCCESS; +} diff --git a/libs/serialization/test/test_primitive.cpp b/libs/serialization/test/test_primitive.cpp index aa94bd4413..d95854584f 100644 --- a/libs/serialization/test/test_primitive.cpp +++ b/libs/serialization/test/test_primitive.cpp @@ -11,6 +11,8 @@ #include <cstddef> // NULL #include <fstream> +#include <boost/config.hpp> + #include "test_tools.hpp" #include <boost/serialization/level.hpp> diff --git a/libs/serialization/test/test_private_base.cpp b/libs/serialization/test/test_private_base.cpp index e5c1bce7ae..38ffefa126 100644 --- a/libs/serialization/test/test_private_base.cpp +++ b/libs/serialization/test/test_private_base.cpp @@ -29,7 +29,7 @@ class Base { int m_i; template<class Archive> void serialize(Archive & ar, const unsigned int version){ - ar & m_i; + ar & BOOST_SERIALIZATION_NVP(m_i); } protected: bool equals(const Base &rhs) const { @@ -38,22 +38,21 @@ protected: Base(int i = 0) : m_i(i) {} - virtual ~Base(){}; public: - virtual bool operator==(const Base &rhs) const { - return false; - }// = 0; }; -class Derived : private Base { +class Derived : private Base { friend class boost::serialization::access; private: + Base & base_cast(){ + return static_cast<Base &>(*this); + } template<class Archive> void serialize(Archive & ar, const unsigned int version){ - ar & boost::serialization::base_object<Base>(*this); + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base); } public: - virtual bool operator==(const Derived &rhs) const { + bool operator==(const Derived &rhs) const { return Base::equals(static_cast<const Base &>(rhs)); } Derived(int i = 0) : @@ -61,9 +60,7 @@ public: {} }; -BOOST_CLASS_EXPORT(Derived) - -int +int test_main( int /* argc */, char* /* argv */[] ) { const char * testfile = boost::archive::tmpnam(NULL); @@ -83,24 +80,5 @@ test_main( int /* argc */, char* /* argv */[] ) BOOST_CHECK_EQUAL(a, a1); std::remove(testfile); - Base *ta = new Derived(1); - Base *ta1 = NULL; - - { - test_ostream os(testfile, TEST_STREAM_FLAGS); - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << boost::serialization::make_nvp("ta", ta); - } - { - test_istream is(testfile, TEST_STREAM_FLAGS); - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("ta", ta1); - } - BOOST_CHECK(ta != ta1); - BOOST_CHECK(*ta == *ta1); - //BOOST_CHECK(*static_cast<Derived *>(ta) == *static_cast<Derived *>(ta1)); - - std::remove(testfile); - return 0; } diff --git a/libs/serialization/test/test_private_base2.cpp b/libs/serialization/test/test_private_base2.cpp new file mode 100644 index 0000000000..19476ee298 --- /dev/null +++ b/libs/serialization/test/test_private_base2.cpp @@ -0,0 +1,104 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_private_base.cpp + +// (C) Copyright 2009 Eric Moyer - 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 + +// invoke header for a custom archive test. + +#include <fstream> +#include <boost/config.hpp> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +#include <boost/serialization/access.hpp> +#include <boost/serialization/base_object.hpp> +#include <boost/serialization/export.hpp> + +#include "test_tools.hpp" + +class Base { + friend class boost::serialization::access; + int m_i; + template<class Archive> + void serialize(Archive & ar, const unsigned int version){ + ar & BOOST_SERIALIZATION_NVP(m_i); + } +protected: + bool equals(const Base &rhs) const { + return m_i == rhs.m_i; + } + Base(int i = 0) : + m_i(i) + {} + virtual ~Base(){}; +public: + virtual bool operator==(const Base &rhs) const { + return false; + }// = 0; +}; + +class Derived : private Base { + friend class boost::serialization::access; +public: + virtual bool operator==(const Derived &rhs) const { + return Base::equals(static_cast<const Base &>(rhs)); + } + Derived(int i = 0) : + Base(i) + {} +}; + +//BOOST_CLASS_EXPORT(Derived) + +int +test_main( int /* argc */, char* /* argv */[] ) +{ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + Derived a(1), a1(2); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("a", a); + } + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("a", a1); + } + BOOST_CHECK_EQUAL(a, a1); + std::remove(testfile); + + //Base *ta = static_cast<Base *>(&a); + //Base *ta1 = NULL; + + Derived *ta = &a; + Derived *ta1 = NULL; + + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("ta", ta); + } + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("ta", ta1); + } + BOOST_CHECK(ta != ta1); + BOOST_CHECK(*ta == *ta1); + //BOOST_CHECK(*static_cast<Derived *>(ta) == *static_cast<Derived *>(ta1)); + + std::remove(testfile); + + return 0; +} diff --git a/libs/serialization/test/test_private_ctor.cpp b/libs/serialization/test/test_private_ctor.cpp index 72b3904fcf..c8bcdb24e4 100644 --- a/libs/serialization/test/test_private_ctor.cpp +++ b/libs/serialization/test/test_private_ctor.cpp @@ -16,18 +16,20 @@ #include <boost/archive/text_oarchive.hpp> class V { +private: friend int test_main(int /* argc */, char * /* argv */[]); friend class boost::serialization::access; int m_i; V() : m_i(0) {} - ~V(){} template<class Archive> void serialize(Archive& ar, unsigned /*version*/) { ar & m_i; } +public: + ~V(){} bool operator==(const V & v) const { return m_i == v.m_i; } @@ -47,5 +49,18 @@ int test_main(int /* argc */, char * /* argv */[]) ia >> v1; } BOOST_CHECK(v == v1); + + const V *vptr = & v; + { + boost::archive::text_oarchive oa(ss); + oa << vptr; + } + V *vptr1; + { + boost::archive::text_iarchive ia(ss); + ia >> vptr1; + } + BOOST_CHECK(*vptr == *vptr1); + return EXIT_SUCCESS; } diff --git a/libs/serialization/test/test_set.cpp b/libs/serialization/test/test_set.cpp index 8379c77f7f..6a86f049bc 100644 --- a/libs/serialization/test/test_set.cpp +++ b/libs/serialization/test/test_set.cpp @@ -87,176 +87,9 @@ test_multiset(){ std::remove(testfile); } -#ifdef BOOST_HAS_HASH - -#include <boost/serialization/hash_set.hpp> - -namespace BOOST_STD_EXTENSION_NAMESPACE { - template<> - struct hash<A> { - std::size_t operator()(const A& a) const { - return static_cast<std::size_t>(a); - } - }; -} - -void -test_hash_set(){ - const char * testfile = boost::archive::tmpnam(NULL); - BOOST_REQUIRE(NULL != testfile); - - // test array of objects - BOOST_STD_EXTENSION_NAMESPACE::hash_set<A> ahash_set; - A a, a1; - ahash_set.insert(a); - ahash_set.insert(a1); - { - test_ostream os(testfile, TEST_STREAM_FLAGS); - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << boost::serialization::make_nvp("ahash_set", ahash_set); - } - BOOST_STD_EXTENSION_NAMESPACE::hash_set<A> ahash_set1; - { - test_istream is(testfile, TEST_STREAM_FLAGS); - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("ahash_set", ahash_set1); - } - std::vector<A> tvec, tvec1; - tvec.clear(); - tvec1.clear(); - std::copy(ahash_set.begin(), ahash_set.end(), std::back_inserter(tvec)); - std::sort(tvec.begin(), tvec.end()); - std::copy(ahash_set1.begin(), ahash_set1.end(), std::back_inserter(tvec1)); - std::sort(tvec1.begin(), tvec1.end()); - BOOST_CHECK(tvec == tvec1); - std::remove(testfile); -} - -void -test_hash_multiset(){ - const char * testfile = boost::archive::tmpnam(NULL); - BOOST_REQUIRE(NULL != testfile); - - BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<A> ahash_multiset; - ahash_multiset.insert(A()); - ahash_multiset.insert(A()); - { - test_ostream os(testfile, TEST_STREAM_FLAGS); - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << boost::serialization::make_nvp("ahash_multiset", ahash_multiset); - } - BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<A> ahash_multiset1; - { - test_istream is(testfile, TEST_STREAM_FLAGS); - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("ahash_multiset", ahash_multiset1); - } - - std::vector<A> tvec, tvec1; - tvec.clear(); - tvec1.clear(); - std::copy(ahash_multiset.begin(), ahash_multiset.end(), std::back_inserter(tvec)); - std::sort(tvec.begin(), tvec.end()); - std::copy(ahash_multiset1.begin(), ahash_multiset1.end(), std::back_inserter(tvec1)); - std::sort(tvec1.begin(), tvec1.end()); - BOOST_CHECK(tvec == tvec1); - - std::remove(testfile); -} -#endif - -#ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET - -#include <boost/serialization/unordered_set.hpp> -#include <functional> // requires changeset [69520]; Ticket #5254 - -namespace std { - template<> - struct hash<A> { - std::size_t operator()(const A& a) const { - return static_cast<std::size_t>(a); - } - }; -} // namespace std - -void -test_unordered_set(){ - const char * testfile = boost::archive::tmpnam(NULL); - BOOST_REQUIRE(NULL != testfile); - - // test array of objects - std::unordered_set<A> anunordered_set; - A a, a1; - anunordered_set.insert(a); - anunordered_set.insert(a1); - { - test_ostream os(testfile, TEST_STREAM_FLAGS); - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << boost::serialization::make_nvp("anunordered_set", anunordered_set); - } - std::unordered_set<A> anunordered_set1; - { - test_istream is(testfile, TEST_STREAM_FLAGS); - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("anunordered_set", anunordered_set1); - } - std::vector<A> tvec, tvec1; - tvec.clear(); - tvec1.clear(); - std::copy(anunordered_set.begin(), anunordered_set.end(), std::back_inserter(tvec)); - std::sort(tvec.begin(), tvec.end()); - std::copy(anunordered_set1.begin(), anunordered_set1.end(), std::back_inserter(tvec1)); - std::sort(tvec1.begin(), tvec1.end()); - BOOST_CHECK(tvec == tvec1); - std::remove(testfile); -} - -void -test_unordered_multiset(){ - const char * testfile = boost::archive::tmpnam(NULL); - BOOST_REQUIRE(NULL != testfile); - - std::unordered_multiset<A> anunordered_multiset; - anunordered_multiset.insert(A()); - anunordered_multiset.insert(A()); - { - test_ostream os(testfile, TEST_STREAM_FLAGS); - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset); - } - std::unordered_multiset<A> anunordered_multiset1; - { - test_istream is(testfile, TEST_STREAM_FLAGS); - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset1); - } - - std::vector<A> tvec, tvec1; - tvec.clear(); - tvec1.clear(); - std::copy(anunordered_multiset.begin(), anunordered_multiset.end(), std::back_inserter(tvec)); - std::sort(tvec.begin(), tvec.end()); - std::copy(anunordered_multiset1.begin(), anunordered_multiset1.end(), std::back_inserter(tvec1)); - std::sort(tvec1.begin(), tvec1.end()); - BOOST_CHECK(tvec == tvec1); - - std::remove(testfile); -} -#endif - int test_main( int /* argc */, char* /* argv */[] ){ test_set(); test_multiset(); - #ifdef BOOST_HAS_HASH - test_hash_set(); - test_hash_multiset(); - #endif - - #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET - test_unordered_set(); - test_unordered_multiset(); - #endif - return EXIT_SUCCESS; } diff --git a/libs/serialization/test/test_set_boost_unordered.cpp b/libs/serialization/test/test_set_boost_unordered.cpp new file mode 100644 index 0000000000..ce29374c0a --- /dev/null +++ b/libs/serialization/test/test_set_boost_unordered.cpp @@ -0,0 +1,123 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_set.cpp + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// (C) Copyright 2014 Jim Bell +// 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 <cstddef> // NULLsize_t +#include <cstdio> // remove +#include <fstream> + +#include <algorithm> // std::copy +#include <vector> + +#include <boost/config.hpp> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::size_t; +} +#endif + +#include <boost/detail/workaround.hpp> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +#include <boost/archive/archive_exception.hpp> + +#include "test_tools.hpp" + +#include <boost/serialization/nvp.hpp> +#include <boost/serialization/set.hpp> + +#include "A.hpp" +#include "A.ipp" + +#include <boost/serialization/boost_unordered_set.hpp> +#include <functional> // requires changeset [69520]; Ticket #5254 + +namespace boost { + template<> + struct hash<A> { + std::size_t operator()(const A& a) const { + return static_cast<std::size_t>(a); + } + }; +} // namespace boost + +void +test_unordered_set(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + // test array of objects + boost::unordered_set<A> anunordered_set; + A a, a1; + anunordered_set.insert(a); + anunordered_set.insert(a1); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunordered_set", anunordered_set); + } + boost::unordered_set<A> anunordered_set1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunordered_set", anunordered_set1); + } + std::vector<A> tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(anunordered_set.begin(), anunordered_set.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_set1.begin(), anunordered_set1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + std::remove(testfile); +} + +void +test_unordered_multiset(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + boost::unordered_multiset<A> anunordered_multiset; + anunordered_multiset.insert(A()); + anunordered_multiset.insert(A()); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset); + } + boost::unordered_multiset<A> anunordered_multiset1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset1); + } + + std::vector<A> tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(anunordered_multiset.begin(), anunordered_multiset.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_multiset1.begin(), anunordered_multiset1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + + std::remove(testfile); +} + +int test_main( int /* argc */, char* /* argv */[] ){ + test_unordered_set(); + test_unordered_multiset(); + return EXIT_SUCCESS; +} diff --git a/libs/serialization/test/test_set_hashed.cpp b/libs/serialization/test/test_set_hashed.cpp new file mode 100644 index 0000000000..8379c77f7f --- /dev/null +++ b/libs/serialization/test/test_set_hashed.cpp @@ -0,0 +1,262 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_set.cpp + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// (C) Copyright 2014 Jim Bell +// 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 <cstddef> // NULLsize_t +#include <cstdio> // remove +#include <fstream> + +#include <algorithm> // std::copy +#include <vector> + +#include <boost/config.hpp> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::size_t; +} +#endif + +#include <boost/detail/workaround.hpp> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +#include <boost/archive/archive_exception.hpp> + +#include "test_tools.hpp" + +#include <boost/serialization/nvp.hpp> +#include <boost/serialization/set.hpp> + +#include "A.hpp" +#include "A.ipp" + +void +test_set(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + // test array of objects + std::set<A> aset; + aset.insert(A()); + aset.insert(A()); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("aset", aset); + } + std::set<A> aset1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("aset", aset1); + } + BOOST_CHECK(aset == aset1); + std::remove(testfile); +} + +void +test_multiset(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + std::multiset<A> amultiset; + amultiset.insert(A()); + amultiset.insert(A()); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("amultiset", amultiset); + } + std::multiset<A> amultiset1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("amultiset", amultiset1); + } + BOOST_CHECK(amultiset == amultiset1); + std::remove(testfile); +} + +#ifdef BOOST_HAS_HASH + +#include <boost/serialization/hash_set.hpp> + +namespace BOOST_STD_EXTENSION_NAMESPACE { + template<> + struct hash<A> { + std::size_t operator()(const A& a) const { + return static_cast<std::size_t>(a); + } + }; +} + +void +test_hash_set(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + // test array of objects + BOOST_STD_EXTENSION_NAMESPACE::hash_set<A> ahash_set; + A a, a1; + ahash_set.insert(a); + ahash_set.insert(a1); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("ahash_set", ahash_set); + } + BOOST_STD_EXTENSION_NAMESPACE::hash_set<A> ahash_set1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("ahash_set", ahash_set1); + } + std::vector<A> tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(ahash_set.begin(), ahash_set.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(ahash_set1.begin(), ahash_set1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + std::remove(testfile); +} + +void +test_hash_multiset(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<A> ahash_multiset; + ahash_multiset.insert(A()); + ahash_multiset.insert(A()); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("ahash_multiset", ahash_multiset); + } + BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<A> ahash_multiset1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("ahash_multiset", ahash_multiset1); + } + + std::vector<A> tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(ahash_multiset.begin(), ahash_multiset.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(ahash_multiset1.begin(), ahash_multiset1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + + std::remove(testfile); +} +#endif + +#ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET + +#include <boost/serialization/unordered_set.hpp> +#include <functional> // requires changeset [69520]; Ticket #5254 + +namespace std { + template<> + struct hash<A> { + std::size_t operator()(const A& a) const { + return static_cast<std::size_t>(a); + } + }; +} // namespace std + +void +test_unordered_set(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + // test array of objects + std::unordered_set<A> anunordered_set; + A a, a1; + anunordered_set.insert(a); + anunordered_set.insert(a1); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunordered_set", anunordered_set); + } + std::unordered_set<A> anunordered_set1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunordered_set", anunordered_set1); + } + std::vector<A> tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(anunordered_set.begin(), anunordered_set.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_set1.begin(), anunordered_set1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + std::remove(testfile); +} + +void +test_unordered_multiset(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + std::unordered_multiset<A> anunordered_multiset; + anunordered_multiset.insert(A()); + anunordered_multiset.insert(A()); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset); + } + std::unordered_multiset<A> anunordered_multiset1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset1); + } + + std::vector<A> tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(anunordered_multiset.begin(), anunordered_multiset.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_multiset1.begin(), anunordered_multiset1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + + std::remove(testfile); +} +#endif + +int test_main( int /* argc */, char* /* argv */[] ){ + test_set(); + test_multiset(); + + #ifdef BOOST_HAS_HASH + test_hash_set(); + test_hash_multiset(); + #endif + + #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET + test_unordered_set(); + test_unordered_multiset(); + #endif + + return EXIT_SUCCESS; +} diff --git a/libs/serialization/test/test_set_unordered.cpp b/libs/serialization/test/test_set_unordered.cpp new file mode 100644 index 0000000000..31ec256a73 --- /dev/null +++ b/libs/serialization/test/test_set_unordered.cpp @@ -0,0 +1,123 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_set.cpp + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// (C) Copyright 2014 Jim Bell +// 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 <cstddef> // NULLsize_t +#include <cstdio> // remove +#include <fstream> + +#include <algorithm> // std::copy +#include <vector> + +#include <boost/config.hpp> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::size_t; +} +#endif + +#include <boost/detail/workaround.hpp> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +#include <boost/archive/archive_exception.hpp> + +#include "test_tools.hpp" + +#include <boost/serialization/nvp.hpp> +#include <boost/serialization/set.hpp> + +#include "A.hpp" +#include "A.ipp" + +#include <boost/serialization/unordered_set.hpp> +#include <functional> // requires changeset [69520]; Ticket #5254 + +namespace std { + template<> + struct hash<A> { + std::size_t operator()(const A& a) const { + return static_cast<std::size_t>(a); + } + }; +} // namespace std + +void +test_unordered_set(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + // test array of objects + std::unordered_set<A> anunordered_set; + A a, a1; + anunordered_set.insert(a); + anunordered_set.insert(a1); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunordered_set", anunordered_set); + } + std::unordered_set<A> anunordered_set1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunordered_set", anunordered_set1); + } + std::vector<A> tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(anunordered_set.begin(), anunordered_set.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_set1.begin(), anunordered_set1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + std::remove(testfile); +} + +void +test_unordered_multiset(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + std::unordered_multiset<A> anunordered_multiset; + anunordered_multiset.insert(A()); + anunordered_multiset.insert(A()); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset); + } + std::unordered_multiset<A> anunordered_multiset1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset1); + } + + std::vector<A> tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(anunordered_multiset.begin(), anunordered_multiset.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_multiset1.begin(), anunordered_multiset1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + + std::remove(testfile); +} + +int test_main( int /* argc */, char* /* argv */[] ){ + test_unordered_set(); + test_unordered_multiset(); + return EXIT_SUCCESS; +} diff --git a/libs/serialization/test/test_tools.hpp b/libs/serialization/test/test_tools.hpp index 4ac7368c74..8c25db85dc 100644 --- a/libs/serialization/test/test_tools.hpp +++ b/libs/serialization/test/test_tools.hpp @@ -157,7 +157,7 @@ namespace archive { #endif // defined(__hpux) #endif // defined(_WIN32) || defined(__WIN32__) || defined(WIN32) -#include <boost/detail/lightweight_test.hpp> +#include <boost/core/lightweight_test.hpp> #define BOOST_CHECK( P ) \ BOOST_TEST( (P) ) diff --git a/libs/serialization/test/test_utf8_codecvt.cpp b/libs/serialization/test/test_utf8_codecvt.cpp index 3d35b5e120..41d7bbd99f 100644 --- a/libs/serialization/test/test_utf8_codecvt.cpp +++ b/libs/serialization/test/test_utf8_codecvt.cpp @@ -18,6 +18,8 @@ #include <cwchar> #include <boost/config.hpp> +#include <boost/archive/detail/utf8_codecvt_facet.hpp> + #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ using ::size_t; @@ -41,17 +43,6 @@ namespace std{ #include "test_tools.hpp" -#include <boost/archive/add_facet.hpp> - -#ifndef BOOST_NO_CXX11_HDR_CODECVT - #include <codecvt> - namespace boost { namespace archive { namespace detail { - typedef std::codecvt_utf8<wchar_t> utf8_codecvt_facet; - } } } -#else - #include <boost/archive/detail/utf8_codecvt_facet.hpp> -#endif - template<std::size_t s> struct test_data { @@ -125,8 +116,8 @@ wchar_t test_data<4>::wchar_encoding[] = { int test_main(int /* argc */, char * /* argv */[]) { - std::locale * utf8_locale - = boost::archive::add_facet( + std::locale utf8_locale + = std::locale( std::locale::classic(), new boost::archive::detail::utf8_codecvt_facet ); @@ -142,13 +133,7 @@ test_main(int /* argc */, char * /* argv */[]) { ofs.open("test.dat"); std::copy( td::utf8_encoding, - #if ! defined(__BORLANDC__) - // borland 5.60 complains about this - td::utf8_encoding + sizeof(td::utf8_encoding) / sizeof(unsigned char), - #else - // so use this instead - td::utf8_encoding + 12, - #endif + td::utf8_encoding + sizeof(td::utf8_encoding) / sizeof(unsigned char), std::ostream_iterator<utf8_t>(ofs) ); } @@ -157,7 +142,7 @@ test_main(int /* argc */, char * /* argv */[]) { std::vector<wchar_t> from_file; { std::wifstream ifs; - ifs.imbue(*utf8_locale); + ifs.imbue(utf8_locale); ifs.open("test.dat"); std::wint_t item = 0; @@ -174,21 +159,12 @@ test_main(int /* argc */, char * /* argv */[]) { } } - // compare the data read back in with the orginal - #if ! defined(__BORLANDC__) - // borland 5.60 complains about this - BOOST_CHECK(from_file.size() == sizeof(td::wchar_encoding)/sizeof(wchar_t)); - #else - // so use this instead - BOOST_CHECK(from_file.size() == 6); - #endif - BOOST_CHECK(std::equal(from_file.begin(), from_file.end(), td::wchar_encoding)); // Send the UCS4_data back out, converting to UTF-8 { std::wofstream ofs; - ofs.imbue(*utf8_locale); + ofs.imbue(utf8_locale); ofs.open("test2.dat"); std::copy( from_file.begin(), @@ -249,7 +225,7 @@ test_main(int /* argc */, char * /* argv */[]) { std::size_t l = std::wcslen(test3_data); { std::wofstream ofs; - ofs.imbue(*utf8_locale); + ofs.imbue(utf8_locale); ofs.open("test3.dat"); std::copy( test3_data, @@ -261,7 +237,7 @@ test_main(int /* argc */, char * /* argv */[]) { // Make sure that both files are the same { std::wifstream ifs; - ifs.imbue(*utf8_locale); + ifs.imbue(utf8_locale); ifs.open("test3.dat"); ifs >> std::noskipws; BOOST_CHECK( @@ -272,7 +248,5 @@ test_main(int /* argc */, char * /* argv */[]) { ) ); } - - delete utf8_locale; return EXIT_SUCCESS; } diff --git a/libs/serialization/test/test_vector.cpp b/libs/serialization/test/test_vector.cpp index b5f72a84ac..130ddab490 100644 --- a/libs/serialization/test/test_vector.cpp +++ b/libs/serialization/test/test_vector.cpp @@ -18,25 +18,23 @@ namespace std{ using ::remove; } #endif - +#include <boost/static_assert.hpp> #include "test_tools.hpp" #include <boost/serialization/vector.hpp> +// normal class with default constructor #include "A.hpp" #include "A.ipp" template <class T> -int test_vector() +int test_vector_detail(const std::vector<T> & avector) { const char * testfile = boost::archive::tmpnam(NULL); BOOST_REQUIRE(NULL != testfile); // test array of objects - std::vector< T > avector; - avector.push_back(T()); - avector.push_back(T()); - { + { test_ostream os(testfile, TEST_STREAM_FLAGS); test_oarchive oa(os, TEST_ARCHIVE_FLAGS); oa << boost::serialization::make_nvp("avector", avector); @@ -52,16 +50,79 @@ int test_vector() return EXIT_SUCCESS; } +template <class T> +int test_default_constructible() +{ + // test array of objects + std::vector<T> avector; + avector.push_back(T()); + avector.push_back(T()); + return test_vector_detail(avector); +} + +// class without default constructor +struct X { + //BOOST_DELETED_FUNCTION(X()); +public: + int m_i; + X(const X & x) : + m_i(x.m_i) + {} + X(const int & i) : + m_i(i) + {} + bool operator==(const X & rhs) const { + return m_i == rhs.m_i; + } + template<class Archive> + void serialize(Archive & ar, const unsigned int /*version*/){ + ar & BOOST_SERIALIZATION_NVP(m_i); + } +}; + +template<class Archive> +inline void save_construct_data( + Archive & ar, + const X * x, + const unsigned int /* file_version */ +){ + // variable used for construction + ar << boost::serialization::make_nvp("i", x->m_i); +} + +template<class Archive> +inline void load_construct_data( + Archive & ar, + X * x, + const unsigned int /* file_version */ +){ + int i; + ar >> boost::serialization::make_nvp("i", i); + ::new(x)X(i); +} + +int test_non_default_constructible() +{ + // test array of objects + std::vector<X> avector; + avector.push_back(X(123)); + avector.push_back(X(456)); + return test_vector_detail(avector); +} + int test_main( int /* argc */, char* /* argv */[] ) { - int res = test_vector<A>(); + int res; + res = test_default_constructible<A>(); // test an int vector for which optimized versions should be available - if (res == EXIT_SUCCESS) - res = test_vector<int>(); + if (res == EXIT_SUCCESS) + res = test_default_constructible<int>(); // test a bool vector - if (res == EXIT_SUCCESS) - res = test_vector<bool>(); - return res; + if (res == EXIT_SUCCESS) + res = test_default_constructible<bool>(); + if (res == EXIT_SUCCESS) + res = test_non_default_constructible(); + return res; } // EOF diff --git a/libs/serialization/test/test_z.cpp b/libs/serialization/test/test_z.cpp index d76d7cfc3d..bd8aa34652 100644 --- a/libs/serialization/test/test_z.cpp +++ b/libs/serialization/test/test_z.cpp @@ -1,45 +1,122 @@ +#if 0 +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_optional.cpp + +// (C) Copyright 2004 Pavel Vozenilek +// 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 <cstddef> // NULL +#include <cstdio> // remove +#include <fstream> -/* #include <boost/config.hpp> -#include <iostream> -#include <type_traits> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +#include <boost/archive/archive_exception.hpp> + +#define BOOST_ARCHIVE_TEST xml_archive.hpp + +#include "test_tools.hpp" + +#include <boost/serialization/optional.hpp> + +#include "A.hpp" +#include "A.ipp" + +int test_main( int /* argc */, char* /* argv */[] ) +{ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); -struct A { - A(); -}; + const boost::optional<int> aoptional1; + const boost::optional<int> aoptional2(123); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + //oa << boost::serialization::make_nvp("aoptional1",aoptional1); + //oa << boost::serialization::make_nvp("aoptional2",aoptional2); + } + /* + boost::optional<int> aoptional1a(999); + boost::optional<int> aoptional2a; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("aoptional1",aoptional1a); + ia >> boost::serialization::make_nvp("aoptional2",aoptional2a); + } + BOOST_CHECK(aoptional1 == aoptional1a); + BOOST_CHECK(aoptional2 == aoptional2a); + */ + std::remove(testfile); + return EXIT_SUCCESS; +} + +// EOF + +#elseif 0 + +#include <fstream> + +#include <boost/archive/xml_woarchive.hpp> +#include <boost/archive/xml_wiarchive.hpp> +#include <boost/serialization/string.hpp> + +#include "test_tools.hpp" -struct NA { - NA(int); -}; +int test_main(int, char *argv[]) +{ + const char * testfile = boost::archive::tmpnam(NULL); + std::string s1 = "kkkabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; + std::wstring w1 = L"kkk"; + std::wstring w2 = L"апр"; // some non-latin (for example russians) letters + { + std::wofstream ofs(testfile); + { + boost::archive::xml_woarchive oa(ofs); + oa << boost::serialization::make_nvp("key1", s1); + //oa << boost::serialization::make_nvp("key2", w1); + //oa << boost::serialization::make_nvp("key3", w2); // here exception is thrown + } + } + std::string new_s1; + //std::wstring new_w1; + //std::wstring new_w2; + { + std::wifstream ifs(testfile); + { + boost::archive::xml_wiarchive ia(ifs); + ia >> boost::serialization::make_nvp("key1", new_s1); + //ia >> boost::serialization::make_nvp("key2", new_w1); + //ia >> boost::serialization::make_nvp("key3", new_w2); // here exception is thrown + } + } + BOOST_CHECK(s1 == new_s1); + //BOOST_CHECK(w1 == new_w1); + //BOOST_CHECK(w2 == new_w2); + return 0; +} -#ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS - #pragma message("BOOST_NO_CXX11_HDR_TYPE_TRAITS NOT defined") #else - #pragma message("BOOST_NO_CXX11_HDR_TYPE_TRAITS defined") -#endif -int main(int argc, char * argv[]){ - static_assert( - std::is_default_constructible<A>::value, - "A is NOT default constructible" - ); - static_assert( - ! std::is_default_constructible<NA>::value, - "NA IS default constructible" - ); - - std::cout << std::boolalpha - << "A is default-constructible? " - << std::is_default_constructible<A>::value << '\n' - << "A is trivially default-constructible? " - << std::is_trivially_default_constructible<A>::value << '\n' - << "NA is default-constructible? " - << std::is_default_constructible<NA>::value << '\n' - << "NA is trivially default-constructible? " - << std::is_trivially_default_constructible<NA>::value << '\n' - ; - return 0; +#include <boost/archive/xml_oarchive.hpp> +#include <boost/serialization/nvp.hpp> + +#include <iostream> + +int main() { + boost::archive::xml_oarchive oa( std::cerr ); + int bob = 3; + oa << boost::serialization::make_nvp( "bob", bob ); } -*/ -#include "../../config/test/config_info.cpp" + +#endif
\ No newline at end of file diff --git a/libs/serialization/test/testfile2 b/libs/serialization/test/testfile2 Binary files differdeleted file mode 100644 index c3fab95005..0000000000 --- a/libs/serialization/test/testfile2 +++ /dev/null diff --git a/libs/serialization/util/test.jam b/libs/serialization/util/test.jam index 18178c37e6..b6031d7016 100644 --- a/libs/serialization/util/test.jam +++ b/libs/serialization/util/test.jam @@ -34,20 +34,20 @@ rule run-template ( test-name : sources * : requirements * ) { : # input files : # requirements # toolset warnings - # <toolset>gcc:<cxxflags>"-Wno-non-virtual-dtor -Wno-ctor-dtor-privacy" <toolset>borland:<cxxflags>"-w-8080 -w-8071 -w-8057 -w-8062 -w-8008 -w-0018 -w-8066" - <toolset>gcc:<warnings>all # ? - <toolset>gcc:<cxxflags>"-Wno-long-long" + #<toolset>gcc:<warnings>all # ? + <toolset>gcc:<cxxflags>"-Wno-unused-variable -Wno-long-long" + <toolset>darwin:<cxxflags>"-Wno-unused-variable -Wno-long-long" <toolset>msvc:<warnings>all # == /W4 <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE <toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE <toolset>msvc:<cxxflags>"-wd4996" + <toolset>clang:<variant>debug:<cxxflags>"-fsanitize=memory" # toolset optimizations <toolset>gcc:<cxxflags>"-ftemplate-depth-255" <toolset>clang:<cxxflags>"-ftemplate-depth-255" - <toolset>clang-darwin:<cxxflags>"-ftemplate-depth-255" <toolset>darwin:<cxxflags>"-ftemplate-depth-255" <toolset>msvc:<cxxflags>"-Gy" $(requirements) @@ -176,16 +176,15 @@ rule test-bsl-run_files ( test-name : sources * : libs * : requirements * ) { return $(tests) ; } -rule test-bsl-run_polymorphic_archive ( test-name : sources * ) { +rule test-bsl-run_polymorphic_archive ( test-name : sources * : requirements * ) { local tests ; for local defn in $(BOOST_ARCHIVE_LIST) { tests += [ test-bsl-run_archive $(test-name) : polymorphic_$(defn:LB) - : $(test-name) $(sources) + : $(test-name) $(sources) $(requirements) ] ; } return $(tests) ; } - |