mirror of
https://github.com/boostorg/serialization.git
synced 2026-02-23 03:52:24 +00:00
Merge trunk to release
[SVN r55350]
This commit is contained in:
@@ -89,7 +89,7 @@ A::A() :
|
||||
#ifndef BOOST_NO_CWCHAR
|
||||
r(std::rand()),
|
||||
#endif
|
||||
c(std::rand()),
|
||||
c(0xff & std::rand()),
|
||||
s(std::rand()),
|
||||
t(std::rand()),
|
||||
u(std::rand()),
|
||||
|
||||
30
test/A.hpp
30
test/A.hpp
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <ostream> // for friend output operators
|
||||
#include <cstddef> // size_t
|
||||
#include <string>
|
||||
#include <boost/config.hpp>
|
||||
#if defined(BOOST_NO_STDC_NAMESPACE)
|
||||
namespace std{
|
||||
@@ -41,11 +42,19 @@ namespace std{
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/string.hpp>
|
||||
|
||||
#ifndef DLL_DECL
|
||||
#define DLL_DECL
|
||||
#include <boost/preprocessor/facilities/empty.hpp>
|
||||
|
||||
#include "test_decl.hpp"
|
||||
|
||||
#if defined(A_IMPORT)
|
||||
#define DLL_DECL IMPORT_DECL
|
||||
#elif defined(A_EXPORT)
|
||||
#define DLL_DECL EXPORT_DECL
|
||||
#else
|
||||
#define DLL_DECL(x)
|
||||
#endif
|
||||
|
||||
class DLL_DECL A
|
||||
class DLL_DECL(BOOST_PP_EMPTY()) A
|
||||
{
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
@@ -56,7 +65,7 @@ private:
|
||||
// reason we can't make abstract.
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
template<class Archive>
|
||||
void A::serialize(
|
||||
void serialize(
|
||||
Archive &ar,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
@@ -98,12 +107,13 @@ private:
|
||||
ar & BOOST_SERIALIZATION_NVP(z);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
template<class Archive>
|
||||
void serialize(
|
||||
Archive &ar,
|
||||
const unsigned int /* file_version */
|
||||
);
|
||||
#endif
|
||||
template<class Archive>
|
||||
DLL_DECL void serialize(
|
||||
Archive &ar,
|
||||
const unsigned int /* file_version */
|
||||
);
|
||||
bool b;
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
boost::int64_t f;
|
||||
@@ -143,4 +153,6 @@ public:
|
||||
friend std::ostream & operator<<(std::ostream & os, A const & a);
|
||||
};
|
||||
|
||||
#undef DLL_DECL
|
||||
|
||||
#endif // BOOST_SERIALIZATION_TEST_A_HPP
|
||||
|
||||
@@ -8,17 +8,14 @@
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#if ! BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
|
||||
#include "A.hpp"
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
|
||||
#include <boost/archive/dinkumware.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/string.hpp>
|
||||
#include "A.hpp"
|
||||
|
||||
template<class Archive>
|
||||
void A::serialize(
|
||||
@@ -64,4 +61,4 @@ void A::serialize(
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // workaround
|
||||
#endif // workaround BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
|
||||
@@ -108,11 +108,8 @@ serialization_test_allarchives(test_derived_class test_derived_class.cpp A.cpp)
|
||||
serialization_test_allarchives(test_derived_class_ptr test_derived_class_ptr.cpp A.cpp)
|
||||
serialization_test_allarchives(test_diamond)
|
||||
serialization_test_allarchives(test_exported)
|
||||
# The order of the save/load tests is important, because the "save"
|
||||
# tests save data that is later loaded by the "load" test. CTest will
|
||||
# always run tests in the order given in this file.
|
||||
serialization_test_allarchives(test_class_info_save)
|
||||
serialization_test_allarchives(test_class_info_load)
|
||||
serialization_test_allarchives(test_class_info_save)
|
||||
serialization_test_allarchives(test_object)
|
||||
serialization_test_allarchives(test_primitive)
|
||||
serialization_test_allarchives(test_list test_list.cpp A.cpp)
|
||||
|
||||
@@ -25,19 +25,54 @@ import ../util/test :
|
||||
|
||||
BOOST_ARCHIVE_LIST = [ modules.peek : BOOST_ARCHIVE_LIST ] ;
|
||||
|
||||
lib dll_a_lib
|
||||
:
|
||||
dll_a.cpp
|
||||
../build//boost_serialization
|
||||
:
|
||||
<link>shared
|
||||
;
|
||||
|
||||
lib dll_base_lib
|
||||
:
|
||||
dll_base.cpp
|
||||
../build//boost_serialization
|
||||
:
|
||||
<link>shared
|
||||
;
|
||||
|
||||
lib dll_derived2_lib
|
||||
:
|
||||
dll_derived2.cpp
|
||||
dll_base_lib
|
||||
../build//boost_serialization
|
||||
:
|
||||
<link>shared
|
||||
;
|
||||
|
||||
lib dll_polymorphic_derived2_lib
|
||||
:
|
||||
polymorphic_derived2.cpp
|
||||
polymorphic_base.cpp
|
||||
../build//boost_serialization
|
||||
:
|
||||
<link>shared
|
||||
;
|
||||
|
||||
test-suite "serialization" :
|
||||
[ test-bsl-run_files test_array : A ]
|
||||
[ test-bsl-run_files test_binary ]
|
||||
[ test-bsl-run_files test_bitset ]
|
||||
[ test-bsl-run_files test_complex ]
|
||||
[ test-bsl-run_files test_contained_class : A ]
|
||||
[ test-bsl-run_files test_cyclic_ptrs : A ]
|
||||
[ test-bsl-run_files test_delete_pointer ]
|
||||
[ test-bsl-run_files test_deque : A ]
|
||||
# [ test-bsl-run_files test_derived ]
|
||||
[ test-bsl-run_files test_derived ]
|
||||
[ test-bsl-run_files test_derived_class : A ]
|
||||
[ test-bsl-run_files test_derived_class_ptr : A ]
|
||||
[ test-bsl-run_files test_diamond ]
|
||||
[ test-bsl-run_files test_exported ]
|
||||
[ test-bsl-run_files test_exported : polymorphic_base ]
|
||||
[ test-bsl-run_files test_class_info_load ]
|
||||
[ test-bsl-run_files test_class_info_save ]
|
||||
[ test-bsl-run_files test_object ]
|
||||
@@ -47,8 +82,9 @@ test-suite "serialization" :
|
||||
[ test-bsl-run_files test_map : A ]
|
||||
[ test-bsl-run_files test_mi ]
|
||||
[ test-bsl-run_files test_multiple_ptrs : A ]
|
||||
[ test-bsl-run_files test_multiple_inheritance ]
|
||||
[ test-bsl-run_files test_no_rtti
|
||||
: polymorphic_base polymorphic_derived1 polymorphic_derived2
|
||||
: polymorphic_base polymorphic_derived1
|
||||
]
|
||||
[ test-bsl-run_files test_non_intrusive ]
|
||||
[ test-bsl-run_files test_non_default_ctor ]
|
||||
@@ -69,12 +105,17 @@ test-suite "serialization" :
|
||||
[ test-bsl-run_files test_new_operator : A ]
|
||||
[ test-bsl-run_files test_optional ]
|
||||
[ test-bsl-run_files test_shared_ptr ]
|
||||
[ test-bsl-run_files test_shared_ptr_multi_base ]
|
||||
[ test-bsl-run_files test_shared_ptr_132 ]
|
||||
[ test-bsl-run_polymorphic_archive test_polymorphic : test_polymorphic_A A ]
|
||||
;
|
||||
;
|
||||
|
||||
if ! $(BOOST_ARCHIVE_LIST) {
|
||||
test-suite "serialization2" :
|
||||
[ test-bsl-run test_dll_exported : polymorphic_base : dll_polymorphic_derived2_lib : <runtime-link>shared ]
|
||||
# [ test-bsl-run test_dll_plugin : : dll_base_lib dll_derived2_lib : <runtime-link>shared ]
|
||||
[ test-bsl-run test_dll_simple : : dll_a_lib : <runtime-link>shared ]
|
||||
|
||||
[ test-bsl-run test_private_ctor ]
|
||||
[ test-bsl-run test_reset_object_address : A ]
|
||||
[ test-bsl-run test_void_cast ]
|
||||
|
||||
@@ -18,20 +18,29 @@
|
||||
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <boost/serialization/assume_abstract.hpp>
|
||||
#include <boost/preprocessor/facilities/empty.hpp>
|
||||
|
||||
#ifndef DLL_DECL
|
||||
#define DLL_DECL
|
||||
#include "test_decl.hpp"
|
||||
|
||||
#if defined(BASE_IMPORT)
|
||||
#define DLL_DECL IMPORT_DECL
|
||||
#elif defined(BASE_EXPORT)
|
||||
#define DLL_DECL EXPORT_DECL
|
||||
#else
|
||||
#define DLL_DECL(x)
|
||||
#endif
|
||||
|
||||
class DLL_DECL polymorphic_base
|
||||
class DLL_DECL(BOOST_PP_EMPTY()) base
|
||||
{
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive & /* ar */, const unsigned int /* file_version */);
|
||||
public:
|
||||
virtual ~polymorphic_base(){};
|
||||
virtual ~base(){};
|
||||
};
|
||||
|
||||
BOOST_SERIALIZATION_ASSUME_ABSTRACT(polymorphic_base)
|
||||
BOOST_SERIALIZATION_ASSUME_ABSTRACT(base)
|
||||
|
||||
#undef DLL_DECL
|
||||
|
||||
#endif // BOOST_SERIALIZATION_TEST_BASE_HPP
|
||||
|
||||
@@ -19,22 +19,32 @@
|
||||
#include <boost/serialization/export.hpp>
|
||||
#include <boost/serialization/access.hpp>
|
||||
|
||||
#define BASE_IMPORT
|
||||
#include "base.hpp"
|
||||
|
||||
#ifndef DLL_DECL
|
||||
#define DLL_DECL
|
||||
#include "test_decl.hpp"
|
||||
|
||||
#if defined(DERIVED2_IMPORT)
|
||||
#define DLL_DECL IMPORT_DECL
|
||||
#elif defined(DERIVED2_EXPORT)
|
||||
#define DLL_DECL EXPORT_DECL
|
||||
#else
|
||||
#define DLL_DECL(x)
|
||||
#endif
|
||||
|
||||
class DLL_DECL polymorphic_derived2 : public polymorphic_base
|
||||
class DLL_DECL(BOOST_PP_EMPTY()) derived2 :
|
||||
public base
|
||||
{
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive &ar, const unsigned int /* file_version */);
|
||||
public:
|
||||
~polymorphic_derived2(){}
|
||||
~derived2(){}
|
||||
};
|
||||
|
||||
#undef DLL_DECL
|
||||
|
||||
// MWerks users can do this to make their code work
|
||||
BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived2)
|
||||
BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(base, derived2)
|
||||
|
||||
#endif // BOOST_SERIALIZATION_TEST_DERIVED2_HPP
|
||||
|
||||
@@ -8,13 +8,11 @@
|
||||
|
||||
// Build a dll which contains the serialization for a class A
|
||||
// used in testing distribution of serialization code in DLLS
|
||||
#include "test_decl.hpp"
|
||||
|
||||
#define DLL_DECL EXPORT_DECL(BOOST_PP_EMPTY())
|
||||
#define A_EXPORT
|
||||
#include "A.hpp"
|
||||
#include "A.ipp"
|
||||
#include "A.cpp"
|
||||
#undef DLL_DECL
|
||||
|
||||
// instantiate code for text archives
|
||||
|
||||
|
||||
@@ -10,17 +10,11 @@
|
||||
// used in testing distribution of serialization code in DLLS
|
||||
#include <boost/serialization/export.hpp>
|
||||
|
||||
#include "test_decl.hpp"
|
||||
#define DLL_DECL EXPORT_DECL(BOOST_PP_EMPTY())
|
||||
#define BASE_EXPORT
|
||||
#include "base.hpp"
|
||||
#undef DLL_DECL
|
||||
|
||||
// instantiate code for text archives
|
||||
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
|
||||
template<class Archive>
|
||||
void polymorphic_base::serialize(
|
||||
void base::serialize(
|
||||
Archive &ar,
|
||||
const unsigned int /* file_version */){
|
||||
}
|
||||
@@ -43,19 +37,19 @@ void polymorphic_base::serialize(
|
||||
// explicit instantiation in this case.
|
||||
//BOOST_CLASS_EXPORT(polymorphic_base)
|
||||
|
||||
template EXPORT_DECL(void) polymorphic_base::serialize(
|
||||
template EXPORT_DECL(void) base::serialize(
|
||||
boost::archive::text_oarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
template EXPORT_DECL(void) polymorphic_base::serialize(
|
||||
template EXPORT_DECL(void) base::serialize(
|
||||
boost::archive::text_iarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
template EXPORT_DECL(void) polymorphic_base::serialize(
|
||||
template EXPORT_DECL(void) base::serialize(
|
||||
boost::archive::polymorphic_oarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
template EXPORT_DECL(void) polymorphic_base::serialize(
|
||||
template EXPORT_DECL(void) base::serialize(
|
||||
boost::archive::polymorphic_iarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
|
||||
@@ -8,35 +8,47 @@
|
||||
|
||||
// Build a dll which contains the serialization for a class A
|
||||
// used in testing distribution of serialization code in DLLS
|
||||
#include "test_decl.hpp"
|
||||
|
||||
#define DLL_DECL IMPORT_DECL
|
||||
#include "base.hpp"
|
||||
#undef DLL_DECL
|
||||
|
||||
#define DLL_DECL EXPORT_DECL(BOOST_PP_EMPTY())
|
||||
#include "derived2.hpp"
|
||||
#undef DLL_DECL
|
||||
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
|
||||
#define DERIVED2_EXPORT
|
||||
#include "derived2.hpp"
|
||||
|
||||
template<class Archive>
|
||||
void polymorphic_derived2::serialize(
|
||||
void derived2::serialize(
|
||||
Archive &ar,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(base);
|
||||
}
|
||||
|
||||
// instantiate code for text archives
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
|
||||
// instantiate code for polymorphic archives
|
||||
template EXPORT_DECL(void) derived2::serialize(
|
||||
boost::archive::text_oarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
template EXPORT_DECL(void) derived2::serialize(
|
||||
boost::archive::text_iarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
|
||||
#include <boost/archive/polymorphic_oarchive.hpp>
|
||||
#include <boost/archive/polymorphic_iarchive.hpp>
|
||||
|
||||
template EXPORT_DECL(void) derived2::serialize(
|
||||
boost::archive::polymorphic_oarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
template EXPORT_DECL(void) derived2::serialize(
|
||||
boost::archive::polymorphic_iarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
|
||||
// note: export has to be AFTER #includes for all archive classes
|
||||
|
||||
#include <boost/serialization/factory.hpp>
|
||||
BOOST_SERIALIZATION_FACTORY_0(polymorphic_derived2)
|
||||
BOOST_CLASS_EXPORT(polymorphic_derived2)
|
||||
BOOST_SERIALIZATION_FACTORY_0(derived2)
|
||||
BOOST_CLASS_EXPORT(derived2)
|
||||
|
||||
@@ -12,3 +12,10 @@
|
||||
#include "polymorphic_base.hpp"
|
||||
|
||||
BOOST_CLASS_EXPORT(polymorphic_base)
|
||||
|
||||
const char * polymorphic_base::get_key() const{
|
||||
return
|
||||
boost::serialization::type_info_implementation<
|
||||
polymorphic_base
|
||||
>::type::get_const_instance().get_key();
|
||||
}
|
||||
|
||||
@@ -24,10 +24,15 @@ class polymorphic_base
|
||||
{
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive & /* ar */, const unsigned int /* file_version */){
|
||||
}
|
||||
void serialize(
|
||||
Archive & /* ar */,
|
||||
const unsigned int /* file_version */
|
||||
){}
|
||||
public:
|
||||
virtual const char * get_key() const = 0;
|
||||
// note that since this class uses the "no_rtti"
|
||||
// extended_type_info implementation, it MUST
|
||||
// implement this function
|
||||
virtual const char * get_key() const;
|
||||
virtual ~polymorphic_base(){};
|
||||
};
|
||||
|
||||
@@ -35,7 +40,7 @@ BOOST_SERIALIZATION_ASSUME_ABSTRACT(polymorphic_base)
|
||||
|
||||
BOOST_CLASS_TYPE_INFO(
|
||||
polymorphic_base,
|
||||
extended_type_info_no_rtti<polymorphic_base>
|
||||
boost::serialization::extended_type_info_no_rtti<polymorphic_base>
|
||||
)
|
||||
|
||||
#endif // POLYMORPHIC_BASE_HPP
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
#include "polymorphic_derived1.hpp"
|
||||
|
||||
BOOST_CLASS_EXPORT(polymorphic_derived1)
|
||||
|
||||
const char * polymorphic_derived1::get_key() const {
|
||||
return
|
||||
boost::serialization::type_info_implementation<
|
||||
polymorphic_derived1
|
||||
>::type::get_const_instance().get_key();
|
||||
}
|
||||
|
||||
BOOST_CLASS_EXPORT(polymorphic_derived1)
|
||||
|
||||
@@ -12,16 +12,47 @@
|
||||
#include <boost/serialization/extended_type_info_no_rtti.hpp>
|
||||
#include <boost/serialization/export.hpp>
|
||||
|
||||
#define POLYMORPHIC_DERIVED2_EXPORT
|
||||
#include "polymorphic_derived2.hpp"
|
||||
|
||||
// note: types which use ...no_rtti MUST be exported
|
||||
// instantiate code for text archives
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
|
||||
template EXPORT_DECL(void) polymorphic_derived2::serialize(
|
||||
boost::archive::text_oarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
template EXPORT_DECL(void) polymorphic_derived2::serialize(
|
||||
boost::archive::text_iarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
|
||||
// instantiate code for polymorphic archives
|
||||
#include <boost/archive/polymorphic_iarchive.hpp>
|
||||
#include <boost/archive/polymorphic_oarchive.hpp>
|
||||
|
||||
template EXPORT_DECL(void) polymorphic_derived2::serialize(
|
||||
boost::archive::polymorphic_oarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
template EXPORT_DECL(void) polymorphic_derived2::serialize(
|
||||
boost::archive::polymorphic_iarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
|
||||
// MWerks users can do this to make their code work
|
||||
BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived2)
|
||||
|
||||
// note: export has to be AFTER #includes for all archive classes
|
||||
BOOST_CLASS_EXPORT(polymorphic_derived2)
|
||||
|
||||
const char * polymorphic_derived2::get_key() const {
|
||||
// use the exported key as the identifier
|
||||
return
|
||||
boost::serialization::type_info_implementation<
|
||||
polymorphic_derived2
|
||||
>::type::get_const_instance().get_key();
|
||||
}
|
||||
// export plug-in not yet working !!!
|
||||
#if 0
|
||||
#include <boost/serialization/factory.hpp>
|
||||
BOOST_SERIALIZATION_FACTORY_0(polymorphic_derived2)
|
||||
|
||||
template
|
||||
EXPORT_DECL(polymorphic_derived2 *)
|
||||
boost::serialization::factory<polymorphic_derived2, 0>(std::va_list ap);
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef POLYMORPHIC_DERIVED2_HPP
|
||||
#define POLYMORPHIC_DERIVED2_HPP
|
||||
#ifndef DERIVED2_HPP
|
||||
#define DERIVED2_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
@@ -7,7 +7,7 @@
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// polymorphic_derived1.hpp simple class test
|
||||
// derived1.hpp simple class test
|
||||
|
||||
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
@@ -21,18 +21,34 @@
|
||||
#include <boost/serialization/base_object.hpp>
|
||||
#include <boost/serialization/type_info_implementation.hpp>
|
||||
#include <boost/serialization/extended_type_info_typeid.hpp>
|
||||
#include <boost/preprocessor/empty.hpp>
|
||||
|
||||
#include "polymorphic_base.hpp"
|
||||
|
||||
class polymorphic_derived2 : public polymorphic_base
|
||||
#include "test_decl.hpp"
|
||||
|
||||
#if defined(POLYMORPHIC_DERIVED2_IMPORT)
|
||||
#define DLL_DECL IMPORT_DECL
|
||||
#elif defined(POLYMORPHIC_DERIVED2_EXPORT)
|
||||
#define DLL_DECL EXPORT_DECL
|
||||
#else
|
||||
#define DLL_DECL(x)
|
||||
#endif
|
||||
|
||||
class DLL_DECL(BOOST_PP_EMPTY()) polymorphic_derived2 :
|
||||
public polymorphic_base
|
||||
{
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive &ar, const unsigned int /* file_version */){
|
||||
void serialize(
|
||||
Archive &ar,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
|
||||
}
|
||||
public:
|
||||
virtual const char * get_key() const ;
|
||||
virtual const char * get_key() const {
|
||||
return "polymorphic_derived2";
|
||||
}
|
||||
};
|
||||
|
||||
// note the mixing of type_info systems is supported.
|
||||
@@ -41,5 +57,7 @@ BOOST_CLASS_TYPE_INFO(
|
||||
boost::serialization::extended_type_info_typeid<polymorphic_derived2>
|
||||
)
|
||||
|
||||
#endif // POLYMORPHIC_DERIVED2_HPP
|
||||
#undef DLL_DECL
|
||||
|
||||
#endif // DERIVED2_HPP
|
||||
|
||||
|
||||
63
test/test_bitset.cpp
Normal file
63
test/test_bitset.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/*!
|
||||
* \file test_bitset.cpp
|
||||
* \brief Test that serialization of std::bitset works.
|
||||
* \note Should pass compilation and execution
|
||||
* \author Brian Ravnsgaard Riis
|
||||
* \author Kenneth Riddile
|
||||
* \date 16.09.2004, updated 04.03.2009
|
||||
* \license Boost Software License 1.0
|
||||
*/
|
||||
|
||||
#include <cstddef> // NULL
|
||||
#include <cstdio> // remove
|
||||
#include <fstream>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined( BOOST_NO_STDC_NAMESPACE )
|
||||
namespace std
|
||||
{
|
||||
using ::remove;
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "test_tools.hpp"
|
||||
|
||||
#include <boost/serialization/bitset.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
|
||||
int test_main( int /* argc */, char* /* argv */[] )
|
||||
{
|
||||
const char* testfile = boost::archive::tmpnam( NULL );
|
||||
BOOST_REQUIRE( NULL != testfile );
|
||||
|
||||
std::bitset<8> bitsetA;
|
||||
bitsetA.set( 0, false );
|
||||
bitsetA.set( 1, true );
|
||||
bitsetA.set( 2, false );
|
||||
bitsetA.set( 3, true );
|
||||
bitsetA.set( 4, false );
|
||||
bitsetA.set( 5, false );
|
||||
bitsetA.set( 6, true );
|
||||
bitsetA.set( 7, true );
|
||||
|
||||
{
|
||||
test_ostream os( testfile, TEST_STREAM_FLAGS );
|
||||
test_oarchive oa( os );
|
||||
oa << boost::serialization::make_nvp( "bitset", bitsetA );
|
||||
}
|
||||
|
||||
std::bitset<8> bitsetB;
|
||||
{
|
||||
test_istream is( testfile, TEST_STREAM_FLAGS );
|
||||
test_iarchive ia( is );
|
||||
ia >> boost::serialization::make_nvp( "bitset", bitsetB );
|
||||
}
|
||||
|
||||
BOOST_CHECK( bitsetA == bitsetB );
|
||||
|
||||
std::remove( testfile );
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// EOF
|
||||
@@ -18,27 +18,38 @@
|
||||
// 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:
|
||||
//
|
||||
// #define DLL_DECL IMPORT_DECL
|
||||
// #include "A.hpp"
|
||||
// #undef DLL_DECL
|
||||
//
|
||||
// for declarations used in dlls for exporting, and
|
||||
//
|
||||
// #define DLL_DECL EXPORT_DECL
|
||||
// code which builds dll should like like
|
||||
//
|
||||
// #define A_CPP
|
||||
// #include "A.hpp"
|
||||
// #include "A.ipp"
|
||||
// #undef DLL_DECL
|
||||
//
|
||||
// when a declaration is to be imported.
|
||||
// A::A(){
|
||||
// ...
|
||||
// }
|
||||
// ...
|
||||
//
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/preprocessor/facilities/empty.hpp>
|
||||
|
||||
#ifdef BOOST_HAS_DECLSPEC // defined in config system
|
||||
#if ! defined(EXPORT_DECL)
|
||||
@@ -50,11 +61,14 @@
|
||||
#endif
|
||||
#if ! defined(IMPORT_DECL)
|
||||
#if defined(__BORLANDC__)
|
||||
#define IMPORT_DECL __import
|
||||
#define IMPORT_DECL(T) T __import
|
||||
#else
|
||||
#define IMPORT_DECL __declspec(dllimport)
|
||||
#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
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// test_diamond.cpp
|
||||
|
||||
// (C) Copyright 2002 Vladimir Prus.
|
||||
// (C) Copyright 2002-2009 Vladimir Prus and Robert Ramey.
|
||||
// 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)
|
||||
|
||||
// test of serialization library for diamond intheritence situations
|
||||
// test of serialization library for diamond inheritence situations
|
||||
|
||||
#include <cstddef> // NULL
|
||||
#include <fstream>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// test_exported.cpp
|
||||
// test_dll_exported.cpp
|
||||
|
||||
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
@@ -8,6 +8,22 @@
|
||||
|
||||
// should pass compilation and execution
|
||||
|
||||
// This is an overly complex test. The purpose of this test is to
|
||||
// demostrate and test the ability to serialize a hiarchy of class
|
||||
// through a base class pointer even though those class might be
|
||||
// implemente in different dlls and use different extended type info
|
||||
// systems.
|
||||
//
|
||||
// polymorphic_ base is locally declared and defined. It use the
|
||||
// "no_rtti" extended type info system.
|
||||
|
||||
// polymorphic_derived1 is locally declared and defined. It uses
|
||||
// the default "type_id" extended type info system
|
||||
|
||||
// polymorphic_derived2 is declared in polymorphic_derived.hpp
|
||||
// and defined in dll_polymorphic_derived2. It uses the typeid
|
||||
// system.
|
||||
|
||||
#include <cstddef> // NULL
|
||||
#include <fstream>
|
||||
|
||||
@@ -19,19 +35,19 @@ namespace std{
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <boost/archive/archive_exception.hpp>
|
||||
// for now, only test with simple text archive
|
||||
#define BOOST_ARCHIVE_TEST text_archive.hpp
|
||||
#include "test_tools.hpp"
|
||||
#include "test_decl.hpp"
|
||||
|
||||
#define DLL_DECL IMPORT_DECL
|
||||
#include "base.hpp"
|
||||
#undef DLL_DECL
|
||||
#include <boost/archive/archive_exception.hpp>
|
||||
|
||||
#include <boost/serialization/base_object.hpp>
|
||||
#include <boost/serialization/export.hpp>
|
||||
#include <boost/serialization/type_info_implementation.hpp>
|
||||
#include <boost/serialization/access.hpp>
|
||||
|
||||
#include "polymorphic_base.hpp"
|
||||
|
||||
class polymorphic_derived1 : public polymorphic_base
|
||||
{
|
||||
friend class boost::serialization::access;
|
||||
@@ -39,18 +55,20 @@ class polymorphic_derived1 : public polymorphic_base
|
||||
void serialize(Archive &ar, const unsigned int /* file_version */){
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
|
||||
}
|
||||
virtual const char * get_key() const {
|
||||
return "polymorphic_derived1";
|
||||
}
|
||||
public:
|
||||
virtual ~polymorphic_derived1(){}
|
||||
};
|
||||
|
||||
BOOST_CLASS_EXPORT(polymorphic_derived1)
|
||||
|
||||
// MWerks users can do this to make their code work
|
||||
BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived1)
|
||||
|
||||
#define DLL_DECL IMPORT_DECL
|
||||
#include "derived2.hpp"
|
||||
#undef DLL_DECL
|
||||
BOOST_CLASS_EXPORT(polymorphic_derived1)
|
||||
|
||||
#define POLYMORPHIC_DERIVED2_IMPORT
|
||||
#include "polymorphic_derived2.hpp"
|
||||
|
||||
// save exported polymorphic class
|
||||
void save_exported(const char *testfile)
|
||||
|
||||
@@ -27,12 +27,13 @@ namespace std{
|
||||
#endif
|
||||
|
||||
#include <boost/archive/archive_exception.hpp>
|
||||
#include "test_tools.hpp"
|
||||
#include "test_decl.hpp"
|
||||
|
||||
#define DLL_DECL IMPORT_DECL
|
||||
#include "base.hpp"
|
||||
#undef DLL_DECL
|
||||
// for now, only test with simple text and polymorphic archive
|
||||
#define BOOST_ARCHIVE_TEST polymorphic_text_archive.hpp
|
||||
#include "test_tools.hpp"
|
||||
|
||||
#include <boost/archive/polymorphic_text_oarchive.hpp>
|
||||
#include <boost/archive/polymorphic_text_iarchive.hpp>
|
||||
|
||||
#include <boost/serialization/base_object.hpp>
|
||||
#include <boost/serialization/export.hpp>
|
||||
@@ -41,6 +42,9 @@ namespace std{
|
||||
#include <boost/serialization/void_cast.hpp>
|
||||
#include <boost/serialization/extended_type_info.hpp>
|
||||
|
||||
#include "polymorphic_base.hpp"
|
||||
|
||||
// declare and implement a derived class in our own executable
|
||||
class polymorphic_derived1 : public polymorphic_base
|
||||
{
|
||||
friend class boost::serialization::access;
|
||||
@@ -152,7 +156,8 @@ test_main( int /* argc */, char* /* argv */[] )
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
|
||||
HINSTANCE hDLL; // Handle to DLL
|
||||
hDLL = LoadLibrary("derived2.dll");
|
||||
hDLL = LoadLibrary("dll_polymorphic_derived2.dll");
|
||||
assert(0 != hDLL);
|
||||
save_exported(testfile);
|
||||
load_exported(testfile);
|
||||
FreeLibrary(hDLL);
|
||||
|
||||
@@ -22,18 +22,15 @@ namespace std{
|
||||
}
|
||||
#endif
|
||||
|
||||
// for now, only test with simple text and polymorphic archive
|
||||
#include "test_tools.hpp"
|
||||
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
#include "text_archive.hpp"
|
||||
|
||||
#include <boost/archive/polymorphic_text_oarchive.hpp>
|
||||
#include <boost/archive/polymorphic_text_iarchive.hpp>
|
||||
|
||||
#include "test_decl.hpp"
|
||||
#define DLL_DECL IMPORT_DECL
|
||||
#define A_IMPORT
|
||||
#include "A.hpp"
|
||||
#undef DLL_DECL
|
||||
|
||||
// simple class with text archive compiled in dll
|
||||
void
|
||||
@@ -41,7 +38,8 @@ test1(){
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
|
||||
A a, a1;
|
||||
const A a;
|
||||
A a1;
|
||||
{
|
||||
test_ostream os(testfile, TEST_STREAM_FLAGS);
|
||||
boost::archive::text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
|
||||
@@ -63,16 +61,19 @@ test2(){
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
|
||||
A a, a1;
|
||||
const A a;
|
||||
A a1;
|
||||
{
|
||||
test_ostream os(testfile, TEST_STREAM_FLAGS);
|
||||
boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
|
||||
oa << boost::serialization::make_nvp("a", a);
|
||||
boost::archive::polymorphic_oarchive & poa(oa);
|
||||
poa << boost::serialization::make_nvp("a", a);
|
||||
}
|
||||
{
|
||||
test_istream is(testfile, TEST_STREAM_FLAGS);
|
||||
boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
|
||||
ia >> boost::serialization::make_nvp("a", a1);
|
||||
boost::archive::polymorphic_iarchive & pia(ia);
|
||||
pia >> boost::serialization::make_nvp("a", a1);
|
||||
}
|
||||
BOOST_CHECK_EQUAL(a, a1);
|
||||
|
||||
@@ -85,7 +86,7 @@ test3(){
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
|
||||
A *a = & A();
|
||||
const A *a = new A;
|
||||
A *a1;
|
||||
{
|
||||
test_ostream os(testfile, TEST_STREAM_FLAGS);
|
||||
@@ -100,6 +101,7 @@ test3(){
|
||||
BOOST_CHECK_EQUAL(*a, *a1);
|
||||
|
||||
std::remove(testfile);
|
||||
delete a;
|
||||
}
|
||||
|
||||
// simple class pointer with polymorphic archive compiled in dll
|
||||
@@ -108,26 +110,27 @@ test4(){
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
|
||||
A *a = & A();
|
||||
const A *a = new A;
|
||||
A *a1;
|
||||
{
|
||||
test_ostream os(testfile, TEST_STREAM_FLAGS);
|
||||
boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
|
||||
oa << boost::serialization::make_nvp("a", a);
|
||||
boost::archive::polymorphic_oarchive & poa(oa);
|
||||
poa << boost::serialization::make_nvp("a", a);
|
||||
}
|
||||
{
|
||||
test_istream is(testfile, TEST_STREAM_FLAGS);
|
||||
boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
|
||||
ia >> boost::serialization::make_nvp("a", a1);
|
||||
boost::archive::polymorphic_iarchive & pia(ia);
|
||||
pia >> boost::serialization::make_nvp("a", a1);
|
||||
}
|
||||
BOOST_CHECK_EQUAL(*a, *a1);
|
||||
|
||||
std::remove(testfile);
|
||||
delete a;
|
||||
}
|
||||
|
||||
#define DLL_DECL IMPORT_DECL
|
||||
#include "B.hpp"
|
||||
#undef DLL_DECL
|
||||
|
||||
// derived class with base text archive compiled in dll
|
||||
void
|
||||
@@ -135,7 +138,8 @@ test5(){
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
|
||||
B b, b1;
|
||||
const B b;
|
||||
B b1;
|
||||
{
|
||||
test_ostream os(testfile, TEST_STREAM_FLAGS);
|
||||
boost::archive::text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
|
||||
@@ -157,16 +161,19 @@ test6(){
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
|
||||
B b, b1;
|
||||
const B b;
|
||||
B b1;
|
||||
{
|
||||
test_ostream os(testfile, TEST_STREAM_FLAGS);
|
||||
boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
|
||||
oa << boost::serialization::make_nvp("b", b);
|
||||
boost::archive::polymorphic_oarchive & poa(oa);
|
||||
poa << boost::serialization::make_nvp("b", b);
|
||||
}
|
||||
{
|
||||
test_istream is(testfile, TEST_STREAM_FLAGS);
|
||||
boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
|
||||
ia >> boost::serialization::make_nvp("b", b1);
|
||||
boost::archive::polymorphic_iarchive & pia(ia);
|
||||
pia >> boost::serialization::make_nvp("b", b1);
|
||||
}
|
||||
BOOST_CHECK_EQUAL(b, b1);
|
||||
|
||||
@@ -179,7 +186,7 @@ test7(){
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
|
||||
B *b = & B();
|
||||
const B *b = new B;
|
||||
B *b1;
|
||||
{
|
||||
test_ostream os(testfile, TEST_STREAM_FLAGS);
|
||||
@@ -194,6 +201,7 @@ test7(){
|
||||
BOOST_CHECK_EQUAL(*b, *b1);
|
||||
|
||||
std::remove(testfile);
|
||||
delete b;
|
||||
}
|
||||
|
||||
// derived class pointer with base polymorphic archive compiled in dll
|
||||
@@ -202,21 +210,24 @@ test8(){
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
|
||||
B *b = & B();
|
||||
const B *b = new B;
|
||||
B *b1;
|
||||
{
|
||||
test_ostream os(testfile, TEST_STREAM_FLAGS);
|
||||
boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
|
||||
oa << boost::serialization::make_nvp("b", b);
|
||||
boost::archive::polymorphic_oarchive & poa(oa);
|
||||
poa << boost::serialization::make_nvp("b", b);
|
||||
}
|
||||
{
|
||||
test_istream is(testfile, TEST_STREAM_FLAGS);
|
||||
boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
|
||||
ia >> boost::serialization::make_nvp("b", b1);
|
||||
boost::archive::polymorphic_iarchive & pia(ia);
|
||||
pia >> boost::serialization::make_nvp("b", b1);
|
||||
}
|
||||
BOOST_CHECK_EQUAL(*b, *b1);
|
||||
|
||||
std::remove(testfile);
|
||||
delete b;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,17 +22,12 @@ namespace std{
|
||||
#include <boost/serialization/export.hpp>
|
||||
#include <boost/serialization/base_object.hpp>
|
||||
#include <boost/serialization/type_info_implementation.hpp>
|
||||
#include <boost/serialization/extended_type_info_typeid.hpp>
|
||||
|
||||
#include <boost/archive/archive_exception.hpp>
|
||||
#include "test_tools.hpp"
|
||||
|
||||
#include "base.hpp"
|
||||
|
||||
template<class Archive>
|
||||
void polymorphic_base::serialize(
|
||||
Archive & /* ar */,
|
||||
const unsigned int /* file_version */){
|
||||
}
|
||||
#include "polymorphic_base.hpp"
|
||||
|
||||
class polymorphic_derived1 : public polymorphic_base
|
||||
{
|
||||
@@ -41,6 +36,9 @@ class polymorphic_derived1 : public polymorphic_base
|
||||
void serialize(Archive & ar, const unsigned int /* file_version */){
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
|
||||
}
|
||||
virtual const char * get_key() const {
|
||||
return "polymorphic_derived1";
|
||||
}
|
||||
public:
|
||||
~polymorphic_derived1(){}
|
||||
};
|
||||
@@ -50,17 +48,13 @@ BOOST_CLASS_EXPORT(polymorphic_derived1)
|
||||
// MWerks users can do this to make their code work
|
||||
BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived1)
|
||||
|
||||
#include "derived2.hpp"
|
||||
#include "polymorphic_derived2.hpp"
|
||||
|
||||
template<class Archive>
|
||||
void polymorphic_derived2::serialize(
|
||||
Archive &ar,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
|
||||
}
|
||||
BOOST_CLASS_EXPORT(polymorphic_derived2)
|
||||
|
||||
// MWerks users can do this to make their code work
|
||||
BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived2)
|
||||
|
||||
// save exported polymorphic class
|
||||
void save_exported(const char *testfile)
|
||||
{
|
||||
|
||||
125
test/test_multiple_inheritance.cpp
Normal file
125
test/test_multiple_inheritance.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// test_multiple_inheritance.cpp
|
||||
|
||||
// (C) Copyright 2009 Robert Ramey.
|
||||
// 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)
|
||||
|
||||
// test of serialization library for multiple inheritence situations
|
||||
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <cstdio> // remove
|
||||
#if defined(BOOST_NO_STDC_NAMESPACE)
|
||||
namespace std{
|
||||
using ::remove;
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "test_tools.hpp"
|
||||
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <boost/serialization/base_object.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/export.hpp>
|
||||
|
||||
struct Base1 {
|
||||
int m_x;
|
||||
Base1(){}
|
||||
Base1(int x) : m_x(1 + x) {}
|
||||
virtual ~Base1() {}
|
||||
bool operator==(Base1 & rhs) const {
|
||||
return m_x == rhs.m_x;
|
||||
}
|
||||
// serialize
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int /* file_version */) {
|
||||
ar & BOOST_SERIALIZATION_NVP(m_x);
|
||||
}
|
||||
};
|
||||
|
||||
//BOOST_CLASS_EXPORT(Base1)
|
||||
|
||||
struct Base2 {
|
||||
int m_x;
|
||||
Base2(){}
|
||||
Base2(int x) : m_x(2 + x) {}
|
||||
virtual ~Base2() {}
|
||||
bool operator==(Base2 & rhs) const {
|
||||
return m_x == rhs.m_x;
|
||||
}
|
||||
// serialize
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int /* file_version */) {
|
||||
ar & BOOST_SERIALIZATION_NVP(m_x);
|
||||
}
|
||||
};
|
||||
|
||||
//BOOST_CLASS_EXPORT(Base2)
|
||||
|
||||
struct Sub :
|
||||
public Base1,
|
||||
public Base2
|
||||
{
|
||||
int m_x;
|
||||
Sub(){}
|
||||
Sub(int x) :
|
||||
Base1(x),
|
||||
Base2(x),
|
||||
m_x(x)
|
||||
{}
|
||||
bool operator==(Sub & rhs) const {
|
||||
if(! Base2::operator==(rhs))
|
||||
return false;
|
||||
if(! Base1::operator==(rhs))
|
||||
return false;
|
||||
return m_x == rhs.m_x;
|
||||
}
|
||||
virtual ~Sub() {}
|
||||
|
||||
// serialize
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive &ar, const unsigned int /* file_version */)
|
||||
{
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base1);
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base2);
|
||||
ar & BOOST_SERIALIZATION_NVP(m_x);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_CLASS_EXPORT(Sub)
|
||||
|
||||
int
|
||||
test_main( int /* argc */, char* /* argv */[] )
|
||||
{
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
Base2 * pb2;
|
||||
{
|
||||
// serialize
|
||||
pb2 = new Sub(2);
|
||||
|
||||
test_ostream ofs(testfile);
|
||||
test_oarchive oa(ofs);
|
||||
oa << boost::serialization::make_nvp("Base2", pb2);
|
||||
}
|
||||
Base2 * pb2_1;
|
||||
{
|
||||
// de-serialize
|
||||
test_istream ifs(testfile);
|
||||
test_iarchive ia(ifs);
|
||||
ia >> boost::serialization::make_nvp("Base2", pb2_1);
|
||||
}
|
||||
Sub *s1 = dynamic_cast<Sub *>(pb2);
|
||||
BOOST_CHECK(0 != s1);
|
||||
Sub *s2 = dynamic_cast<Sub *>(pb2_1);
|
||||
BOOST_CHECK(0 != s2);
|
||||
BOOST_CHECK(*s1 == *s2);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <cstdio> // remove
|
||||
@@ -35,10 +36,23 @@ namespace std{
|
||||
|
||||
#include <boost/serialization/type_info_implementation.hpp>
|
||||
#include <boost/serialization/extended_type_info_no_rtti.hpp>
|
||||
#include <boost/serialization/export.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
|
||||
#include "polymorphic_base.hpp"
|
||||
#include "polymorphic_derived1.hpp"
|
||||
|
||||
#include "polymorphic_derived2.hpp"
|
||||
BOOST_CLASS_EXPORT(polymorphic_derived2)
|
||||
|
||||
template void polymorphic_derived2::serialize(
|
||||
test_oarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
template void polymorphic_derived2::serialize(
|
||||
test_iarchive & ar,
|
||||
const unsigned int version
|
||||
);
|
||||
|
||||
// save derived polymorphic class
|
||||
void save_derived(const char *testfile)
|
||||
@@ -49,7 +63,9 @@ void save_derived(const char *testfile)
|
||||
polymorphic_derived1 *rd1 = new polymorphic_derived1;
|
||||
polymorphic_derived2 *rd2 = new polymorphic_derived2;
|
||||
|
||||
std::cout << "saving polymorphic_derived1 (no_rtti)\n";
|
||||
oa << BOOST_SERIALIZATION_NVP(rd1);
|
||||
std::cout << "saving polymorphic_derived2\n";
|
||||
oa << BOOST_SERIALIZATION_NVP(rd2);
|
||||
|
||||
// the above opereration registers the derived classes as a side
|
||||
@@ -57,7 +73,9 @@ void save_derived(const char *testfile)
|
||||
// a base class pointer.
|
||||
polymorphic_base *rb1 = rd1;
|
||||
polymorphic_base *rb2 = rd2;
|
||||
std::cout << "saving polymorphic_derived1 (no_rtti) through base (no_rtti)\n";
|
||||
oa << BOOST_SERIALIZATION_NVP(rb1);
|
||||
std::cout << "saving polymorphic_derived2 through base (no_rtti)\n";
|
||||
oa << BOOST_SERIALIZATION_NVP(rb2);
|
||||
|
||||
delete rd1;
|
||||
@@ -73,6 +91,7 @@ void load_derived(const char *testfile)
|
||||
polymorphic_derived1 *rd1 = NULL;
|
||||
polymorphic_derived2 *rd2 = NULL;
|
||||
|
||||
std::cout << "loading polymorphic_derived1 (no_rtti)\n";
|
||||
ia >> BOOST_SERIALIZATION_NVP(rd1);
|
||||
|
||||
BOOST_CHECK_MESSAGE(
|
||||
@@ -87,8 +106,8 @@ void load_derived(const char *testfile)
|
||||
"restored pointer d1 not of correct type"
|
||||
);
|
||||
|
||||
std::cout << "loading polymorphic_derived2\n";
|
||||
ia >> BOOST_SERIALIZATION_NVP(rd2);
|
||||
|
||||
BOOST_CHECK_MESSAGE(
|
||||
boost::serialization::type_info_implementation<
|
||||
polymorphic_derived2
|
||||
@@ -100,13 +119,13 @@ void load_derived(const char *testfile)
|
||||
,
|
||||
"restored pointer d2 not of correct type"
|
||||
);
|
||||
|
||||
polymorphic_base *rb1 = NULL;
|
||||
polymorphic_base *rb2 = NULL;
|
||||
|
||||
// the above opereration registers the derived classes as a side
|
||||
// effect. Hence, instances can now be correctly serialized through
|
||||
// a base class pointer.
|
||||
std::cout << "loading polymorphic_derived1 (no_rtti) through base (no_rtti)\n";
|
||||
ia >> BOOST_SERIALIZATION_NVP(rb1);
|
||||
|
||||
BOOST_CHECK_MESSAGE(
|
||||
@@ -126,6 +145,7 @@ void load_derived(const char *testfile)
|
||||
"restored pointer b1 not of correct type"
|
||||
);
|
||||
|
||||
std::cout << "loading polymorphic_derived2 through base (no_rtti)\n";
|
||||
ia >> BOOST_SERIALIZATION_NVP(rb2);
|
||||
|
||||
BOOST_CHECK_MESSAGE(
|
||||
|
||||
99
test/test_private_base.cpp
Normal file
99
test/test_private_base.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/////////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 & m_i;
|
||||
}
|
||||
protected:
|
||||
bool operator==(const Base &rhs) const {
|
||||
return m_i == rhs.m_i;
|
||||
}
|
||||
Base(int i = 0) :
|
||||
m_i(i)
|
||||
{}
|
||||
virtual ~Base();
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
friend class boost::serialization::access;
|
||||
private:
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int version){
|
||||
ar & boost::serialization::base_object<Base>(*this);
|
||||
}
|
||||
public:
|
||||
bool operator==(const Derived &rhs) const {
|
||||
return Base::operator==(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 = 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(*static_cast<Derived *>(ta) == *static_cast<Derived *>(ta1));
|
||||
std::remove(testfile);
|
||||
return 0;
|
||||
}
|
||||
@@ -48,7 +48,6 @@ public:
|
||||
virtual ~A(){--count;} // default destructor
|
||||
};
|
||||
|
||||
//BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(A)
|
||||
BOOST_SERIALIZATION_SHARED_PTR(A)
|
||||
|
||||
// B is a subclass of A
|
||||
|
||||
242
test/test_shared_ptr_multi_base.cpp
Normal file
242
test/test_shared_ptr_multi_base.cpp
Normal file
@@ -0,0 +1,242 @@
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// test_shared_ptr_multi_base.cpp
|
||||
|
||||
// (C) Copyright 2002 Robert Ramey- http://www.rrsd.com 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 <cstddef> // NULL
|
||||
#include <cstdio> // remove
|
||||
#include <fstream>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if defined(BOOST_NO_STDC_NAMESPACE)
|
||||
namespace std{
|
||||
using ::remove;
|
||||
}
|
||||
#endif
|
||||
#include <boost/type_traits/broken_compiler_spec.hpp>
|
||||
|
||||
#include <boost/serialization/shared_ptr.hpp>
|
||||
#include <boost/serialization/weak_ptr.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/export.hpp>
|
||||
|
||||
#include "test_tools.hpp"
|
||||
|
||||
struct Base1 {
|
||||
Base1() {}
|
||||
Base1(int x) : m_x(1 + x) {}
|
||||
virtual ~Base1() {}
|
||||
int m_x;
|
||||
// serialize
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive &ar, const unsigned int /* file_version */)
|
||||
{
|
||||
ar & BOOST_SERIALIZATION_NVP(m_x);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_SERIALIZATION_SHARED_PTR(Base1)
|
||||
|
||||
struct Base2 {
|
||||
Base2() {}
|
||||
Base2(int x) : m_x(2 + x) {}
|
||||
int m_x;
|
||||
virtual ~Base2() {}
|
||||
// serialize
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive &ar, const unsigned int /* file_version */)
|
||||
{
|
||||
ar & BOOST_SERIALIZATION_NVP(m_x);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_SERIALIZATION_SHARED_PTR(Base2)
|
||||
|
||||
struct Base3 {
|
||||
Base3() {}
|
||||
Base3(int x) : m_x(3 + x) {}
|
||||
virtual ~Base3() {}
|
||||
int m_x;
|
||||
// serialize
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive &ar, const unsigned int /* file_version */)
|
||||
{
|
||||
ar & BOOST_SERIALIZATION_NVP(m_x);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_SERIALIZATION_SHARED_PTR(Base3)
|
||||
|
||||
// Sub is a subclass of Base1, Base1 and Base3.
|
||||
struct Sub:public Base1, public Base2, public Base3 {
|
||||
Sub() {}
|
||||
Sub(int x) :
|
||||
Base1(x),
|
||||
Base2(x),
|
||||
m_x(x)
|
||||
{}
|
||||
virtual ~Sub() {}
|
||||
int m_x;
|
||||
// serialize
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive &ar, const unsigned int /* file_version */)
|
||||
{
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base1);
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base2);
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base3);
|
||||
ar & BOOST_SERIALIZATION_NVP(m_x);
|
||||
}
|
||||
};
|
||||
|
||||
// Sub needs to be exported because its serialized via a base class pointer
|
||||
BOOST_CLASS_EXPORT(Sub)
|
||||
BOOST_SERIALIZATION_SHARED_PTR(Sub)
|
||||
|
||||
template <class FIRST, class SECOND>
|
||||
void save2(
|
||||
const char * testfile,
|
||||
const FIRST& first,
|
||||
const SECOND& second
|
||||
){
|
||||
test_ostream os(testfile, TEST_STREAM_FLAGS);
|
||||
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
|
||||
oa << BOOST_SERIALIZATION_NVP(first);
|
||||
oa << BOOST_SERIALIZATION_NVP(second);
|
||||
}
|
||||
|
||||
template <class FIRST, class SECOND>
|
||||
void load2(
|
||||
const char * testfile,
|
||||
FIRST& first,
|
||||
SECOND& second)
|
||||
{
|
||||
test_istream is(testfile, TEST_STREAM_FLAGS);
|
||||
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
|
||||
ia >> BOOST_SERIALIZATION_NVP(first);
|
||||
ia >> BOOST_SERIALIZATION_NVP(second);
|
||||
}
|
||||
|
||||
// Run tests by serializing two shared_ptrs into an archive,
|
||||
// clearing them (deleting the objects) and then reloading the
|
||||
// objects back from an archive.
|
||||
|
||||
// Serialization sequence
|
||||
// First, shared_ptr
|
||||
// Second, weak_ptr
|
||||
template <class FIRST, class SECOND>
|
||||
void shared_weak(
|
||||
boost::shared_ptr<FIRST>& first,
|
||||
boost::weak_ptr<SECOND>& second
|
||||
){
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
int firstm = first->m_x;
|
||||
int secondm = second.lock()->m_x;
|
||||
save2(testfile, first, second);
|
||||
|
||||
// Clear the pointers, thereby destroying the objects they contain
|
||||
second.reset();
|
||||
first.reset();
|
||||
|
||||
load2(testfile, first, second);
|
||||
|
||||
// Check data member
|
||||
BOOST_CHECK(firstm == first->m_x);
|
||||
BOOST_CHECK(secondm == second.lock()->m_x);
|
||||
// Check pointer to vtable
|
||||
BOOST_CHECK(boost::dynamic_pointer_cast<Sub>(first));
|
||||
BOOST_CHECK(boost::dynamic_pointer_cast<Sub>(second.lock()));
|
||||
std::remove(testfile);
|
||||
}
|
||||
|
||||
// Serialization sequence
|
||||
// First, weak_ptr
|
||||
// Second, shared_ptr
|
||||
template <class FIRST, class SECOND>
|
||||
void weak_shared(
|
||||
boost::weak_ptr<FIRST>& first,
|
||||
boost::shared_ptr<SECOND>& second
|
||||
){
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
int firstm = first.lock()->m_x;
|
||||
int secondm = second->m_x;
|
||||
save2(testfile, first, second);
|
||||
|
||||
// Clear the pointers, thereby destroying the objects they contain
|
||||
first.reset();
|
||||
second.reset();
|
||||
|
||||
load2(testfile, first, second);
|
||||
|
||||
// Check data member
|
||||
BOOST_CHECK(firstm == first.lock()->m_x);
|
||||
BOOST_CHECK(secondm == second->m_x);
|
||||
// Check pointer to vtable
|
||||
BOOST_CHECK(boost::dynamic_pointer_cast<Sub>(first.lock()));
|
||||
BOOST_CHECK(boost::dynamic_pointer_cast<Sub>(second));
|
||||
std::remove(testfile);
|
||||
}
|
||||
|
||||
// This does the tests
|
||||
int test_main(int /* argc */, char * /* argv */[])
|
||||
{
|
||||
// Both Sub
|
||||
boost::shared_ptr<Sub> tc1_sp(new Sub(10));
|
||||
boost::weak_ptr<Sub> tc1_wp(tc1_sp);
|
||||
shared_weak(tc1_sp, tc1_wp);
|
||||
weak_shared(tc1_wp, tc1_sp);
|
||||
|
||||
// Sub and Base1
|
||||
boost::shared_ptr<Sub> tc2_sp(new Sub(10));
|
||||
boost::weak_ptr<Base1> tc2_wp(tc2_sp);
|
||||
shared_weak(tc2_sp, tc2_wp);
|
||||
weak_shared(tc2_wp, tc2_sp);
|
||||
|
||||
// Sub and Base2
|
||||
boost::shared_ptr<Sub> tc3_sp(new Sub(10));
|
||||
boost::weak_ptr<Base2> tc3_wp(tc3_sp);
|
||||
shared_weak(tc3_sp, tc3_wp);
|
||||
weak_shared(tc3_wp, tc3_sp);
|
||||
|
||||
// Sub and Base3
|
||||
boost::shared_ptr<Sub> tc4_sp(new Sub(10));
|
||||
boost::weak_ptr<Base3> tc4_wp(tc4_sp);
|
||||
shared_weak(tc4_sp, tc4_wp);
|
||||
weak_shared(tc4_wp, tc4_sp);
|
||||
|
||||
// Base1 and Base2
|
||||
boost::shared_ptr<Sub> tc5_sp_tmp(new Sub(10));
|
||||
boost::shared_ptr<Base1> tc5_sp(tc5_sp_tmp);
|
||||
boost::weak_ptr<Base2> tc5_wp(tc5_sp_tmp);
|
||||
tc5_sp_tmp.reset();
|
||||
shared_weak(tc5_sp, tc5_wp);
|
||||
weak_shared(tc5_wp, tc5_sp);
|
||||
|
||||
// Base2 and Base3
|
||||
boost::shared_ptr<Sub> tc6_sp_tmp(new Sub(10));
|
||||
boost::shared_ptr<Base2> tc6_sp(tc6_sp_tmp);
|
||||
boost::weak_ptr<Base3> tc6_wp(tc6_sp_tmp);
|
||||
tc6_sp_tmp.reset();
|
||||
shared_weak(tc6_sp, tc6_wp);
|
||||
weak_shared(tc6_wp, tc6_sp);
|
||||
|
||||
// Base3 and Base1
|
||||
boost::shared_ptr<Sub> tc7_sp_tmp(new Sub(10));
|
||||
boost::shared_ptr<Base3> tc7_sp(tc7_sp_tmp);
|
||||
boost::weak_ptr<Base1> tc7_wp(tc7_sp_tmp);
|
||||
tc7_sp_tmp.reset();
|
||||
shared_weak(tc7_sp, tc7_wp);
|
||||
weak_shared(tc7_wp, tc7_sp);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -46,5 +46,5 @@ test_main( int /* argc */, char* /* argv */[] )
|
||||
}
|
||||
BOOST_CHECK_EQUAL(a, a1);
|
||||
std::remove(testfile);
|
||||
return (a == a1) ? EXIT_SUCCESS : EXIT_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user