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:37
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
Helper class which provides the Collimation Length for SANS instruments.
STL namespace.