#pragma once #include "RTTI_Meta.h" // Interface RTTI GENERATE_META(IRTTI) class IRTTI { // Fast array class FastContainer final { long long _size = 0; Classes* array = nullptr; public: long long constexpr size() const { return _size; } void push_back(const Classes object); bool find(const Classes& Type) const; }; FastContainer Tree; Classes type; protected: // That method set type value and add type to inheritance tree void SetType(Classes Type); IRTTI(); ~IRTTI() = default; friend class RTTI; }; // RTTI methods class RTTI final { RTTI() = default; // That method allow compare given type with real type object template static bool IsA(const Classes type) { return Meta::Type == type; } public: template static bool IsA(const IRTTI* object) { return IsA(object->type); } // That method realized dynamic_cast template static To* dyn_cast(From* object) { IRTTI* InterfaceOfObject = static_cast(object); if (IsA(InterfaceOfObject->type)) return reinterpret_cast(object); if (InterfaceOfObject->Tree.find(Meta::Type)) return reinterpret_cast(object); return nullptr; } // That method return real type object in the form of enum value static Classes GetType(const IRTTI* object); };