Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
FunctionUtils::FunctionContainer< TReturn, TArgs > Class Template Reference

Container for functions, allowing for dynamic storage and invocation. More...

#include <FunctionContainer.hpp>

Classes

struct  is_derived_from_function_type
 Type trait to check if a type is derived from BaseFunction. More...

Public Types

using FunctionType = BaseFunction<TReturn, TArgs...>

Public Member Functions

 FunctionContainer ()=default
 Default constructor for FunctionContainer.
 ~FunctionContainer ()=default
 Default destructor for FunctionContainer.
 FunctionContainer (const FunctionContainer &)=delete
 Deleted copy constructor (FunctionContainer is not copyable due to unique_ptr).
FunctionContaineroperator= (const FunctionContainer &)=delete
 Deleted copy assignment (FunctionContainer is not copyable due to unique_ptr).
 FunctionContainer (FunctionContainer &&) noexcept=default
 Move constructor.
FunctionContaineroperator= (FunctionContainer &&) noexcept=default
 Move assignment.
template<typename TCallable>
FunctionID AddFunction (TCallable callable)
 Adds a function to the container.
FunctionID AddFunction (std::unique_ptr< FunctionType > &&function)
 Adds a wrapped function to the container.
template<typename... TFunctions>
decltype(auto) AddFunctions (TFunctions... functions)
 Adds multiple functions to the container.
const std::list< std::unique_ptr< FunctionType > > & GetFunctions ()
 Gets the list of functions in the container.
bool IsEmpty () const
 Returns true if the container is empty.
std::size_t Size () const
 Returns the number of functions in the container.
std::unique_ptr< FunctionTypeDeleteFunction (FunctionID id)
 Deletes a function from the container.
bool Contains (FunctionID id) const
template<typename TCallable>
FunctionUtils::FunctionID AddFunction (TCallable callable)

Private Attributes

std::list< std::unique_ptr< FunctionType > > _orderedFunctions
 List to store functions in order.
std::unordered_map< FunctionID, typename std::list< std::unique_ptr< FunctionType > >::iterator > _idToIterator
 Map to store iterators for O(1) deletion.

Detailed Description

template<typename TReturn, typename... TArgs>
class FunctionUtils::FunctionContainer< TReturn, TArgs >

Container for functions, allowing for dynamic storage and invocation.

Examples
/home/runner/work/EngineSquared/EngineSquared/src/plugin/sound/src/resource/SoundManager.hpp.

Member Typedef Documentation

◆ FunctionType

template<typename TReturn, typename... TArgs>
using FunctionUtils::FunctionContainer< TReturn, TArgs >::FunctionType = BaseFunction<TReturn, TArgs...>

Constructor & Destructor Documentation

◆ FunctionContainer() [1/3]

template<typename TReturn, typename... TArgs>
FunctionUtils::FunctionContainer< TReturn, TArgs >::FunctionContainer ( )
default

Default constructor for FunctionContainer.

◆ ~FunctionContainer()

template<typename TReturn, typename... TArgs>
FunctionUtils::FunctionContainer< TReturn, TArgs >::~FunctionContainer ( )
default

Default destructor for FunctionContainer.

◆ FunctionContainer() [2/3]

template<typename TReturn, typename... TArgs>
FunctionUtils::FunctionContainer< TReturn, TArgs >::FunctionContainer ( const FunctionContainer< TReturn, TArgs > & )
delete

Deleted copy constructor (FunctionContainer is not copyable due to unique_ptr).

◆ FunctionContainer() [3/3]

template<typename TReturn, typename... TArgs>
FunctionUtils::FunctionContainer< TReturn, TArgs >::FunctionContainer ( FunctionContainer< TReturn, TArgs > && )
defaultnoexcept

Move constructor.

Member Function Documentation

◆ AddFunction() [1/3]

template<typename TReturn, typename... TArgs>
FunctionUtils::FunctionID FunctionUtils::FunctionContainer< TReturn, TArgs >::AddFunction ( std::unique_ptr< FunctionType > && function)

Adds a wrapped function to the container.

Parameters
functionA wrapped function to be added.
Note
A wrapped function is a unique pointer to a class derived from BaseFunction.

◆ AddFunction() [2/3]

template<typename TReturn, typename... TArgs>
template<typename TCallable>
FunctionID FunctionUtils::FunctionContainer< TReturn, TArgs >::AddFunction ( TCallable callable)

Adds a function to the container.

Template Parameters
TCallableType of the callable function.
Parameters
callableThe callable function to be added.
Examples
/home/runner/work/EngineSquared/EngineSquared/src/plugin/sound/src/resource/SoundManager.hpp.

◆ AddFunction() [3/3]

template<typename TReturn, typename... TArgs>
template<typename TCallable>
FunctionUtils::FunctionID FunctionUtils::FunctionContainer< TReturn, TArgs >::AddFunction ( TCallable callable)

◆ AddFunctions()

template<typename TReturn, typename... TArgs>
template<typename... TFunctions>
decltype(auto) FunctionUtils::FunctionContainer< TReturn, TArgs >::AddFunctions ( TFunctions... functions)
inline

Adds multiple functions to the container.

Template Parameters
TFunctionsVariadic template parameter for function types.
Parameters
functionsThe functions to be added.
Returns
a tuple of FunctionIDs for the added functions.

◆ Contains()

template<typename TReturn, typename... TArgs>
bool FunctionUtils::FunctionContainer< TReturn, TArgs >::Contains ( FunctionID id) const
inline

◆ DeleteFunction()

template<typename TReturn, typename... TArgs>
std::unique_ptr< typename FunctionUtils::FunctionContainer< TReturn, TArgs... >::FunctionType > FunctionUtils::FunctionContainer< TReturn, TArgs >::DeleteFunction ( FunctionUtils::FunctionID id)

Deletes a function from the container.

Parameters
idThe ID of the function to be deleted.
Returns
True if the function was deleted, false otherwise.
Examples
/home/runner/work/EngineSquared/EngineSquared/src/plugin/sound/src/resource/SoundManager.hpp.

◆ GetFunctions()

template<typename TReturn, typename... TArgs>
const std::list< std::unique_ptr< FunctionType > > & FunctionUtils::FunctionContainer< TReturn, TArgs >::GetFunctions ( )
inline

Gets the list of functions in the container.

Returns
Const reference to the vector of unique pointers to BaseFunction.
Examples
/home/runner/work/EngineSquared/EngineSquared/src/plugin/sound/src/resource/SoundManager.hpp.

◆ IsEmpty()

template<typename TReturn, typename... TArgs>
bool FunctionUtils::FunctionContainer< TReturn, TArgs >::IsEmpty ( ) const
inline

Returns true if the container is empty.

Returns
True if the container is empty, false otherwise.

◆ operator=() [1/2]

template<typename TReturn, typename... TArgs>
FunctionContainer & FunctionUtils::FunctionContainer< TReturn, TArgs >::operator= ( const FunctionContainer< TReturn, TArgs > & )
delete

Deleted copy assignment (FunctionContainer is not copyable due to unique_ptr).

◆ operator=() [2/2]

template<typename TReturn, typename... TArgs>
FunctionContainer & FunctionUtils::FunctionContainer< TReturn, TArgs >::operator= ( FunctionContainer< TReturn, TArgs > && )
defaultnoexcept

Move assignment.

◆ Size()

template<typename TReturn, typename... TArgs>
std::size_t FunctionUtils::FunctionContainer< TReturn, TArgs >::Size ( ) const
inline

Returns the number of functions in the container.

Returns
The number of functions in the container.

Member Data Documentation

◆ _idToIterator

template<typename TReturn, typename... TArgs>
std::unordered_map<FunctionID, typename std::list<std::unique_ptr<FunctionType> >::iterator> FunctionUtils::FunctionContainer< TReturn, TArgs >::_idToIterator
private

Map to store iterators for O(1) deletion.

◆ _orderedFunctions

template<typename TReturn, typename... TArgs>
std::list<std::unique_ptr<FunctionType> > FunctionUtils::FunctionContainer< TReturn, TArgs >::_orderedFunctions
private

List to store functions in order.


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