2
0

CmManagedDataBlock.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include "CmPrerequisitesUtil.h"
  3. namespace CamelotEngine
  4. {
  5. /**
  6. * @brief Data block holding an array of bytes, usually used in serialization.
  7. */
  8. class CM_UTILITY_EXPORT ManagedDataBlock
  9. {
  10. public:
  11. /**
  12. * @brief Constructor
  13. *
  14. * @param [in] data Array of bytes to store. Direct pointer to the provided
  15. * array will be stored, no copying will be done. Data won't be modified
  16. * unless "managed" is true.
  17. * @param size Size of the array, in bytes.
  18. * @param managed If true then the provided data array will be deleted once
  19. * it is no longer being used. When serializing it is always faster to provide direct
  20. * pointer to the data, but sometimes you need to provide a copy of the data
  21. * instead (e.g. maybe it's needed in a different format).
  22. * In that case set managed to true so it can be properly freed.
  23. */
  24. ManagedDataBlock(UINT8* data, UINT32 size, bool managed);
  25. ManagedDataBlock(const ManagedDataBlock& source);
  26. ~ManagedDataBlock();
  27. /**
  28. * @brief Destroy underlying buffers for unmanaged data blocks.
  29. */
  30. void destroy();
  31. UINT8* getData() { return mData; }
  32. UINT32 getSize() { return mData ? mSize : 0; }
  33. private:
  34. UINT8* mData;
  35. UINT32 mSize;
  36. bool mManaged;
  37. mutable bool mIsDataOwner;
  38. };
  39. }