libtasks Documentation  1.6
exec_task.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #ifndef _TASKS_EXEC_TASK_H_
9 #define _TASKS_EXEC_TASK_H_
10 
11 #include <tasks/task.h>
12 #include <tasks/logging.h>
13 #include <functional>
14 #include <sstream>
15 
16 namespace tasks {
17 
18 class exec_task : public task {
19  public:
20  typedef std::function<void()> func_t;
21 
22  exec_task(func_t f) : m_func(f) {}
23  virtual ~exec_task() {}
24 
25  inline std::string get_string() const {
26  std::ostringstream os;
27  os << "exec_task(" << this << ")";
28  return os.str();
29  }
30 
31  virtual void execute() {
32  tdbg(get_string() << ": executing m_func" << std::endl);
33  m_func();
34  }
35 
36  private:
38 };
39 
40 } // tasks
41 
42 #endif // _TASKS_EXEC_TASK_H_
The base class for any task.
Definition: task.h:19
std::string get_string() const
Definition: exec_task.h:25
#define tdbg(m)
Definition: logging.h:54
virtual void execute()
Definition: exec_task.h:31
virtual ~exec_task()
Definition: exec_task.h:23
std::function< void()> func_t
Definition: exec_task.h:20
exec_task(func_t f)
Definition: exec_task.h:22