distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
SignalSet.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_SIGNALSET_HPP_
13 #define INCLUDE_DISTORTOS_SIGNALSET_HPP_
14 
15 #include <bitset>
16 
17 namespace distortos
18 {
19 
28 class SignalSet
29 {
30 public:
31 
33  using Bitset = std::bitset<32>;
34 
36  struct Empty
37  {
38 
39  };
40 
42  struct Full
43  {
44 
45  };
46 
48  constexpr static Empty empty = {};
49 
51  constexpr static Full full = {};
52 
59  constexpr explicit SignalSet(uint32_t bitmask) :
60  bitset_{bitmask}
61  {
62 
63  }
64 
71  constexpr explicit SignalSet(const Bitset& bitset) :
72  bitset_{bitset}
73  {
74 
75  }
76 
85  constexpr explicit SignalSet(const Empty&) :
86  SignalSet{uint32_t{}}
87  {
88 
89  }
90 
99  constexpr explicit SignalSet(const Full&) :
100  SignalSet{~uint32_t{}}
101  {
102 
103  }
104 
116  int add(const uint8_t signalNumber)
117  {
118  return set(signalNumber, true);
119  }
120 
126  {
127  return bitset_;
128  }
129 
141  int remove(const uint8_t signalNumber)
142  {
143  return set(signalNumber, false);
144  }
145 
157  std::pair<int, bool> test(uint8_t signalNumber) const;
158 
159 private:
160 
171  int set(uint8_t signalNumber, bool value);
172 
175 };
176 
177 } // namespace distortos
178 
179 #endif // INCLUDE_DISTORTOS_SIGNALSET_HPP_
tag struct to construct empty SignalSet
Definition: SignalSet.hpp:36
int add(const uint8_t signalNumber)
Sets single bit.
Definition: SignalSet.hpp:116
constexpr SignalSet(uint32_t bitmask)
SignalSet&#39;s constructor.
Definition: SignalSet.hpp:59
constexpr SignalSet(const Full &)
SignalSet&#39;s constructor.
Definition: SignalSet.hpp:99
constexpr SignalSet(const Empty &)
SignalSet&#39;s constructor.
Definition: SignalSet.hpp:85
static constexpr Full full
tag object to construct full SignalSet
Definition: SignalSet.hpp:51
SignalSet class is used as a set of signals.
Definition: SignalSet.hpp:28
std::pair< int, bool > test(uint8_t signalNumber) const
Tests whether the bit is set.
Definition: SignalSet.cpp:31
Top-level namespace of distortos project.
Bitset bitset_
internal bitset for 32 signals
Definition: SignalSet.hpp:174
Bitset getBitset() const
Definition: SignalSet.hpp:125
tag struct to construct full SignalSet
Definition: SignalSet.hpp:42
constexpr SignalSet(const Bitset &bitset)
SignalSet&#39;s constructor.
Definition: SignalSet.hpp:71
std::bitset< 32 > Bitset
type of internal bitset for 32 signals
Definition: SignalSet.hpp:33
static constexpr Empty empty
tag object to construct empty SignalSet
Definition: SignalSet.hpp:48