mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-19 04:12:09 +00:00
Add optional serialization support
This implemenents non-intrusive serialization support to dynamic_bitset<> based on Boost Serialization - it supports archives that require named elements - it gets private member access using a nested friend class (to decouple the interface entirely) - relies on boost/serialization/vector.hpp for actual implementation
This commit is contained in:
@@ -348,6 +348,10 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
public:
|
||||
// forward declaration for optional zero-copy serialization support
|
||||
class serialize_impl;
|
||||
friend class serialize_impl;
|
||||
|
||||
private:
|
||||
BOOST_STATIC_CONSTANT(block_width_type, ulong_width = std::numeric_limits<unsigned long>::digits);
|
||||
|
||||
46
include/boost/dynamic_bitset/serialization.hpp
Normal file
46
include/boost/dynamic_bitset/serialization.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// -----------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2015 Seth Heeren
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#ifndef BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
|
||||
#define BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
|
||||
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include <boost/serialization/vector.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
// implementation for optional zero-copy serialization support
|
||||
template <typename Block, typename Allocator>
|
||||
class dynamic_bitset<Block, Allocator>::serialize_impl
|
||||
{
|
||||
public:
|
||||
template <typename Ar>
|
||||
static void serialize(Ar& ar, dynamic_bitset<Block, Allocator>& bs, unsigned) {
|
||||
ar & serialization::make_nvp("m_num_bits", bs.m_num_bits)
|
||||
& serialization::make_nvp("m_bits", bs.m_bits);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// ADL hook to Boost Serialization library
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
template <typename Ar, typename Block, typename Allocator>
|
||||
void serialize(Ar& ar, dynamic_bitset<Block, Allocator>& bs, unsigned version) {
|
||||
dynamic_bitset<Block, Allocator>::serialize_impl::serialize(ar, bs, version);
|
||||
}
|
||||
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
||||
|
||||
Reference in New Issue
Block a user