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