BsRTTIType.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. #pragma once
  2. #include <string>
  3. #include <algorithm>
  4. #include <unordered_map>
  5. #include "BsPrerequisitesUtil.h"
  6. #include "BsManagedDataBlock.h"
  7. #include "BsRTTIField.h"
  8. #include "BsRTTIPlainField.h"
  9. #include "BsRTTIReflectableField.h"
  10. #include "BsRTTIReflectablePtrField.h"
  11. #include "BsRTTIManagedDataBlockField.h"
  12. #include "BsIReflectable.h"
  13. namespace BansheeEngine
  14. {
  15. #define BS_SETGET_MEMBER(name, type, parentType) \
  16. type##& get##name(parentType##* obj) { return obj->##name; } \
  17. void Set##name(parentType##* obj, type##& val) { obj->##name = val; }
  18. #define BS_ADD_PLAINFIELD(name, id, parentType) \
  19. addPlainField(#name, id##, &##parentType##::get##name, &##parentType##::Set##name);
  20. /**
  21. * @brief Provides an interface for accessing fields of a certain class.
  22. * Data can be easily accessed by getter and setter methods.
  23. *
  24. * Supported data types:
  25. * - Plain types - All types defined in BsRTTIField.h, mostly native types and POD (plain old data) structs. Data is parsed byte by byte.
  26. * No pointers to plain types are supported. Data is passed around by value.
  27. * - Reflectable types - Any class deriving from IReflectable. Data is parsed based on fields in its RTTI class. Can be pointer or value type.
  28. * - Arrays of both plain and reflectable types are supported
  29. * - Data blocks - A managed or unmanaged block of data. See BsManagedDataBlock.h
  30. */
  31. class BS_UTILITY_EXPORT RTTITypeBase
  32. {
  33. public:
  34. RTTITypeBase();
  35. virtual ~RTTITypeBase();
  36. /**
  37. * @brief Returns RTTI type information for all classes that derive from the class
  38. * that owns this RTTI type.
  39. */
  40. virtual Vector<RTTITypeBase*>& getDerivedClasses() = 0;
  41. /**
  42. * @brief Returns RTTI type information for the class that owns this RTTI type.
  43. * If the class has not base type, null is returned instead.
  44. */
  45. virtual RTTITypeBase* getBaseClass() = 0;
  46. /**
  47. * @brief Returns true if current RTTI class is derived from "base".
  48. * (Or if it is the same type as base)
  49. */
  50. virtual bool isDerivedFrom(RTTITypeBase* base) = 0;
  51. /**
  52. * @brief Internal method. Called by the RTTI system when a class is first found in
  53. * order to form child/parent class hierarchy.
  54. */
  55. virtual void _registerDerivedClass(RTTITypeBase* derivedClass) = 0;
  56. /**
  57. * @brief Creates a new instance of the class owning this RTTI type.
  58. */
  59. virtual std::shared_ptr<IReflectable> newRTTIObject() = 0;
  60. /**
  61. * @brief Returns the name of the class owning this RTTI type.
  62. */
  63. virtual const String& getRTTIName() = 0;
  64. /**
  65. * @brief Returns an RTTI id that uniquely represents each class in the RTTI
  66. * system.
  67. */
  68. virtual UINT32 getRTTIId() = 0;
  69. /**
  70. * @brief Called by the serializers when serialization for this object has started.
  71. * Use this to do any preprocessing on data you might need during serialization itself.
  72. */
  73. virtual void onSerializationStarted(IReflectable* obj) {}
  74. /**
  75. * @brief Called by the serializers when serialization for this object has ended.
  76. * After serialization has ended you can be sure that the type has been fully serialized,
  77. * and you may clean up any temporary data.
  78. */
  79. virtual void onSerializationEnded(IReflectable* obj) {}
  80. /**
  81. * @brief Called by the serializers when deserialization for this object has started.
  82. * Use this to do any preprocessing on data you might need during deserialization itself.
  83. */
  84. virtual void onDeserializationStarted(IReflectable* obj) {}
  85. /**
  86. * @brief Called by the serializers when deserialization for this object has ended.
  87. * At this point you can be sure the instance has been fully deserialized and you
  88. * may safely use it.
  89. *
  90. * One exception being are fields you marked with "WeakRef" flag, as they might be resolved
  91. * only after deserialization has fully completed for all objects.
  92. */
  93. virtual void onDeserializationEnded(IReflectable* obj) {}
  94. /**
  95. * @brief Allows you to assign a value to a plain field with the specified name on
  96. * the provided instance.
  97. *
  98. * @note Caller must ensure instance and value types are valid for this field.
  99. */
  100. template <class ObjectType, class DataType>
  101. void setPlainValue(ObjectType* object, const String& name, DataType& value)
  102. {
  103. RTTIField* genericField = findField(name);
  104. genericField->checkIsPlain(false);
  105. RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
  106. UINT32 typeSize = 0;
  107. if(RTTIPlainType<DataType>::hasDynamicSize)
  108. typeSize = RTTIPlainType<DataType>::getDynamicSize(value);
  109. else
  110. typeSize = sizeof(DataType);
  111. UINT8* tempBuffer = (UINT8*)stackAlloc(typeSize);
  112. RTTIPlainType<DataType>::toMemory(value, (char*)tempBuffer);
  113. field->fromBuffer(object, tempBuffer);
  114. stackDeallocLast(tempBuffer);
  115. }
  116. /**
  117. * @brief Allows you to assign a value to a plain field array element with the
  118. * specified name and index on the provided instance.
  119. *
  120. * @note Caller must ensure instance and value types are valid for this field.
  121. */
  122. template <class ObjectType, class DataType>
  123. void setPlainArrayValue(ObjectType* object, const String& name, UINT32 index, DataType& value)
  124. {
  125. RTTIField* genericField = findField(name);
  126. genericField->checkIsPlain(true);
  127. RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
  128. UINT32 typeSize = 0;
  129. if(RTTIPlainType<DataType>::hasDynamicSize)
  130. typeSize = RTTIPlainType<DataType>::getDynamicSize(value);
  131. else
  132. typeSize = sizeof(DataType);
  133. UINT8* tempBuffer = (UINT8*)stackAlloc(typeSize);
  134. RTTIPlainType<DataType>::toMemory(value, (char*)tempBuffer);
  135. field->arrayElemFromBuffer(object, index, tempBuffer);
  136. stackDeallocLast(tempBuffer);
  137. }
  138. /**
  139. * @brief Allows you to assign a value to a reflectable field with the specified name on
  140. * the provided instance.
  141. *
  142. * @note Caller must ensure instance and value types are valid for this field.
  143. */
  144. template <class ObjectType, class DataType>
  145. void setReflectableValue(ObjectType* object, const String& name, DataType& value)
  146. {
  147. static_assert((std::is_base_of<BansheeEngine::IReflectable, DataType>::value),
  148. "Invalid data type for complex field. It needs to derive from BansheeEngine::IReflectable.");
  149. RTTIField* genericField = findField(name);
  150. genericField->checkIsComplex(false);
  151. RTTIReflectableFieldBase* field = static_cast<RTTIReflectableFieldBase*>(genericField);
  152. field->setValue(object, value);
  153. }
  154. /**
  155. * @brief Allows you to assign a value to a reflectable field array element with the
  156. * specified name and index on the provided instance.
  157. *
  158. * @note Caller must ensure instance and value types are valid for this field.
  159. */
  160. template <class ObjectType, class DataType>
  161. void setReflectableArrayValue(ObjectType* object, const String& name, UINT32 index, DataType& value)
  162. {
  163. static_assert((std::is_base_of<BansheeEngine::IReflectable, DataType>::value),
  164. "Invalid data type for complex field. It needs to derive from BansheeEngine::IReflectable.");
  165. RTTIField* genericField = findField(name);
  166. genericField->checkIsComplex(true);
  167. RTTIReflectableFieldBase* field = static_cast<RTTIReflectableFieldBase*>(genericField);
  168. field->setArrayValue(object, index, value);
  169. }
  170. /**
  171. * @brief Allows you to assign a value to a managed data block field with the specified name on
  172. * the provided instance.
  173. *
  174. * @note Caller must ensure instance type is valid for this field.
  175. */
  176. template <class ObjectType>
  177. void setDataBlockValue(ObjectType* object, const String& name, ManagedDataBlock value)
  178. {
  179. RTTIField* genericField = findField(name);
  180. genericField->checkIsDataBlock();
  181. RTTIManagedDataBlockFieldBase* field = static_cast<RTTIManagedDataBlockFieldBase*>(genericField);
  182. field->setValue(object, value);
  183. }
  184. /**
  185. * @brief Allows you to assign a value to a reflectable pointer field with the specified name on
  186. * the provided instance.
  187. *
  188. * @note Caller must ensure instance and value types are valid for this field.
  189. */
  190. template <class ObjectType, class DataType>
  191. void setReflectablePtrValue(ObjectType* object, const String& name, std::shared_ptr<DataType> value)
  192. {
  193. static_assert((std::is_base_of<BansheeEngine::IReflectable, DataType>::value),
  194. "Invalid data type for complex field. It needs to derive from BansheeEngine::IReflectable.");
  195. RTTIField* genericField = findField(name);
  196. genericField->checkIsComplexPtr(false);
  197. RTTIReflectablePtrFieldBase* field = static_cast<RTTIReflectablePtrFieldBase*>(genericField);
  198. field->setValue(object, value);
  199. }
  200. /**
  201. * @brief Allows you to assign a value to a reflectable pointer field array element with the
  202. * specified name and index on the provided instance.
  203. *
  204. * @note Caller must ensure instance and value types are valid for this field.
  205. */
  206. template <class ObjectType, class DataType>
  207. void setReflectablePtrArrayValue(ObjectType* object, const String& name, UINT32 index, std::shared_ptr<DataType> value)
  208. {
  209. static_assert((std::is_base_of<BansheeEngine::IReflectable, DataType>::value),
  210. "Invalid data type for complex field. It needs to derive from BansheeEngine::IReflectable.");
  211. RTTIField* genericField = findField(name);
  212. genericField->checkIsComplexPtr(true);
  213. RTTIReflectablePtrFieldBase* field = static_cast<RTTIReflectablePtrFieldBase*>(genericField);
  214. field->setArrayValue(object, index, value);
  215. }
  216. /**
  217. * @brief Reads a value from a plain field with the specified name from the provided instance.
  218. *
  219. * @note Caller must ensure instance and value types are valid for this field.
  220. */
  221. template <class ObjectType, class DataType>
  222. void getPlainValue(ObjectType* object, const String& name, DataType& value)
  223. {
  224. RTTIField* genericField = findField(name);
  225. genericField->checkIsPlain(false);
  226. RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
  227. UINT32 typeSize = 0;
  228. if(field->hasDynamicSize())
  229. typeSize = field->getDynamicSize(object);
  230. else
  231. typeSize = field->getTypeSize();
  232. UINT8* tempBuffer = (UINT8*)stackAlloc(typeSize);
  233. field->toBuffer(object, tempBuffer);
  234. RTTIPlainType<DataType>::fromMemory(value, (char*)tempBuffer);
  235. stackDeallocLast(tempBuffer);
  236. }
  237. /**
  238. * @brief Reads a value from a plain array field with the specified name and index from the provided instance.
  239. *
  240. * @note Caller must ensure instance and value types are valid for this field.
  241. */
  242. template <class ObjectType, class DataType>
  243. void getPlainArrayValue(ObjectType* object, const String& name, UINT32 index, DataType& value)
  244. {
  245. RTTIField* genericField = findField(name);
  246. genericField->checkIsPlain(true);
  247. RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
  248. UINT32 typeSize = 0;
  249. if(field->hasDynamicSize())
  250. typeSize = field->getArrayElemDynamicSize(object, arrIdx);
  251. else
  252. typeSize = field->getTypeSize();
  253. UINT8* tempBuffer = (UINT8*)stackAlloc(typeSize);
  254. field->arrayElemToBuffer(object, index, tempBuffer);
  255. RTTIPlainType<DataType>::fromMemory(value, (char*)tempBuffer);
  256. stackDeallocLast(tempBuffer);
  257. }
  258. /**
  259. * @brief Reads a value from a reflectable object field with the specified name from the provided instance.
  260. *
  261. * @note Caller must ensure instance and value types are valid for this field.
  262. */
  263. template <class ObjectType>
  264. IReflectable& getReflectableValue(ObjectType* object, const String& name)
  265. {
  266. RTTIField* genericField = findField(name);
  267. genericField->checkIsComplex(false);
  268. RTTIReflectableFieldBase* field = static_cast<RTTIReflectableFieldBase*>(genericField);
  269. return field->getValue(object);
  270. }
  271. /**
  272. * @brief Reads a value from a reflectable object array field with the specified name and index from the provided instance.
  273. *
  274. * @note Caller must ensure instance and value types are valid for this field.
  275. */
  276. template <class ObjectType>
  277. IReflectable& getReflectableArrayValue(ObjectType* object, const String& name, UINT32 index)
  278. {
  279. RTTIField* genericField = findField(name);
  280. genericField->checkIsComplex(true);
  281. RTTIReflectableFieldBase* field = static_cast<RTTIReflectableFieldBase*>(genericField);
  282. return field->getArrayValue(object, index);
  283. }
  284. /**
  285. * @brief Reads a managed data block field with the specified name from the provided instance.
  286. *
  287. * @note Caller must ensure instance type is valid for this field.
  288. */
  289. template <class ObjectType>
  290. ManagedDataBlock getDataBlockValue(ObjectType* object, const String& name)
  291. {
  292. RTTIField* genericField = findField(name);
  293. genericField->checkIsDataBlock();
  294. RTTIManagedDataBlockFieldBase* field = static_cast<RTTIManagedDataBlockFieldBase*>(genericField);
  295. return field->getValue(object);
  296. }
  297. /**
  298. * @brief Reads a value from a reflectable object pointer field with the specified name from the provided instance.
  299. *
  300. * @note Caller must ensure instance and value types are valid for this field.
  301. */
  302. template <class ObjectType>
  303. std::shared_ptr<IReflectable> getReflectablePtrValue(ObjectType* object, const String& name)
  304. {
  305. RTTIField* genericField = findField(name);
  306. genericField->checkIsComplexPtr(false);
  307. RTTIReflectablePtrFieldBase* field = static_cast<RTTIReflectablePtrFieldBase*>(genericField);
  308. return field->getValue(object);
  309. }
  310. /**
  311. * @brief Reads a value from a reflectable pointer array field with the specified name and index from the provided instance.
  312. *
  313. * @note Caller must ensure instance and value types are valid for this field.
  314. */
  315. template <class ObjectType>
  316. std::shared_ptr<IReflectable> getReflectablePtrArrayValue(ObjectType* object, const String& name, UINT32 index)
  317. {
  318. RTTIField* genericField = findField(name);
  319. genericField->checkIsComplexPtr(true);
  320. RTTIReflectablePtrFieldBase* field = static_cast<RTTIReflectablePtrFieldBase*>(genericField);
  321. return field->getArrayValue(object, index);
  322. }
  323. /**
  324. * @brief Returns the size of the array of the field with the specified name on the provided instance.
  325. *
  326. * @note Caller must ensure instance type is valid and that the field as an array.
  327. */
  328. template <class ObjectType>
  329. UINT32 getArraySize(ObjectType* object, const String& name)
  330. {
  331. RTTIField* field = findField(name);
  332. return field->getArraySize(object);
  333. }
  334. /**
  335. * @brief Sets the size of the array of the field with the specified name on the provided instance.
  336. *
  337. * @note Caller must ensure instance type is valid and that the field as an array.
  338. * This might clear any existing data from the array.
  339. */
  340. template <class ObjectType>
  341. void setArraySize(ObjectType* object, const String& name, UINT32 size)
  342. {
  343. RTTIField* field = findField(name);
  344. field->setArraySize(object, size);
  345. }
  346. /**
  347. * @brief Returns the total number of fields in this RTTI type.
  348. */
  349. UINT32 getNumFields() { return (UINT32)mFields.size(); }
  350. /**
  351. * @brief Returns a field based on the field index. Use "getNumFields" to
  352. * get total number of fields available.
  353. */
  354. RTTIField* getField(UINT32 idx) { return mFields.at(idx); }
  355. /**
  356. * @brief Tries to find a field with the specified name. Throws an exception if it can't.
  357. *
  358. * @param name The name of the field.
  359. */
  360. RTTIField* findField(const String& name);
  361. /**
  362. * @brief Tries to find a field with the specified unique ID. Doesn't throw an exception
  363. * if it can't find the field (Unlike findField(name)).
  364. *
  365. * @param uniqueFieldId Unique identifier for the field.
  366. *
  367. * @return nullptr if it can't find the field.
  368. */
  369. RTTIField* findField(int uniqueFieldId);
  370. protected:
  371. /**
  372. * @brief Tries to add a new field to the fields array, and throws an exception
  373. * if a field with the same name or id already exists.
  374. *
  375. * @param [in] field Field, must be non-null.
  376. */
  377. void addNewField(RTTIField* field);
  378. /**
  379. * @brief Checks if the templated DataType has any references back to us, that aren't weak.
  380. *
  381. * @note This method assumes this class holds a non-weak reference to DataType.
  382. * DataType must derive from IReflectable and implement getRTTIStatic method.
  383. */
  384. template<class DataType>
  385. void checkForCircularReferences()
  386. {
  387. RTTITypeBase* type = DataType::getRTTIStatic();
  388. for(UINT32 i = 0; i < type->getNumFields(); i++)
  389. {
  390. RTTIField* field = type->getField(i);
  391. if(!field->isReflectablePtrType())
  392. continue;
  393. RTTIReflectablePtrFieldBase* reflectablePtrField = static_cast<RTTIReflectablePtrFieldBase*>(field);
  394. if(reflectablePtrField->getRTTIId() == getRTTIId() && ((reflectablePtrField->getFlags() & RTTI_Flag_WeakRef) == 0))
  395. {
  396. throwCircularRefException(getRTTIName(), reflectablePtrField->getRTTIName());
  397. }
  398. }
  399. }
  400. /**
  401. * @brief Throws an exception warning the user that a circular reference was found.
  402. *
  403. * @note Only a separate function so I don't need to include BsException header.
  404. */
  405. void throwCircularRefException(const String& myType, const String& otherType) const;
  406. private:
  407. Vector<RTTIField*> mFields;
  408. };
  409. /**
  410. * @brief Used for initializing a certain type as soon as the program is loaded.
  411. */
  412. template<typename Type, typename BaseType>
  413. struct InitRTTIOnStart
  414. {
  415. public:
  416. InitRTTIOnStart()
  417. {
  418. BaseType::getRTTIStatic()->_registerDerivedClass(Type::getRTTIStatic());
  419. }
  420. void makeSureIAmInstantiated() { }
  421. };
  422. /**
  423. * @brief Specialization for root class of RTTI hierarchy - IReflectable
  424. */
  425. template<typename Type>
  426. struct InitRTTIOnStart<Type, IReflectable>
  427. {
  428. public:
  429. InitRTTIOnStart()
  430. {
  431. IReflectable::_registerDerivedClass(Type::getRTTIStatic());
  432. }
  433. void makeSureIAmInstantiated() { }
  434. };
  435. /**
  436. * @brief Template that returns RTTI type of the specified type, unless the specified
  437. * type is IReflectable in which case it returns a null.
  438. */
  439. template<typename Type>
  440. struct GetRTTIType
  441. {
  442. RTTITypeBase* operator()() { return Type::getRTTIStatic(); }
  443. };
  444. /**
  445. * @brief Specialization for root class of RTTI hierarchy - IReflectable
  446. */
  447. template<>
  448. struct GetRTTIType<IReflectable>
  449. {
  450. RTTITypeBase* operator()() { return nullptr; }
  451. };
  452. /**
  453. * @brief Allows you to provide a run-time type information for a specific class, along with
  454. * support for serialization/deserialization.
  455. *
  456. * Derive from this class and return the that class from IReflectable::getRTTI.
  457. * This way you can separate serialization logic from the actual class you're serializing.
  458. *
  459. * This class will provide a way to register individual fields in the class, together with ways to
  460. * read and write them, as well a providing information about class hierarchy, and run-time type checking.
  461. */
  462. template <typename Type, typename BaseType, typename MyRTTIType>
  463. class RTTIType : public RTTITypeBase
  464. {
  465. protected:
  466. /************************************************************************/
  467. /* RTTI CLASS META DATA */
  468. /************************************************************************/
  469. static InitRTTIOnStart<Type, BaseType> initOnStart;
  470. public:
  471. RTTIType()
  472. {
  473. // Compiler will only generate code for stuff that is directly used, including static data members,
  474. // so we fool it here like we're using the class directly. Otherwise compiler won't generate the code for the member
  475. // and our type won't get initialized on start (Actual behavior is a bit more random)
  476. initOnStart.makeSureIAmInstantiated();
  477. }
  478. virtual ~RTTIType() {}
  479. /**
  480. * @brief Returns a singleton of this RTTI type.
  481. */
  482. static MyRTTIType* instance()
  483. {
  484. static MyRTTIType inst;
  485. return &inst;
  486. }
  487. /**
  488. * @copydoc RTTITypeBase::getDerivedClasses
  489. */
  490. virtual Vector<RTTITypeBase*>& getDerivedClasses()
  491. {
  492. static Vector<RTTITypeBase*> mRTTIDerivedClasses;
  493. return mRTTIDerivedClasses;
  494. }
  495. /**
  496. * @copydoc RTTITypeBase::getBaseClass
  497. */
  498. virtual RTTITypeBase* getBaseClass()
  499. {
  500. return GetRTTIType<BaseType>()();
  501. }
  502. /**
  503. * @copydoc RTTITypeBase::isDerivedFrom
  504. */
  505. bool RTTITypeBase::isDerivedFrom(RTTITypeBase* base)
  506. {
  507. assert(base != nullptr);
  508. Stack<RTTITypeBase*> todo;
  509. todo.push(base);
  510. while (!todo.empty())
  511. {
  512. RTTITypeBase* currentType = todo.top();
  513. todo.pop();
  514. if (currentType->getRTTIId() == getRTTIId())
  515. return true;
  516. Vector<RTTITypeBase*>& derivedClasses = currentType->getDerivedClasses();
  517. for (auto iter = derivedClasses.begin(); iter != derivedClasses.end(); ++iter)
  518. todo.push(*iter);
  519. }
  520. return false;
  521. }
  522. /**
  523. * @copydoc RTTITypeBase::_registerDerivedClass
  524. */
  525. virtual void _registerDerivedClass(RTTITypeBase* derivedClass)
  526. {
  527. if(IReflectable::_isTypeIdDuplicate(derivedClass->getRTTIId()))
  528. {
  529. BS_EXCEPT(InternalErrorException, "RTTI type \"" + derivedClass->getRTTIName() +
  530. "\" has a duplicate ID: " + toString(derivedClass->getRTTIId()));
  531. }
  532. getDerivedClasses().push_back(derivedClass);
  533. }
  534. /************************************************************************/
  535. /* FIELDS OPERATING DIRECTLY ON SERIALIZABLE OBJECT */
  536. /************************************************************************/
  537. /**
  538. * @brief Registers a new plain field. This field can then be accessed dynamically from the RTTI system and
  539. * used for automatic serialization. See RTTIField for more information about field types.
  540. *
  541. * @param name Name of the field.
  542. * @param uniqueId Unique identifier for this field. Although name is also a unique
  543. * identifier we want a small data type that can be used for efficiently
  544. * serializing data to disk and similar. It is primarily used for compatibility
  545. * between different versions of serialized data.
  546. * @param getter Method used for retrieving the value of this field.
  547. * @param setter Method used for setting the value of this field.
  548. * @param flags Various flags you can use to specialize how systems handle this field. See RTTIFieldFlag.
  549. */
  550. template<class ObjectType, class DataType>
  551. void addPlainField(const String& name, UINT32 uniqueId, DataType& (ObjectType::*getter)(),
  552. void (ObjectType::*setter)(DataType&) = nullptr, UINT64 flags = 0)
  553. {
  554. addPlainField<ObjectType, DataType>(name, uniqueId,
  555. std::function<DataType&(ObjectType*)>(getter),
  556. std::function<void(ObjectType*, DataType&)>(setter), flags);
  557. }
  558. /**
  559. * @brief Registers a new reflectable object field. This field can then be accessed dynamically from the RTTI system and
  560. * used for automatic serialization. See RTTIField for more information about field types.
  561. *
  562. * @param name Name of the field.
  563. * @param uniqueId Unique identifier for this field. Although name is also a unique
  564. * identifier we want a small data type that can be used for efficiently
  565. * serializing data to disk and similar. It is primarily used for compatibility
  566. * between different versions of serialized data.
  567. * @param getter Method used for retrieving the value of this field.
  568. * @param setter Method used for setting the value of this field.
  569. * @param flags Various flags you can use to specialize how systems handle this field. See RTTIFieldFlag.
  570. */
  571. template<class ObjectType, class DataType>
  572. void addReflectableField(const String& name, UINT32 uniqueId, DataType& (ObjectType::*getter)(),
  573. void (ObjectType::*setter)(DataType&) = nullptr, UINT64 flags = 0)
  574. {
  575. addReflectableField<ObjectType, DataType>(name, uniqueId,
  576. std::function<DataType&(ObjectType*)>(getter),
  577. std::function<void(ObjectType*, DataType&)>(setter), flags);
  578. }
  579. /**
  580. * @brief Registers a new reflectable object pointer field. This field can then be accessed dynamically from the RTTI system and
  581. * used for automatic serialization. See RTTIField for more information about field types.
  582. *
  583. * @param name Name of the field.
  584. * @param uniqueId Unique identifier for this field. Although name is also a unique
  585. * identifier we want a small data type that can be used for efficiently
  586. * serializing data to disk and similar. It is primarily used for compatibility
  587. * between different versions of serialized data.
  588. * @param getter Method used for retrieving the value of this field.
  589. * @param setter Method used for setting the value of this field.
  590. * @param flags Various flags you can use to specialize how systems handle this field. See RTTIFieldFlag.
  591. */
  592. template<class ObjectType, class DataType>
  593. void addReflectablePtrField(const String& name, UINT32 uniqueId, std::shared_ptr<DataType> (ObjectType::*getter)(),
  594. void (ObjectType::*setter)(std::shared_ptr<DataType>) = nullptr, UINT64 flags = 0)
  595. {
  596. addReflectablePtrField<ObjectType, DataType>(name, uniqueId,
  597. std::function<std::shared_ptr<DataType>(ObjectType*)>(getter),
  598. std::function<void(ObjectType*, std::shared_ptr<DataType>)>(setter), flags);
  599. }
  600. /**
  601. * @brief Registers a new field containg an array of plain values. This field can then be accessed dynamically from the RTTI system and
  602. * used for automatic serialization. See RTTIField for more information about field types.
  603. *
  604. * @param name Name of the field.
  605. * @param uniqueId Unique identifier for this field. Although name is also a unique
  606. * identifier we want a small data type that can be used for efficiently
  607. * serializing data to disk and similar. It is primarily used for compatibility
  608. * between different versions of serialized data.
  609. * @param getter Method used for retrieving a single element of the array.
  610. * @param getSize Getter method that returns the size of the array.
  611. * @param setter Method used for setting the a single element of the field.
  612. * @param setSize Setter method that allows you to resize the array.
  613. * @param flags Various flags you can use to specialize how systems handle this field. See RTTIFieldFlag.
  614. */
  615. template<class ObjectType, class DataType>
  616. void addPlainArrayField(const String& name, UINT32 uniqueId, DataType& (ObjectType::*getter)(UINT32), UINT32 (ObjectType::*getSize)(),
  617. void (ObjectType::*setter)(UINT32, DataType&) = nullptr, void(ObjectType::*setSize)(UINT32) = nullptr, UINT64 flags = 0)
  618. {
  619. addPlainArrayField<ObjectType, DataType>(name, uniqueId,
  620. std::function<DataType&(ObjectType*, UINT32)>(getter),
  621. std::function<UINT32(ObjectType*)>(getSize),
  622. std::function<void(ObjectType*, UINT32, DataType&)>(setter),
  623. std::function<void(ObjectType*, UINT32)>(setSize), flags);
  624. }
  625. /**
  626. * @brief Registers a new field containg an array of reflectable object values. This field can then be accessed
  627. * dynamically from the RTTI system and used for automatic serialization. See RTTIField for more information
  628. * about field types.
  629. *
  630. * @param name Name of the field.
  631. * @param uniqueId Unique identifier for this field. Although name is also a unique
  632. * identifier we want a small data type that can be used for efficiently
  633. * serializing data to disk and similar. It is primarily used for compatibility
  634. * between different versions of serialized data.
  635. * @param getter Method used for retrieving a single element of the array.
  636. * @param getSize Getter method that returns the size of the array.
  637. * @param setter Method used for setting the a single element of the field.
  638. * @param setSize Setter method that allows you to resize the array.
  639. * @param flags Various flags you can use to specialize how systems handle this field. See RTTIFieldFlag.
  640. */
  641. template<class ObjectType, class DataType>
  642. void addReflectableArrayField(const String& name, UINT32 uniqueId, DataType& (ObjectType::*getter)(UINT32), UINT32 (ObjectType::*getSize)(),
  643. void (ObjectType::*setter)(UINT32, DataType&) = nullptr, void(ObjectType::*setSize)(UINT32) = nullptr, UINT64 flags = 0)
  644. {
  645. addReflectableArrayField<ObjectType, DataType>(name, uniqueId,
  646. std::function<DataType&(ObjectType*, UINT32)>(getter),
  647. std::function<UINT32(ObjectType*)>(getSize),
  648. std::function<void(ObjectType*, UINT32, DataType&)>(setter),
  649. std::function<void(ObjectType*, UINT32)>(setSize), flags);
  650. }
  651. /**
  652. * @brief Registers a new field containg an array of reflectable obejct pointers. This field can then be accessed
  653. * dynamically from the RTTI system and used for automatic serialization. See RTTIField for more information
  654. * about field types.
  655. *
  656. * @param name Name of the field.
  657. * @param uniqueId Unique identifier for this field. Although name is also a unique
  658. * identifier we want a small data type that can be used for efficiently
  659. * serializing data to disk and similar. It is primarily used for compatibility
  660. * between different versions of serialized data.
  661. * @param getter Method used for retrieving a single element of the array.
  662. * @param getSize Getter method that returns the size of the array.
  663. * @param setter Method used for setting the a single element of the field.
  664. * @param setSize Setter method that allows you to resize the array.
  665. * @param flags Various flags you can use to specialize how systems handle this field. See RTTIFieldFlag.
  666. */
  667. template<class ObjectType, class DataType>
  668. void addReflectablePtrArrayField(const String& name, UINT32 uniqueId, std::shared_ptr<DataType> (ObjectType::*getter)(UINT32), UINT32 (ObjectType::*getSize)(),
  669. void (ObjectType::*setter)(UINT32, std::shared_ptr<DataType>) = nullptr, void(ObjectType::*setSize)(UINT32) = nullptr, UINT64 flags = 0)
  670. {
  671. addReflectablePtrArrayField<ObjectType, DataType>(name, uniqueId,
  672. std::function<std::shared_ptr<DataType>(ObjectType*, UINT32)>(getter),
  673. std::function<UINT32(ObjectType*)>(getSize),
  674. std::function<void(ObjectType*, UINT32, std::shared_ptr<DataType>)>(setter),
  675. std::function<void(ObjectType*, UINT32)>(setSize), flags);
  676. }
  677. /**
  678. * @brief Registers a new managed data block field. This field can then be accessed dynamically from the RTTI system and
  679. * used for automatic serialization. See RTTIField for more information about field types.
  680. *
  681. * @param name Name of the field.
  682. * @param uniqueId Unique identifier for this field. Although name is also a unique
  683. * identifier we want a small data type that can be used for efficiently
  684. * serializing data to disk and similar. It is primarily used for compatibility
  685. * between different versions of serialized data.
  686. * @param getter Method used for retrieving the value of this field.
  687. * @param setter Method used for setting the value of this field.
  688. * @param flags Various flags you can use to specialize how systems handle this field. See RTTIFieldFlag.
  689. */
  690. template<class ObjectType>
  691. void addDataBlockField(const String& name, UINT32 uniqueId, ManagedDataBlock (ObjectType::*getter)(),
  692. void (ObjectType::*setter)(ManagedDataBlock) = nullptr, UINT64 flags = 0, UINT8* (customAllocator)(ObjectType*, UINT32) = 0)
  693. {
  694. addDataBlockField<ObjectType>(name, uniqueId,
  695. std::function<ManagedDataBlock(ObjectType*)>(getter),
  696. std::function<void(ObjectType*, ManagedDataBlock)>(setter), flags, customAllocator);
  697. }
  698. protected:
  699. virtual void initSerializableFields() {}
  700. /************************************************************************/
  701. /* FIELDS OPERATING ON DERIVED SERIALIZATION INTERFACE */
  702. /* (Needs an extra pointer to the actual object) */
  703. /************************************************************************/
  704. template<class InterfaceType, class ObjectType, class DataType>
  705. void addPlainField(const String& name, UINT32 uniqueId,
  706. DataType& (InterfaceType::*getter)(ObjectType*),
  707. void (InterfaceType::*setter)(ObjectType*, DataType&), UINT64 flags = 0)
  708. {
  709. using namespace std::placeholders;
  710. static_assert((std::is_base_of<BansheeEngine::RTTIType<Type, BaseType, MyRTTIType>, InterfaceType>::value),
  711. "Class with the get/set methods must derive from BansheeEngine::RTTIType.");
  712. static_assert(!(std::is_base_of<BansheeEngine::IReflectable, DataType>::value),
  713. "Data type derives from IReflectable but it is being added as a plain field.");
  714. addPlainField<ObjectType, DataType>(name, uniqueId,
  715. std::function<DataType&(ObjectType*)>(std::bind(getter, static_cast<InterfaceType*>(this), _1)),
  716. std::function<void(ObjectType*, DataType&)>(std::bind(setter, static_cast<InterfaceType*>(this), _1, _2)), flags);
  717. }
  718. template<class InterfaceType, class ObjectType, class DataType>
  719. void addReflectableField(const String& name, UINT32 uniqueId,
  720. DataType& (InterfaceType::*getter)(ObjectType*),
  721. void (InterfaceType::*setter)(ObjectType*, DataType&), UINT64 flags = 0)
  722. {
  723. using namespace std::placeholders;
  724. addReflectableField<ObjectType, DataType>(name, uniqueId,
  725. std::function<DataType&(ObjectType*)>(std::bind(getter, static_cast<InterfaceType*>(this), _1)),
  726. std::function<void(ObjectType*, DataType&)>(std::bind(setter, static_cast<InterfaceType*>(this), _1, _2)), flags);
  727. }
  728. template<class InterfaceType, class ObjectType, class DataType>
  729. void addReflectablePtrField(const String& name, UINT32 uniqueId,
  730. std::shared_ptr<DataType> (InterfaceType::*getter)(ObjectType*),
  731. void (InterfaceType::*setter)(ObjectType*, std::shared_ptr<DataType>), UINT64 flags = 0)
  732. {
  733. using namespace std::placeholders;
  734. addReflectablePtrField<ObjectType, DataType>(name, uniqueId,
  735. std::function<std::shared_ptr<DataType>(ObjectType*)>(std::bind(getter, static_cast<InterfaceType*>(this), _1)),
  736. std::function<void(ObjectType*, std::shared_ptr<DataType>)>(std::bind(setter, static_cast<InterfaceType*>(this), _1, _2)), flags);
  737. }
  738. template<class InterfaceType, class ObjectType, class DataType>
  739. void addPlainArrayField(const String& name, UINT32 uniqueId,
  740. DataType& (InterfaceType::*getter)(ObjectType*, UINT32),
  741. UINT32 (InterfaceType::*getSize)(ObjectType*),
  742. void (InterfaceType::*setter)(ObjectType*, UINT32, DataType&),
  743. void(InterfaceType::*setSize)(ObjectType*, UINT32), UINT64 flags = 0)
  744. {
  745. using namespace std::placeholders;
  746. static_assert((std::is_base_of<BansheeEngine::RTTIType<Type, BaseType, MyRTTIType>, InterfaceType>::value),
  747. "Class with the get/set methods must derive from BansheeEngine::RTTIType.");
  748. static_assert(!(std::is_base_of<BansheeEngine::IReflectable, DataType>::value),
  749. "Data type derives from IReflectable but it is being added as a plain field.");
  750. addPlainArrayField<ObjectType, DataType>(name, uniqueId,
  751. std::function<DataType&(ObjectType*, UINT32)>(std::bind(getter, static_cast<InterfaceType*>(this), _1, _2)),
  752. std::function<UINT32(ObjectType*)>(std::bind(getSize, static_cast<InterfaceType*>(this), _1)),
  753. std::function<void(ObjectType*, UINT32, DataType&)>(std::bind(setter, static_cast<InterfaceType*>(this), _1, _2, _3)),
  754. std::function<void(ObjectType*, UINT32)>(std::bind(setSize, static_cast<InterfaceType*>(this), _1, _2)), flags);
  755. }
  756. template<class InterfaceType, class ObjectType, class DataType>
  757. void addReflectableArrayField(const String& name, UINT32 uniqueId,
  758. DataType& (InterfaceType::*getter)(ObjectType*, UINT32),
  759. UINT32 (InterfaceType::*getSize)(ObjectType*),
  760. void (InterfaceType::*setter)(ObjectType*, UINT32, DataType&),
  761. void(InterfaceType::*setSize)(ObjectType*, UINT32), UINT64 flags = 0)
  762. {
  763. using namespace std::placeholders;
  764. addReflectableArrayField<ObjectType, DataType>(name, uniqueId,
  765. std::function<DataType&(ObjectType*, UINT32)>(std::bind(getter, static_cast<InterfaceType*>(this), _1, _2)),
  766. std::function<UINT32(ObjectType*)>(std::bind(getSize, static_cast<InterfaceType*>(this), _1)),
  767. std::function<void(ObjectType*, UINT32, DataType&)>(std::bind(setter, static_cast<InterfaceType*>(this), _1, _2, _3)),
  768. std::function<void(ObjectType*, UINT32)>(std::bind(setSize, static_cast<InterfaceType*>(this), _1, _2)), flags);
  769. }
  770. template<class InterfaceType, class ObjectType, class DataType>
  771. void addReflectablePtrArrayField(const String& name, UINT32 uniqueId,
  772. std::shared_ptr<DataType> (InterfaceType::*getter)(ObjectType*, UINT32),
  773. UINT32 (InterfaceType::*getSize)(ObjectType*),
  774. void (InterfaceType::*setter)(ObjectType*, UINT32, std::shared_ptr<DataType>),
  775. void(InterfaceType::*setSize)(ObjectType*, UINT32), UINT64 flags = 0)
  776. {
  777. using namespace std::placeholders;
  778. addReflectablePtrArrayField<ObjectType, DataType>(name, uniqueId,
  779. std::function<std::shared_ptr<DataType>(ObjectType*, UINT32)>(std::bind(getter, static_cast<InterfaceType*>(this), _1, _2)),
  780. std::function<UINT32(ObjectType*)>(std::bind(getSize, static_cast<InterfaceType*>(this), _1)),
  781. std::function<void(ObjectType*, UINT32, std::shared_ptr<DataType>)>(std::bind(setter, static_cast<InterfaceType*>(this), _1, _2, _3)),
  782. std::function<void(ObjectType*, UINT32)>(std::bind(setSize, static_cast<InterfaceType*>(this), _1, _2)), flags);
  783. }
  784. template<class InterfaceType, class ObjectType>
  785. void addDataBlockField(const String& name, UINT32 uniqueId, ManagedDataBlock (InterfaceType::*getter)(ObjectType*),
  786. void (InterfaceType::*setter)(ObjectType*, ManagedDataBlock), UINT64 flags = 0,
  787. UINT8* (customAllocator)(ObjectType*, UINT32) = 0)
  788. {
  789. using namespace std::placeholders;
  790. if(customAllocator != 0)
  791. {
  792. std::function<UINT8*(ObjectType*, UINT32)> customAllocFunc = std::bind(customAllocator, _1, _2);
  793. addDataBlockField<ObjectType>(name, uniqueId,
  794. std::function<ManagedDataBlock(ObjectType*)>(std::bind(getter, static_cast<InterfaceType*>(this), _1)),
  795. std::function<void(ObjectType*, ManagedDataBlock)>(std::bind(setter, static_cast<InterfaceType*>(this), _1, _2)), flags,
  796. customAllocFunc);
  797. }
  798. else
  799. {
  800. addDataBlockField<ObjectType>(name, uniqueId,
  801. std::function<ManagedDataBlock(ObjectType*)>(std::bind(getter, static_cast<InterfaceType*>(this), _1)),
  802. std::function<void(ObjectType*, ManagedDataBlock)>(std::bind(setter, static_cast<InterfaceType*>(this), _1, _2)), flags);
  803. }
  804. }
  805. private:
  806. template<class ObjectType, class DataType>
  807. void addPlainField(const String& name, UINT32 uniqueId, Any getter, Any setter, UINT64 flags)
  808. {
  809. RTTIPlainField<DataType, ObjectType>* newField =
  810. bs_new<RTTIPlainField<DataType, ObjectType>>();
  811. newField->initSingle(name, uniqueId, getter, setter, flags);
  812. addNewField(newField);
  813. }
  814. template<class ObjectType, class DataType>
  815. void addReflectableField(const String& name, UINT32 uniqueId, Any getter, Any setter, UINT64 flags)
  816. {
  817. static_assert((std::is_base_of<BansheeEngine::IReflectable, DataType>::value),
  818. "Invalid data type for complex field. It needs to derive from BansheeEngine::IReflectable.");
  819. RTTIReflectableField<DataType, ObjectType>* newField =
  820. bs_new<RTTIReflectableField<DataType, ObjectType>>();
  821. newField->initSingle(name, uniqueId, getter, setter, flags);
  822. addNewField(newField);
  823. }
  824. template<class ObjectType, class DataType>
  825. void addReflectablePtrField(const String& name, UINT32 uniqueId, Any getter, Any setter, UINT64 flags)
  826. {
  827. static_assert((std::is_base_of<BansheeEngine::IReflectable, DataType>::value),
  828. "Invalid data type for complex field. It needs to derive from BansheeEngine::IReflectable.");
  829. if((flags & RTTI_Flag_WeakRef) == 0)
  830. checkForCircularReferences<DataType>();
  831. RTTIReflectablePtrField<DataType, ObjectType>* newField =
  832. bs_new<RTTIReflectablePtrField<DataType, ObjectType>>();
  833. newField->initSingle(name, uniqueId, getter, setter, flags);
  834. addNewField(newField);
  835. }
  836. template<class ObjectType, class DataType>
  837. void addPlainArrayField(const String& name, UINT32 uniqueId, Any getter, Any getSize,
  838. Any setter, Any setSize, UINT64 flags)
  839. {
  840. RTTIPlainField<DataType, ObjectType>* newField =
  841. bs_new<RTTIPlainField<DataType, ObjectType>>();
  842. newField->initArray(name, uniqueId, getter, getSize, setter, setSize, flags);
  843. addNewField(newField);
  844. }
  845. template<class ObjectType, class DataType>
  846. void addReflectableArrayField(const String& name, UINT32 uniqueId, Any getter, Any getSize,
  847. Any setter, Any setSize, UINT64 flags)
  848. {
  849. static_assert((std::is_base_of<BansheeEngine::IReflectable, DataType>::value),
  850. "Invalid data type for complex field. It needs to derive from BansheeEngine::IReflectable.");
  851. RTTIReflectableField<DataType, ObjectType>* newField =
  852. bs_new<RTTIReflectableField<DataType, ObjectType>>();
  853. newField->initArray(name, uniqueId, getter, getSize, setter, setSize, flags);
  854. addNewField(newField);
  855. }
  856. template<class ObjectType, class DataType>
  857. void addReflectablePtrArrayField(const String& name, UINT32 uniqueId, Any getter, Any getSize,
  858. Any setter, Any setSize, UINT64 flags)
  859. {
  860. static_assert((std::is_base_of<BansheeEngine::IReflectable, DataType>::value),
  861. "Invalid data type for complex field. It needs to derive from BansheeEngine::IReflectable.");
  862. if((flags & RTTI_Flag_WeakRef) == 0)
  863. checkForCircularReferences<DataType>();
  864. RTTIReflectablePtrField<DataType, ObjectType>* newField =
  865. bs_new<RTTIReflectablePtrField<DataType, ObjectType>>();
  866. newField->initArray(name, uniqueId, getter, getSize, setter, setSize, flags);
  867. addNewField(newField);
  868. }
  869. template<class ObjectType>
  870. void addDataBlockField(const String& name, UINT32 uniqueId, Any getter, Any setter, UINT64 flags,
  871. Any customAllocator = Any())
  872. {
  873. RTTIManagedDataBlockField<ManagedDataBlock, ObjectType>* newField =
  874. bs_new<RTTIManagedDataBlockField<ManagedDataBlock, ObjectType>>();
  875. newField->initSingle(name, uniqueId, getter, setter, flags, customAllocator);
  876. addNewField(newField);
  877. }
  878. };
  879. template <typename Type, typename BaseType, typename MyRTTIType>
  880. InitRTTIOnStart<Type, BaseType> RTTIType<Type, BaseType, MyRTTIType>::initOnStart;
  881. /**
  882. * @brief Returns true if the provided object can be safely cast into type T.
  883. */
  884. template<class T>
  885. bool rtti_is_of_type(IReflectable* object)
  886. {
  887. static_assert((std::is_base_of<BansheeEngine::IReflectable, T>::value),
  888. "Invalid data type for type checking. It needs to derive from BansheeEngine::IReflectable.");
  889. return object->getTypeId() == T::getRTTIStatic()->getRTTIId();
  890. }
  891. /**
  892. * @brief Returns true if the provided object can be safely cast into type T.
  893. */
  894. template<class T>
  895. bool rtti_is_of_type(std::shared_ptr<IReflectable> object)
  896. {
  897. static_assert((std::is_base_of<BansheeEngine::IReflectable, T>::value),
  898. "Invalid data type for type checking. It needs to derive from BansheeEngine::IReflectable.");
  899. return object->getTypeId() == T::getRTTIStatic()->getRTTIId();
  900. }
  901. /**
  902. * @brief Creates a new object just from its type ID.
  903. */
  904. std::shared_ptr<IReflectable> rtti_create(UINT32 rttiId);
  905. /**
  906. * @brief Checks is the current object a subclass of some type.
  907. */
  908. template<class T>
  909. bool rtti_is_subclass(IReflectable* object)
  910. {
  911. static_assert((std::is_base_of<BansheeEngine::IReflectable, T>::value),
  912. "Invalid data type for type checking. It needs to derive from BansheeEngine::IReflectable.");
  913. return object->isDerivedFrom(T::getRTTIStatic());
  914. }
  915. }