|
|
|
@ -19,6 +19,7 @@
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <climits>
|
|
|
|
|
#include "../System/SHSystem.h"
|
|
|
|
|
#include "../General/SHFamily.h"
|
|
|
|
|
|
|
|
|
@ -33,7 +34,7 @@ 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>>;
|
|
|
|
|
using SystemContainer = std::unordered_map<SystemID, std::unique_ptr<SHSystem>>;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static SystemContainer systemContainer;
|
|
|
|
@ -57,14 +58,18 @@ namespace SHADE
|
|
|
|
|
* none
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
template<typename T>
|
|
|
|
|
static std::enable_if_t<std::is_base_of_v<SHSystem, T>, void> CreateSystem(std::string const& name)
|
|
|
|
|
static std::enable_if_t<std::is_base_of_v<SHSystem, T>, void> CreateSystem()
|
|
|
|
|
{
|
|
|
|
|
if (systemContainer.find(name) != systemContainer.end())
|
|
|
|
|
{
|
|
|
|
|
assert("System Creation Error: System with the same name already exist.");
|
|
|
|
|
}
|
|
|
|
|
SystemTypeID typeID = SystemFamily::GetID<T>();
|
|
|
|
|
|
|
|
|
|
systemContainer.emplace(name, std::make_unique<T>());
|
|
|
|
|
SystemVersionID version = 0;
|
|
|
|
|
SystemID id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID;
|
|
|
|
|
while (systemContainer.find(id) != systemContainer.end())
|
|
|
|
|
{
|
|
|
|
|
++version;
|
|
|
|
|
SystemID id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID;
|
|
|
|
|
}
|
|
|
|
|
systemContainer.emplace(id, std::make_unique<T>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -77,7 +82,21 @@ namespace SHADE
|
|
|
|
|
* \return
|
|
|
|
|
* Base System pointer.
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
static SHSystem* GetSystem(std::string name);
|
|
|
|
|
template<typename T>
|
|
|
|
|
static std::enable_if_t<std::is_base_of_v<SHSystem, T>, T*> GetSystem(SystemVersionID version = 0)
|
|
|
|
|
{
|
|
|
|
|
SystemTypeID typeID = SystemFamily::GetID<T>();
|
|
|
|
|
|
|
|
|
|
SystemID id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID;
|
|
|
|
|
|
|
|
|
|
if (systemContainer.find(id) == systemContainer.end())
|
|
|
|
|
{
|
|
|
|
|
std::cout << "System Manager error: System Version " << version << " does not exit." << std::endl;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (T*)systemContainer.find(id)->second.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
|
* \brief
|
|
|
|
|