CPP-TOOLBOX
Loading...
Searching...
No Matches
temporal_binary_switch.hpp
Go to the documentation of this file.
1#ifndef TEMPORAL_BINARY_SWITCH_HPP
2#define TEMPORAL_BINARY_SWITCH_HPP
3
81 private:
82 bool state = false;
83 bool m_just_switched_on = false;
84 bool m_just_switched_off = false;
85 public:
90
97 void set_true() {
98 if (!state) { // ...v^
99 m_just_switched_on = true;
100 m_just_switched_off = false;
101 } else { // ...^^
102 m_just_switched_on = false;
103 }
104 state = true;
105 }
106
113 void set_false() {
114 if (state) { // ...^v
115 m_just_switched_off = true;
116 m_just_switched_on = false;
117 } else { // ...vv
118 m_just_switched_off = false;
119 }
120 state = false;
121 }
122
129 bool just_switched_on() const { return m_just_switched_on; }
130
137 bool just_switched_off() const { return m_just_switched_off; }
138
139 // NOTE: I don't think the below functions have much use...
140
150 if (m_just_switched_on) {
151 m_just_switched_on = false;
152 return true;
153 }
154 return false;
155 }
156
166 if (m_just_switched_off) {
167 m_just_switched_off = false;
168 return true;
169 }
170 return false;
171 }
172};
173
174#endif // TEMPORAL_BINARY_SWITCH_HPP
bool just_switched_off_temporal()
Checks if the switch has just switched off (temporal).
Definition temporal_binary_switch.hpp:165
bool just_switched_off() const
Checks if the switch has just switched off (non-temporal).
Definition temporal_binary_switch.hpp:137
void set_true()
Sets the switch state to true (on).
Definition temporal_binary_switch.hpp:97
bool just_switched_on() const
Checks if the switch has just switched on (non-temporal).
Definition temporal_binary_switch.hpp:129
void set_false()
Sets the switch state to false (off).
Definition temporal_binary_switch.hpp:113
bool just_switched_on_temporal()
Checks if the switch has just switched on (temporal).
Definition temporal_binary_switch.hpp:149
TemporalBinarySwitch()
Default constructor. Initializes the switch to an off state.
Definition temporal_binary_switch.hpp:89