PVData C++  8.0.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bitSet.h
1 /* bitSet.h */
2 /*
3  * Copyright information and license terms for this software can be
4  * found in the file LICENSE that is included with the distribution
5  */
9 #ifndef BITSET_H
10 #define BITSET_H
11 
12 #if __cplusplus>=201103L
13 # include <initializer_list>
14 #endif
15 
16 #include <vector>
17 
18 #include <pv/pvType.h>
19 #include <pv/serialize.h>
20 #include <pv/sharedPtr.h>
21 
22 #include <shareLib.h>
23 
24 namespace epics { namespace pvData {
25 
26  class BitSet;
27  typedef std::tr1::shared_ptr<BitSet> BitSetPtr;
28 
56  class epicsShareClass BitSet : public Serializable {
57  public:
58  POINTER_DEFINITIONS(BitSet);
59  static BitSetPtr create(uint32 nbits);
63  BitSet();
64 
72  BitSet(uint32 nbits);
73 
74 #if __cplusplus>=201103L
75 
82 #endif
83 
87  virtual ~BitSet();
88 
95  BitSet& flip(uint32 bitIndex);
96 
102  BitSet& set(uint32 bitIndex);
103 
109  BitSet& clear(uint32 bitIndex);
110 
117  void set(uint32 bitIndex, bool value);
118 
127  bool get(uint32 bitIndex) const;
128 
132  void clear();
133 
151  int32 nextSetBit(uint32 fromIndex) const;
152 
160  int32 nextClearBit(uint32 fromIndex) const;
161 
168  bool isEmpty() const;
169 
175  uint32 cardinality() const;
176 
184  uint32 size() const;
185 
187  bool logical_and(const BitSet& other) const;
189  bool logical_or(const BitSet& other) const;
190 
200  BitSet& operator&=(const BitSet& set);
201 
211  BitSet& operator|=(const BitSet& set);
212 
227  BitSet& operator^=(const BitSet& set);
228 
232  BitSet& operator=(const BitSet &set);
233 
235  void swap(BitSet& set);
236 
243  void or_and(const BitSet& set1, const BitSet& set2);
244 
248  bool operator==(const BitSet &set) const;
249 
250  bool operator!=(const BitSet &set) const;
251 
252  virtual void serialize(ByteBuffer *buffer,
253  SerializableControl *flusher) const;
254  virtual void deserialize(ByteBuffer *buffer,
255  DeserializableControl *flusher);
256 
257  private:
258 
261  words_t words;
262 
263  private:
269  void recalculateWordsInUse();
270 
275  void ensureCapacity(uint32 wordsRequired);
276 
284  void expandTo(uint32 wordIndex);
285 
298  static uint32 numberOfTrailingZeros(uint64 i);
299 
308  static uint32 bitCount(uint64 i);
309 
310  };
311 
312  epicsShareExtern std::ostream& operator<<(std::ostream& o, const BitSet& b);
313 
314 }}
315 #endif /* BITSET_H */
316 
317 
318 
basic_ostream< _CharT, _Traits > & operator<<(basic_ostream< _CharT, _Traits > &__os, const basic_string< _CharT, _Traits, _Alloc > &__str)
valarray< size_t > size() const
uint32_t uint32
Definition: pvType.h:99
T swap(T val)
Definition: byteBuffer.h:212
Callback class for serialization.
Definition: serialize.h:42
constexpr complex< _Tp > & operator=(const _Tp &)
valarray< _Tp > & operator&=(const _Tp &)
valarray< _Tp > & operator|=(const _Tp &)
This class implements a Bytebuffer that is like the java.nio.ByteBuffer.
Definition: byteBuffer.h:236
bool operator==(const _CharT *__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
int32_t int32
Definition: pvType.h:83
Callback class for deserialization.
Definition: serialize.h:93
bool operator!=(const _CharT *__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
valarray< _Tp > & operator^=(const _Tp &)
Base class for serialization.
Definition: serialize.h:138
A vector of bits.
Definition: bitSet.h:56
uint64_t uint64
Definition: pvType.h:103