BsIReflectable.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #include "BsPrerequisitesUtil.h"
  3. #include "BsAny.h"
  4. namespace BansheeEngine
  5. {
  6. /** @addtogroup RTTI
  7. * @{
  8. */
  9. /**
  10. * Interface implemented by classes that provide run time type information.
  11. *
  12. * @note
  13. * Any class implementing this interface must implement the getRTTI() method, as well as a static getRTTIStatic()
  14. * method, returning the same value as getRTTI(). Object returned by those methods is used for retrieving actual RTTI
  15. * data about the class.
  16. */
  17. class BS_UTILITY_EXPORT IReflectable
  18. {
  19. public:
  20. virtual ~IReflectable() {}
  21. /**
  22. * Returns an interface you can use to access class' Run Time Type Information.
  23. *
  24. * @note
  25. * You must derive your own version of RTTITypeBase, in which you may encapsulate all reflection specific operations.
  26. */
  27. virtual RTTITypeBase* getRTTI() const = 0;
  28. /** Returns all classes deriving directly from IReflectable. */
  29. static Vector<RTTITypeBase*>& getDerivedClasses()
  30. {
  31. static Vector<RTTITypeBase*> mRTTIDerivedClasses;
  32. return mRTTIDerivedClasses;
  33. }
  34. /** Returns true if current RTTI class is derived from @p base (Or if it is the same type as base). */
  35. bool isDerivedFrom(RTTITypeBase* base);
  36. /** Returns an unique type identifier of the class. */
  37. UINT32 getTypeId() const;
  38. /**
  39. * Returns the type name of the class.
  40. *
  41. * @note Name is not necessarily unique.
  42. */
  43. const String& getTypeName() const;
  44. /** Creates an empty instance of a class from a type identifier. */
  45. static std::shared_ptr<IReflectable> createInstanceFromTypeId(UINT32 rttiTypeId);
  46. /**
  47. * Called by each type deriving from IReflectable, on program load.
  48. *
  49. * @note Internal method.
  50. */
  51. static void _registerDerivedClass(RTTITypeBase* derivedClass);
  52. /**
  53. * Returns class' RTTI type from type id.
  54. *
  55. * @note Internal method.
  56. */
  57. static RTTITypeBase* _getRTTIfromTypeId(UINT32 rttiTypeId);
  58. /**
  59. * Checks if the provided type id is unique.
  60. *
  61. * @note Internal method.
  62. */
  63. static bool _isTypeIdDuplicate(UINT32 typeId);
  64. protected:
  65. Any mRTTIData; /**< Temporary per-instance data storage used during various RTTI operations.
  66. Needed since there is one RTTI class instance per type and sometimes we need per-instance data. */
  67. };
  68. /** @} */
  69. }