Mantid
Loading...
Searching...
No Matches
FunctionTask.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include "MantidKernel/Task.h"
10#include <functional>
11#include <stdexcept>
12
13#ifndef Q_MOC_RUN
14#include <boost/function.hpp>
15#include <utility>
16
17#endif
18
19namespace Mantid {
20
21namespace Kernel {
22
23//==============================================================================================
31class DLLExport FunctionTask final : public Task {
32public:
34 using voidFunction = void (*)();
35 //---------------------------------------------------------------------------------------------
48 FunctionTask(voidFunction func, double cost = 1.0) : Task(cost), m_voidFunc(func) {}
49
50 //---------------------------------------------------------------------------------------------
63 FunctionTask(std::function<void()> func, double cost = 1.0) : Task(cost), m_voidFunc(std::move(func)) {}
64
65 //---------------------------------------------------------------------------------------------
67 void run() override {
68 if (m_voidFunc)
69 m_voidFunc();
70 else
71 throw std::runtime_error("FunctionTask: NULL method pointer provided.");
72 }
73
74protected:
75 std::function<void()> m_voidFunc;
76};
77
78} // namespace Kernel
79} // namespace Mantid
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
A FunctionTask can easily create a Task from a method pointer.
Definition: FunctionTask.h:31
void(*)() voidFunction
Typedef for a function with no arguments and no return.
Definition: FunctionTask.h:34
FunctionTask(std::function< void()> func, double cost=1.0)
Constructor for a simple boost bound function.
Definition: FunctionTask.h:63
FunctionTask(voidFunction func, double cost=1.0)
Constructor for a simple void function.
Definition: FunctionTask.h:48
void run() override
Main method that performs the work for the task.
Definition: FunctionTask.h:67
std::function< void()> m_voidFunc
Definition: FunctionTask.h:75
A Task is a unit of work to be scheduled and run by a ThreadPool.
Definition: Task.h:29
Helper class which provides the Collimation Length for SANS instruments.
STL namespace.