43 lines
951 B
C++
43 lines
951 B
C++
#pragma once
|
|
|
|
#include "resources/Identifier.h"
|
|
|
|
#include <map>
|
|
|
|
namespace Feather
|
|
{
|
|
// Registry that maps Identifiers to objects
|
|
// TODO: optimize ownership (move, forward, copying, etc). perhaps use pointers
|
|
template <class T>
|
|
class RegistryMap
|
|
{
|
|
std::map<Identifier, T> map;
|
|
|
|
public:
|
|
inline void Register(const Identifier& id, T&& value)
|
|
{
|
|
map.insert({ id, std::move(value) });
|
|
}
|
|
|
|
inline const T& Get(const Identifier& id) const { return map.at(id); }
|
|
|
|
//inline Identifier& GetKey(T& value) const {}
|
|
|
|
inline size_t Size() const { return map.size(); }
|
|
};
|
|
|
|
template <class T>
|
|
class DefaultedRegistry : public RegistryMap<T>
|
|
{
|
|
using string = std::string;
|
|
|
|
const Identifier defaultKey;
|
|
T& defaultValue;
|
|
|
|
public:
|
|
DefaultedRegistry(const string&& defaultKey) : defaultKey(Identifier(defaultKey)) {}
|
|
|
|
|
|
};
|
|
}
|