Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <util/MacroUtils.h>
- #define ENUMERATE_ALL_COMPONENT_EVENTS(A)\
- A(earliest_update)\
- A(early_update)\
- A(update)\
- A(late_update)\
- A(always_update)\
- A(latest_update)\
- A(early_unlocked_update)\
- A(unlocked_update)\
- A(late_unlocked_update)\
- A(prerender)\
- A(render_event)\
- A(debug_render_event)\
- A(postrender)\
- namespace glaiel {
- template <typename T> \
- class ComponentInfo { \
- };
- #define IMPL_CLASSINFO(classname, basename, classid) \
- template <> \
- class ComponentInfo<classname> { \
- public: \
- static constexpr const char* const name = #classname; \
- static constexpr int id = classid; \
- typedef basename base; \
- }
- template <typename SELF, typename BASE>
- class DeriveComponentWithBoilerplate : public BASE {
- public:
- using self = SELF;
- using super = BASE;
- using BASE::BASE;
- static int Type() {
- return ComponentInfo<self>::id;
- }
- static std::string TypeSTR() {
- return ComponentInfo<self>::name;
- }
- virtual std::string GetObjectTypeSTR() const {
- return TypeSTR();
- }
- virtual int GetObjectType() const {
- return Type();
- }
- static std::vector<int> Hierarchy() {
- std::vector<int> a = super::Hierarchy();
- a.push_back(Type());
- return a;
- }
- virtual const std::vector<int>& GetObjectHierarchy() const {
- static std::vector<int> hierarchy = Hierarchy();
- return hierarchy;
- }
- #define REFLECT_OVERRIDE(f) virtual bool overrides_##f() const { return IS_OVERRIDDEN(Component, self, f); }
- ENUMERATE_ALL_COMPONENT_EVENTS(REFLECT_OVERRIDE);
- #undef REFLECT_OVERRIDE
- };
- #define COMPONENT(...) EXPAND_VARGS(OVERLOAD_MACRO2(__VA_ARGS__, _MCOMP2, _MCOMP1)(__VA_ARGS__))
- #define _MCOMP1(classname) _MCOMP2(classname, Component)
- #define _MCOMP2(classname, baseclass) \
- class classname; \
- IMPL_CLASSINFO(classname, baseclass, ComponentType::classname); \
- class classname : public DeriveComponentWithBoilerplate<classname, baseclass>
- #define CORE_COMPONENT(classname, baseclass) \
- class classname; \
- IMPL_CLASSINFO(classname, baseclass, CoreComponentType::classname); \
- class classname : public DeriveComponentWithBoilerplate<classname, baseclass>
- class Component;
- template <>
- class ComponentInfo<Component> {
- public:
- static constexpr const char* const name = "Component";
- static constexpr int id = CoreComponentType::Component;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement