ezEngine  Milestone 7
ArrayBase.h
1 #pragma once
2 
3 #include <Foundation/Algorithm/Sorting.h>
4 #include <Foundation/Math/Math.h>
5 #include <Foundation/Types/ArrayPtr.h>
6 
8 #define ezInvalidIndex 0xFFFFFFFF
9 
11 template <typename T, typename Derived>
13 {
14 public:
16  ezArrayBase(); // [tested]
17 
19  ~ezArrayBase(); // [tested]
20 
22  void operator= (const ezArrayPtr<const T>& rhs); // [tested]
23 
25  operator ezArrayPtr<const T>() const; // [tested]
26 
28  operator ezArrayPtr<T>(); // [tested]
29 
31  bool operator== (const ezArrayPtr<const T>& rhs) const; // [tested]
32 
34  bool operator!= (const ezArrayPtr<const T>& rhs) const; // [tested]
35 
37  const T& operator[](ezUInt32 uiIndex) const; // [tested]
38 
40  T& operator[](ezUInt32 uiIndex); // [tested]
41 
43  void SetCount(ezUInt32 uiCount); // [tested]
44 
46  void SetCountUninitialized(ezUInt32 uiCount); // [tested]
47 
49  ezUInt32 GetCount() const; // [tested]
50 
52  bool IsEmpty() const; // [tested]
53 
55  void Clear(); // [tested]
56 
58  bool Contains(const T& value) const; // [tested]
59 
61  void Insert(const T& value, ezUInt32 uiIndex); // [tested]
62 
64  void Insert(T&& value, ezUInt32 uiIndex); // [tested]
65 
67  bool Remove(const T& value); // [tested]
68 
70  bool RemoveSwap(const T& value); // [tested]
71 
73  void RemoveAt(ezUInt32 uiIndex); // [tested]
74 
76  void RemoveAtSwap(ezUInt32 uiIndex); // [tested]
77 
79  ezUInt32 IndexOf(const T& value, ezUInt32 uiStartIndex = 0) const; // [tested]
80 
82  ezUInt32 LastIndexOf(const T& value, ezUInt32 uiStartIndex = ezInvalidIndex) const; // [tested]
83 
85  T& ExpandAndGetRef(); // [tested]
86 
88  void PushBack(const T& value); // [tested]
89 
91  void PushBack(T&& value); // [tested]
92 
94  void PushBackUnchecked(const T& value); // [tested]
95 
97  void PushBackUnchecked(T&& value); // [tested]
98 
100  void PushBackRange(const ezArrayPtr<const T>& range); // [tested]
101 
103  void PopBack(ezUInt32 uiCountToRemove = 1); // [tested]
104 
106  T& PeekBack(); // [tested]
107 
109  const T& PeekBack() const; // [tested]
110 
112  template <typename Comparer>
113  void Sort(const Comparer& comparer); // [tested]
114 
116  void Sort(); // [tested]
117 
119  T* GetData();
120 
122  const T* GetData() const;
123 
125  ezArrayPtr<T> GetArrayPtr(); // [tested]
126 
128  ezArrayPtr<const T> GetArrayPtr() const; // [tested]
129 
130  typedef T const * const_iterator;
132  typedef T * iterator;
134 
135 
136 protected:
137 
140 
142  ezUInt32 m_uiCount;
143 
145  ezUInt32 m_uiCapacity;
146 };
147 
148 template <typename T, typename Derived>
149 typename ezArrayBase<T, Derived>::iterator begin(ezArrayBase<T, Derived>& container) { return container.GetData(); }
150 
151 template <typename T, typename Derived>
152 typename ezArrayBase<T, Derived>::const_iterator begin(const ezArrayBase<T, Derived>& container) { return container.GetData(); }
153 
154 template <typename T, typename Derived>
155 typename ezArrayBase<T, Derived>::const_iterator cbegin(const ezArrayBase<T, Derived>& container) { return container.GetData(); }
156 
157 template <typename T, typename Derived>
158 typename ezArrayBase<T, Derived>::reverse_iterator rbegin(ezArrayBase<T, Derived>& container) { return typename ezArrayBase<T, Derived>::reverse_iterator(container.GetData() + container.GetCount() - 1); }
159 
160 template <typename T, typename Derived>
161 typename ezArrayBase<T, Derived>::const_reverse_iterator rbegin(const ezArrayBase<T, Derived>& container) { return typename ezArrayBase<T, Derived>::const_reverse_iterator(container.GetData() + container.GetCount() - 1); }
162 
163 template <typename T, typename Derived>
164 typename ezArrayBase<T, Derived>::const_reverse_iterator crbegin(const ezArrayBase<T, Derived>& container) { return typename ezArrayBase<T, Derived>::const_reverse_iterator(container.GetData() + container.GetCount() - 1); }
165 
166 template <typename T, typename Derived>
167 typename ezArrayBase<T, Derived>::iterator end(ezArrayBase<T, Derived>& container) { return container.GetData() + container.GetCount(); }
168 
169 template <typename T, typename Derived>
170 typename ezArrayBase<T, Derived>::const_iterator end(const ezArrayBase<T, Derived>& container) { return container.GetData() + container.GetCount(); }
171 
172 template <typename T, typename Derived>
173 typename ezArrayBase<T, Derived>::const_iterator cend(const ezArrayBase<T, Derived>& container) { return container.GetData() + container.GetCount(); }
174 
175 template <typename T, typename Derived>
177 
178 template <typename T, typename Derived>
180 
181 template <typename T, typename Derived>
183 
184 
185 #include <Foundation/Containers/Implementation/ArrayBase_inl.h>
186