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/DllConfig.h"
10#include "MantidKernel/Task.h"
11#include <functional>
12#include <stdexcept>
13
14#ifndef Q_MOC_RUN
15#include <boost/function.hpp>
16#include <utility>
17
18#endif
19
20namespace Mantid {
21
22namespace Kernel {
23
24//==============================================================================================
32class FunctionTask final : public Task {
33public:
35 using voidFunction = void (*)();
36 //---------------------------------------------------------------------------------------------
49 FunctionTask(voidFunction func, double cost = 1.0) : Task(cost), m_voidFunc(func) {}
50
51 //---------------------------------------------------------------------------------------------
64 FunctionTask(std::function<void()> func, double cost = 1.0) : Task(cost), m_voidFunc(std::move(func)) {}
65
66 //---------------------------------------------------------------------------------------------
68 void run() override {
69 if (m_voidFunc)
70 m_voidFunc();
71 else
72 throw std::runtime_error("FunctionTask: NULL method pointer provided.");
73 }
74
75protected:
76 std::function<void()> m_voidFunc;
77};
78
79} // namespace Kernel
80} // namespace Mantid
A FunctionTask can easily create a Task from a method pointer.
void(*)() voidFunction
Typedef for a function with no arguments and no return.
FunctionTask(std::function< void()> func, double cost=1.0)
Constructor for a simple boost bound function.
FunctionTask(voidFunction func, double cost=1.0)
Constructor for a simple void function.
void run() override
Main method that performs the work for the task.
std::function< void()> m_voidFunc
A Task is a unit of work to be scheduled and run by a ThreadPool.
Definition Task.h:29
virtual double cost()
What is the computational cost of this task?
Definition Task.h:53
Helper class which provides the Collimation Length for SANS instruments.
STL namespace.