Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Engine::SchedulerContainer Class Reference

Manages a collection of schedulers, allowing addition, retrieval, and deletion of schedulers. More...

#include <SchedulerContainer.hpp>

Public Member Functions

 SchedulerContainer ()=default
 Default constructor for SchedulerContainer.
 ~SchedulerContainer ()=default
 Destructor for SchedulerContainer.
template<typename TScheduler, typename... Args>
void AddScheduler (Core &core, Args &&...args)
 Adds a scheduler to the container.
template<typename TScheduler>
TScheduler & GetScheduler ()
 Retrieves a scheduler of the specified type.
std::shared_ptr< Scheduler::ASchedulerGetScheduler (std::type_index id)
 Retrieves a scheduler identified by the given type index.
void RunSchedulers ()
 Runs all schedulers in the container. This function iterates through the ordered list of schedulers and calls the RunSystems method on each scheduler. It ensures that the schedulers are executed in the order defined by their dependencies.
template<typename TScheduler>
void DeleteScheduler ()
 Deletes a scheduler of the specified type.
void DeleteScheduler (std::type_index id)
 Deletes a scheduler identified by the given type index.
template<typename TBefore, typename TAfter>
void Before ()
 Add a dependency between two schedulers. It will set the first scheduler to be before the second one.
template<typename TAfter, typename TBefore>
void After ()
 Add a dependency between two schedulers. It will set the first scheduler to be after the second one.
template<typename TBefore, typename TAfter>
void RemoveDependencyBefore ()
 Remove a dependency between two schedulers. It will remove the dependency that the first scheduler is before the second one.
template<typename TAfter, typename TBefore>
void RemoveDependencyAfter ()
 Remove a dependency between two schedulers. It will remove the dependency that the first scheduler is after the second one.
template<typename TScheduler>
bool Contains () const
 Checks if a scheduler of the specified type exists in the container.
bool Contains (std::type_index id) const
 Checks if a scheduler identified by the given type index exists in the container.
void SetErrorPolicyForAllSchedulers (Scheduler::SchedulerErrorPolicy policy)
 Sets the error policy for all schedulers in the container.

Private Member Functions

void Update ()
 Updates the order of schedulers based on their dependencies. This function performs a topological sort on the schedulers to determine the correct execution order. It checks for circular dependencies.
void TopologicalSort ()
 Apply a topological sort between all schedulers based on their dependencies.
void ProcessDependencies (std::type_index current, std::queue< std::type_index > &q, std::map< std::type_index, size_t > &inDegree) const
 Helper function to process the dependencies of a scheduler during the topological sort. It updates the in-degree of the dependent schedulers and adds them to the queue if their in-degree becomes zero.

Private Attributes

bool _dirty = false
 A flag indicating whether the order of schedulers needs to be updated.
std::map< std::type_index, std::shared_ptr< Scheduler::AScheduler > > _schedulers
 A map of the schedulers.
std::unordered_map< std::type_index, std::unordered_set< std::type_index > > _dependencies
 A map of the dependencies between schedulers. The key is the type index of a scheduler, and the value is a set of type indices of schedulers that depend on the key scheduler.
std::list< std::shared_ptr< Scheduler::AScheduler > > _orderedSchedulers
 A list of the the ordered list of schedulers.

Detailed Description

Manages a collection of schedulers, allowing addition, retrieval, and deletion of schedulers.

See also
Engine::Scheduler::IScheduler
Engine::Scheduler::AScheduler
Engine::Scheduler::SchedulerError

Constructor & Destructor Documentation

◆ SchedulerContainer()

Engine::SchedulerContainer::SchedulerContainer ( )
default

Default constructor for SchedulerContainer.

◆ ~SchedulerContainer()

Engine::SchedulerContainer::~SchedulerContainer ( )
default

Destructor for SchedulerContainer.

Member Function Documentation

◆ AddScheduler()

template<typename TScheduler, typename... Args>
void Engine::SchedulerContainer::AddScheduler ( Core & core,
Args &&... args )

Adds a scheduler to the container.

Parameters
coreA reference to the Core.
argsThe arguments to be forwarded to the scheduler's constructor.
Template Parameters
TSchedulerThe type of the scheduler to be added.
ArgsThe types of the arguments to be forwarded to the scheduler's constructor.

◆ After()

template<typename TAfter, typename TBefore>
void Engine::SchedulerContainer::After ( )
inline

Add a dependency between two schedulers. It will set the first scheduler to be after the second one.

Template Parameters
TAfterThe type of the first scheduler.
TBeforeThe type of the second scheduler.

◆ Before()

template<typename TBefore, typename TAfter>
void Engine::SchedulerContainer::Before ( )
inline

Add a dependency between two schedulers. It will set the first scheduler to be before the second one.

Template Parameters
TBeforeThe type of the first scheduler.
TAfterThe type of the second scheduler.

◆ Contains() [1/2]

template<typename TScheduler>
bool Engine::SchedulerContainer::Contains ( ) const
inline

Checks if a scheduler of the specified type exists in the container.

Template Parameters
TSchedulerThe type of the scheduler to check for.
Returns
true if the scheduler exists, false otherwise.

◆ Contains() [2/2]

bool Engine::SchedulerContainer::Contains ( std::type_index id) const
inline

Checks if a scheduler identified by the given type index exists in the container.

Parameters
idThe type index of the scheduler to check for.
Returns
true if the scheduler exists, false otherwise.

◆ DeleteScheduler() [1/2]

template<typename TScheduler>
void Engine::SchedulerContainer::DeleteScheduler ( )
inline

Deletes a scheduler of the specified type.

Template Parameters
TSchedulerThe type of the scheduler to be deleted.
Todo
Put the implementation in the inl file

◆ DeleteScheduler() [2/2]

void Engine::SchedulerContainer::DeleteScheduler ( std::type_index id)

Deletes a scheduler identified by the given type index.

Parameters
idThe type index of the scheduler to be deleted.

◆ GetScheduler() [1/2]

template<typename TScheduler>
TScheduler & Engine::SchedulerContainer::GetScheduler ( )
inline

Retrieves a scheduler of the specified type.

Template Parameters
TSchedulerThe type of the scheduler to retrieve.

◆ GetScheduler() [2/2]

std::shared_ptr< Engine::Scheduler::AScheduler > Engine::SchedulerContainer::GetScheduler ( std::type_index id)
inline

Retrieves a scheduler identified by the given type index.

Parameters
idThe type index of the scheduler to retrieve.
Returns
A shared pointer to the scheduler of the specified type.

◆ ProcessDependencies()

void Engine::SchedulerContainer::ProcessDependencies ( std::type_index current,
std::queue< std::type_index > & q,
std::map< std::type_index, size_t > & inDegree ) const
private

Helper function to process the dependencies of a scheduler during the topological sort. It updates the in-degree of the dependent schedulers and adds them to the queue if their in-degree becomes zero.

Parameters
currentThe type index of the current scheduler being processed.
qThe queue used for the topological sort, containing schedulers with zero in-degree.
inDegreeA map that keeps track of the in-degree of each scheduler, which is the number of dependencies it has.

◆ RemoveDependencyAfter()

template<typename TAfter, typename TBefore>
void Engine::SchedulerContainer::RemoveDependencyAfter ( )

Remove a dependency between two schedulers. It will remove the dependency that the first scheduler is after the second one.

Template Parameters
TAfterThe type of the first scheduler.
TBeforeThe type of the second scheduler.

◆ RemoveDependencyBefore()

template<typename TBefore, typename TAfter>
void Engine::SchedulerContainer::RemoveDependencyBefore ( )

Remove a dependency between two schedulers. It will remove the dependency that the first scheduler is before the second one.

Template Parameters
TBeforeThe type of the first scheduler.
TAfterThe type of the second scheduler.

◆ RunSchedulers()

void Engine::SchedulerContainer::RunSchedulers ( )
inline

Runs all schedulers in the container. This function iterates through the ordered list of schedulers and calls the RunSystems method on each scheduler. It ensures that the schedulers are executed in the order defined by their dependencies.

◆ SetErrorPolicyForAllSchedulers()

void Engine::SchedulerContainer::SetErrorPolicyForAllSchedulers ( Scheduler::SchedulerErrorPolicy policy)

Sets the error policy for all schedulers in the container.

Parameters
policyThe error policy to be applied to all schedulers.
See also
Engine::Scheduler::SchedulerErrorPolicy

◆ TopologicalSort()

void Engine::SchedulerContainer::TopologicalSort ( )
private

Apply a topological sort between all schedulers based on their dependencies.

◆ Update()

void Engine::SchedulerContainer::Update ( )
private

Updates the order of schedulers based on their dependencies. This function performs a topological sort on the schedulers to determine the correct execution order. It checks for circular dependencies.

Member Data Documentation

◆ _dependencies

std::unordered_map<std::type_index, std::unordered_set<std::type_index> > Engine::SchedulerContainer::_dependencies
private

A map of the dependencies between schedulers. The key is the type index of a scheduler, and the value is a set of type indices of schedulers that depend on the key scheduler.

◆ _dirty

bool Engine::SchedulerContainer::_dirty = false
private

A flag indicating whether the order of schedulers needs to be updated.

◆ _orderedSchedulers

std::list<std::shared_ptr<Scheduler::AScheduler> > Engine::SchedulerContainer::_orderedSchedulers
private

A list of the the ordered list of schedulers.

◆ _schedulers

std::map<std::type_index, std::shared_ptr<Scheduler::AScheduler> > Engine::SchedulerContainer::_schedulers
private

A map of the schedulers.


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