CmIReflectable.h 1.7 KB

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