OpenZWave Library  1.6.913
Bitfield.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Bitfield.h
4 //
5 // Variable length bitfield implementation
6 //
7 // Copyright (c) 2011 Mal Lansell <openzwave@lansell.org>
8 //
9 // SOFTWARE NOTICE AND LICENSE
10 //
11 // This file is part of OpenZWave.
12 //
13 // OpenZWave is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU Lesser General Public License as published
15 // by the Free Software Foundation, either version 3 of the License,
16 // or (at your option) any later version.
17 //
18 // OpenZWave is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public License
24 // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25 //
26 //-----------------------------------------------------------------------------
27 
28 #ifndef _Bitfield_H
29 #define _Bitfield_H
30 
31 #include <vector>
32 #include "Defs.h"
33 
34 namespace OpenZWave
35 {
36  namespace Internal
37  {
38 
40  {
41  friend class Iterator;
42 
43  public:
44  Bitfield();
45  Bitfield(uint32 value);
46  ~Bitfield();
47  bool Set(uint8 _idx);
48  bool Clear(uint8 _idx);
49  bool IsSet(uint8 _idx) const;
50  uint32 GetNumSetBits() const;
51  uint32 GetValue() const;
52  bool SetValue(uint32 val);
53  uint32 GetSize() const;
54  class Iterator
55  {
56  friend class Bitfield;
57 
58  public:
59  uint32 operator *() const;
60  Iterator& operator++();
61  Iterator operator++(int);
62 
63  bool operator ==(const Iterator &rhs);
64  bool operator !=(const Iterator &rhs);
65  private:
66  Iterator(Bitfield const* _bitfield, uint32 _idx);
67 
68  void NextSetBit();
69 
70  uint32 m_idx;
71  Bitfield const* m_bitfield;
72  };
73 
74  Iterator Begin() const;
75  Iterator End() const;
76 
77  private:
79  vector<uint32> m_bits;OPENZWAVE_EXPORT_WARNINGS_ON
80  uint32 m_numSetBits;
81  uint32 m_value;
82  };
83  } // namespace OpenZWave
84 } // namespace OpenZWave
85 
86 #endif
87 
Definition: Bitfield.cpp:30
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:53
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:52
unsigned int uint32
Definition: Defs.h:92
Definition: Bitfield.h:39
unsigned char uint8
Definition: Defs.h:86