Faro Engine
0.0.0.b519570 (main)
Loading...
Searching...
No Matches
Source
Engine
Core
Source
Util
ClassRegistry.hpp
Go to the documentation of this file.
1
#pragma once
2
#include "../Containers/Map.hpp"
3
#include "../Containers/String.hpp"
4
#include <functional>
5
6
#define DEFINE_INSTANCE_REGISTRY(NAME, TYPE) namespace InstanceRegistry_##NAME { static Faro::Map<Faro::String, TYPE*> & Get() { static Faro::Map<Faro::String, TYPE*> instances; return instances; } } extern void InstanceRegistrationFunction_##NAME(Faro::String, TYPE*); template<class T> struct InstanceRegistration_##NAME { T instance; InstanceRegistration_##NAME(Faro::String id){ InstanceRegistrationFunction_##NAME(id, &instance); } };
7
#define IMPLEMENT_INSTANCE_REGISTRY(NAME, TYPE) void InstanceRegistrationFunction_##NAME(Faro::String name, TYPE* ptr){ InstanceRegistry_##NAME::Get().Add(name, ptr); }
8
#define REGISTER_INSTANCE(NAME, CLASS) namespace { InstanceRegistration_##NAME<CLASS> NAME##_##CLASS##_instance_reg(#CLASS); };
9
10
#define DEFINE_CLASS_REGISTRY(NAME, TYPE) namespace ClassRegistry_##NAME { static Map<String, std::function<TYPE*(void)>> & Get() { static Map<String, std::function<TYPE*(void)>> instances; return instances; } static TYPE* Instantiate(String id) { if(!Get().Contains(id)) return nullptr; else return Get()[id](); } } template<class T> struct ClassRegistration_##NAME { ClassRegistration_##NAME(String id){ ClassRegistry_##NAME::Get().Add(id, [](){ return new T(); }); } };
11
#define REGISTER_CLASS(NAME, CLASS) namespace { ClassRegistration_##NAME<CLASS> NAME##_##CLASS##_class_reg(#CLASS); };
Generated by
1.9.8