Ticket #2912: bitset.hpp

File bitset.hpp, 1.7 KB (added by kfriddile@…, 14 years ago)

serialization support for std::bitset

Line 
1/*!
2 * \file bitset.hpp
3 * \brief Provides Boost.Serialization support for std::bitset
4 * \author Brian Ravnsgaard Riis
5 * \author Kenneth Riddile
6 * \date 16.09.2004, updated 04.03.2009
7 * \copyright 2004 Brian Ravnsgaard Riis
8 * \license Boost Software License 1.0
9 */
10#ifndef BOOST_SERIALIZATION_BITSET_HPP
11#define BOOST_SERIALIZATION_BITSET_HPP
12
13#include <bitset>
14#include <string>
15
16#include <boost/config.hpp>
17#include <boost/serialization/split_free.hpp>
18#include <boost/serialization/string.hpp>
19#include <boost/serialization/nvp.hpp>
20
21#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
22#define STD _STLP_STD
23#else
24#define STD std
25#endif
26
27#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
28namespace boost {
29 namespace serialization {
30#else
31namespace STD {
32#endif
33
34 template <class Archive, unsigned size>
35 inline void save(Archive & ar,
36 STD::bitset<size> const & t,
37 const unsigned int version)
38 {
39 std::string bits = t.to_string();
40 ar << BOOST_SERIALIZATION_NVP( bits );
41 }
42
43 template <class Archive, unsigned size>
44 inline void load(Archive & ar,
45 STD::bitset<size> & t,
46 const unsigned int version)
47 {
48 std::string bits;
49 ar >> BOOST_SERIALIZATION_NVP( bits );
50
51 t._Construct( bits, 0, size, '0' );
52 }
53
54 template <class Archive, unsigned size>
55 inline void serialize(Archive & ar,
56 STD::bitset<size> & t,
57 const unsigned int version)
58 {
59 boost::serialization::split_free( ar, t, version );
60 }
61
62#ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
63} // namespace STD
64#else
65 } // namespace serialization
66} // namespace boost
67#endif
68
69#endif // BOOST_SERIALIZATION_BITSET_HPP
70