-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttonCached.hpp
More file actions
58 lines (46 loc) · 1.33 KB
/
Copy pathbuttonCached.hpp
File metadata and controls
58 lines (46 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef DYNAMIC_BUTTON_CACHED_HPP
#define DYNAMIC_BUTTON_CACHED_HPP
// ----------------------------------------------------------------------------------------------------
/**
* @brief The ButtonCache class monitors an actual button and provides state-change information.
* Button will have to provide the following member function:
* - bool isDown(),
* - initialization [if any] in Button(args...),
* - deinitialization [if any] in ~Button().
*/
template <typename Button, typename... Args>
class ButtonCached : public Button
{
public:
ButtonCached(Args... args)
: Button(args...)
, isDown_(Button::isDown())
{
}
/**
* @brief Updates the internal cache value with the current state of Button.
* If this is not called often enough, intermediate states will be lost.
*/
void update()
{
isDown_ = Button::isDown();
}
/**
* @brief isDown - button was pressed down during last update().
*/
bool isDown() const
{
return isDown_;
}
/**
* @brief isDown - button was not pressed down during last update().
*/
bool isUp() const
{
return !isDown();
}
private:
bool isDown_;
};
// ----------------------------------------------------------------------------------------------------
#endif // DYNAMIC_BUTTON_CACHED_HPP