Added serialization for STL types
This commit is contained in:
parent
1acb9699ac
commit
d2a5baa1ad
72
boost/serialization/archive_input_unordered_set.hpp
Normal file
72
boost/serialization/archive_input_unordered_set.hpp
Normal file
@ -0,0 +1,72 @@
|
||||
#ifndef BOOST_SERIALIZATION_ARCHIVE_INPUT_UNORDERED_SET_HPP
|
||||
#define BOOST_SERIALIZATION_ARCHIVE_INPUT_UNORDERED_SET_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// archive_input_unordered_set.hpp
|
||||
|
||||
// (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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <utility>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/detail/stack_constructor.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
namespace stl {
|
||||
|
||||
// unordered_set input
|
||||
template<class Archive, class Container>
|
||||
struct archive_input_unordered_set
|
||||
{
|
||||
inline void operator()(
|
||||
Archive &ar,
|
||||
Container &s,
|
||||
const unsigned int v
|
||||
){
|
||||
typedef typename Container::value_type type;
|
||||
detail::stack_construct<Archive, type> t(ar, v);
|
||||
// borland fails silently w/o full namespace
|
||||
ar >> boost::serialization::make_nvp("item", t.reference());
|
||||
std::pair<typename Container::const_iterator, bool> result =
|
||||
s.insert(boost::move(t.reference()));
|
||||
if(result.second)
|
||||
ar.reset_object_address(& (* result.first), & t.reference());
|
||||
}
|
||||
};
|
||||
|
||||
// unordered_multiset input
|
||||
template<class Archive, class Container>
|
||||
struct archive_input_unordered_multiset
|
||||
{
|
||||
inline void operator()(
|
||||
Archive &ar,
|
||||
Container &s,
|
||||
const unsigned int v
|
||||
){
|
||||
typedef typename Container::value_type type;
|
||||
detail::stack_construct<Archive, type> t(ar, v);
|
||||
ar >> boost::serialization::make_nvp("item", t.reference());
|
||||
typename Container::const_iterator result =
|
||||
s.insert(boost::move(t.reference()));
|
||||
ar.reset_object_address(& (* result), & t.reference());
|
||||
}
|
||||
};
|
||||
|
||||
} // stl
|
||||
} // serialization
|
||||
} // boost
|
||||
|
||||
#endif // BOOST_SERIALIZATION_ARCHIVE_INPUT_UNORDERED_SET_HPP
|
48
boost/serialization/array.hpp
Normal file
48
boost/serialization/array.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef BOOST_SERIALIZATION_ARRAY_HPP
|
||||
#define BOOST_SERIALIZATION_ARRAY_HPP
|
||||
|
||||
// (C) Copyright 2005 Matthias Troyer and Dave Abrahams
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// for serialization of <array>. If <array> not supported by the standard
|
||||
// library - this file becomes empty. This is to avoid breaking backward
|
||||
// compatibiliy for applications which used this header to support
|
||||
// serialization of native arrays. Code to serialize native arrays is
|
||||
// now always include by default. RR
|
||||
|
||||
#include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
|
||||
|
||||
#if defined(BOOST_NO_STDC_NAMESPACE)
|
||||
|
||||
#include <iostream>
|
||||
#include <cstddef> // std::size_t
|
||||
namespace std{
|
||||
using ::size_t;
|
||||
} // namespace std
|
||||
#endif
|
||||
|
||||
#include <boost/serialization/array_wrapper.hpp>
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
|
||||
#include <array>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
|
||||
namespace boost { namespace serialization {
|
||||
|
||||
template <class Archive, class T, std::size_t N>
|
||||
void serialize(Archive& ar, std::array<T,N>& a, const unsigned int /* version */)
|
||||
{
|
||||
ar & boost::serialization::make_nvp(
|
||||
"elems",
|
||||
*static_cast<T (*)[N]>(static_cast<void *>(a.data()))
|
||||
);
|
||||
|
||||
}
|
||||
} } // end namespace boost::serialization
|
||||
|
||||
#endif // BOOST_NO_CXX11_HDR_ARRAY
|
||||
|
||||
#endif //BOOST_SERIALIZATION_ARRAY_HPP
|
79
boost/serialization/collection_traits.hpp
Normal file
79
boost/serialization/collection_traits.hpp
Normal file
@ -0,0 +1,79 @@
|
||||
#ifndef BOOST_SERIALIZATION_COLLECTION_TRAITS_HPP
|
||||
#define BOOST_SERIALIZATION_COLLECTION_TRAITS_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// collection_traits.hpp:
|
||||
|
||||
// (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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
// This header assigns a level implemenation trait to a collection type
|
||||
// for all primitives. It is needed so that archives which are meant to be
|
||||
// portable don't write class information in the archive. Since, not all
|
||||
// compiles recognize the same set of primitive types, the possibility
|
||||
// exists for archives to be non-portable if class information for primitive
|
||||
// types is included. This is addressed by the following macros.
|
||||
#include <boost/config.hpp>
|
||||
//#include <boost/mpl/integral_c.hpp>
|
||||
#include <boost/mpl/integral_c_tag.hpp>
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/integer_traits.hpp>
|
||||
#include <climits> // ULONG_MAX
|
||||
#include <boost/serialization/level.hpp>
|
||||
|
||||
#define BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(T, C) \
|
||||
template<> \
|
||||
struct implementation_level< C < T > > { \
|
||||
typedef mpl::integral_c_tag tag; \
|
||||
typedef mpl::int_<object_serializable> type; \
|
||||
BOOST_STATIC_CONSTANT(int, value = object_serializable); \
|
||||
}; \
|
||||
/**/
|
||||
|
||||
#if defined(BOOST_NO_CWCHAR) || defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
||||
#define BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_WCHAR(C)
|
||||
#else
|
||||
#define BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_WCHAR(C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(wchar_t, C) \
|
||||
/**/
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_HAS_LONG_LONG)
|
||||
#define BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_INT64(C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(boost::long_long_type, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(boost::ulong_long_type, C) \
|
||||
/**/
|
||||
#else
|
||||
#define BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_INT64(C)
|
||||
#endif
|
||||
|
||||
#define BOOST_SERIALIZATION_COLLECTION_TRAITS(C) \
|
||||
namespace boost { namespace serialization { \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(bool, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(char, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(signed char, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(unsigned char, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(signed int, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(unsigned int, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(signed long, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(unsigned long, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(float, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(double, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(unsigned short, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(signed short, C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_INT64(C) \
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_WCHAR(C) \
|
||||
} } \
|
||||
/**/
|
||||
|
||||
#endif // BOOST_SERIALIZATION_COLLECTION_TRAITS
|
106
boost/serialization/collections_load_imp.hpp
Normal file
106
boost/serialization/collections_load_imp.hpp
Normal file
@ -0,0 +1,106 @@
|
||||
#ifndef BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
|
||||
#define BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER <= 1020)
|
||||
# pragma warning (disable : 4786) // too long name, harmless warning
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// collections_load_imp.hpp: serialization for loading stl collections
|
||||
|
||||
// (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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
// helper function templates for serialization of collections
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <cstddef> // size_t
|
||||
#include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
|
||||
#if defined(BOOST_NO_STDC_NAMESPACE)
|
||||
namespace std{
|
||||
using ::size_t;
|
||||
} // namespace std
|
||||
#endif
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#include <boost/archive/detail/basic_iarchive.hpp>
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/detail/stack_constructor.hpp>
|
||||
#include <boost/serialization/collection_size_type.hpp>
|
||||
#include <boost/serialization/item_version_type.hpp>
|
||||
#include <boost/serialization/detail/is_default_constructible.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
|
||||
namespace boost{
|
||||
namespace serialization {
|
||||
namespace stl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// implementation of serialization for STL containers
|
||||
//
|
||||
|
||||
template<
|
||||
class Archive,
|
||||
class T
|
||||
>
|
||||
typename boost::enable_if<
|
||||
typename detail::is_default_constructible<
|
||||
typename T::value_type
|
||||
>,
|
||||
void
|
||||
>::type
|
||||
collection_load_impl(
|
||||
Archive & ar,
|
||||
T & t,
|
||||
collection_size_type count,
|
||||
item_version_type /*item_version*/
|
||||
){
|
||||
t.resize(count);
|
||||
typename T::iterator hint;
|
||||
hint = t.begin();
|
||||
while(count-- > 0){
|
||||
ar >> boost::serialization::make_nvp("item", *hint++);
|
||||
}
|
||||
}
|
||||
|
||||
template<
|
||||
class Archive,
|
||||
class T
|
||||
>
|
||||
typename boost::disable_if<
|
||||
typename detail::is_default_constructible<
|
||||
typename T::value_type
|
||||
>,
|
||||
void
|
||||
>::type
|
||||
collection_load_impl(
|
||||
Archive & ar,
|
||||
T & t,
|
||||
collection_size_type count,
|
||||
item_version_type item_version
|
||||
){
|
||||
t.clear();
|
||||
while(count-- > 0){
|
||||
detail::stack_construct<Archive, typename T::value_type> u(ar, item_version);
|
||||
ar >> boost::serialization::make_nvp("item", u.reference());
|
||||
t.push_back(boost::move(u.reference()));
|
||||
ar.reset_object_address(& t.back() , & u.reference());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace stl
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif //BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
|
83
boost/serialization/collections_save_imp.hpp
Normal file
83
boost/serialization/collections_save_imp.hpp
Normal file
@ -0,0 +1,83 @@
|
||||
#ifndef BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
|
||||
#define BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// collections_save_imp.hpp: serialization for stl collections
|
||||
|
||||
// (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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
// helper function templates for serialization of collections
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/core/addressof.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#include <boost/serialization/version.hpp>
|
||||
#include <boost/serialization/collection_size_type.hpp>
|
||||
#include <boost/serialization/item_version_type.hpp>
|
||||
|
||||
namespace boost{
|
||||
namespace serialization {
|
||||
namespace stl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// implementation of serialization for STL containers
|
||||
//
|
||||
|
||||
template<class Archive, class Container>
|
||||
inline void save_collection(
|
||||
Archive & ar,
|
||||
const Container &s,
|
||||
collection_size_type count)
|
||||
{
|
||||
ar << BOOST_SERIALIZATION_NVP(count);
|
||||
// record number of elements
|
||||
const item_version_type item_version(
|
||||
version<typename Container::value_type>::value
|
||||
);
|
||||
#if 0
|
||||
boost::archive::library_version_type library_version(
|
||||
ar.get_library_version()
|
||||
);
|
||||
if(boost::archive::library_version_type(3) < library_version){
|
||||
ar << BOOST_SERIALIZATION_NVP(item_version);
|
||||
}
|
||||
#else
|
||||
ar << BOOST_SERIALIZATION_NVP(item_version);
|
||||
#endif
|
||||
|
||||
typename Container::const_iterator it = s.begin();
|
||||
while(count-- > 0){
|
||||
// note borland emits a no-op without the explicit namespace
|
||||
boost::serialization::save_construct_data_adl(
|
||||
ar,
|
||||
boost::addressof(*it),
|
||||
item_version
|
||||
);
|
||||
ar << boost::serialization::make_nvp("item", *it++);
|
||||
}
|
||||
}
|
||||
|
||||
template<class Archive, class Container>
|
||||
inline void save_collection(Archive & ar, const Container &s)
|
||||
{
|
||||
// record number of elements
|
||||
collection_size_type count(s.size());
|
||||
save_collection(ar, s, count);
|
||||
}
|
||||
|
||||
} // namespace stl
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif //BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
|
54
boost/serialization/detail/is_default_constructible.hpp
Normal file
54
boost/serialization/detail/is_default_constructible.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
#ifndef BOOST_SERIALIZATION_DETAIL_IS_DEFAULT_CONSTRUCTIBLE_HPP
|
||||
#define BOOST_SERIALIZATION_DETAIL_IS_DEFAULT_CONSTRUCTIBLE_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// is_default_constructible.hpp: serialization for loading stl collections
|
||||
//
|
||||
// (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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if ! defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
||||
#include <type_traits>
|
||||
namespace boost{
|
||||
namespace serialization {
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
struct is_default_constructible : public std::is_default_constructible<T> {};
|
||||
|
||||
} // detail
|
||||
} // serializaition
|
||||
} // boost
|
||||
#else
|
||||
// we don't have standard library support for is_default_constructible
|
||||
// so we fake it by using boost::has_trivial_construtor. But this is not
|
||||
// actually correct because it's possible that a default constructor
|
||||
// to be non trivial. So when using this, make sure you're not using your
|
||||
// own definition of of T() but are using the actual default one!
|
||||
#include <boost/type_traits/has_trivial_constructor.hpp>
|
||||
namespace boost{
|
||||
namespace serialization {
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
struct is_default_constructible : public boost::has_trivial_constructor<T> {};
|
||||
|
||||
} // detail
|
||||
} // serializaition
|
||||
} // boost
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // BOOST_SERIALIZATION_DETAIL_IS_DEFAULT_CONSTRUCTIBLE_HPP
|
66
boost/serialization/detail/stack_constructor.hpp
Normal file
66
boost/serialization/detail/stack_constructor.hpp
Normal file
@ -0,0 +1,66 @@
|
||||
#ifndef BOOST_SERIALIZATION_DETAIL_STACK_CONSTRUCTOR_HPP
|
||||
#define BOOST_SERIALIZATION_DETAIL_STACK_CONSTRUCTOR_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// stack_constructor.hpp: serialization for loading stl collections
|
||||
|
||||
// (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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <boost/aligned_storage.hpp>
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
|
||||
namespace boost{
|
||||
namespace serialization {
|
||||
namespace detail {
|
||||
|
||||
// reserve space on stack for an object of type T without actually
|
||||
// construction such an object
|
||||
template<typename T >
|
||||
struct stack_allocate
|
||||
{
|
||||
T * address() {
|
||||
return static_cast<T*>(storage_.address());
|
||||
}
|
||||
T & reference() {
|
||||
return * address();
|
||||
}
|
||||
private:
|
||||
typedef typename boost::aligned_storage<
|
||||
sizeof(T),
|
||||
boost::alignment_of<T>::value
|
||||
> type;
|
||||
type storage_;
|
||||
};
|
||||
|
||||
// construct element on the stack
|
||||
template<class Archive, class T>
|
||||
struct stack_construct : public stack_allocate<T>
|
||||
{
|
||||
stack_construct(Archive & ar, const unsigned int version){
|
||||
// note borland emits a no-op without the explicit namespace
|
||||
boost::serialization::load_construct_data_adl(
|
||||
ar,
|
||||
this->address(),
|
||||
version
|
||||
);
|
||||
}
|
||||
~stack_construct(){
|
||||
this->address()->~T(); // undo load_construct_data above
|
||||
}
|
||||
};
|
||||
|
||||
} // detail
|
||||
} // serializaition
|
||||
} // boost
|
||||
|
||||
#endif // BOOST_SERIALIZATION_DETAIL_STACH_CONSTRUCTOR_HPP
|
139
boost/serialization/map.hpp
Normal file
139
boost/serialization/map.hpp
Normal file
@ -0,0 +1,139 @@
|
||||
#ifndef BOOST_SERIALIZATION_MAP_HPP
|
||||
#define BOOST_SERIALIZATION_MAP_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// serialization/map.hpp:
|
||||
// serialization for stl map templates
|
||||
|
||||
// (C) Copyright 2002-2014 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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <boost/archive/detail/basic_iarchive.hpp>
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/collection_size_type.hpp>
|
||||
#include <boost/serialization/item_version_type.hpp>
|
||||
#include <boost/serialization/detail/stack_constructor.hpp>
|
||||
|
||||
#include <boost/serialization/utility.hpp>
|
||||
#include <boost/serialization/collections_save_imp.hpp>
|
||||
#include <boost/serialization/split_free.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// implementation of serialization for map and mult-map STL containers
|
||||
|
||||
template<class Archive, class Container>
|
||||
inline void load_map_collection(Archive & ar, Container &s)
|
||||
{
|
||||
s.clear();
|
||||
const boost::archive::library_version_type library_version(
|
||||
ar.get_library_version()
|
||||
);
|
||||
// retrieve number of elements
|
||||
item_version_type item_version(0);
|
||||
collection_size_type count;
|
||||
ar >> BOOST_SERIALIZATION_NVP(count);
|
||||
if(boost::archive::library_version_type(3) < library_version){
|
||||
ar >> BOOST_SERIALIZATION_NVP(item_version);
|
||||
}
|
||||
typename Container::iterator hint;
|
||||
hint = s.begin();
|
||||
while(count-- > 0){
|
||||
typedef typename Container::value_type type;
|
||||
detail::stack_construct<Archive, type> t(ar, item_version);
|
||||
ar >> boost::serialization::make_nvp("item", t.reference());
|
||||
typename Container::iterator result =
|
||||
s.insert(hint, boost::move(t.reference()));
|
||||
ar.reset_object_address(& (result->second), & t.reference().second);
|
||||
hint = result;
|
||||
++hint;
|
||||
}
|
||||
}
|
||||
|
||||
// map
|
||||
template<class Archive, class Type, class Key, class Compare, class Allocator >
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::map<Key, Type, Compare, Allocator> &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
boost::serialization::stl::save_collection<
|
||||
Archive,
|
||||
std::map<Key, Type, Compare, Allocator>
|
||||
>(ar, t);
|
||||
}
|
||||
|
||||
template<class Archive, class Type, class Key, class Compare, class Allocator >
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::map<Key, Type, Compare, Allocator> &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
load_map_collection(ar, t);
|
||||
}
|
||||
|
||||
// split non-intrusive serialization function member into separate
|
||||
// non intrusive save/load member functions
|
||||
template<class Archive, class Type, class Key, class Compare, class Allocator >
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::map<Key, Type, Compare, Allocator> &t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
boost::serialization::split_free(ar, t, file_version);
|
||||
}
|
||||
|
||||
// multimap
|
||||
template<class Archive, class Type, class Key, class Compare, class Allocator >
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::multimap<Key, Type, Compare, Allocator> &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
boost::serialization::stl::save_collection<
|
||||
Archive,
|
||||
std::multimap<Key, Type, Compare, Allocator>
|
||||
>(ar, t);
|
||||
}
|
||||
|
||||
template<class Archive, class Type, class Key, class Compare, class Allocator >
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::multimap<Key, Type, Compare, Allocator> &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
load_map_collection(ar, t);
|
||||
}
|
||||
|
||||
// split non-intrusive serialization function member into separate
|
||||
// non intrusive save/load member functions
|
||||
template<class Archive, class Type, class Key, class Compare, class Allocator >
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::multimap<Key, Type, Compare, Allocator> &t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
boost::serialization::split_free(ar, t, file_version);
|
||||
}
|
||||
|
||||
} // serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_SERIALIZATION_MAP_HPP
|
138
boost/serialization/set.hpp
Normal file
138
boost/serialization/set.hpp
Normal file
@ -0,0 +1,138 @@
|
||||
#ifndef BOOST_SERIALIZATION_SET_HPP
|
||||
#define BOOST_SERIALIZATION_SET_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// set.hpp: serialization for stl set templates
|
||||
|
||||
// (C) Copyright 2002-2014 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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <boost/archive/detail/basic_iarchive.hpp>
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/detail/stack_constructor.hpp>
|
||||
#include <boost/serialization/collection_size_type.hpp>
|
||||
#include <boost/serialization/item_version_type.hpp>
|
||||
|
||||
#include <boost/serialization/collections_save_imp.hpp>
|
||||
#include <boost/serialization/split_free.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
template<class Archive, class Container>
|
||||
inline void load_set_collection(Archive & ar, Container &s)
|
||||
{
|
||||
s.clear();
|
||||
const boost::archive::library_version_type library_version(
|
||||
ar.get_library_version()
|
||||
);
|
||||
// retrieve number of elements
|
||||
item_version_type item_version(0);
|
||||
collection_size_type count;
|
||||
ar >> BOOST_SERIALIZATION_NVP(count);
|
||||
if(boost::archive::library_version_type(3) < library_version){
|
||||
ar >> BOOST_SERIALIZATION_NVP(item_version);
|
||||
}
|
||||
typename Container::iterator hint;
|
||||
hint = s.begin();
|
||||
while(count-- > 0){
|
||||
typedef typename Container::value_type type;
|
||||
detail::stack_construct<Archive, type> t(ar, item_version);
|
||||
// borland fails silently w/o full namespace
|
||||
ar >> boost::serialization::make_nvp("item", t.reference());
|
||||
typename Container::iterator result =
|
||||
s.insert(hint, boost::move(t.reference()));
|
||||
const type * new_address = & (* result);
|
||||
ar.reset_object_address(new_address, & t.reference());
|
||||
hint = result;
|
||||
}
|
||||
}
|
||||
|
||||
template<class Archive, class Key, class Compare, class Allocator >
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::set<Key, Compare, Allocator> &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
boost::serialization::stl::save_collection<
|
||||
Archive, std::set<Key, Compare, Allocator>
|
||||
>(ar, t);
|
||||
}
|
||||
|
||||
template<class Archive, class Key, class Compare, class Allocator >
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::set<Key, Compare, Allocator> &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
load_set_collection(ar, t);
|
||||
}
|
||||
|
||||
// split non-intrusive serialization function member into separate
|
||||
// non intrusive save/load member functions
|
||||
template<class Archive, class Key, class Compare, class Allocator >
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::set<Key, Compare, Allocator> & t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
boost::serialization::split_free(ar, t, file_version);
|
||||
}
|
||||
|
||||
// multiset
|
||||
template<class Archive, class Key, class Compare, class Allocator >
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::multiset<Key, Compare, Allocator> &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
boost::serialization::stl::save_collection<
|
||||
Archive,
|
||||
std::multiset<Key, Compare, Allocator>
|
||||
>(ar, t);
|
||||
}
|
||||
|
||||
template<class Archive, class Key, class Compare, class Allocator >
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::multiset<Key, Compare, Allocator> &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
load_set_collection(ar, t);
|
||||
}
|
||||
|
||||
// split non-intrusive serialization function member into separate
|
||||
// non intrusive save/load member functions
|
||||
template<class Archive, class Key, class Compare, class Allocator >
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::multiset<Key, Compare, Allocator> & t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
boost::serialization::split_free(ar, t, file_version);
|
||||
}
|
||||
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/serialization/collection_traits.hpp>
|
||||
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS(std::set)
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS(std::multiset)
|
||||
|
||||
#endif // BOOST_SERIALIZATION_SET_HPP
|
281
boost/serialization/shared_ptr.hpp
Normal file
281
boost/serialization/shared_ptr.hpp
Normal file
@ -0,0 +1,281 @@
|
||||
#ifndef BOOST_SERIALIZATION_SHARED_PTR_HPP
|
||||
#define BOOST_SERIALIZATION_SHARED_PTR_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// shared_ptr.hpp: serialization for boost shared pointer
|
||||
|
||||
// (C) Copyright 2004 Robert Ramey and Martin Ecker
|
||||
// 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 <memory>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/mpl/integral_c.hpp>
|
||||
#include <boost/mpl/integral_c_tag.hpp>
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <boost/serialization/shared_ptr_helper.hpp>
|
||||
#include <boost/serialization/split_free.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/version.hpp>
|
||||
#include <boost/serialization/tracking.hpp>
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// boost:: shared_ptr serialization traits
|
||||
// version 1 to distinguish from boost 1.32 version. Note: we can only do this
|
||||
// for a template when the compiler supports partial template specialization
|
||||
|
||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
namespace boost {
|
||||
namespace serialization{
|
||||
template<class T>
|
||||
struct version< ::boost::shared_ptr< T > > {
|
||||
typedef mpl::integral_c_tag tag;
|
||||
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
|
||||
typedef typename mpl::int_<1> type;
|
||||
#else
|
||||
typedef mpl::int_<1> type;
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT(int, value = type::value);
|
||||
};
|
||||
// don't track shared pointers
|
||||
template<class T>
|
||||
struct tracking_level< ::boost::shared_ptr< T > > {
|
||||
typedef mpl::integral_c_tag tag;
|
||||
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
|
||||
typedef typename mpl::int_< ::boost::serialization::track_never> type;
|
||||
#else
|
||||
typedef mpl::int_< ::boost::serialization::track_never> type;
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT(int, value = type::value);
|
||||
};
|
||||
}}
|
||||
#define BOOST_SERIALIZATION_SHARED_PTR(T)
|
||||
#else
|
||||
// define macro to let users of these compilers do this
|
||||
#define BOOST_SERIALIZATION_SHARED_PTR(T) \
|
||||
BOOST_CLASS_VERSION( \
|
||||
::boost::shared_ptr< T >, \
|
||||
1 \
|
||||
) \
|
||||
BOOST_CLASS_TRACKING( \
|
||||
::boost::shared_ptr< T >, \
|
||||
::boost::serialization::track_never \
|
||||
) \
|
||||
/**/
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace serialization{
|
||||
|
||||
struct null_deleter {
|
||||
void operator()(void const *) const {}
|
||||
};
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// serialization for boost::shared_ptr
|
||||
|
||||
// Using a constant means that all shared pointers are held in the same set.
|
||||
// Thus we detect handle multiple pointers to the same value instances
|
||||
// in the archive.
|
||||
void * const shared_ptr_helper_id = 0;
|
||||
|
||||
template<class Archive, class T>
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const boost::shared_ptr< T > &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
// The most common cause of trapping here would be serializing
|
||||
// something like shared_ptr<int>. This occurs because int
|
||||
// is never tracked by default. Wrap int in a trackable type
|
||||
BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
|
||||
const T * t_ptr = t.get();
|
||||
ar << boost::serialization::make_nvp("px", t_ptr);
|
||||
}
|
||||
|
||||
#ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
|
||||
template<class Archive, class T>
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
boost::shared_ptr< T > &t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
// something like shared_ptr<int>. This occurs because int
|
||||
// is never tracked by default. Wrap int in a trackable type
|
||||
BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
|
||||
T* r;
|
||||
if(file_version < 1){
|
||||
ar.register_type(static_cast<
|
||||
boost_132::detail::sp_counted_base_impl<T *, null_deleter > *
|
||||
>(NULL));
|
||||
boost_132::shared_ptr< T > sp;
|
||||
ar >> boost::serialization::make_nvp("px", sp.px);
|
||||
ar >> boost::serialization::make_nvp("pn", sp.pn);
|
||||
// got to keep the sps around so the sp.pns don't disappear
|
||||
boost::serialization::shared_ptr_helper<boost::shared_ptr> & h =
|
||||
ar.template get_helper< shared_ptr_helper<boost::shared_ptr> >(
|
||||
shared_ptr_helper_id
|
||||
);
|
||||
h.append(sp);
|
||||
r = sp.get();
|
||||
}
|
||||
else{
|
||||
ar >> boost::serialization::make_nvp("px", r);
|
||||
}
|
||||
shared_ptr_helper<boost::shared_ptr> & h =
|
||||
ar.template get_helper<shared_ptr_helper<boost::shared_ptr> >(
|
||||
shared_ptr_helper_id
|
||||
);
|
||||
h.reset(t,r);
|
||||
}
|
||||
#else
|
||||
|
||||
template<class Archive, class T>
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
boost::shared_ptr< T > &t,
|
||||
const unsigned int /*file_version*/
|
||||
){
|
||||
// The most common cause of trapping here would be serializing
|
||||
// something like shared_ptr<int>. This occurs because int
|
||||
// is never tracked by default. Wrap int in a trackable type
|
||||
BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
|
||||
T* r;
|
||||
ar >> boost::serialization::make_nvp("px", r);
|
||||
|
||||
boost::serialization::shared_ptr_helper<boost::shared_ptr> & h =
|
||||
ar.template get_helper<shared_ptr_helper<boost::shared_ptr> >(
|
||||
shared_ptr_helper_id
|
||||
);
|
||||
h.reset(t,r);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class Archive, class T>
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
boost::shared_ptr< T > &t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
// correct shared_ptr serialization depends upon object tracking
|
||||
// being used.
|
||||
BOOST_STATIC_ASSERT(
|
||||
boost::serialization::tracking_level< T >::value
|
||||
!= boost::serialization::track_never
|
||||
);
|
||||
boost::serialization::split_free(ar, t, file_version);
|
||||
}
|
||||
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// std::shared_ptr serialization traits
|
||||
// version 1 to distinguish from boost 1.32 version. Note: we can only do this
|
||||
// for a template when the compiler supports partial template specialization
|
||||
|
||||
#ifndef BOOST_NO_CXX11_SMART_PTR
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
// note: we presume that any compiler/library which supports C++11
|
||||
// std::pointers also supports template partial specialization
|
||||
// trap here if such presumption were to turn out to wrong!!!
|
||||
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
BOOST_STATIC_ASSERT(false);
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace serialization{
|
||||
template<class T>
|
||||
struct version< ::std::shared_ptr< T > > {
|
||||
typedef mpl::integral_c_tag tag;
|
||||
typedef mpl::int_<1> type;
|
||||
BOOST_STATIC_CONSTANT(int, value = type::value);
|
||||
};
|
||||
// don't track shared pointers
|
||||
template<class T>
|
||||
struct tracking_level< ::std::shared_ptr< T > > {
|
||||
typedef mpl::integral_c_tag tag;
|
||||
typedef mpl::int_< ::boost::serialization::track_never> type;
|
||||
BOOST_STATIC_CONSTANT(int, value = type::value);
|
||||
};
|
||||
}}
|
||||
// the following just keeps older programs from breaking
|
||||
#define BOOST_SERIALIZATION_SHARED_PTR(T)
|
||||
|
||||
namespace boost {
|
||||
namespace serialization{
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// serialization for std::shared_ptr
|
||||
|
||||
template<class Archive, class T>
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::shared_ptr< T > &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
// The most common cause of trapping here would be serializing
|
||||
// something like shared_ptr<int>. This occurs because int
|
||||
// is never tracked by default. Wrap int in a trackable type
|
||||
BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
|
||||
const T * t_ptr = t.get();
|
||||
ar << boost::serialization::make_nvp("px", t_ptr);
|
||||
}
|
||||
|
||||
template<class Archive, class T>
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::shared_ptr< T > &t,
|
||||
const unsigned int /*file_version*/
|
||||
){
|
||||
// The most common cause of trapping here would be serializing
|
||||
// something like shared_ptr<int>. This occurs because int
|
||||
// is never tracked by default. Wrap int in a trackable type
|
||||
BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
|
||||
T* r;
|
||||
ar >> boost::serialization::make_nvp("px", r);
|
||||
//void (* const id)(Archive &, std::shared_ptr< T > &, const unsigned int) = & load;
|
||||
boost::serialization::shared_ptr_helper<std::shared_ptr> & h =
|
||||
ar.template get_helper<
|
||||
shared_ptr_helper<std::shared_ptr>
|
||||
>(
|
||||
shared_ptr_helper_id
|
||||
);
|
||||
h.reset(t,r);
|
||||
}
|
||||
|
||||
template<class Archive, class T>
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::shared_ptr< T > &t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
// correct shared_ptr serialization depends upon object tracking
|
||||
// being used.
|
||||
BOOST_STATIC_ASSERT(
|
||||
boost::serialization::tracking_level< T >::value
|
||||
!= boost::serialization::track_never
|
||||
);
|
||||
boost::serialization::split_free(ar, t, file_version);
|
||||
}
|
||||
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_NO_CXX11_SMART_PTR
|
||||
|
||||
#endif // BOOST_SERIALIZATION_SHARED_PTR_HPP
|
209
boost/serialization/shared_ptr_helper.hpp
Normal file
209
boost/serialization/shared_ptr_helper.hpp
Normal file
@ -0,0 +1,209 @@
|
||||
#ifndef BOOST_SERIALIZATION_SHARED_PTR_HELPER_HPP
|
||||
#define BOOST_SERIALIZATION_SHARED_PTR_HELPER_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////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 <boost/config.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/type_traits/is_polymorphic.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
|
||||
#include <boost/serialization/singleton.hpp>
|
||||
#include <boost/serialization/extended_type_info.hpp>
|
||||
#include <boost/serialization/throw_exception.hpp>
|
||||
#include <boost/serialization/type_info_implementation.hpp>
|
||||
#include <boost/archive/archive_exception.hpp>
|
||||
|
||||
namespace boost_132 {
|
||||
template<class T> class shared_ptr;
|
||||
}
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
||||
template<class Archive, template<class U> class SPT >
|
||||
void load(
|
||||
Archive & ar,
|
||||
SPT< class U > &t,
|
||||
const unsigned int file_version
|
||||
);
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// a common class for holding various types of shared pointers
|
||||
|
||||
template<template<class T> class SPT>
|
||||
class shared_ptr_helper {
|
||||
typedef std::map<
|
||||
const void *, // address of object
|
||||
SPT<const void> // address shared ptr to single instance
|
||||
> object_shared_pointer_map;
|
||||
|
||||
// list of shared_pointers create accessable by raw pointer. This
|
||||
// is used to "match up" shared pointers loaded at different
|
||||
// points in the archive. Note, we delay construction until
|
||||
// it is actually used since this is by default included as
|
||||
// a "mix-in" even if shared_ptr isn't used.
|
||||
object_shared_pointer_map * m_o_sp;
|
||||
|
||||
struct null_deleter {
|
||||
void operator()(void const *) const {}
|
||||
};
|
||||
|
||||
#if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) \
|
||||
|| defined(BOOST_MSVC) \
|
||||
|| defined(__SUNPRO_CC)
|
||||
public:
|
||||
#else
|
||||
template<class Archive, class U>
|
||||
friend void boost::serialization::load(
|
||||
Archive & ar,
|
||||
SPT< U > &t,
|
||||
const unsigned int file_version
|
||||
);
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
|
||||
// list of loaded pointers. This is used to be sure that the pointers
|
||||
// stay around long enough to be "matched" with other pointers loaded
|
||||
// by the same archive. These are created with a "null_deleter" so that
|
||||
// when this list is destroyed - the underlaying raw pointers are not
|
||||
// destroyed. This has to be done because the pointers are also held by
|
||||
// new system which is disjoint from this set. This is implemented
|
||||
// by a change in load_construct_data below. It makes this file suitable
|
||||
// only for loading pointers into a 1.33 or later boost system.
|
||||
std::list<boost_132::shared_ptr<const void> > * m_pointers_132;
|
||||
void
|
||||
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
|
||||
|
||||
struct non_polymorphic {
|
||||
template<class U>
|
||||
static const boost::serialization::extended_type_info *
|
||||
get_object_type(U & ){
|
||||
return & boost::serialization::singleton<
|
||||
typename
|
||||
boost::serialization::type_info_implementation< U >::type
|
||||
>::get_const_instance();
|
||||
}
|
||||
};
|
||||
struct polymorphic {
|
||||
template<class U>
|
||||
static const boost::serialization::extended_type_info *
|
||||
get_object_type(U & u){
|
||||
return boost::serialization::singleton<
|
||||
typename
|
||||
boost::serialization::type_info_implementation< U >::type
|
||||
>::get_const_instance().get_derived_extended_type_info(u);
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
template<class T>
|
||||
void reset(SPT< T > & s, T * t){
|
||||
if(NULL == t){
|
||||
s.reset();
|
||||
return;
|
||||
}
|
||||
const boost::serialization::extended_type_info * this_type
|
||||
= & boost::serialization::type_info_implementation< T >::type
|
||||
::get_const_instance();
|
||||
|
||||
// get pointer to the most derived object's eti. This is effectively
|
||||
// the object type identifer
|
||||
typedef typename mpl::if_<
|
||||
is_polymorphic< T >,
|
||||
polymorphic,
|
||||
non_polymorphic
|
||||
>::type type;
|
||||
|
||||
const boost::serialization::extended_type_info * true_type
|
||||
= type::get_object_type(*t);
|
||||
|
||||
// note:if this exception is thrown, be sure that derived pointern
|
||||
// is either registered or exported.
|
||||
if(NULL == true_type)
|
||||
boost::serialization::throw_exception(
|
||||
boost::archive::archive_exception(
|
||||
boost::archive::archive_exception::unregistered_class,
|
||||
this_type->get_debug_info()
|
||||
)
|
||||
);
|
||||
// get void pointer to the most derived type
|
||||
// this uniquely identifies the object referred to
|
||||
// oid = "object identifier"
|
||||
const void * oid = void_downcast(
|
||||
*true_type,
|
||||
*this_type,
|
||||
t
|
||||
);
|
||||
if(NULL == oid)
|
||||
boost::serialization::throw_exception(
|
||||
boost::archive::archive_exception(
|
||||
boost::archive::archive_exception::unregistered_cast,
|
||||
true_type->get_debug_info(),
|
||||
this_type->get_debug_info()
|
||||
)
|
||||
);
|
||||
|
||||
// make tracking array if necessary
|
||||
if(NULL == m_o_sp)
|
||||
m_o_sp = new object_shared_pointer_map;
|
||||
|
||||
typename object_shared_pointer_map::iterator i = m_o_sp->find(oid);
|
||||
|
||||
// if it's a new object
|
||||
if(i == m_o_sp->end()){
|
||||
s.reset(t);
|
||||
std::pair<typename object_shared_pointer_map::iterator, bool> result;
|
||||
result = m_o_sp->insert(std::make_pair(oid, s));
|
||||
BOOST_ASSERT(result.second);
|
||||
}
|
||||
// if the object has already been seen
|
||||
else{
|
||||
s = SPT<T>(i->second, t);
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr_helper() :
|
||||
m_o_sp(NULL)
|
||||
#ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
|
||||
, m_pointers_132(NULL)
|
||||
#endif
|
||||
{}
|
||||
virtual ~shared_ptr_helper(){
|
||||
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
|
||||
|
||||
#endif // BOOST_SERIALIZATION_SHARED_PTR_HELPER_HPP
|
68
boost/serialization/unique_ptr.hpp
Normal file
68
boost/serialization/unique_ptr.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
#ifndef BOOST_SERIALIZATION_UNIQUE_PTR_HPP
|
||||
#define BOOST_SERIALIZATION_UNIQUE_PTR_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// unique_ptr.hpp:
|
||||
|
||||
// (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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
#include <memory>
|
||||
#include <boost/serialization/split_free.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// implement serialization for unique_ptr< T >
|
||||
// note: this must be added to the boost namespace in order to
|
||||
// be called by the library
|
||||
template<class Archive, class T>
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::unique_ptr< T > &t,
|
||||
const unsigned int /*file_version*/
|
||||
){
|
||||
// only the raw pointer has to be saved
|
||||
// the ref count is rebuilt automatically on load
|
||||
const T * const tx = t.get();
|
||||
ar << BOOST_SERIALIZATION_NVP(tx);
|
||||
}
|
||||
|
||||
template<class Archive, class T>
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::unique_ptr< T > &t,
|
||||
const unsigned int /*file_version*/
|
||||
){
|
||||
T *tx;
|
||||
ar >> BOOST_SERIALIZATION_NVP(tx);
|
||||
// note that the reset automagically maintains the reference count
|
||||
t.reset(tx);
|
||||
}
|
||||
|
||||
// split non-intrusive serialization function member into separate
|
||||
// non intrusive save/load member functions
|
||||
template<class Archive, class T>
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::unique_ptr< T > &t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
boost::serialization::split_free(ar, t, file_version);
|
||||
}
|
||||
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_SERIALIZATION_UNIQUE_PTR_HPP
|
73
boost/serialization/unordered_collections_load_imp.hpp
Normal file
73
boost/serialization/unordered_collections_load_imp.hpp
Normal file
@ -0,0 +1,73 @@
|
||||
#ifndef BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP
|
||||
#define BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
# pragma warning (disable : 4786) // too long name, harmless warning
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// unordered_collections_load_imp.hpp: serialization for loading stl collections
|
||||
|
||||
// (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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
// helper function templates for serialization of collections
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <cstddef> // size_t
|
||||
#include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
|
||||
#if defined(BOOST_NO_STDC_NAMESPACE)
|
||||
namespace std{
|
||||
using ::size_t;
|
||||
} // namespace std
|
||||
#endif
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#include <boost/archive/detail/basic_iarchive.hpp>
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/collection_size_type.hpp>
|
||||
#include <boost/serialization/item_version_type.hpp>
|
||||
|
||||
namespace boost{
|
||||
namespace serialization {
|
||||
namespace stl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// implementation of serialization for STL containers
|
||||
//
|
||||
template<class Archive, class Container, class InputFunction>
|
||||
inline void load_unordered_collection(Archive & ar, Container &s)
|
||||
{
|
||||
collection_size_type count;
|
||||
collection_size_type bucket_count;
|
||||
boost::serialization::item_version_type item_version(0);
|
||||
boost::archive::library_version_type library_version(
|
||||
ar.get_library_version()
|
||||
);
|
||||
// retrieve number of elements
|
||||
ar >> BOOST_SERIALIZATION_NVP(count);
|
||||
ar >> BOOST_SERIALIZATION_NVP(bucket_count);
|
||||
if(boost::archive::library_version_type(3) < library_version){
|
||||
ar >> BOOST_SERIALIZATION_NVP(item_version);
|
||||
}
|
||||
s.clear();
|
||||
s.rehash(bucket_count);
|
||||
InputFunction ifunc;
|
||||
while(count-- > 0){
|
||||
ifunc(ar, s, item_version);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace stl
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP
|
86
boost/serialization/unordered_collections_save_imp.hpp
Normal file
86
boost/serialization/unordered_collections_save_imp.hpp
Normal file
@ -0,0 +1,86 @@
|
||||
#ifndef BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
|
||||
#define BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// hash_collections_save_imp.hpp: serialization for stl collections
|
||||
|
||||
// (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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
// helper function templates for serialization of collections
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#include <boost/serialization/version.hpp>
|
||||
#include <boost/serialization/collection_size_type.hpp>
|
||||
#include <boost/serialization/item_version_type.hpp>
|
||||
|
||||
namespace boost{
|
||||
namespace serialization {
|
||||
namespace stl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// implementation of serialization for STL containers
|
||||
//
|
||||
|
||||
template<class Archive, class Container>
|
||||
inline void save_unordered_collection(Archive & ar, const Container &s)
|
||||
{
|
||||
collection_size_type count(s.size());
|
||||
const collection_size_type bucket_count(s.bucket_count());
|
||||
const item_version_type item_version(
|
||||
version<typename Container::value_type>::value
|
||||
);
|
||||
|
||||
#if 0
|
||||
/* should only be necessary to create archives of previous versions
|
||||
* which is not currently supported. So for now comment this out
|
||||
*/
|
||||
boost::archive::library_version_type library_version(
|
||||
ar.get_library_version()
|
||||
);
|
||||
// retrieve number of elements
|
||||
ar << BOOST_SERIALIZATION_NVP(count);
|
||||
ar << BOOST_SERIALIZATION_NVP(bucket_count);
|
||||
if(boost::archive::library_version_type(3) < library_version){
|
||||
// record number of elements
|
||||
// make sure the target type is registered so we can retrieve
|
||||
// the version when we load
|
||||
ar << BOOST_SERIALIZATION_NVP(item_version);
|
||||
}
|
||||
#else
|
||||
ar << BOOST_SERIALIZATION_NVP(count);
|
||||
ar << BOOST_SERIALIZATION_NVP(bucket_count);
|
||||
ar << BOOST_SERIALIZATION_NVP(item_version);
|
||||
#endif
|
||||
|
||||
typename Container::const_iterator it = s.begin();
|
||||
while(count-- > 0){
|
||||
// note borland emits a no-op without the explicit namespace
|
||||
boost::serialization::save_construct_data_adl(
|
||||
ar,
|
||||
&(*it),
|
||||
boost::serialization::version<
|
||||
typename Container::value_type
|
||||
>::value
|
||||
);
|
||||
ar << boost::serialization::make_nvp("item", *it++);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace stl
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
|
162
boost/serialization/unordered_set.hpp
Normal file
162
boost/serialization/unordered_set.hpp
Normal file
@ -0,0 +1,162 @@
|
||||
#ifndef BOOST_SERIALIZATION_UNORDERED_SET_HPP
|
||||
#define BOOST_SERIALIZATION_UNORDERED_SET_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// unordered_set.hpp: serialization for stl unordered_set templates
|
||||
|
||||
// (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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#include <boost/serialization/unordered_collections_save_imp.hpp>
|
||||
#include <boost/serialization/unordered_collections_load_imp.hpp>
|
||||
#include <boost/serialization/archive_input_unordered_set.hpp>
|
||||
#include <boost/serialization/split_free.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
template<
|
||||
class Archive,
|
||||
class Key,
|
||||
class HashFcn,
|
||||
class EqualKey,
|
||||
class Allocator
|
||||
>
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::unordered_set<
|
||||
Key, HashFcn, EqualKey, Allocator
|
||||
> &t,
|
||||
const unsigned int /*file_version*/
|
||||
){
|
||||
boost::serialization::stl::save_unordered_collection<
|
||||
Archive,
|
||||
std::unordered_set<Key, HashFcn, EqualKey, Allocator>
|
||||
>(ar, t);
|
||||
}
|
||||
|
||||
template<
|
||||
class Archive,
|
||||
class Key,
|
||||
class HashFcn,
|
||||
class EqualKey,
|
||||
class Allocator
|
||||
>
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::unordered_set<
|
||||
Key, HashFcn, EqualKey, Allocator
|
||||
> &t,
|
||||
const unsigned int /*file_version*/
|
||||
){
|
||||
boost::serialization::stl::load_unordered_collection<
|
||||
Archive,
|
||||
std::unordered_set<Key, HashFcn, EqualKey, Allocator>,
|
||||
stl::archive_input_unordered_set<
|
||||
Archive,
|
||||
std::unordered_set<
|
||||
Key, HashFcn, EqualKey, Allocator
|
||||
>
|
||||
>
|
||||
>(ar, t);
|
||||
}
|
||||
|
||||
// split non-intrusive serialization function member into separate
|
||||
// non intrusive save/load member functions
|
||||
template<
|
||||
class Archive,
|
||||
class Key,
|
||||
class HashFcn,
|
||||
class EqualKey,
|
||||
class Allocator
|
||||
>
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::unordered_set<
|
||||
Key, HashFcn, EqualKey, Allocator
|
||||
> &t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
split_free(ar, t, file_version);
|
||||
}
|
||||
|
||||
// unordered_multiset
|
||||
template<
|
||||
class Archive,
|
||||
class Key,
|
||||
class HashFcn,
|
||||
class EqualKey,
|
||||
class Allocator
|
||||
>
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::unordered_multiset<
|
||||
Key, HashFcn, EqualKey, Allocator
|
||||
> &t,
|
||||
const unsigned int /*file_version*/
|
||||
){
|
||||
stl::save_unordered_collection<
|
||||
Archive,
|
||||
std::unordered_multiset<Key, HashFcn, EqualKey, Allocator>
|
||||
>(ar, t);
|
||||
}
|
||||
|
||||
template<
|
||||
class Archive,
|
||||
class Key,
|
||||
class HashFcn,
|
||||
class EqualKey,
|
||||
class Allocator
|
||||
>
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::unordered_multiset<
|
||||
Key, HashFcn, EqualKey, Allocator
|
||||
> &t,
|
||||
const unsigned int /*file_version*/
|
||||
){
|
||||
boost::serialization::stl::load_unordered_collection<
|
||||
Archive,
|
||||
std::unordered_multiset<Key, HashFcn, EqualKey, Allocator>,
|
||||
boost::serialization::stl::archive_input_unordered_multiset<
|
||||
Archive,
|
||||
std::unordered_multiset<Key, HashFcn, EqualKey, Allocator>
|
||||
>
|
||||
>(ar, t);
|
||||
}
|
||||
|
||||
// split non-intrusive serialization function member into separate
|
||||
// non intrusive save/load member functions
|
||||
template<
|
||||
class Archive,
|
||||
class Key,
|
||||
class HashFcn,
|
||||
class EqualKey,
|
||||
class Allocator
|
||||
>
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::unordered_multiset<Key, HashFcn, EqualKey, Allocator> &t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
boost::serialization::split_free(ar, t, file_version);
|
||||
}
|
||||
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_SERIALIZATION_UNORDERED_SET_HPP
|
56
boost/serialization/utility.hpp
Normal file
56
boost/serialization/utility.hpp
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef BOOST_SERIALIZATION_UTILITY_HPP
|
||||
#define BOOST_SERIALIZATION_UTILITY_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// serialization/utility.hpp:
|
||||
// serialization for stl utility templates
|
||||
|
||||
// (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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <utility>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/is_bitwise_serializable.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
// pair
|
||||
template<class Archive, class F, class S>
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::pair<F, S> & p,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
// note: we remove any const-ness on the first argument. The reason is that
|
||||
// for stl maps, the type saved is pair<const key, T). We remove
|
||||
// the const-ness in order to be able to load it.
|
||||
typedef typename boost::remove_const<F>::type typef;
|
||||
ar & boost::serialization::make_nvp("first", const_cast<typef &>(p.first));
|
||||
ar & boost::serialization::make_nvp("second", p.second);
|
||||
}
|
||||
|
||||
/// specialization of is_bitwise_serializable for pairs
|
||||
template <class T, class U>
|
||||
struct is_bitwise_serializable<std::pair<T,U> >
|
||||
: public mpl::and_<is_bitwise_serializable< T >,is_bitwise_serializable<U> >
|
||||
{
|
||||
};
|
||||
|
||||
} // serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_SERIALIZATION_UTILITY_HPP
|
233
boost/serialization/vector.hpp
Normal file
233
boost/serialization/vector.hpp
Normal file
@ -0,0 +1,233 @@
|
||||
#ifndef BOOST_SERIALIZATION_VECTOR_HPP
|
||||
#define BOOST_SERIALIZATION_VECTOR_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// vector.hpp: serialization for stl vector templates
|
||||
|
||||
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
||||
// fast array serialization (C) Copyright 2005 Matthias Troyer
|
||||
// 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 <vector>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#include <boost/archive/detail/basic_iarchive.hpp>
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/collection_size_type.hpp>
|
||||
#include <boost/serialization/item_version_type.hpp>
|
||||
|
||||
#include <boost/serialization/collections_save_imp.hpp>
|
||||
#include <boost/serialization/collections_load_imp.hpp>
|
||||
#include <boost/serialization/split_free.hpp>
|
||||
#include <boost/serialization/array_wrapper.hpp>
|
||||
#include <boost/mpl/bool_fwd.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
|
||||
// default is being compatible with version 1.34.1 files, not 1.35 files
|
||||
#ifndef BOOST_SERIALIZATION_VECTOR_VERSIONED
|
||||
#define BOOST_SERIALIZATION_VECTOR_VERSIONED(V) (V==4 || V==5)
|
||||
#endif
|
||||
|
||||
// function specializations must be defined in the appropriate
|
||||
// namespace - boost::serialization
|
||||
#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
|
||||
#define STD _STLP_STD
|
||||
#else
|
||||
#define STD std
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// vector< T >
|
||||
|
||||
// the default versions
|
||||
|
||||
template<class Archive, class U, class Allocator>
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::vector<U, Allocator> &t,
|
||||
const unsigned int /* file_version */,
|
||||
mpl::false_
|
||||
){
|
||||
boost::serialization::stl::save_collection<Archive, STD::vector<U, Allocator> >(
|
||||
ar, t
|
||||
);
|
||||
}
|
||||
|
||||
template<class Archive, class U, class Allocator>
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::vector<U, Allocator> &t,
|
||||
const unsigned int /* file_version */,
|
||||
mpl::false_
|
||||
){
|
||||
const boost::archive::library_version_type library_version(
|
||||
ar.get_library_version()
|
||||
);
|
||||
// retrieve number of elements
|
||||
item_version_type item_version(0);
|
||||
collection_size_type count;
|
||||
ar >> BOOST_SERIALIZATION_NVP(count);
|
||||
if(boost::archive::library_version_type(3) < library_version){
|
||||
ar >> BOOST_SERIALIZATION_NVP(item_version);
|
||||
}
|
||||
t.reserve(count);
|
||||
stl::collection_load_impl(ar, t, count, item_version);
|
||||
}
|
||||
|
||||
// the optimized versions
|
||||
|
||||
template<class Archive, class U, class Allocator>
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::vector<U, Allocator> &t,
|
||||
const unsigned int /* file_version */,
|
||||
mpl::true_
|
||||
){
|
||||
const collection_size_type count(t.size());
|
||||
ar << BOOST_SERIALIZATION_NVP(count);
|
||||
if (!t.empty())
|
||||
// explict template arguments to pass intel C++ compiler
|
||||
ar << serialization::make_array<const U, collection_size_type>(
|
||||
static_cast<const U *>(&t[0]),
|
||||
count
|
||||
);
|
||||
}
|
||||
|
||||
template<class Archive, class U, class Allocator>
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::vector<U, Allocator> &t,
|
||||
const unsigned int /* file_version */,
|
||||
mpl::true_
|
||||
){
|
||||
collection_size_type count(t.size());
|
||||
ar >> BOOST_SERIALIZATION_NVP(count);
|
||||
t.resize(count);
|
||||
unsigned int item_version=0;
|
||||
if(BOOST_SERIALIZATION_VECTOR_VERSIONED(ar.get_library_version())) {
|
||||
ar >> BOOST_SERIALIZATION_NVP(item_version);
|
||||
}
|
||||
if (!t.empty())
|
||||
// explict template arguments to pass intel C++ compiler
|
||||
ar >> serialization::make_array<U, collection_size_type>(
|
||||
static_cast<U *>(&t[0]),
|
||||
count
|
||||
);
|
||||
}
|
||||
|
||||
// dispatch to either default or optimized versions
|
||||
|
||||
template<class Archive, class U, class Allocator>
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::vector<U, Allocator> &t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
typedef typename
|
||||
boost::serialization::use_array_optimization<Archive>::template apply<
|
||||
typename remove_const<U>::type
|
||||
>::type use_optimized;
|
||||
save(ar,t,file_version, use_optimized());
|
||||
}
|
||||
|
||||
template<class Archive, class U, class Allocator>
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::vector<U, Allocator> &t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
#ifdef BOOST_SERIALIZATION_VECTOR_135_HPP
|
||||
if (ar.get_library_version()==boost::archive::library_version_type(5))
|
||||
{
|
||||
load(ar,t,file_version, boost::is_arithmetic<U>());
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
typedef typename
|
||||
boost::serialization::use_array_optimization<Archive>::template apply<
|
||||
typename remove_const<U>::type
|
||||
>::type use_optimized;
|
||||
load(ar,t,file_version, use_optimized());
|
||||
}
|
||||
|
||||
// split non-intrusive serialization function member into separate
|
||||
// non intrusive save/load member functions
|
||||
template<class Archive, class U, class Allocator>
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::vector<U, Allocator> & t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
boost::serialization::split_free(ar, t, file_version);
|
||||
}
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// vector<bool>
|
||||
template<class Archive, class Allocator>
|
||||
inline void save(
|
||||
Archive & ar,
|
||||
const std::vector<bool, Allocator> &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
// record number of elements
|
||||
collection_size_type count (t.size());
|
||||
ar << BOOST_SERIALIZATION_NVP(count);
|
||||
std::vector<bool>::const_iterator it = t.begin();
|
||||
while(count-- > 0){
|
||||
bool tb = *it++;
|
||||
ar << boost::serialization::make_nvp("item", tb);
|
||||
}
|
||||
}
|
||||
|
||||
template<class Archive, class Allocator>
|
||||
inline void load(
|
||||
Archive & ar,
|
||||
std::vector<bool, Allocator> &t,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
// retrieve number of elements
|
||||
collection_size_type count;
|
||||
ar >> BOOST_SERIALIZATION_NVP(count);
|
||||
t.resize(count);
|
||||
for(collection_size_type i = collection_size_type(0); i < count; ++i){
|
||||
bool b;
|
||||
ar >> boost::serialization::make_nvp("item", b);
|
||||
t[i] = b;
|
||||
}
|
||||
}
|
||||
|
||||
// split non-intrusive serialization function member into separate
|
||||
// non intrusive save/load member functions
|
||||
template<class Archive, class Allocator>
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::vector<bool, Allocator> & t,
|
||||
const unsigned int file_version
|
||||
){
|
||||
boost::serialization::split_free(ar, t, file_version);
|
||||
}
|
||||
|
||||
} // serialization
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/serialization/collection_traits.hpp>
|
||||
|
||||
BOOST_SERIALIZATION_COLLECTION_TRAITS(std::vector)
|
||||
#undef STD
|
||||
|
||||
#endif // BOOST_SERIALIZATION_VECTOR_HPP
|
@ -16,4 +16,11 @@ bcp ^
|
||||
boost/variant/ ^
|
||||
boost/archive/binary_iarchive.hpp ^
|
||||
boost/archive/binary_oarchive.hpp ^
|
||||
boost/serialization/array.hpp ^
|
||||
boost/serialization/vector.hpp ^
|
||||
boost/serialization/set.hpp ^
|
||||
boost/serialization/map.hpp ^
|
||||
boost/serialization/unordered_set.hpp ^
|
||||
boost/serialization/shared_ptr.hpp ^
|
||||
boost/serialization/unique_ptr.hpp ^
|
||||
--boost="%1" .
|
||||
|
Loading…
x
Reference in New Issue
Block a user