1 // -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi:tw=80:et:ts=2:sts=2
3 //
4 // -----------------------------------------------------------------------
5 //
6 // This file is part of RLVM, a RealLive virtual machine clone.
7 //
8 // -----------------------------------------------------------------------
9 //
10 // Copyright (C) 2008 Elliot Glaysher
11 //
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
25 // -----------------------------------------------------------------------
26 
27 #ifndef SRC_UTILITIES_DYNAMIC_BITSET_SERIALIZE_H_
28 #define SRC_UTILITIES_DYNAMIC_BITSET_SERIALIZE_H_
29 
30 // boost::serialization doesn't come with built in support for
31 // serializing dynamic_bitset, so write our own version.
32 //
33 // This implementation is in no way optimal, but is meant to be
34 // portable. This representation isn't that bad once you think about
35 // how the data is going to be pumped through gzip.
36 
37 #include <boost/dynamic_bitset.hpp>
38 #include <boost/serialization/split_free.hpp>
39 #include <boost/serialization/string.hpp>
40 
41 #include <ostream>
42 #include <string>
43 
44 namespace boost {
45 namespace serialization {
46 
47 template <class Archive, class Block, class Allocator>
save(Archive & ar,const boost::dynamic_bitset<Block,Allocator> & bs,const unsigned int)48 inline void save(Archive& ar,
49                  const boost::dynamic_bitset<Block, Allocator>& bs,
50                  const unsigned int /* file_version */) {
51   std::string text_representation;
52   boost::to_string(bs, text_representation);
53   ar& text_representation;
54 }
55 
56 template <class Archive, class Block, class Allocator>
load(Archive & ar,boost::dynamic_bitset<Block,Allocator> & bs,const unsigned int)57 inline void load(Archive& ar,
58                  boost::dynamic_bitset<Block, Allocator>& bs,
59                  const unsigned int /* file_version */) {
60   std::string text_representation;
61   ar& text_representation;
62   bs = boost::dynamic_bitset<Block, Allocator>(text_representation);
63 }
64 
65 // split non-intrusive serialization function member into separate
66 // non intrusive save/load member functions
67 template <class Archive, class Block, class Allocator>
serialize(Archive & ar,boost::dynamic_bitset<Block,Allocator> & bs,const unsigned int file_version)68 inline void serialize(Archive& ar,
69                       boost::dynamic_bitset<Block, Allocator>& bs,
70                       const unsigned int file_version) {
71   boost::serialization::split_free(ar, bs, file_version);
72 }
73 
74 }  // namespace serialization
75 }  // namespace boost
76 
77 #endif  // SRC_UTILITIES_DYNAMIC_BITSET_SERIALIZE_H_
78