| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #pragma once
- #include "CmPrerequisitesUtil.h"
- namespace CamelotEngine
- {
- /**
- * @brief Data block holding an array of bytes, usually used in serialization.
- */
- class CM_UTILITY_EXPORT ManagedDataBlock
- {
- public:
- /**
- * @brief Constructor
- *
- * @param [in] data Array of bytes to store. Direct pointer to the provided
- * array will be stored, no copying will be done. Data won't be modified
- * unless "managed" is true.
- * @param size Size of the array, in bytes.
- * @param managed If true then the provided data array will be deleted once
- * it is no longer being used. When serializing it is always faster to provide direct
- * pointer to the data, but sometimes you need to provide a copy of the data
- * instead (e.g. maybe it's needed in a different format).
- * In that case set managed to true so it can be properly freed.
- */
- ManagedDataBlock(UINT8* data, UINT32 size, bool managed);
- ManagedDataBlock(const ManagedDataBlock& source);
- ~ManagedDataBlock();
- /**
- * @brief Destroy underlying buffers for unmanaged data blocks.
- */
- void destroy();
- UINT8* getData() { return mData; }
- UINT32 getSize() { return mData ? mSize : 0; }
- private:
- UINT8* mData;
- UINT32 mSize;
- bool mManaged;
- mutable bool mIsDataOwner;
- };
- }
|