Plasma Engine  2.0
Loading...
Searching...
No Matches
InstanceDataAllocator.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Containers/Blob.h>
5#include <Foundation/Containers/DynamicArray.h>
6
16struct PL_FOUNDATION_DLL plInstanceDataDesc
17{
18 plUInt32 m_uiTypeSize = 0;
19 plUInt32 m_uiTypeAlignment = 0;
20 plMemoryUtils::ConstructorFunction m_ConstructorFunction = nullptr;
21 plMemoryUtils::DestructorFunction m_DestructorFunction = nullptr;
22
23 template <typename T>
24 PL_ALWAYS_INLINE void FillFromType()
25 {
26 m_uiTypeSize = sizeof(T);
27 m_uiTypeAlignment = PL_ALIGNMENT_OF(T);
29 m_DestructorFunction = plMemoryUtils::MakeDestructorFunction<T>();
30 }
31};
32
34class PL_FOUNDATION_DLL plInstanceDataAllocator
35{
36public:
38 [[nodiscard]] plUInt32 AddDesc(const plInstanceDataDesc& desc);
39
41 void ClearDescs();
42
44 void Construct(plByteBlobPtr blobPtr) const;
45
47 void Destruct(plByteBlobPtr blobPtr) const;
48
50 [[nodiscard]] plBlob AllocateAndConstruct() const;
51
53 void DestructAndDeallocate(plBlob& ref_blob) const;
54
56 plUInt32 GetTotalDataSize() const { return m_uiTotalDataSize; }
57
59 PL_ALWAYS_INLINE static void* GetInstanceData(const plByteBlobPtr& blobPtr, plUInt32 uiOffset)
60 {
61 return (uiOffset != plInvalidIndex) ? blobPtr.GetPtr() + uiOffset : nullptr;
62 }
63
64private:
66 plUInt32 m_uiTotalDataSize = 0;
67};
plBlob allows to store simple binary data larger than 4GB. This storage class is used by plImage to a...
Definition Blob.h:319
PL_ALWAYS_INLINE PointerType GetPtr() const
Returns the pointer to the array.
Definition Blob.h:80
Definition DynamicArray.h:81
Helper class to manager instance data allocation, construction and destruction.
Definition InstanceDataAllocator.h:35
plUInt32 GetTotalDataSize() const
The total size in bytes taken up by all instance data objects that were added.
Definition InstanceDataAllocator.h:56
static PL_ALWAYS_INLINE void * GetInstanceData(const plByteBlobPtr &blobPtr, plUInt32 uiOffset)
Retrieves a void pointer to the instance data within the given blob at the given offset,...
Definition InstanceDataAllocator.h:59
static ConstructorFunction MakeConstructorFunction()
Returns a function pointer to construct an instance of T. Returns nullptr for trivial types.
static DestructorFunction MakeDestructorFunction()
Returns a function pointer to destruct an instance of T. Returns nullptr for POD-types.
Structure to describe an instance data type.
Definition InstanceDataAllocator.h:17