YAGE  v0.3.1
Yet Another Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
active.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * active.h
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com>
5  * MIT License, see LICENSE file for more details.
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef YAGE_UTIL_ACTIVE_H
10 #define YAGE_UTIL_ACTIVE_H
11 
12 #include "syncqueue.h"
13 
14 #include <functional>
15 #include <memory>
16 #include <thread>
17 
18 namespace yage
19 {
20 
21 class Active
22 {
23 public:
24  typedef std::function<void()> Callback;
25 
26  Active(const Active &) = delete;
27  Active &operator=(const Active &) = delete;
28 
29  ~Active();
30 
31  static std::unique_ptr<Active> create();
32 
33  void send(Callback message);
34 
35 private:
36  Active();
37  void run();
38 
39  bool running_;
41  std::thread thread_;
42 };
43 
44 } // namespace yage
45 
46 #endif
void run()
Definition: active.cpp:36
void send(Callback message)
Definition: active.cpp:31
Definition: active.h:21
std::function< void()> Callback
Definition: active.h:24
Active & operator=(const Active &)=delete
Active()
Definition: active.cpp:14
~Active()
Definition: active.cpp:16
std::thread thread_
Definition: active.h:41
static std::unique_ptr< Active > create()
Definition: active.cpp:22
bool running_
Definition: active.h:39
SyncQueue< Callback > queue_
Definition: active.h:40