Public Member Functions | List of all members
SingleTimeExecutor Class Reference

Executes the supplied code block a single time. More...

#include <SingleTimeExecutor.hpp>

Public Member Functions

 SingleTimeExecutor (std::function< void()> code_)
 Create a single time executor with a code block. More...
 
 SingleTimeExecutor (std::function< void()> code_, std::function< void()> destructorCode_)
 Create a single time executor with a code block and a destructor code block. More...
 
 ~SingleTimeExecutor ()
 Destroy the single time executor. More...
 
std::mutex & getMutex ()
 Get the internal mutex in order to synchronise on external code. More...
 
bool hasExecuted () const
 Returns true if the code has been executed. More...
 
void operator() ()
 Execute the code a single time. More...
 

Detailed Description

Executes the supplied code block a single time.

Optionally register a code block to run in the destructor, only if the execution has happened.

Constructor & Destructor Documentation

◆ SingleTimeExecutor() [1/2]

SingleTimeExecutor ( std::function< void()>  code_)
inlineexplicit

Create a single time executor with a code block.

◆ SingleTimeExecutor() [2/2]

SingleTimeExecutor ( std::function< void()>  code_,
std::function< void()>  destructorCode_ 
)
inline

Create a single time executor with a code block and a destructor code block.

The executor will execute the first supplied code block a single time and will execute the second supplied code block if the first had already been executed at the time of destruction.

◆ ~SingleTimeExecutor()

~SingleTimeExecutor ( )
inline

Destroy the single time executor.

Member Function Documentation

◆ getMutex()

std::mutex& getMutex ( )
inline

Get the internal mutex in order to synchronise on external code.

Use with care.

◆ hasExecuted()

bool hasExecuted ( ) const
inline

Returns true if the code has been executed.

If the operator () is being concurrently run in other threads whilst this method is called, this method will not necessarily reflect any objective reality to whether the code has been run at the time of the call. This method should thus only be used when there is no possibility of the operator () being run in other threads, otherwise it will return a meaningless result.

◆ operator()()

void operator() ( )
inline

Execute the code a single time.


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