MeVisLab Toolbox Reference
mlMainExecutor.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2021, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#pragma once
14
17
18#include <mlTypeDefs.h>
19#include <stlab/concurrency/task.hpp>
20
21ML_START_NAMESPACE
22
23//-----------------------------------------------------------------------
28{
29 using result_type = void;
30
31 class MainExecutorMessage final : public BackgroundTaskMessage
32 {
33 stlab::task<void()> _f;
34
35 public:
36 template <typename F>
37 void setTask(F&& f)
38 {
39 _f = std::forward<F>(f);
40 }
41
42 void execute() override
43 {
44 _f();
45 }
46 };
47
48public:
49
52 template <typename F>
53 void operator()(F f) const
54 {
55 auto message = std::make_unique<MainExecutorMessage>();
56 message->setTask(std::move(f));
57 BackgroundTaskManager::self().sendMessageToGUI(message.release());
58 }
59};
60
66constexpr auto MainExecutor = MainExecutorT{};
67
68ML_END_NAMESPACE
@ F
The base class of all background messages.
This class implements an executor that allows you to execute a task in the ML's main loop without imp...
void operator()(F f) const
Submit an function object of type 'void()' that should be executed within the ML's main loop.
constexpr auto MainExecutor
The only necessary instance of this main executor.