BsManagedSerializableList.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsIReflectable.h"
  4. #include <mono/jit/jit.h>
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief TODO
  9. *
  10. * @note This class can be in two states:
  11. * - Linked - When the object has a link to a managed object. This is the default
  12. * state when a new instance of ManagedSerializableObject is created.
  13. * Any operations during this state will operate directly on the linked
  14. * managed object.
  15. * - Serialized - When the object has no link to the managed object but instead just
  16. * contains cached object and field data that may be used for initializing
  17. * a managed object. Any operations during this state will operate
  18. * only on the cached internal data.
  19. * You can transfer between these states by calling serialize(linked->serialized) &
  20. *
  21. */
  22. class BS_SCR_BE_EXPORT ManagedSerializableList : public IReflectable
  23. {
  24. private:
  25. struct ConstructPrivately {};
  26. public:
  27. ManagedSerializableList(const ConstructPrivately& dummy, const ManagedSerializableTypeInfoListPtr& typeInfo, MonoObject* managedInstance);
  28. ManagedSerializableList(const ConstructPrivately& dummy);
  29. MonoObject* getManagedInstance() const { return mManagedInstance; }
  30. ManagedSerializableTypeInfoListPtr getTypeInfo() const { return mListTypeInfo; }
  31. void resize(UINT32 newSize);
  32. void setFieldData(UINT32 arrayIdx, const ManagedSerializableFieldDataPtr& val);
  33. ManagedSerializableFieldDataPtr getFieldData(UINT32 arrayIdx);
  34. UINT32 getLength() const { return mNumElements; }
  35. void serialize();
  36. void deserialize();
  37. static ManagedSerializableListPtr createFromExisting(MonoObject* managedInstance, const ManagedSerializableTypeInfoListPtr& typeInfo);
  38. static ManagedSerializableListPtr createNew(const ManagedSerializableTypeInfoListPtr& typeInfo, UINT32 size);
  39. static MonoObject* createManagedInstance(const ManagedSerializableTypeInfoListPtr& typeInfo, UINT32 size);
  40. protected:
  41. MonoObject* mManagedInstance;
  42. MonoMethod* mAddMethod;
  43. MonoMethod* mAddRangeMethod;
  44. MonoMethod* mClearMethod;
  45. MonoMethod* mCopyToMethod;
  46. MonoProperty* mItemProp;
  47. MonoProperty* mCountProp;
  48. ManagedSerializableTypeInfoListPtr mListTypeInfo;
  49. Vector<ManagedSerializableFieldDataPtr> mCachedEntries;
  50. UINT32 mNumElements;
  51. void initMonoObjects(MonoClass* listClass);
  52. UINT32 getLengthInternal() const;
  53. void addFieldDataInternal(const ManagedSerializableFieldDataPtr& val);
  54. /************************************************************************/
  55. /* RTTI */
  56. /************************************************************************/
  57. static ManagedSerializableListPtr createEmpty();
  58. public:
  59. friend class ManagedSerializableListRTTI;
  60. static RTTITypeBase* getRTTIStatic();
  61. virtual RTTITypeBase* getRTTI() const;
  62. };
  63. }