10#include <unordered_map>
11#include <unordered_set>
23 explicit SchedulerError(
const std::string &message) :
msg(fmt::format(
"Scheduler error: {}", message)) {};
27 const char *
what()
const throw()
override {
return this->
msg.c_str(); };
52 template <
typename TScheduler,
typename... Args>
void AddScheduler(
Core &core, Args &&...args);
56 template <
typename TScheduler> TScheduler &
GetScheduler();
61 std::shared_ptr<Scheduler::AScheduler>
GetScheduler(std::type_index
id);
80 template <
typename TBefore,
typename TAfter>
void Before();
85 template <
typename TAfter,
typename TBefore>
void After();
102 template <
typename TScheduler>
bool Contains()
const;
107 bool Contains(std::type_index
id)
const;
129 std::map<std::type_index, size_t> &inDegree)
const;
136 std::map<std::type_index, std::shared_ptr<Scheduler::AScheduler>>
_schedulers;
140 std::unordered_map<std::type_index, std::unordered_set<std::type_index>>
_dependencies;
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
void TopologicalSort()
Apply a topological sort between all schedulers based on their dependencies.
Definition SchedulerContainer.cpp:46
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,...
Definition SchedulerContainer.hpp:140
std::list< std::shared_ptr< Scheduler::AScheduler > > _orderedSchedulers
A list of the the ordered list of schedulers.
Definition SchedulerContainer.hpp:143
void DeleteScheduler()
Deletes a scheduler of the specified type.
Definition SchedulerContainer.hpp:71
void Update()
Updates the order of schedulers based on their dependencies. This function performs a topological sor...
Definition SchedulerContainer.cpp:89
SchedulerContainer()=default
Default constructor for SchedulerContainer.
void Before()
Add a dependency between two schedulers. It will set the first scheduler to be before the second one.
Definition SchedulerContainer.inl:27
void After()
Add a dependency between two schedulers. It will set the first scheduler to be after the second one.
Definition SchedulerContainer.inl:33
void RunSchedulers()
Runs all schedulers in the container. This function iterates through the ordered list of schedulers a...
Definition SchedulerContainer.inl:59
bool Contains() const
Checks if a scheduler of the specified type exists in the container.
Definition SchedulerContainer.inl:75
std::map< std::type_index, std::shared_ptr< Scheduler::AScheduler > > _schedulers
A map of the schedulers.
Definition SchedulerContainer.hpp:136
void SetErrorPolicyForAllSchedulers(Scheduler::SchedulerErrorPolicy policy)
Sets the error policy for all schedulers in the container.
Definition SchedulerContainer.cpp:97
bool _dirty
A flag indicating whether the order of schedulers needs to be updated.
Definition SchedulerContainer.hpp:133
~SchedulerContainer()=default
Destructor for SchedulerContainer.
void RemoveDependencyAfter()
Remove a dependency between two schedulers. It will remove the dependency that the first scheduler is...
Definition SchedulerContainer.inl:54
TScheduler & GetScheduler()
Retrieves a scheduler of the specified type.
Definition SchedulerContainer.inl:17
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....
Definition SchedulerContainer.cpp:30
void RemoveDependencyBefore()
Remove a dependency between two schedulers. It will remove the dependency that the first scheduler is...
Definition SchedulerContainer.inl:38
void AddScheduler(Core &core, Args &&...args)
Adds a scheduler to the container.
Definition SchedulerContainer.inl:4
std::string msg
The error message associated with the exception.
Definition SchedulerContainer.hpp:31
const char * what() const override
Gets the error message.
Definition SchedulerContainer.hpp:27
SchedulerError(const std::string &message)
Constructor for SchedulerError.
Definition SchedulerContainer.hpp:23
SchedulerErrorPolicy
Enum that defines how the scheduler will handle errors.
Definition IScheduler.hpp:11