UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
task.h
Go to the documentation of this file.
1 #ifndef UGDK_SYSTEM_TASK_H_
2 #define UGDK_SYSTEM_TASK_H_
3 
4 #include <functional>
5 
6 namespace ugdk {
7 namespace system {
8 
9 class Task {
10 public:
14  template<typename Callable>
15  Task(Callable c, double priotity = 0.5) : priority_(priotity) {
16  CallableAdapter<decltype(c(0.0))>::Set(function_, c);
17  }
18  ~Task() {}
19 
20  double priority() const { return priority_; }
21  bool operator()(double dt) {
22  return function_(dt);
23  }
24  bool operator<(const Task& other) const {
25  return priority_ < other.priority_;
26  }
27 
28 private:
29  template<typename Ret>
30  struct CallableAdapter {
31  template<typename Callable>
32  static void Set(std::function<bool (double)>& function, Callable c) {
33  function = c;
34  }
35  };
36 
37  double priority_;
38  std::function<bool (double)> function_;
39 };
40 
41 template<>
42 struct Task::CallableAdapter<void> {
43  template<typename Callable>
44  static void Set(std::function<bool (double)>& function, Callable c) {
45  function = [c](double dt) {
46  c(dt);
47  return true;
48  };
49  }
50 };
51 
52 } // namespace action */
53 } // namespace ugdk */
54 
55 #endif /* UGDK_SYSTEM_TASKPLAYER_H_ */
bool operator()(double dt)
Definition: task.h:21
~Task()
Definition: task.h:18
Definition: animation.h:11
Definition: task.h:9
Task(Callable c, double priotity=0.5)
Definition: task.h:15
bool operator<(const Task &other) const
Definition: task.h:24
static void Set(std::function< bool(double)> &function, Callable c)
Definition: task.h:44
double priority() const
Definition: task.h:20