ezEngine  Milestone 7
HybridArray.h
1 #pragma once
2 
3 #include <Foundation/Containers/ArrayBase.h>
4 #include <Foundation/Memory/AllocatorWrapper.h>
5 
11 template <typename T, ezUInt32 Size>
12 class ezHybridArrayBase : public ezArrayBase<T, ezHybridArrayBase<T, Size> >
13 {
14 protected:
16  ezHybridArrayBase(ezAllocatorBase* pAllocator); // [tested]
17 
19  ezHybridArrayBase(const ezHybridArrayBase<T, Size>& other, ezAllocatorBase* pAllocator); // [tested]
20 
22  ezHybridArrayBase(ezHybridArrayBase<T, Size>&& other, ezAllocatorBase* pAllocator); // [tested]
23 
25  ezHybridArrayBase(const ezArrayPtr<const T>& other, ezAllocatorBase* pAllocator); // [tested]
26 
28  ~ezHybridArrayBase(); // [tested]
29 
31  void operator= (const ezHybridArrayBase<T, Size>& rhs); // [tested]
32 
34  void operator= (ezHybridArrayBase<T, Size>&& rhs); // [tested]
35 
36 public:
37 
39  void Reserve(ezUInt32 uiCapacity); // [tested]
40 
42  void Compact(); // [tested]
43 
45  ezAllocatorBase* GetAllocator() const { return m_pAllocator; }
46 
48  ezUInt64 GetHeapMemoryUsage() const; // [tested]
49 
50 private:
51  T* GetStaticArray();
52 
54  struct : ezAligned<EZ_ALIGNMENT_OF(T)>
55  {
56  ezUInt8 m_StaticData[Size * sizeof(T)];
57  };
58 
59  ezAllocatorBase* m_pAllocator;
60 
61  enum { CAPACITY_ALIGNMENT = 16 };
62 
63  void SetCapacity(ezUInt32 uiCapacity);
64 };
65 
66 
68 template <typename T, ezUInt32 Size, typename AllocatorWrapper = ezDefaultAllocatorWrapper>
69 class ezHybridArray : public ezHybridArrayBase<T, Size>
70 {
71 public:
72  ezHybridArray();
73  ezHybridArray(ezAllocatorBase* pAllocator);
74 
77  explicit ezHybridArray(const ezArrayPtr<const T>& other);
78 
81 
82  void operator=(const ezHybridArray<T, Size, AllocatorWrapper>& rhs);
83  void operator=(const ezHybridArrayBase<T, Size>& rhs);
84  void operator=(const ezArrayPtr<const T>& rhs);
85 
86  void operator=(ezHybridArray<T, Size, AllocatorWrapper>&& rhs);
87  void operator=(ezHybridArrayBase<T, Size>&& rhs);
88 
89 };
90 
91 #include <Foundation/Containers/Implementation/HybridArray_inl.h>
92