libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Timer.hpp
Go to the documentation of this file.
1 #ifndef TIMER_HPP
2 #define TIMER_HPP
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include <functional>
22 #include <map>
23 #include <list>
24 #include <iostream>
25 
26 namespace AlgAudio{
27 
28 
29 struct TimerHandle{
30 public:
31  friend class Timer;
34  void Release();
35 
37  TimerHandle(TimerHandle&& other);
40 
41  TimerHandle& operator=(const TimerHandle&) = delete; // No copying.
42  TimerHandle(const TimerHandle&) = delete; // No copying.
43  TimerHandle() : id(-1) {}
44 private:
45  TimerHandle(int i) : id(i) {}
46  int id;
47 };
48 
49 
52 class Timer{
53 public:
60  static TimerHandle Schedule(float seconds, std::function<void()> f);
61 
64  static void Trigger(void* param);
65 
66 private:
67  static int counter;
68 };
69 
72 public:
73  TimerHandleList(const TimerHandleList& other) = delete;
74  std::list<TimerHandle> list;
75  void ReleaseAll() {
76  for(auto& th : list) th.Release();
77  list.clear();
78  }
80  list.push_back(std::move(s));
81  return *this;
82  }
83  TimerHandleList() : list(0){}
85 };
86 
98 public:
100 };
101 
102 } // namespace AlgAudio
103 
104 #endif // TIMER_HPP
TimerHandle()
Definition: Timer.hpp:43
static void Trigger(void *param)
std::list< TimerHandle > list
Definition: Timer.hpp:74
Definition: Timer.hpp:52
Definition: Timer.hpp:71
TimerHandleList & operator+=(TimerHandle &&s)
Definition: Timer.hpp:79
void ReleaseAll()
Definition: Timer.hpp:75
TimerHandleList timerhandles
Definition: Timer.hpp:99
Definition: Timer.hpp:97
~TimerHandleList()
Definition: Timer.hpp:84
Definition: Timer.hpp:29
Definition: Alertable.hpp:26
TimerHandleList()
Definition: Timer.hpp:83
static TimerHandle Schedule(float seconds, std::function< void()> f)
TimerHandle & operator=(TimerHandle &&other)