Leviathan  0.8.0.0
Leviathan game engine
Leviathan::QueuedTask Class Reference

Encapsulates a function that can later be ran in a free thread. More...

#include <QueuedTask.h>

+ Inheritance diagram for Leviathan::QueuedTask:

Public Member Functions

DLLEXPORT QueuedTask (std::function< void()> functorun)
 Takes in the function which is ran when the Task is ran. More...
 
virtual DLLEXPORT ~QueuedTask ()
 
virtual DLLEXPORT void RunTask ()
 Runs the stored function. More...
 
virtual DLLEXPORT bool CanBeRan (const QueuedTaskCheckValues *const checkvalues)
 Function called by ThreadingManager before running this task. More...
 
virtual DLLEXPORT bool MustBeRanBefore (int eventtypeidentifier)
 Function called by ThreadingManager before certain events to make proper tasks finish before certain operations. More...
 
virtual DLLEXPORT bool IsRepeating ()
 Function called by ThreadingManager AFTER running the task //. More...
 

Detailed Description

Encapsulates a function that can later be ran in a free thread.

Warning
Function passed to this class should be thread safe
This is not explicitly thread safe, it might be through std::Thread

Definition at line 34 of file QueuedTask.h.

Constructor & Destructor Documentation

◆ QueuedTask()

DLLEXPORT Leviathan::QueuedTask::QueuedTask ( std::function< void()>  functorun)

Takes in the function which is ran when the Task is ran.

Definition at line 6 of file QueuedTask.cpp.

6  :
7  FunctionToRun(functorun)
8 {
9 
10 }

◆ ~QueuedTask()

DLLEXPORT Leviathan::QueuedTask::~QueuedTask ( )
virtual

Definition at line 12 of file QueuedTask.cpp.

12  {
13 
14 }

Member Function Documentation

◆ CanBeRan()

DLLEXPORT bool Leviathan::QueuedTask::CanBeRan ( const QueuedTaskCheckValues *const  checkvalues)
virtual

Function called by ThreadingManager before running this task.

Returns
By default returns always true, but child classes can perform various checks before returning

Reimplemented in Leviathan::RepeatCountedDelayedTask, Leviathan::DelayedTask, Leviathan::ConditionalDelayedTask, and Leviathan::ConditionalTask.

Definition at line 33 of file QueuedTask.cpp.

33  {
34  return true;
35 }

◆ IsRepeating()

DLLEXPORT bool Leviathan::QueuedTask::IsRepeating ( )
virtual

Function called by ThreadingManager AFTER running the task //.

Returns
By default returns always false (so will be removed from queue), but child classes can perform various checks or an internal state which holds information about repeating the task, such as repeat x times or repeat until success etc.
Note
This is guaranteed to be called only once per execution so this can be used to implement an execution times monitor

Reimplemented in Leviathan::RepeatCountedTask, and Leviathan::RepeatingDelayedTask.

Definition at line 41 of file QueuedTask.cpp.

41  {
42  return false;
43 }

◆ MustBeRanBefore()

DLLEXPORT bool Leviathan::QueuedTask::MustBeRanBefore ( int  eventtypeidentifier)
virtual

Function called by ThreadingManager before certain events to make proper tasks finish before certain operations.

Returns
By default returns true when passed TASK_MUSTBERAN_BEFORE_EXIT, but child classes can store internal variables to match only certain types

Definition at line 37 of file QueuedTask.cpp.

37  {
38  return eventtypeidentifier == TASK_MUSTBERAN_BEFORE_EXIT;
39 }
#define TASK_MUSTBERAN_BEFORE_EXIT
Default value to pass for ignoring this setting //.
Definition: QueuedTask.h:9

◆ RunTask()

DLLEXPORT void Leviathan::QueuedTask::RunTask ( )
virtual

Runs the stored function.

Definition at line 16 of file QueuedTask.cpp.

16  {
17  // Run the function //
18  _PreFunctionRun();
19 
20  FunctionToRun();
21 
22  _PostFunctionRun();
23 }

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