SHADE_Y3/SHADE_Engine/src/ECS_Base/System/SHSystemManager.h

103 lines
3.0 KiB
C
Raw Normal View History

2022-09-08 11:08:23 +08:00
/*********************************************************************
* \file SHSystemManager.h
* \author Daniel Chua Yee Chen
* \brief Declaration for the SHSystemManager class.
* SHSystemManager is the interface class where users of the engine create
* the systems that gives the components their functionality. This also ensures that the Init and Exit functions are ran at the appropriate time
*
* \copyright Copyright (c) 2021 DigiPen Institute of Technology. Reproduction
or disclosure of this file or its contents without the prior written
consent of DigiPen Institute of Technology is prohibited.
*********************************************************************/
#ifndef SH_SYSTEM_MANAGER_H
#define SH_SYSTEM_MANAGER_H
#include <unordered_map>
#include <memory>
#include <string>
#include <cassert>
#include "../System/SHSystem.h"
namespace SHADE
{
class SHSystemManager
{
//type definition for the container we use to store our system
using SystemContainer = std::unordered_map<std::string, std::unique_ptr<SHSystem>>;
private:
static SystemContainer systemContainer;
public:
/*!*************************************************************************
* This class is used as a static class.
* No objects of this type should be created
***************************************************************************/
SHSystemManager() = delete;
~SHSystemManager() = delete;
/**************************************************************************
* \brief
* Create a system of type T and map it to a name.
* throws an error if a system with the same name already exists.
* \param name
* name of the system
* \return
* none
***************************************************************************/
template<typename T>
static std::enable_if_t<std::is_base_of_v<SHSystem, T>, void> CreateSystem(std::string const& name)
{
if (systemContainer.find(name) != systemContainer.end())
{
assert("System Creation Error: System with the same name already exist.");
}
systemContainer.emplace(name, std::make_unique<T>());
}
/**************************************************************************
* \brief
* Get a pointer to the System with a specified name.
* \param name
* Name of the system in the map
* \return
* Base System pointer.
***************************************************************************/
static SHSystem* GetSystem(std::string name);
/**************************************************************************
* \brief
* Call the Init function of all systems.
* \return
* none
***************************************************************************/
static void Init() noexcept;
/**************************************************************************
* \brief
* Call the Exit function of all systems.
* \return
***************************************************************************/
static void Exit() noexcept;
protected:
};
}
#endif