You.i Engine
CYIStaticTask< ResultType > Class Template Reference

Detailed Description

template<typename ResultType = void>
class CYIStaticTask< ResultType >

An utility class used to create a task from a static function.

The provided static function can be either a 'raw' static function, or a static member function of a given class.

Between 0 and 4 function parameters can be used with this class. A copy of the function parameter values is stored within the CYIStaticTask object.

The return type of the static function must match the templated type of the static task. Void functions are supported (use a CYIStaticTask<> when creating the static task).

Note
When passing function parameters to the Static Task constructor, it is important to use exact types. Template type inference (e.g. int32_t to int64_t or "foo" to CYIString("foo")) does not always work and sometimes requires specific casting or construction.
Warning
Passing raw pointers to tasks is not recommended as ownership of the raw pointer and lifetime of the pointed-to memory is difficult to manage.

Sample usage:

CYITask<CYIString> *pMyTask = new CYIStaticTask(myFutureObj, &MyClass::MyStaticFunction, 42, CYIString("foo"));
Template Parameters
ResultTypethe return type of the static function.
See also
CYITask<ResultType>

#include <thread/YiStaticTask.h>

Inheritance diagram for CYIStaticTask< ResultType >:

Public Member Functions

 CYIStaticTask (CYIFuture< ResultType > &rFuture, ResultType(*const pFunc)())
 
template<typename P1 >
 CYIStaticTask (CYIFuture< ResultType > &rFuture, ResultType(*const pFunc)(P1), P1 const &funcParam1)
 
template<typename P1 , typename P2 >
 CYIStaticTask (CYIFuture< ResultType > &rFuture, ResultType(*const pFunc)(P1, P2), P1 const &funcParam1, P2 const &funcParam2)
 
template<typename P1 , typename P2 , typename P3 >
 CYIStaticTask (CYIFuture< ResultType > &rFuture, ResultType(*const pFunc)(P1, P2, P3), P1 const &funcParam1, P2 const &funcParam2, P3 const &funcParam3)
 
template<typename P1 , typename P2 , typename P3 , typename P4 >
 CYIStaticTask (CYIFuture< ResultType > &rFuture, ResultType(*const pFunc)(P1, P2, P3, P4), P1 const &funcParam1, P2 const &funcParam2, P3 const &funcParam3, P4 const &funcParam4)
 
 CYIStaticTask (std::unique_ptr< CYIFuture< ResultType >> pFuture, ResultType(*const pFunc)())
 
template<typename P1 >
 CYIStaticTask (std::unique_ptr< CYIFuture< ResultType >> pFuture, ResultType(*const pFunc)(P1), P1 const &funcParam1)
 
template<typename P1 , typename P2 >
 CYIStaticTask (std::unique_ptr< CYIFuture< ResultType >> pFuture, ResultType(*const pFunc)(P1, P2), P1 const &funcParam1, P2 const &funcParam2)
 
template<typename P1 , typename P2 , typename P3 >
 CYIStaticTask (std::unique_ptr< CYIFuture< ResultType >> pFuture, ResultType(*const pFunc)(P1, P2, P3), P1 const &funcParam1, P2 const &funcParam2, P3 const &funcParam3)
 
template<typename P1 , typename P2 , typename P3 , typename P4 >
 CYIStaticTask (std::unique_ptr< CYIFuture< ResultType >> pFuture, ResultType(*const pFunc)(P1, P2, P3, P4), P1 const &funcParam1, P2 const &funcParam2, P3 const &funcParam3, P4 const &funcParam4)
 
 CYIStaticTask (ResultType(*const pFunc)())
 
template<typename P1 >
 CYIStaticTask (ResultType(*const pFunc)(P1), P1 const &funcParam1)
 
template<typename P1 , typename P2 >
 CYIStaticTask (ResultType(*const pFunc)(P1, P2), P1 const &funcParam1, P2 const &funcParam2)
 
template<typename P1 , typename P2 , typename P3 >
 CYIStaticTask (ResultType(*const pFunc)(P1, P2, P3), P1 const &funcParam1, P2 const &funcParam2, P3 const &funcParam3)
 
template<typename P1 , typename P2 , typename P3 , typename P4 >
 CYIStaticTask (ResultType(*const pFunc)(P1, P2, P3, P4), P1 const &funcParam1, P2 const &funcParam2, P3 const &funcParam3, P4 const &funcParam4)
 
virtual ~CYIStaticTask ()
 
- Public Member Functions inherited from CYITask< ResultType >
 CYITask ()
 
 CYITask (CYIFuture< ResultType > &rFuture)
 
 CYITask (std::unique_ptr< CYIFuture< ResultType >> pFuture)
 
virtual ~CYITask ()
 
bool SetFuture (CYIFuture< ResultType > &rFuture)
 
bool SetFuture (std::unique_ptr< CYIFuture< ResultType >> rFuture)
 
- Public Member Functions inherited from CYITaskBase
virtual ~CYITaskBase ()
 
virtual bool TakeOwnershipOfFuture (std::unique_ptr< CYIAbstractFuture > pFuture)
 
TASK_STATE GetState () const
 
bool IsFutureOwner () const
 
bool MarkPendingExecution ()
 
void RequestCancellation ()
 
bool Execute ()
 

Protected Member Functions

virtual ResultType Run () override
 
- Protected Member Functions inherited from CYITaskBase
bool IsCancellationRequested () const
 
void SetCancellationRequestSucceeded ()
 
virtual void CleanUpAfterCancellation ()
 

Additional Inherited Members

- Public Types inherited from CYITaskBase
enum  TASK_STATE {
  TASK_NEW,
  TASK_PENDING_EXECUTION,
  TASK_EXECUTING,
  TASK_COMPLETED,
  TASK_CANCELLED
}
 
- Protected Attributes inherited from CYITaskBase
CYIMutex m_mutex
 

Constructor & Destructor Documentation

template<typename ResultType = void>
CYIStaticTask< ResultType >::CYIStaticTask ( CYIFuture< ResultType > &  rFuture,
ResultType(*)()  pFunc 
)

Creates a task from pFunc, which is a static function. Creates an association with rFuture.

template<typename ResultType = void>
template<typename P1 >
CYIStaticTask< ResultType >::CYIStaticTask ( CYIFuture< ResultType > &  rFuture,
ResultType(*)(P1)  pFunc,
P1 const &  funcParam1 
)

Creates a task from pFunc, which is a static function. Creates an association with rFuture. funcParam1 is passed to the static function.

template<typename ResultType = void>
template<typename P1 , typename P2 >
CYIStaticTask< ResultType >::CYIStaticTask ( CYIFuture< ResultType > &  rFuture,
ResultType(*)(P1, P2)  pFunc,
P1 const &  funcParam1,
P2 const &  funcParam2 
)

Creates a task from pFunc, which is a static function. Creates an association with rFuture. funcParam1, funcParam2 are passed to the static function.

template<typename ResultType = void>
template<typename P1 , typename P2 , typename P3 >
CYIStaticTask< ResultType >::CYIStaticTask ( CYIFuture< ResultType > &  rFuture,
ResultType(*)(P1, P2, P3)  pFunc,
P1 const &  funcParam1,
P2 const &  funcParam2,
P3 const &  funcParam3 
)

Creates a task from pFunc, which is a static function. Creates an association with rFuture. funcParam1, funcParam2, funcParam3 are passed to the static function.

template<typename ResultType = void>
template<typename P1 , typename P2 , typename P3 , typename P4 >
CYIStaticTask< ResultType >::CYIStaticTask ( CYIFuture< ResultType > &  rFuture,
ResultType(*)(P1, P2, P3, P4)  pFunc,
P1 const &  funcParam1,
P2 const &  funcParam2,
P3 const &  funcParam3,
P4 const &  funcParam4 
)

Creates a task from pFunc, which is a static function. Creates an association with rFuture. funcParam1, funcParam2, funcParam3, funcParam4 are passed to the static function.

template<typename ResultType = void>
CYIStaticTask< ResultType >::CYIStaticTask ( std::unique_ptr< CYIFuture< ResultType >>  pFuture,
ResultType(*)()  pFunc 
)

Creates a task from pFunc, which is a static function. Creates an association with pFuture, which this task takes the ownership of.

template<typename ResultType = void>
template<typename P1 >
CYIStaticTask< ResultType >::CYIStaticTask ( std::unique_ptr< CYIFuture< ResultType >>  pFuture,
ResultType(*)(P1)  pFunc,
P1 const &  funcParam1 
)

Creates a task from pFunc, which is a static function. Creates an association with pFuture, which this task takes the ownership of. funcParam1 is passed to the static function.

template<typename ResultType = void>
template<typename P1 , typename P2 >
CYIStaticTask< ResultType >::CYIStaticTask ( std::unique_ptr< CYIFuture< ResultType >>  pFuture,
ResultType(*)(P1, P2)  pFunc,
P1 const &  funcParam1,
P2 const &  funcParam2 
)

Creates a task from pFunc, which is a static function. Creates an association with pFuture, which this task takes the ownership of. funcParam1, funcParam2 are passed to the static function.

template<typename ResultType = void>
template<typename P1 , typename P2 , typename P3 >
CYIStaticTask< ResultType >::CYIStaticTask ( std::unique_ptr< CYIFuture< ResultType >>  pFuture,
ResultType(*)(P1, P2, P3)  pFunc,
P1 const &  funcParam1,
P2 const &  funcParam2,
P3 const &  funcParam3 
)

Creates a task from pFunc, which is a static function. Creates an association with pFuture, which this task takes the ownership of. funcParam1, funcParam2, funcParam3 are passed to the static function.

template<typename ResultType = void>
template<typename P1 , typename P2 , typename P3 , typename P4 >
CYIStaticTask< ResultType >::CYIStaticTask ( std::unique_ptr< CYIFuture< ResultType >>  pFuture,
ResultType(*)(P1, P2, P3, P4)  pFunc,
P1 const &  funcParam1,
P2 const &  funcParam2,
P3 const &  funcParam3,
P4 const &  funcParam4 
)

Creates a task from pFunc, which is a static function. Creates an association with pFuture, which this task takes the ownership of. funcParam1, funcParam2, funcParam3, funcParam4 are passed to the static function.

template<typename ResultType = void>
CYIStaticTask< ResultType >::CYIStaticTask ( ResultType(*)()  pFunc)

Creates a task from pFunc, which is a static function.

template<typename ResultType = void>
template<typename P1 >
CYIStaticTask< ResultType >::CYIStaticTask ( ResultType(*)(P1)  pFunc,
P1 const &  funcParam1 
)

Creates a task from pFunc, which is a static function. funcParam1 is passed to the static function.

template<typename ResultType = void>
template<typename P1 , typename P2 >
CYIStaticTask< ResultType >::CYIStaticTask ( ResultType(*)(P1, P2)  pFunc,
P1 const &  funcParam1,
P2 const &  funcParam2 
)

Creates a task from pFunc, which is a static function. funcParam1, funcParam2 are passed to the static function.

template<typename ResultType = void>
template<typename P1 , typename P2 , typename P3 >
CYIStaticTask< ResultType >::CYIStaticTask ( ResultType(*)(P1, P2, P3)  pFunc,
P1 const &  funcParam1,
P2 const &  funcParam2,
P3 const &  funcParam3 
)

Creates a task from pFunc, which is a static function. funcParam1, funcParam2, funcParam3 are passed to the static function.

template<typename ResultType = void>
template<typename P1 , typename P2 , typename P3 , typename P4 >
CYIStaticTask< ResultType >::CYIStaticTask ( ResultType(*)(P1, P2, P3, P4)  pFunc,
P1 const &  funcParam1,
P2 const &  funcParam2,
P3 const &  funcParam3,
P4 const &  funcParam4 
)

Creates a task from pFunc, which is a static function. funcParam1, funcParam2, funcParam3, funcParam4 are passed to the static function.

template<typename ResultType = void>
virtual CYIStaticTask< ResultType >::~CYIStaticTask ( )
virtual

Member Function Documentation

template<typename ResultType = void>
virtual ResultType CYIStaticTask< ResultType >::Run ( )
overrideprotectedvirtual

Executes the static function to which this object has a reference, using the parameters provided during construction of this static task.

Returns
The result of the execution of the static function.

Implements CYITask< ResultType >.


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