CmIReflectable.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include "CmPrerequisitesUtil.h"
  3. namespace CamelotEngine
  4. {
  5. /**
  6. * @brief Interface implemented by classes that provide run time type information.
  7. */
  8. class CM_UTILITY_EXPORT IReflectable
  9. {
  10. public:
  11. /**
  12. * @brief Returns an interface you can use to access class Run Time Type Information.
  13. *
  14. * @note You must derive your own version of RTTIType, in which you
  15. * may encapsulate all reflection specific operations.
  16. */
  17. virtual RTTITypeBase* getRTTI() const = 0;
  18. /**
  19. * @brief Returns all classes deriving directly from IReflectable.
  20. * You can call another version of this method on the returned type class,
  21. * to find classes deeper in the hierarchy.
  22. */
  23. static vector<RTTITypeBase*>::type& getDerivedClasses()
  24. {
  25. static vector<RTTITypeBase*>::type mRTTIDerivedClasses;
  26. return mRTTIDerivedClasses;
  27. }
  28. /**
  29. * @brief INTERNAL USE. Called by each type deriving from IReflectable,
  30. * on program load.
  31. */
  32. static void registerDerivedClass(RTTITypeBase* derivedClass);
  33. static std::shared_ptr<IReflectable> createInstanceFromTypeId(UINT32 rttiTypeId);
  34. static RTTITypeBase* getRTTIfromTypeId(UINT32 rttiTypeId);
  35. static bool isTypeIdDuplicate(UINT32 typeId);
  36. /**
  37. * @brief Returns true if current RTTI class is derived from "base".
  38. * (Or if it is the same type as base)
  39. */
  40. bool isDerivedFrom(RTTITypeBase* base);
  41. };
  42. }