diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/evas/src/modules/engines/direct3d/array.h | 305 |
1 files changed, 0 insertions, 305 deletions
diff --git a/libraries/evas/src/modules/engines/direct3d/array.h b/libraries/evas/src/modules/engines/direct3d/array.h deleted file mode 100644 index dfd80b7..0000000 --- a/libraries/evas/src/modules/engines/direct3d/array.h +++ /dev/null | |||
@@ -1,305 +0,0 @@ | |||
1 | #ifndef __ARRAY_H__ | ||
2 | #define __ARRAY_H__ | ||
3 | |||
4 | #include "ref.h" | ||
5 | #include <assert.h> | ||
6 | |||
7 | template <class T> | ||
8 | class TArray : virtual public Referenc | ||
9 | { | ||
10 | public: | ||
11 | TArray(); | ||
12 | TArray(const TArray<T> &arr) | ||
13 | { | ||
14 | data = NULL; | ||
15 | size = num = 0; | ||
16 | block_size = arr.block_size; | ||
17 | keep_order = arr.keep_order; | ||
18 | |||
19 | //assert(0 && "Direct assignment for arrays is NOT allowed"); | ||
20 | // risky probably, but anyway | ||
21 | arr.CopyTo(*this); | ||
22 | } | ||
23 | ~TArray(); | ||
24 | |||
25 | bool Allocate(int new_num); | ||
26 | bool Resize(int new_size = 0); | ||
27 | bool Add(T &el); | ||
28 | bool Add(const T &el); | ||
29 | |||
30 | inline T &operator[](int i); | ||
31 | inline const T &operator[](int i) const; | ||
32 | inline const TArray<T> &operator =(const TArray<T> &arr) | ||
33 | { | ||
34 | block_size = arr.block_size; | ||
35 | keep_order = arr.keep_order; | ||
36 | |||
37 | //assert(0 && "Direct assignment for arrays is NOT allowed"); | ||
38 | // risky probably, but anyway | ||
39 | arr.CopyTo(*this); | ||
40 | return *this; | ||
41 | } | ||
42 | |||
43 | T *Last() | ||
44 | { | ||
45 | if (num > 0) | ||
46 | return &data[num - 1]; | ||
47 | return NULL; | ||
48 | } | ||
49 | |||
50 | inline int Length() const | ||
51 | { | ||
52 | return num; | ||
53 | } | ||
54 | |||
55 | inline int Size() const | ||
56 | { | ||
57 | return size; | ||
58 | } | ||
59 | |||
60 | inline int BlockSize() const | ||
61 | { | ||
62 | return block_size; | ||
63 | } | ||
64 | |||
65 | inline T *Data() | ||
66 | { | ||
67 | return data; | ||
68 | } | ||
69 | |||
70 | inline T **DataPtr() | ||
71 | { | ||
72 | return &data; | ||
73 | } | ||
74 | |||
75 | inline const T *Data() const | ||
76 | { | ||
77 | return data; | ||
78 | } | ||
79 | |||
80 | inline void SetKeepOrder(bool enable) | ||
81 | { | ||
82 | keep_order = enable; | ||
83 | } | ||
84 | |||
85 | bool Find(const T &el); | ||
86 | |||
87 | bool Add(TArray<T> &arr); | ||
88 | bool CopyTo(TArray<T> &dest) const; | ||
89 | bool Init(const T *arr, int len); | ||
90 | |||
91 | void Swap(int to, int from); | ||
92 | void Replace(int i); | ||
93 | |||
94 | bool SetBlockSize(int new_size); | ||
95 | void Set(T &el); | ||
96 | void Set(const T &el); | ||
97 | |||
98 | protected: | ||
99 | T *data; | ||
100 | int size; | ||
101 | int num; | ||
102 | int block_size; | ||
103 | // Some operations restricted, order of the elements is fixed | ||
104 | bool keep_order; | ||
105 | |||
106 | }; | ||
107 | |||
108 | namespace Array | ||
109 | { | ||
110 | const int default_block_size = 16; | ||
111 | const int max_array_size = 0xffffff; | ||
112 | } | ||
113 | |||
114 | |||
115 | template <class T> TArray<T>::TArray() | ||
116 | : data(NULL), size(0), num(0), block_size(Array::default_block_size), keep_order(false) | ||
117 | { | ||
118 | } | ||
119 | |||
120 | template <class T> TArray<T>::~TArray() | ||
121 | { | ||
122 | if (data != NULL) | ||
123 | Resize(); | ||
124 | } | ||
125 | |||
126 | template <class T> bool TArray<T>::Allocate(int new_num) | ||
127 | { | ||
128 | assert(new_num >= 0 && new_num <= Array::max_array_size); | ||
129 | if (new_num > size) | ||
130 | { | ||
131 | if (!Resize(new_num)) | ||
132 | return false; | ||
133 | } | ||
134 | num = new_num; | ||
135 | return true; | ||
136 | } | ||
137 | |||
138 | template <class T> bool TArray<T>::Resize(int new_size) | ||
139 | { | ||
140 | assert(new_size >= 0 && new_size <= Array::max_array_size); | ||
141 | if (new_size == 0) | ||
142 | { | ||
143 | delete[] data; | ||
144 | data = NULL; | ||
145 | size = 0; | ||
146 | num = 0; | ||
147 | return true; | ||
148 | } | ||
149 | if (new_size == size) | ||
150 | return true; | ||
151 | |||
152 | T *new_data = new T[new_size]; | ||
153 | if (new_data == NULL) | ||
154 | return false; | ||
155 | |||
156 | if (data != NULL && num > 0) | ||
157 | { | ||
158 | //CopyMemory(new_data, data, num * sizeof(T)); | ||
159 | for (int i = 0; i < num && i < new_size; i++) | ||
160 | new_data[i] = data[i]; | ||
161 | } | ||
162 | delete[] data; | ||
163 | |||
164 | data = new_data; | ||
165 | size = new_size; | ||
166 | return true; | ||
167 | } | ||
168 | |||
169 | template <class T> bool TArray<T>::Add(T &el) | ||
170 | { | ||
171 | if (data == NULL) | ||
172 | Resize(1); | ||
173 | |||
174 | if (num < size) | ||
175 | { | ||
176 | data[num++] = el; | ||
177 | return true; | ||
178 | } | ||
179 | // num >= size | ||
180 | int new_size = size + block_size; | ||
181 | if (!Resize(new_size)) | ||
182 | return false; | ||
183 | |||
184 | data[num++] = el; | ||
185 | return true; | ||
186 | } | ||
187 | |||
188 | template <class T> bool TArray<T>::Add(const T &el) | ||
189 | { | ||
190 | if (data == NULL) | ||
191 | Resize(1); | ||
192 | |||
193 | if (num < size) | ||
194 | { | ||
195 | data[num++] = *(T *)⪙ | ||
196 | return true; | ||
197 | } | ||
198 | // num >= size | ||
199 | int new_size = size + block_size; | ||
200 | if (!Resize(new_size)) | ||
201 | return false; | ||
202 | |||
203 | data[num++] = *(T *)⪙ | ||
204 | return true; | ||
205 | } | ||
206 | |||
207 | template <class T> bool TArray<T>::Add(TArray<T> &arr) | ||
208 | { | ||
209 | if (arr.Length() == 0) | ||
210 | return true; | ||
211 | int numf = num; | ||
212 | if (!Allocate(Length() + arr.Length())) | ||
213 | return false; | ||
214 | CopyMemory(&data[numf], arr.Data(), arr.Length() * sizeof(T)); | ||
215 | return true; | ||
216 | } | ||
217 | |||
218 | template <class T> T &TArray<T>::operator [](int i) | ||
219 | { | ||
220 | assert(i >= 0 && i < num); | ||
221 | return data[i]; | ||
222 | } | ||
223 | |||
224 | template <class T> const T &TArray<T>::operator [](int i) const | ||
225 | { | ||
226 | assert(i >= 0 && i < num); | ||
227 | return data[i]; | ||
228 | } | ||
229 | |||
230 | template <class T> bool TArray<T>::SetBlockSize(int new_size) | ||
231 | { | ||
232 | assert(new_size >= 0 && new_size <= Array::max_array_size); | ||
233 | block_size = new_size; | ||
234 | return true; | ||
235 | } | ||
236 | |||
237 | template <class T> void TArray<T>::Set(T &el) | ||
238 | { | ||
239 | for (int i = 0; i < num; i++) | ||
240 | data[i] = el; | ||
241 | } | ||
242 | |||
243 | template <class T> void TArray<T>::Set(const T &el) | ||
244 | { | ||
245 | for (int i = 0; i < num; i++) | ||
246 | data[i] = el; | ||
247 | } | ||
248 | |||
249 | template <class T> bool TArray<T>::CopyTo(TArray<T> &dest) const | ||
250 | { | ||
251 | if (!dest.Resize(size)) | ||
252 | return false; | ||
253 | dest.num = 0; | ||
254 | for (int i = 0; i < num; i++) | ||
255 | dest.Add(data[i]); | ||
256 | |||
257 | return true; | ||
258 | } | ||
259 | |||
260 | template <class T> bool TArray<T>::Init(const T *arr, int len) | ||
261 | { | ||
262 | assert(arr != NULL); | ||
263 | if (!Resize(len)) | ||
264 | return false; | ||
265 | num = 0; | ||
266 | for (int i = 0; i < len; i++) | ||
267 | Add((T)arr[i]); | ||
268 | |||
269 | return true; | ||
270 | } | ||
271 | |||
272 | template <class T> void TArray<T>::Swap(int to, int from) | ||
273 | { | ||
274 | assert(to >= 0 && to < num && from >= 0 && from < num); | ||
275 | if (keep_order) | ||
276 | return; | ||
277 | T t = data[to]; | ||
278 | data[to] = data[from]; | ||
279 | data[from] = t; | ||
280 | } | ||
281 | |||
282 | template <class T> void TArray<T>::Replace(int i) | ||
283 | { | ||
284 | assert(i >= 0 && i < num); | ||
285 | if (keep_order) | ||
286 | return; | ||
287 | if (num >= 1) | ||
288 | { | ||
289 | data[i] = data[num - 1]; | ||
290 | num--; | ||
291 | } | ||
292 | } | ||
293 | |||
294 | // operator == for type T should be defined | ||
295 | template <class T> bool TArray<T>::Find(const T &el) | ||
296 | { | ||
297 | for (int i = 0; i < num; i++) | ||
298 | { | ||
299 | if (data[i] == el) | ||
300 | return true; | ||
301 | } | ||
302 | return false; | ||
303 | } | ||
304 | |||
305 | #endif // __ARRAY_H__ | ||