Mantid
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
Mantid::Kernel::FunctionTask Class Referencefinal

A FunctionTask can easily create a Task from a method pointer. More...

#include <FunctionTask.h>

Inheritance diagram for Mantid::Kernel::FunctionTask:
Mantid::Kernel::Task

Public Types

using voidFunction = void(*)()
 Typedef for a function with no arguments and no return. More...
 

Public Member Functions

 FunctionTask (std::function< void()> func, double cost=1.0)
 Constructor for a simple boost bound function. More...
 
 FunctionTask (voidFunction func, double cost=1.0)
 Constructor for a simple void function. More...
 
void run () override
 Main method that performs the work for the task. More...
 
- Public Member Functions inherited from Mantid::Kernel::Task
virtual double cost ()
 What is the computational cost of this task? More...
 
std::shared_ptr< std::mutex > getMutex ()
 Get the mutex object for this Task. More...
 
virtual void run ()=0
 Main method that performs the work for the task. More...
 
void setMutex (const std::shared_ptr< std::mutex > &mutex)
 Set the mutex object for this Task. More...
 
void setMutexObject (void *object)
 Use an arbitrary pointer to lock (mutex) the execution of this task. More...
 
 Task ()
 Default constructor. More...
 
 Task (double cost)
 Constructor with cost. More...
 
virtual ~Task ()=default
 Destructor. More...
 

Protected Attributes

std::function< void()> m_voidFunc
 
- Protected Attributes inherited from Mantid::Kernel::Task
double m_cost
 Cached computational cost for the thread. More...
 
std::shared_ptr< std::mutex > m_mutex
 Mutex associated with this task (can be NULL) More...
 

Detailed Description

A FunctionTask can easily create a Task from a method pointer.

The FunctionTask will simply run the provided method.

Author
Janik Zikovsky, SNS
Date
Feb 8, 2011

Definition at line 31 of file FunctionTask.h.

Member Typedef Documentation

◆ voidFunction

Typedef for a function with no arguments and no return.

Definition at line 34 of file FunctionTask.h.

Constructor & Destructor Documentation

◆ FunctionTask() [1/2]

Mantid::Kernel::FunctionTask::FunctionTask ( voidFunction  func,
double  cost = 1.0 
)
inline

Constructor for a simple void function.

Pro-tip: use std::bind(f, argument1, argument2) (for example) to turn a function that takes an argument into a argument-less function pointer.

Use std::bind(&ClassName::function, &*this, arg1, arg2) to bind to a class method of this.

Parameters
func:: pointer to a void function()
cost:: computational cost

Definition at line 48 of file FunctionTask.h.

◆ FunctionTask() [2/2]

Mantid::Kernel::FunctionTask::FunctionTask ( std::function< void()>  func,
double  cost = 1.0 
)
inline

Constructor for a simple boost bound function.

Pro-tip: use std::bind(f, argument1, argument2) (for example) to turn a function that takes an argument into a argument-less function pointer.

Use std::bind(&ClassName::function, &*this, arg1, arg2) to bind to a class method of this.

Parameters
func:: std::function<> returned by std::bind()
cost:: computational cost

Definition at line 63 of file FunctionTask.h.

Member Function Documentation

◆ run()

void Mantid::Kernel::FunctionTask::run ( )
inlineoverridevirtual

Main method that performs the work for the task.

Implements Mantid::Kernel::Task.

Definition at line 67 of file FunctionTask.h.

Member Data Documentation

◆ m_voidFunc

std::function<void()> Mantid::Kernel::FunctionTask::m_voidFunc
protected

Definition at line 75 of file FunctionTask.h.


The documentation for this class was generated from the following file: