2
0

BsManagedDataBlock.h 1.5 KB

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