CmIReflectable.h 1.8 KB

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