CmManagedDataBlock.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include "CmPrerequisitesUtil.h"
  3. namespace CamelotFramework
  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.
  16. * @param size Size of the array, in bytes.
  17. */
  18. ManagedDataBlock(UINT8* data, UINT32 size);
  19. /**
  20. * @brief Constructor that will automatically allocate an internal buffer of the specified size.
  21. * Copying ManagedDataBlock transfers ownership of the buffer to the copy of the buffer.
  22. * Buffer is deleted when the latest copy is deleted.
  23. *
  24. * @param size The size of the data in bytes.
  25. */
  26. ManagedDataBlock(UINT32 size);
  27. ManagedDataBlock(const ManagedDataBlock& source);
  28. ~ManagedDataBlock();
  29. UINT8* getData() { return mData; }
  30. UINT32 getSize() { return mData ? mSize : 0; }
  31. private:
  32. UINT8* mData;
  33. UINT32 mSize;
  34. bool mManaged;
  35. mutable bool mIsDataOwner;
  36. };
  37. }