removed header-level dependency from Boost.Serialization

This commit is contained in:
joaquintides 2023-02-26 19:16:45 +01:00
parent eeac86a37e
commit c42c2509bc
16 changed files with 168 additions and 94 deletions

View File

@ -73,6 +73,16 @@ Acknowledgements
<p> <p>
<ul> <ul>
<li>Serialization now uses <code>unsigned long</code> instead of
<a href="../../serialization/doc/wrappers.html#collection_size_type"><code>collection_size_type</code></a>,
and <code>multi_index_container</code> serialization
<a href="../../serialization/doc/tutorial.html#versioning">class version</a> has been
bumped from 2 to 3 to reflect this change.
Reading old archives may fail for custom archive types giving special treatment to
<code>collection_size_type</code> values: if this is the case, globally define
the macro <code>BOOST_MULTI_INDEX_ENABLE_SERIALIZATION_COMPATIBILITY_V2</code>
to ensure backwards compatibility in reading operations.
</li>
<li>Maintenance work.</li> <li>Maintenance work.</li>
</ul> </ul>
</p> </p>
@ -764,9 +774,9 @@ Acknowledgements
<br> <br>
<p>Revised December 28th 2022</p> <p>Revised February 26th 2023</p>
<p>&copy; Copyright 2003-2022 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz. <p>&copy; Copyright 2003-2023 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software Distributed under the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../LICENSE_1_0.txt"> License, Version 1.0. (See accompanying file <a href="../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt"> LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2022 Joaquin M Lopez Munoz. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -16,7 +16,7 @@
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <boost/core/no_exceptions_support.hpp> #include <boost/core/no_exceptions_support.hpp>
#include <boost/core/noncopyable.hpp> #include <boost/core/noncopyable.hpp>
#include <boost/serialization/serialization.hpp> #include <boost/core/serialization.hpp>
#include <boost/type_traits/aligned_storage.hpp> #include <boost/type_traits/aligned_storage.hpp>
#include <boost/type_traits/alignment_of.hpp> #include <boost/type_traits/alignment_of.hpp>
@ -34,7 +34,7 @@ struct archive_constructed:private noncopyable
template<class Archive> template<class Archive>
archive_constructed(Archive& ar,const unsigned int version) archive_constructed(Archive& ar,const unsigned int version)
{ {
serialization::load_construct_data_adl(ar,&get(),version); core::load_construct_data_adl(ar,&get(),version);
BOOST_TRY{ BOOST_TRY{
ar>>get(); ar>>get();
} }
@ -48,9 +48,9 @@ struct archive_constructed:private noncopyable
template<class Archive> template<class Archive>
archive_constructed(const char* name,Archive& ar,const unsigned int version) archive_constructed(const char* name,Archive& ar,const unsigned int version)
{ {
serialization::load_construct_data_adl(ar,&get(),version); core::load_construct_data_adl(ar,&get(),version);
BOOST_TRY{ BOOST_TRY{
ar>>serialization::make_nvp(name,get()); ar>>core::make_nvp(name,get());
} }
BOOST_CATCH(...){ BOOST_CATCH(...){
(&get())->~T(); (&get())->~T();

View File

@ -0,0 +1,36 @@
/* Copyright 2003-2023 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/multi_index for library home page.
*/
#ifndef BOOST_MULTI_INDEX_BAD_ARCHIVE_EXCEPTION_HPP
#define BOOST_MULTI_INDEX_BAD_ARCHIVE_EXCEPTION_HPP
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <stdexcept>
namespace boost{
namespace multi_index{
namespace detail{
struct bad_archive_exception:std::runtime_error
{
bad_archive_exception():std::runtime_error("Invalid or corrupted archive"){}
};
} /* namespace multi_index::detail */
} /* namespace multi_index */
} /* namespace boost */
#endif

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2018 Joaquin M Lopez Munoz. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -17,8 +17,7 @@
#include <boost/operators.hpp> #include <boost/operators.hpp>
#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
#include <boost/serialization/nvp.hpp> #include <boost/core/serialization.hpp>
#include <boost/serialization/split_member.hpp>
#endif #endif
namespace boost{ namespace boost{
@ -67,7 +66,11 @@ public:
* see explanation in safe_mode_iterator notes in safe_mode.hpp. * see explanation in safe_mode_iterator notes in safe_mode.hpp.
*/ */
BOOST_SERIALIZATION_SPLIT_MEMBER() template<class Archive>
void serialize(Archive& ar,const unsigned int version)
{
core::split_member(ar,*this,version);
}
typedef typename Node::base_type node_base_type; typedef typename Node::base_type node_base_type;
@ -75,14 +78,14 @@ public:
void save(Archive& ar,const unsigned int)const void save(Archive& ar,const unsigned int)const
{ {
node_base_type* bnode=node; node_base_type* bnode=node;
ar<<serialization::make_nvp("pointer",bnode); ar<<core::make_nvp("pointer",bnode);
} }
template<class Archive> template<class Archive>
void load(Archive& ar,const unsigned int) void load(Archive& ar,const unsigned int)
{ {
node_base_type* bnode; node_base_type* bnode;
ar>>serialization::make_nvp("pointer",bnode); ar>>core::make_nvp("pointer",bnode);
node=static_cast<Node*>(bnode); node=static_cast<Node*>(bnode);
} }
#endif #endif

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2022 Joaquin M Lopez Munoz. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -27,8 +27,8 @@
#include <limits.h> #include <limits.h>
#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
#include <boost/archive/archive_exception.hpp> #include <boost/core/serialization.hpp>
#include <boost/serialization/access.hpp> #include <boost/multi_index/detail/bad_archive_exception.hpp>
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#endif #endif
@ -236,8 +236,7 @@ inline void load_construct_data(
Archive&,boost::multi_index::detail::bucket_array<Allocator>*, Archive&,boost::multi_index::detail::bucket_array<Allocator>*,
const unsigned int) const unsigned int)
{ {
throw_exception( throw_exception(bad_archive_exception());
archive::archive_exception(archive::archive_exception::other_exception));
} }
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2020 Joaquin M Lopez Munoz. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -17,9 +17,7 @@
#include <boost/operators.hpp> #include <boost/operators.hpp>
#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
#include <boost/serialization/nvp.hpp> #include <boost/core/serialization.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/version.hpp>
#endif #endif
namespace boost{ namespace boost{
@ -67,7 +65,11 @@ public:
* see explanation in safe_mode_iterator notes in safe_mode.hpp. * see explanation in safe_mode_iterator notes in safe_mode.hpp.
*/ */
BOOST_SERIALIZATION_SPLIT_MEMBER() template<class Archive>
void serialize(Archive& ar,const unsigned int version)
{
core::split_member(ar,*this,version);
}
typedef typename Node::base_type node_base_type; typedef typename Node::base_type node_base_type;
@ -75,7 +77,7 @@ public:
void save(Archive& ar,const unsigned int)const void save(Archive& ar,const unsigned int)const
{ {
node_base_type* bnode=node; node_base_type* bnode=node;
ar<<serialization::make_nvp("pointer",bnode); ar<<core::make_nvp("pointer",bnode);
} }
template<class Archive> template<class Archive>
@ -89,11 +91,11 @@ public:
Archive& ar,const unsigned int version,hashed_index_global_iterator_tag) Archive& ar,const unsigned int version,hashed_index_global_iterator_tag)
{ {
node_base_type* bnode; node_base_type* bnode;
ar>>serialization::make_nvp("pointer",bnode); ar>>core::make_nvp("pointer",bnode);
node=static_cast<Node*>(bnode); node=static_cast<Node*>(bnode);
if(version<1){ if(version<1){
BucketArray* throw_away; /* consume unused ptr */ BucketArray* throw_away; /* consume unused ptr */
ar>>serialization::make_nvp("pointer",throw_away); ar>>core::make_nvp("pointer",throw_away);
} }
} }
@ -102,11 +104,11 @@ public:
Archive& ar,const unsigned int version,hashed_index_local_iterator_tag) Archive& ar,const unsigned int version,hashed_index_local_iterator_tag)
{ {
node_base_type* bnode; node_base_type* bnode;
ar>>serialization::make_nvp("pointer",bnode); ar>>core::make_nvp("pointer",bnode);
node=static_cast<Node*>(bnode); node=static_cast<Node*>(bnode);
if(version<1){ if(version<1){
BucketArray* buckets; BucketArray* buckets;
ar>>serialization::make_nvp("pointer",buckets); ar>>core::make_nvp("pointer",buckets);
if(buckets&&node&&node->impl()==buckets->end()->prior()){ if(buckets&&node&&node->impl()==buckets->end()->prior()){
/* end local_iterators used to point to end node, now they are null */ /* end local_iterators used to point to end node, now they are null */
node=0; node=0;

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2022 Joaquin M Lopez Munoz. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -15,11 +15,11 @@
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <algorithm> #include <algorithm>
#include <boost/archive/archive_exception.hpp>
#include <boost/core/noncopyable.hpp> #include <boost/core/noncopyable.hpp>
#include <boost/core/serialization.hpp>
#include <boost/multi_index/detail/auto_space.hpp> #include <boost/multi_index/detail/auto_space.hpp>
#include <boost/multi_index/detail/bad_archive_exception.hpp>
#include <boost/multi_index/detail/raw_ptr.hpp> #include <boost/multi_index/detail/raw_ptr.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#include <cstddef> #include <cstddef>
@ -30,7 +30,8 @@ namespace multi_index{
namespace detail{ namespace detail{
/* Counterpart of index_saver (check index_saver.hpp for serialization /* Counterpart of index_saver (check index_saver.hpp for serialization
* details.)* multi_index_container is in charge of supplying the info about * details.)
* multi_index_container is in charge of supplying the info about
* the base sequence, and each index can subsequently load itself using the * the base sequence, and each index can subsequently load itself using the
* const interface of index_loader. * const interface of index_loader.
*/ */
@ -47,14 +48,14 @@ public:
template<class Archive> template<class Archive>
void add(Node* node,Archive& ar,const unsigned int) void add(Node* node,Archive& ar,const unsigned int)
{ {
ar>>serialization::make_nvp("position",*node); ar>>core::make_nvp("position",*node);
entries()[n++]=node; entries()[n++]=node;
} }
template<class Archive> template<class Archive>
void add_track(Node* node,Archive& ar,const unsigned int) void add_track(Node* node,Archive& ar,const unsigned int)
{ {
ar>>serialization::make_nvp("position",*node); ar>>core::make_nvp("position",*node);
} }
/* A rearranger is passed two nodes, and is expected to /* A rearranger is passed two nodes, and is expected to
@ -102,7 +103,7 @@ private:
FinalNode* unchecked_load_node(Archive& ar)const FinalNode* unchecked_load_node(Archive& ar)const
{ {
Node* node=0; Node* node=0;
ar>>serialization::make_nvp("pointer",node); ar>>core::make_nvp("pointer",node);
return static_cast<FinalNode*>(node); return static_cast<FinalNode*>(node);
} }
@ -110,7 +111,7 @@ private:
FinalNode* load_node(Archive& ar)const FinalNode* load_node(Archive& ar)const
{ {
Node* node=0; Node* node=0;
ar>>serialization::make_nvp("pointer",node); ar>>core::make_nvp("pointer",node);
check_node(node); check_node(node);
return static_cast<FinalNode*>(node); return static_cast<FinalNode*>(node);
} }
@ -118,9 +119,7 @@ private:
void check_node(Node* node)const void check_node(Node* node)const
{ {
if(node!=0&&!std::binary_search(entries(),entries()+size_,node)){ if(node!=0&&!std::binary_search(entries(),entries()+size_,node)){
throw_exception( throw_exception(bad_archive_exception());
archive::archive_exception(
archive::archive_exception::other_exception));
} }
} }

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2016 Joaquin M Lopez Munoz. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -18,8 +18,8 @@
#include <boost/type_traits/alignment_of.hpp> #include <boost/type_traits/alignment_of.hpp>
#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
#include <boost/archive/archive_exception.hpp> #include <boost/core/serialization.hpp>
#include <boost/serialization/access.hpp> #include <boost/multi_index/detail/bad_archive_exception.hpp>
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#endif #endif
@ -117,8 +117,7 @@ inline void load_construct_data(
Archive&,boost::multi_index::detail::index_node_base<Value,Allocator>*, Archive&,boost::multi_index::detail::index_node_base<Value,Allocator>*,
const unsigned int) const unsigned int)
{ {
throw_exception( throw_exception(bad_archive_exception());
archive::archive_exception(archive::archive_exception::other_exception));
} }
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2022 Joaquin M Lopez Munoz. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -16,7 +16,7 @@
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <boost/multi_index/detail/index_matcher.hpp> #include <boost/multi_index/detail/index_matcher.hpp>
#include <boost/core/noncopyable.hpp> #include <boost/core/noncopyable.hpp>
#include <boost/serialization/nvp.hpp> #include <boost/core/serialization.hpp>
#include <cstddef> #include <cstddef>
namespace boost{ namespace boost{
@ -43,14 +43,14 @@ public:
template<class Archive> template<class Archive>
void add(Node* node,Archive& ar,const unsigned int) void add(Node* node,Archive& ar,const unsigned int)
{ {
ar<<serialization::make_nvp("position",*node); ar<<core::make_nvp("position",*node);
alg.add(node); alg.add(node);
} }
template<class Archive> template<class Archive>
void add_track(Node* node,Archive& ar,const unsigned int) void add_track(Node* node,Archive& ar,const unsigned int)
{ {
ar<<serialization::make_nvp("position",*node); ar<<core::make_nvp("position",*node);
} }
template<typename IndexIterator,class Archive> template<typename IndexIterator,class Archive>
@ -120,7 +120,7 @@ private:
template<typename Archive> template<typename Archive>
static void save_node(Node* node,Archive& ar) static void save_node(Node* node,Archive& ar)
{ {
ar<<serialization::make_nvp("pointer",node); ar<<core::make_nvp("pointer",node);
} }
index_matcher::algorithm<Node,Allocator> alg; index_matcher::algorithm<Node,Allocator> alg;

View File

@ -80,8 +80,8 @@
#endif #endif
#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
#include <boost/archive/archive_exception.hpp>
#include <boost/bind/bind.hpp> #include <boost/bind/bind.hpp>
#include <boost/multi_index/detail/bad_archive_exception.hpp>
#include <boost/multi_index/detail/duplicates_iterator.hpp> #include <boost/multi_index/detail/duplicates_iterator.hpp>
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#endif #endif
@ -1513,9 +1513,7 @@ private:
} }
else if(comp_(key(x->value()),key(position->value()))){ else if(comp_(key(x->value()),key(position->value()))){
/* inconsistent rearrangement */ /* inconsistent rearrangement */
throw_exception( throw_exception(bad_archive_exception());
archive::archive_exception(
archive::archive_exception::other_exception));
} }
else index_node_type::increment(position); else index_node_type::increment(position);

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2018 Joaquin M Lopez Munoz. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -17,8 +17,7 @@
#include <boost/operators.hpp> #include <boost/operators.hpp>
#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
#include <boost/serialization/nvp.hpp> #include <boost/core/serialization.hpp>
#include <boost/serialization/split_member.hpp>
#endif #endif
namespace boost{ namespace boost{
@ -77,7 +76,11 @@ public:
* see explanation in safe_mode_iterator notes in safe_mode.hpp. * see explanation in safe_mode_iterator notes in safe_mode.hpp.
*/ */
BOOST_SERIALIZATION_SPLIT_MEMBER() template<class Archive>
void serialize(Archive& ar,const unsigned int version)
{
core::split_member(ar,*this,version);
}
typedef typename Node::base_type node_base_type; typedef typename Node::base_type node_base_type;
@ -85,14 +88,14 @@ public:
void save(Archive& ar,const unsigned int)const void save(Archive& ar,const unsigned int)const
{ {
node_base_type* bnode=node; node_base_type* bnode=node;
ar<<serialization::make_nvp("pointer",bnode); ar<<core::make_nvp("pointer",bnode);
} }
template<class Archive> template<class Archive>
void load(Archive& ar,const unsigned int) void load(Archive& ar,const unsigned int)
{ {
node_base_type* bnode; node_base_type* bnode;
ar>>serialization::make_nvp("pointer",bnode); ar>>core::make_nvp("pointer",bnode);
node=static_cast<Node*>(bnode); node=static_cast<Node*>(bnode);
} }
#endif #endif

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2022 Joaquin M Lopez Munoz. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -127,8 +127,7 @@
#include <boost/type_traits/is_same.hpp> #include <boost/type_traits/is_same.hpp>
#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
#include <boost/serialization/split_member.hpp> #include <boost/core/serialization.hpp>
#include <boost/serialization/version.hpp>
#endif #endif
#if defined(BOOST_HAS_THREADS) #if defined(BOOST_HAS_THREADS)
@ -556,7 +555,11 @@ private:
friend class boost::serialization::access; friend class boost::serialization::access;
BOOST_SERIALIZATION_SPLIT_MEMBER() template<class Archive>
void serialize(Archive& ar,const unsigned int version)
{
core::split_member(ar,*this,version);
}
template<class Archive> template<class Archive>
void save(Archive& ar,const unsigned int version)const void save(Archive& ar,const unsigned int version)const

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2013 Joaquin M Lopez Munoz. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -14,8 +14,7 @@
#endif #endif
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <boost/serialization/split_member.hpp> #include <boost/core/serialization.hpp>
#include <boost/serialization/version.hpp>
namespace boost{ namespace boost{
@ -42,7 +41,11 @@ struct serialization_version
private: private:
friend class boost::serialization::access; friend class boost::serialization::access;
BOOST_SERIALIZATION_SPLIT_MEMBER() template<class Archive>
void serialize(Archive& ar,const unsigned int version)
{
core::split_member(ar,*this,version);
}
template<class Archive> template<class Archive>
void save(Archive&,const unsigned int)const{} void save(Archive&,const unsigned int)const{}

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2021 Joaquin M Lopez Munoz. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -55,7 +55,7 @@
#endif #endif
#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
#include <boost/serialization/nvp.hpp> #include <boost/core/serialization.hpp>
#endif #endif
#if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING) #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
@ -1238,14 +1238,14 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
void save_( void save_(
Archive& ar,const unsigned int version,const index_saver_type& sm)const Archive& ar,const unsigned int version,const index_saver_type& sm)const
{ {
ar<<serialization::make_nvp("position",buckets); ar<<core::make_nvp("position",buckets);
super::save_(ar,version,sm); super::save_(ar,version,sm);
} }
template<typename Archive> template<typename Archive>
void load_(Archive& ar,const unsigned int version,const index_loader_type& lm) void load_(Archive& ar,const unsigned int version,const index_loader_type& lm)
{ {
ar>>serialization::make_nvp("position",buckets); ar>>core::make_nvp("position",buckets);
super::load_(ar,version,lm); super::load_(ar,version,lm);
} }
#endif #endif

View File

@ -1,6 +1,6 @@
/* Multiply indexed container. /* Multiply indexed container.
* *
* Copyright 2003-2021 Joaquin M Lopez Munoz. * Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -53,13 +53,18 @@
#endif #endif
#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
#include <boost/core/serialization.hpp>
#include <boost/multi_index/detail/archive_constructed.hpp> #include <boost/multi_index/detail/archive_constructed.hpp>
#include <boost/multi_index/detail/bad_archive_exception.hpp>
#include <boost/multi_index/detail/serialization_version.hpp> #include <boost/multi_index/detail/serialization_version.hpp>
#include <boost/serialization/collection_size_type.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/version.hpp>
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#if defined(BOOST_MULTI_INDEX_ENABLE_SERIALIZATION_COMPATIBILITY_V2)
#define BOOST_MULTI_INDEX_BLOCK_BOOSTDEP_HEADER \
<boost/serialization/collection_size_type.hpp>
#include BOOST_MULTI_INDEX_BLOCK_BOOSTDEP_HEADER
#undef BOOST_MULTI_INDEX_BLOCK_BOOSTDEP_HEADER
#endif
#endif #endif
#if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING) #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
@ -1102,7 +1107,11 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
friend class boost::serialization::access; friend class boost::serialization::access;
BOOST_SERIALIZATION_SPLIT_MEMBER() template<class Archive>
void serialize(Archive& ar,const unsigned int version)
{
core::split_member(ar,*this,version);
}
typedef typename super::index_saver_type index_saver_type; typedef typename super::index_saver_type index_saver_type;
typedef typename super::index_loader_type index_loader_type; typedef typename super::index_loader_type index_loader_type;
@ -1110,15 +1119,15 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
template<class Archive> template<class Archive>
void save(Archive& ar,const unsigned int version)const void save(Archive& ar,const unsigned int version)const
{ {
const serialization::collection_size_type s(size_()); const unsigned long s(size_());
const detail::serialization_version<value_type> value_version; const detail::serialization_version<value_type> value_version;
ar<<serialization::make_nvp("count",s); ar<<core::make_nvp("count",s);
ar<<serialization::make_nvp("value_version",value_version); ar<<core::make_nvp("value_version",value_version);
index_saver_type sm(bfm_allocator::member,s); index_saver_type sm(bfm_allocator::member,s);
for(iterator it=super::begin(),it_end=super::end();it!=it_end;++it){ for(iterator it=super::begin(),it_end=super::end();it!=it_end;++it){
serialization::save_construct_data_adl( core::save_construct_data_adl(
ar,boost::addressof(*it),value_version); ar,boost::addressof(*it),value_version);
ar<<serialization::make_nvp("item",*it); ar<<serialization::make_nvp("item",*it);
sm.add(it.get_node(),ar,version); sm.add(it.get_node(),ar,version);
@ -1134,21 +1143,30 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
BOOST_MULTI_INDEX_CHECK_INVARIANT; BOOST_MULTI_INDEX_CHECK_INVARIANT;
clear_(); clear_();
serialization::collection_size_type s; unsigned long s;
detail::serialization_version<value_type> value_version; detail::serialization_version<value_type> value_version;
if(version<1){ if(version<1){
std::size_t sz; std::size_t sz;
ar>>serialization::make_nvp("count",sz); ar>>core::make_nvp("count",sz);
s=static_cast<serialization::collection_size_type>(sz); s=static_cast<unsigned long>(sz);
}
else if(version<3){
#if defined(BOOST_MULTI_INDEX_ENABLE_SERIALIZATION_COMPATIBILITY_V2)
serialization::collection_size_type csz;
ar>>core::make_nvp("count",csz);
s=static_cast<unsigned long>(csz);
#else
ar>>core::make_nvp("count",s);
#endif
} }
else{ else{
ar>>serialization::make_nvp("count",s); ar>>core::make_nvp("count",s);
} }
if(version<2){ if(version<2){
value_version=0; value_version=0;
} }
else{ else{
ar>>serialization::make_nvp("value_version",value_version); ar>>core::make_nvp("value_version",value_version);
} }
index_loader_type lm(bfm_allocator::member,s); index_loader_type lm(bfm_allocator::member,s);
@ -1157,9 +1175,7 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
detail::archive_constructed<Value> value("item",ar,value_version); detail::archive_constructed<Value> value("item",ar,value_version);
std::pair<final_node_type*,bool> p=insert_rv_( std::pair<final_node_type*,bool> p=insert_rv_(
value.get(),super::end().get_node()); value.get(),super::end().get_node());
if(!p.second)throw_exception( if(!p.second)throw_exception(detail::bad_archive_exception());
archive::archive_exception(
archive::archive_exception::other_exception));
ar.reset_object_address( ar.reset_object_address(
boost::addressof(p.first->value()),boost::addressof(value.get())); boost::addressof(p.first->value()),boost::addressof(value.get()));
lm.add(p.first,ar,version); lm.add(p.first,ar,version);
@ -1550,6 +1566,9 @@ void swap(
/* class version = 1 : we now serialize the size through /* class version = 1 : we now serialize the size through
* boost::serialization::collection_size_type. * boost::serialization::collection_size_type.
* class version = 2 : proper use of {save|load}_construct_data. * class version = 2 : proper use of {save|load}_construct_data.
* class version = 3 : dropped boost::serialization::collection_size_type
* in favor of unsigned long --this allows us to provide serialization
* support without including any header from Boost.Serialization.
*/ */
namespace serialization { namespace serialization {
@ -1558,7 +1577,7 @@ struct version<
boost::multi_index_container<Value,IndexSpecifierList,Allocator> boost::multi_index_container<Value,IndexSpecifierList,Allocator>
> >
{ {
BOOST_STATIC_CONSTANT(int,value=2); BOOST_STATIC_CONSTANT(int,value=3);
}; };
} /* namespace serialization */ } /* namespace serialization */
#endif #endif

View File

@ -1,6 +1,6 @@
/* Used in Boost.MultiIndex tests. /* Used in Boost.MultiIndex tests.
* *
* Copyright 2003-2010 Joaquin M Lopez Munoz. * Copyright 2003-2023 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -12,7 +12,7 @@
#define BOOST_MULTI_INDEX_TEST_PAIR_OF_INTS_HPP #define BOOST_MULTI_INDEX_TEST_PAIR_OF_INTS_HPP
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <boost/serialization/nvp.hpp> #include <boost/core/serialization.hpp>
struct pair_of_ints struct pair_of_ints
{ {
@ -66,8 +66,8 @@ namespace serialization{
template<class Archive> template<class Archive>
void serialize(Archive& ar,pair_of_ints& p,const unsigned int) void serialize(Archive& ar,pair_of_ints& p,const unsigned int)
{ {
ar&boost::serialization::make_nvp("first",p.first); ar&boost::core::make_nvp("first",p.first);
ar&boost::serialization::make_nvp("second",p.second); ar&boost::core::make_nvp("second",p.second);
} }
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)