BsManagedDataBlock.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #include "BsPrerequisitesUtil.h"
  3. namespace BansheeEngine
  4. {
  5. /** @addtogroup Serialization
  6. * @{
  7. */
  8. /**
  9. * Data block holding an array of bytes, usually used in serialization.
  10. *
  11. * Ownership of the data blocked is passed to the latest copy of the ManagedDataBlock. Data will be automatically
  12. * freed once the last copy is destroyed.
  13. */
  14. class BS_UTILITY_EXPORT ManagedDataBlock
  15. {
  16. public:
  17. /**
  18. * Constructor
  19. *
  20. * @param[in] data Array of bytes to store. Direct pointer to the provided array will be stored,
  21. * no copying will be done.
  22. * @param[in] size Size of the array, in bytes.
  23. */
  24. ManagedDataBlock(UINT8* data, UINT32 size);
  25. /**
  26. * Constructor that will automatically allocate an internal buffer of the specified size. Copying ManagedDataBlock
  27. * transfers ownership of the buffer to the copy of the buffer. Buffer is deleted when the latest copy is deleted.
  28. *
  29. * @param[in] size The size of the data in bytes.
  30. */
  31. ManagedDataBlock(UINT32 size);
  32. ManagedDataBlock(const ManagedDataBlock& source);
  33. ~ManagedDataBlock();
  34. UINT8* getData() { return mData; }
  35. UINT32 getSize() { return mData ? mSize : 0; }
  36. private:
  37. UINT8* mData;
  38. UINT32 mSize;
  39. bool mManaged;
  40. mutable bool mIsDataOwner;
  41. };
  42. /** @} */
  43. }