distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
DynamicSoftwareTimer.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_DYNAMICSOFTWARETIMER_HPP_
13 #define INCLUDE_DISTORTOS_DYNAMICSOFTWARETIMER_HPP_
14 
16 
17 #include <functional>
18 
19 namespace distortos
20 {
21 
24 
31 {
32 public:
33 
44  template<typename Function, typename... Args>
45  DynamicSoftwareTimer(Function&& function, Args&&... args);
46 
47 private:
48 
55  void run() override;
56 
58  std::function<void()> boundFunction_;
59 };
60 
73 template<typename Function, typename... Args>
74 DynamicSoftwareTimer makeDynamicSoftwareTimer(Function&& function, Args&&... args)
75 {
76  return {std::forward<Function>(function), std::forward<Args>(args)...};
77 }
78 
80 
81 template<typename Function, typename... Args>
82 DynamicSoftwareTimer::DynamicSoftwareTimer(Function&& function, Args&&... args) :
84  boundFunction_{std::bind(std::forward<Function>(function), std::forward<Args>(args)...)}
85 {
86 
87 }
88 
89 } // namespace distortos
90 
91 #endif // INCLUDE_DISTORTOS_DYNAMICSOFTWARETIMER_HPP_
DynamicSoftwareTimer makeDynamicSoftwareTimer(Function &&function, Args &&... args)
Helper factory function to make DynamicSoftwareTimer object.
Definition: DynamicSoftwareTimer.hpp:74
std::function< void()> boundFunction_
bound function object
Definition: DynamicSoftwareTimer.hpp:58
DynamicSoftwareTimer class is a type-erased interface for software timer that has dynamic storage for...
Definition: DynamicSoftwareTimer.hpp:30
void run() override
"Run" function of software timer
Definition: DynamicSoftwareTimer.cpp:21
DynamicSoftwareTimer(Function &&function, Args &&... args)
DynamicSoftwareTimer's constructor.
Definition: DynamicSoftwareTimer.hpp:82
Top-level namespace of distortos project.
Definition: buttons.hpp:33
SoftwareTimerCommon class header.
SoftwareTimerCommon class implements common functionality of software timers.
Definition: SoftwareTimerCommon.hpp:28