Re-remade component and system ids

Former-commit-id: 98b76695cca904c55c7333801c3cdf693da15086
This commit is contained in:
Lynix
2015-03-30 04:18:44 +02:00
parent 3fd217b8a3
commit 6d1ac4fe18
17 changed files with 196 additions and 126 deletions

View File

@@ -8,21 +8,41 @@
#define NDK_BASECOMPONENT_HPP
#include <NDK/Prerequesites.hpp>
#include <functional>
#include <unordered_map>
#include <vector>
namespace Ndk
{
class NDK_API BaseComponent
{
public:
BaseComponent(ComponentId componentId);
using Factory = std::function<BaseComponent*()>;
BaseComponent(ComponentIndex componentIndex);
virtual ~BaseComponent();
virtual BaseComponent* Clone() const = 0;
ComponentId GetId() const;
ComponentIndex GetIndex() const;
template<typename ComponentType, unsigned int N>
static ComponentIndex Register(const char (&name)[N]);
static ComponentIndex Register(ComponentId id, Factory factoryFunc);
protected:
ComponentId m_componentId;
ComponentIndex m_componentIndex;
private:
struct ComponentEntry
{
ComponentId id;
Factory factory;
};
static std::vector<ComponentEntry> s_entries;
static std::unordered_map<ComponentId, ComponentIndex> s_idToIndex;
};
}