BsManagedSerializableObjectInfo.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsIReflectable.h"
  4. #include <mono/jit/jit.h>
  5. namespace BansheeEngine
  6. {
  7. enum class ScriptPrimitiveType
  8. {
  9. Bool,
  10. Char,
  11. I8,
  12. U8,
  13. I16,
  14. U16,
  15. I32,
  16. U32,
  17. I64,
  18. U64,
  19. Float,
  20. Double,
  21. String,
  22. Texture2DRef,
  23. Texture3DRef,
  24. TextureCubeRef,
  25. SpriteTextureRef,
  26. ManagedResourceRef,
  27. PlainTextRef,
  28. ScriptCodeRef,
  29. ShaderRef,
  30. MaterialRef,
  31. SceneObjectRef,
  32. ComponentRef
  33. };
  34. enum class ScriptFieldFlags
  35. {
  36. Serializable = 0x01,
  37. Inspectable = 0x02
  38. };
  39. class BS_SCR_BE_EXPORT ManagedSerializableTypeInfo : public IReflectable
  40. {
  41. public:
  42. virtual ~ManagedSerializableTypeInfo() {}
  43. virtual bool matches(const ManagedSerializableTypeInfoPtr& typeInfo) const = 0;
  44. virtual bool isTypeLoaded() const = 0;
  45. virtual ::MonoClass* getMonoClass() const = 0;
  46. /************************************************************************/
  47. /* RTTI */
  48. /************************************************************************/
  49. public:
  50. friend class ManagedSerializableTypeInfoRTTI;
  51. static RTTITypeBase* getRTTIStatic();
  52. virtual RTTITypeBase* getRTTI() const;
  53. };
  54. class BS_SCR_BE_EXPORT ManagedSerializableTypeInfoPrimitive : public ManagedSerializableTypeInfo
  55. {
  56. public:
  57. ScriptPrimitiveType mType;
  58. bool matches(const ManagedSerializableTypeInfoPtr& typeInfo) const;
  59. bool isTypeLoaded() const;
  60. ::MonoClass* getMonoClass() const;
  61. /************************************************************************/
  62. /* RTTI */
  63. /************************************************************************/
  64. public:
  65. friend class ManagedSerializableTypeInfoPrimitiveRTTI;
  66. static RTTITypeBase* getRTTIStatic();
  67. virtual RTTITypeBase* getRTTI() const;
  68. };
  69. class BS_SCR_BE_EXPORT ManagedSerializableTypeInfoObject : public ManagedSerializableTypeInfo
  70. {
  71. public:
  72. String mTypeNamespace;
  73. String mTypeName;
  74. bool mValueType;
  75. bool matches(const ManagedSerializableTypeInfoPtr& typeInfo) const;
  76. bool isTypeLoaded() const;
  77. ::MonoClass* getMonoClass() const;
  78. /************************************************************************/
  79. /* RTTI */
  80. /************************************************************************/
  81. public:
  82. friend class ManagedSerializableTypeInfoObjectRTTI;
  83. static RTTITypeBase* getRTTIStatic();
  84. virtual RTTITypeBase* getRTTI() const;
  85. };
  86. class BS_SCR_BE_EXPORT ManagedSerializableTypeInfoArray : public ManagedSerializableTypeInfo
  87. {
  88. public:
  89. ManagedSerializableTypeInfoPtr mElementType;
  90. UINT32 mRank;
  91. bool matches(const ManagedSerializableTypeInfoPtr& typeInfo) const;
  92. bool isTypeLoaded() const;
  93. ::MonoClass* getMonoClass() const;
  94. /************************************************************************/
  95. /* RTTI */
  96. /************************************************************************/
  97. public:
  98. friend class ManagedSerializableTypeInfoArrayRTTI;
  99. static RTTITypeBase* getRTTIStatic();
  100. virtual RTTITypeBase* getRTTI() const;
  101. };
  102. class BS_SCR_BE_EXPORT ManagedSerializableTypeInfoList : public ManagedSerializableTypeInfo
  103. {
  104. public:
  105. ManagedSerializableTypeInfoPtr mElementType;
  106. bool matches(const ManagedSerializableTypeInfoPtr& typeInfo) const;
  107. bool isTypeLoaded() const;
  108. ::MonoClass* getMonoClass() const;
  109. /************************************************************************/
  110. /* RTTI */
  111. /************************************************************************/
  112. public:
  113. friend class ManagedSerializableTypeInfoListRTTI;
  114. static RTTITypeBase* getRTTIStatic();
  115. virtual RTTITypeBase* getRTTI() const;
  116. };
  117. class BS_SCR_BE_EXPORT ManagedSerializableTypeInfoDictionary : public ManagedSerializableTypeInfo
  118. {
  119. public:
  120. ManagedSerializableTypeInfoPtr mKeyType;
  121. ManagedSerializableTypeInfoPtr mValueType;
  122. bool matches(const ManagedSerializableTypeInfoPtr& typeInfo) const;
  123. bool isTypeLoaded() const;
  124. ::MonoClass* getMonoClass() const;
  125. /************************************************************************/
  126. /* RTTI */
  127. /************************************************************************/
  128. public:
  129. friend class ManagedSerializableTypeInfoDictionaryRTTI;
  130. static RTTITypeBase* getRTTIStatic();
  131. virtual RTTITypeBase* getRTTI() const;
  132. };
  133. class BS_SCR_BE_EXPORT ManagedSerializableFieldInfo : public IReflectable
  134. {
  135. public:
  136. ManagedSerializableFieldInfo();
  137. String mName;
  138. UINT32 mFieldId;
  139. ManagedSerializableTypeInfoPtr mTypeInfo;
  140. ScriptFieldFlags mFlags;
  141. MonoField* mMonoField;
  142. bool isSerializable() const { return ((UINT32)mFlags & (UINT32)ScriptFieldFlags::Serializable) != 0; }
  143. /************************************************************************/
  144. /* RTTI */
  145. /************************************************************************/
  146. public:
  147. friend class ManagedSerializableFieldInfoRTTI;
  148. static RTTITypeBase* getRTTIStatic();
  149. virtual RTTITypeBase* getRTTI() const;
  150. };
  151. class BS_SCR_BE_EXPORT ManagedSerializableObjectInfo : public IReflectable
  152. {
  153. public:
  154. struct CachedField
  155. {
  156. CachedField(const SPtr<ManagedSerializableFieldInfo>& info, UINT32 typeId)
  157. :info(info), parentTypeId(typeId)
  158. { }
  159. SPtr<ManagedSerializableFieldInfo> info;
  160. UINT32 parentTypeId;
  161. };
  162. ManagedSerializableObjectInfo();
  163. void initialize();
  164. String getFullTypeName() const { return mTypeInfo->mTypeNamespace + "." + mTypeInfo->mTypeName; }
  165. ManagedSerializableTypeInfoObjectPtr mTypeInfo;
  166. UINT32 mTypeId;
  167. MonoClass* mMonoClass;
  168. UnorderedMap<String, UINT32> mFieldNameToId;
  169. UnorderedMap<UINT32, std::shared_ptr<ManagedSerializableFieldInfo>> mFields;
  170. std::shared_ptr<ManagedSerializableObjectInfo> mBaseClass;
  171. Vector<std::weak_ptr<ManagedSerializableObjectInfo>> mDerivedClasses;
  172. Vector<CachedField> mCachedAllFields;
  173. /************************************************************************/
  174. /* RTTI */
  175. /************************************************************************/
  176. public:
  177. friend class ManagedSerializableObjectInfoRTTI;
  178. static RTTITypeBase* getRTTIStatic();
  179. virtual RTTITypeBase* getRTTI() const;
  180. };
  181. class BS_SCR_BE_EXPORT ManagedSerializableAssemblyInfo : public IReflectable
  182. {
  183. public:
  184. String mName;
  185. UnorderedMap<String, UINT32> mTypeNameToId;
  186. UnorderedMap<UINT32, std::shared_ptr<ManagedSerializableObjectInfo>> mObjectInfos;
  187. /************************************************************************/
  188. /* RTTI */
  189. /************************************************************************/
  190. public:
  191. friend class ManagedSerializableAssemblyInfoRTTI;
  192. static RTTITypeBase* getRTTIStatic();
  193. virtual RTTITypeBase* getRTTI() const;
  194. };
  195. }