Remote Call Framework 3.0
bitset.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2018, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 3.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_SF_BITSET_HPP
20 #define INCLUDE_SF_BITSET_HPP
21 
22 #include <bitset>
23 
24 #include <RCF/Export.hpp>
25 #include <RCF/Tools.hpp>
26 
27 namespace SF {
28 
29  class Archive;
30 
31  class I_BitsetWrapper
32  {
33  public:
34  virtual std::size_t size() = 0;
35  virtual void resize(std::size_t newSize) = 0;
36  virtual void setBit(std::size_t idx, bool newValue) = 0;
37  virtual bool getBit(std::size_t idx) = 0;
38  };
39 
40  template<std::size_t N>
41  class BitsetWrapper : public I_BitsetWrapper
42  {
43  public:
44  BitsetWrapper(std::bitset<N> & bits) : mBits(bits)
45  {
46  }
47 
48  virtual std::size_t size()
49  {
50  return mBits.size();
51  }
52 
53  virtual void resize(std::size_t newSize)
54  {
55  RCF_ASSERT(newSize == N);
56  }
57 
58  virtual void setBit(std::size_t idx, bool newValue)
59  {
60  mBits[idx] = newValue;
61  }
62 
63  virtual bool getBit(std::size_t idx)
64  {
65  return mBits[idx];
66  }
67 
68  private:
69 
70  std::bitset<N> & mBits;
71  };
72 
73  RCF_EXPORT void serializeBitset(SF::Archive & ar, I_BitsetWrapper & bits);
74 
75  template<std::size_t N>
76  void serialize(SF::Archive & ar, std::bitset<N> & bits)
77  {
78  BitsetWrapper<N> wrapper(bits);
79  serializeBitset(ar, wrapper);
80  }
81 
82 }
83 
84 #endif // ! INCLUDE_SF_BITSET_HPP
Represents an archive, in which serialized objects are stored.
Definition: Archive.hpp:32
Definition: ByteBuffer.hpp:189