1 | #ifndef __XIOS_ARRAY_HPP__ |
---|
2 | #define __XIOS_ARRAY_HPP__ |
---|
3 | |
---|
4 | #define BZ_COLUMN_MAJOR_ARRAY |
---|
5 | #include <blitz/array.h> |
---|
6 | #include "buffer_in.hpp" |
---|
7 | #include "buffer_out.hpp" |
---|
8 | #include "message.hpp" |
---|
9 | #include <cmath> |
---|
10 | |
---|
11 | using namespace blitz; |
---|
12 | BZ_DECLARE_FUNCTION(round) |
---|
13 | |
---|
14 | namespace xios |
---|
15 | { |
---|
16 | template <typename T_numtype,int N_rank> |
---|
17 | class CArray : public Array<T_numtype,N_rank>, public virtual CBaseType |
---|
18 | { |
---|
19 | private: |
---|
20 | bool initialized; |
---|
21 | |
---|
22 | public: |
---|
23 | typedef typename Array<T_numtype,N_rank>::T_default_storage T_default_storage; |
---|
24 | using Array<T_numtype,N_rank>::operator =; |
---|
25 | |
---|
26 | template<typename T_expr> explicit CArray(_bz_ArrayExpr<T_expr> expr) |
---|
27 | : Array<T_numtype,N_rank>(expr) |
---|
28 | , initialized(true) |
---|
29 | {} |
---|
30 | |
---|
31 | CArray(GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
32 | : Array<T_numtype,N_rank>(storage) |
---|
33 | , initialized(false) |
---|
34 | {} |
---|
35 | |
---|
36 | explicit CArray(int length0, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
37 | : Array<T_numtype,N_rank>(length0, storage) |
---|
38 | , initialized(true) |
---|
39 | {} |
---|
40 | |
---|
41 | CArray(int length0, int length1, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
42 | : Array<T_numtype,N_rank>(length0, length1, storage) |
---|
43 | , initialized(true) |
---|
44 | {} |
---|
45 | |
---|
46 | CArray(int length0, int length1, int length2, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
47 | : Array<T_numtype,N_rank>(length0, length1, length2, storage) |
---|
48 | , initialized(true) |
---|
49 | {} |
---|
50 | |
---|
51 | CArray(int length0, int length1, int length2, int length3, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
52 | : Array<T_numtype,N_rank>(length0, length1, length2, length3, storage) |
---|
53 | , initialized(true) |
---|
54 | {} |
---|
55 | |
---|
56 | CArray(int length0, int length1, int length2, int length3, int length4, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
57 | : Array<T_numtype,N_rank>(length0,length1, length2, length3, length4, storage) |
---|
58 | , initialized(true) |
---|
59 | {} |
---|
60 | |
---|
61 | CArray(int length0, int length1, int length2, int length3, int length4, int length5, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
62 | : Array<T_numtype,N_rank>(length0, length1, length2, length3, length4, length5, storage) |
---|
63 | , initialized(true) |
---|
64 | {} |
---|
65 | |
---|
66 | CArray(int length0, int length1, int length2, int length3, int length4, int length5, int length6, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
67 | : Array<T_numtype,N_rank>(length0, length1, length2, length3, length4, length5, length6, storage) |
---|
68 | , initialized(true) |
---|
69 | {} |
---|
70 | |
---|
71 | CArray(int length0, int length1, int length2, int length3, int length4, int length5, int length6, int length7, |
---|
72 | GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
73 | : Array<T_numtype,N_rank>(length0, length1, length2, length3, length4, length5, length6, length7, storage) |
---|
74 | , initialized(true) |
---|
75 | {} |
---|
76 | |
---|
77 | CArray(int length0, int length1, int length2, int length3, int length4, int length5, int length6, |
---|
78 | int length7, int length8, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
79 | : Array<T_numtype,N_rank>(length0, length1, length2, length3, length4, length5, length6, length7, length8, storage) |
---|
80 | , initialized(true) |
---|
81 | {} |
---|
82 | |
---|
83 | CArray(int length0, int length1, int length2, int length3, int length4, |
---|
84 | int length5, int length6, int length7, int length8, int length9, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
85 | : Array<T_numtype,N_rank>(length0, length1, length2, length3, length4, length5, length6, length7, length8, length9, storage) |
---|
86 | , initialized(true) |
---|
87 | {} |
---|
88 | |
---|
89 | CArray(int length0, int length1, int length2, int length3, int length4, int length5, int length6, |
---|
90 | int length7, int length8, int length9, int length10, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
91 | : Array<T_numtype,N_rank>(length0, length1, length2, length3, length4, length5, length6, length7, length8, length9, length10, storage) |
---|
92 | , initialized(true) |
---|
93 | {} |
---|
94 | |
---|
95 | CArray(T_numtype* restrict dataFirst, TinyVector<int, N_rank> shape, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
96 | : Array<T_numtype,N_rank>(dataFirst, shape, storage) |
---|
97 | , initialized(true) |
---|
98 | {} |
---|
99 | |
---|
100 | CArray(T_numtype* restrict dataFirst, TinyVector<int, N_rank> shape, TinyVector<diffType, N_rank> stride, |
---|
101 | GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
102 | : Array<T_numtype,N_rank>(dataFirst, shape, stride, storage) |
---|
103 | , initialized(true) |
---|
104 | {} |
---|
105 | |
---|
106 | CArray(T_numtype* restrict dataFirst, TinyVector<int, N_rank> shape, preexistingMemoryPolicy deletionPolicy, |
---|
107 | GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
108 | : Array<T_numtype,N_rank>(dataFirst, shape, deletionPolicy, storage) |
---|
109 | , initialized(true) |
---|
110 | {} |
---|
111 | |
---|
112 | CArray(T_numtype* restrict dataFirst, TinyVector<int, N_rank> shape, TinyVector<diffType, N_rank> stride, |
---|
113 | preexistingMemoryPolicy deletionPolicy, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
114 | : Array<T_numtype,N_rank>(dataFirst, shape, stride, deletionPolicy, storage) |
---|
115 | , initialized(true) |
---|
116 | {} |
---|
117 | |
---|
118 | CArray(const TinyVector<int, N_rank>& extent, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
119 | : Array<T_numtype,N_rank>(extent, storage) |
---|
120 | , initialized(true) |
---|
121 | {} |
---|
122 | |
---|
123 | CArray(const TinyVector<int, N_rank>& lbounds, const TinyVector<int, N_rank>& extent, |
---|
124 | const GeneralArrayStorage<N_rank>& storage) |
---|
125 | : Array<T_numtype,N_rank>(lbounds, extent, storage) |
---|
126 | , initialized(true) |
---|
127 | {} |
---|
128 | |
---|
129 | CArray(Range r0, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
130 | : Array<T_numtype,N_rank>(r0, storage) |
---|
131 | , initialized(true) |
---|
132 | {} |
---|
133 | |
---|
134 | CArray(Range r0, Range r1, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
135 | : Array<T_numtype,N_rank>(r0, r1, storage) |
---|
136 | , initialized(true) |
---|
137 | {} |
---|
138 | |
---|
139 | CArray(Range r0, Range r1, Range r2, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
140 | : Array<T_numtype,N_rank>(r0, r1, r2, storage) |
---|
141 | , initialized(true) |
---|
142 | {} |
---|
143 | |
---|
144 | CArray(Range r0, Range r1, Range r2, Range r3, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
145 | : Array<T_numtype,N_rank>(r0, r1, r2, r3, storage) |
---|
146 | , initialized(true) |
---|
147 | {} |
---|
148 | |
---|
149 | CArray(Range r0, Range r1, Range r2, Range r3, Range r4, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
150 | : Array<T_numtype,N_rank>(r0, r1, r2, r3, r4, storage) |
---|
151 | , initialized(true) |
---|
152 | {} |
---|
153 | |
---|
154 | CArray(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
155 | : Array<T_numtype,N_rank>(r0, r1, r2, r3, r4, r5, storage) |
---|
156 | , initialized(true) |
---|
157 | {} |
---|
158 | |
---|
159 | CArray(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, Range r6, |
---|
160 | GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
161 | : Array<T_numtype,N_rank>(r0, r1, r2, r3, r4, r5, r6, storage) |
---|
162 | , initialized(true) |
---|
163 | {} |
---|
164 | |
---|
165 | CArray(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, Range r6, Range r7, |
---|
166 | GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
167 | : Array<T_numtype,N_rank>(r0, r1, r2, r3, r4, r5, r6, r7, storage) |
---|
168 | , initialized(true) |
---|
169 | {} |
---|
170 | |
---|
171 | CArray(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, |
---|
172 | Range r6, Range r7, Range r8, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
173 | : Array<T_numtype,N_rank>(r0, r1, r2, r3, r4, r5, r6, r7, r8, storage) |
---|
174 | , initialized(true) |
---|
175 | {} |
---|
176 | |
---|
177 | CArray(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, |
---|
178 | Range r6, Range r7, Range r8, Range r9, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
179 | : Array<T_numtype,N_rank>(r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, storage) |
---|
180 | , initialized(true) |
---|
181 | {} |
---|
182 | |
---|
183 | CArray(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, Range r6, Range r7, |
---|
184 | Range r8, Range r9, Range r10, GeneralArrayStorage<N_rank> storage = T_default_storage()) |
---|
185 | : Array<T_numtype,N_rank>(r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, storage) |
---|
186 | , initialized(true) |
---|
187 | {} |
---|
188 | |
---|
189 | CArray(const CArray<T_numtype, N_rank>& array) |
---|
190 | : Array<T_numtype,N_rank>(array) |
---|
191 | , initialized(array.initialized) |
---|
192 | {} |
---|
193 | |
---|
194 | CArray(const Array<T_numtype, N_rank>& array) |
---|
195 | : Array<T_numtype,N_rank>(array) |
---|
196 | , initialized(true) |
---|
197 | {} |
---|
198 | |
---|
199 | CArray(const TinyVector<int,N_rank-1>& shape, int lastExtent, const GeneralArrayStorage<N_rank>& storage) |
---|
200 | : Array<T_numtype,N_rank>(shape, lastExtent, storage) |
---|
201 | , initialized(true) |
---|
202 | {} |
---|
203 | |
---|
204 | CArray(Array<T_numtype, N_rank>& array, Range r0) |
---|
205 | : Array<T_numtype,N_rank>(array, r0) |
---|
206 | , initialized(true) |
---|
207 | {} |
---|
208 | |
---|
209 | CArray(Array<T_numtype, N_rank>& array, Range r0, Range r1) |
---|
210 | : Array<T_numtype,N_rank>(array, r0, r1) |
---|
211 | , initialized(true) |
---|
212 | {} |
---|
213 | |
---|
214 | CArray(Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2) |
---|
215 | : Array<T_numtype,N_rank>( array, r0, r1, r2) |
---|
216 | , initialized(true) |
---|
217 | {} |
---|
218 | |
---|
219 | CArray(Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3) |
---|
220 | : Array<T_numtype,N_rank>(array, r0, r1, r2, r3) |
---|
221 | , initialized(true) |
---|
222 | {} |
---|
223 | |
---|
224 | CArray(Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, |
---|
225 | Range r3, Range r4) |
---|
226 | : Array<T_numtype,N_rank>(array, r0, r1, r2, r3, r4) |
---|
227 | , initialized(true) |
---|
228 | {} |
---|
229 | |
---|
230 | CArray(Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, |
---|
231 | Range r3, Range r4, Range r5) |
---|
232 | : Array<T_numtype,N_rank>( array, r0, r1, r2, r3, r4, r5) |
---|
233 | , initialized(true) |
---|
234 | {} |
---|
235 | |
---|
236 | CArray(Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3, |
---|
237 | Range r4, Range r5, Range r6) |
---|
238 | : Array<T_numtype,N_rank>( array, r0, r1, r2, r3, r4, r5, r6) |
---|
239 | , initialized(true) |
---|
240 | {} |
---|
241 | |
---|
242 | CArray(Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3, Range r4, |
---|
243 | Range r5, Range r6, Range r7) |
---|
244 | : Array<T_numtype,N_rank>(array, r0, r1, r2, r3, r4, r5, r6, r7) |
---|
245 | , initialized(true) |
---|
246 | {} |
---|
247 | |
---|
248 | CArray(Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, |
---|
249 | Range r6, Range r7, Range r8) |
---|
250 | : Array<T_numtype,N_rank>(array, r0, r1, r2, r3, r4, r5, r6, r7, r8) |
---|
251 | , initialized(true) |
---|
252 | {} |
---|
253 | |
---|
254 | CArray(Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, |
---|
255 | Range r6, Range r7, Range r8, Range r9) |
---|
256 | : Array<T_numtype,N_rank>(array, r0, r1, r2, r3, r4, r5, r6, r7, r8, r9) |
---|
257 | , initialized(true) |
---|
258 | {} |
---|
259 | |
---|
260 | CArray(Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, Range r6, |
---|
261 | Range r7, Range r8, Range r9, Range r10) |
---|
262 | : Array<T_numtype,N_rank>(array, r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) |
---|
263 | , initialized(true) |
---|
264 | {} |
---|
265 | |
---|
266 | CArray(Array<T_numtype, N_rank>& array, const RectDomain<N_rank>& subdomain) |
---|
267 | : Array<T_numtype,N_rank>(array, subdomain) |
---|
268 | , initialized(true) |
---|
269 | {} |
---|
270 | |
---|
271 | CArray(Array<T_numtype, N_rank>& array, const StridedDomain<N_rank>& subdomain) |
---|
272 | : Array<T_numtype,N_rank>(array, subdomain) |
---|
273 | , initialized(true) |
---|
274 | {} |
---|
275 | |
---|
276 | template<int N_rank2, typename R0, typename R1, typename R2, typename R3, typename R4, typename R5, |
---|
277 | typename R6, typename R7, typename R8, typename R9, typename R10> |
---|
278 | CArray(Array<T_numtype,N_rank2>& array, R0 r0, R1 r1, R2 r2, R3 r3, R4 r4, R5 r5, R6 r6, R7 r7, R8 r8, R9 r9, R10 r10) |
---|
279 | : Array<T_numtype,N_rank>(array, r0,r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) |
---|
280 | , initialized(true) |
---|
281 | {} |
---|
282 | |
---|
283 | virtual ~CArray() {} |
---|
284 | |
---|
285 | CArray<T_numtype, N_rank> copy() const |
---|
286 | { |
---|
287 | CArray<T_numtype, N_rank> copy = Array<T_numtype, N_rank>::copy(); |
---|
288 | copy.initialized = initialized; |
---|
289 | return copy; |
---|
290 | } |
---|
291 | |
---|
292 | void reference(const CArray<T_numtype, N_rank>& array) |
---|
293 | { |
---|
294 | Array<T_numtype,N_rank>::reference(array); |
---|
295 | initialized = array.initialized; |
---|
296 | } |
---|
297 | |
---|
298 | void reference(const Array<T_numtype,N_rank>& array) |
---|
299 | { |
---|
300 | Array<T_numtype,N_rank>::reference(array); |
---|
301 | initialized = true; |
---|
302 | } |
---|
303 | |
---|
304 | bool operator== (const CArray<T_numtype,N_rank>& array) |
---|
305 | { |
---|
306 | size_t nbThis = this->numElements(); |
---|
307 | size_t nbArr = array.numElements(); |
---|
308 | if (nbThis != nbArr) return false; |
---|
309 | if (nbThis==0 && nbArr==0) return true; |
---|
310 | typename Array<T_numtype,N_rank>::const_iterator itx=array.begin(), itxe=array.end(), ity=this->begin() ; |
---|
311 | for(;itx!=itxe;++itx,++ity) if (*itx!=*ity) return false ; |
---|
312 | return true; |
---|
313 | } |
---|
314 | |
---|
315 | bool operator== (const Array<T_numtype,N_rank>& array) |
---|
316 | { |
---|
317 | return ((*this) == (dynamic_cast<const CArray<T_numtype,N_rank>& >(array))); |
---|
318 | } |
---|
319 | |
---|
320 | void resize(int extent) |
---|
321 | { |
---|
322 | Array<T_numtype,N_rank>::resize(extent); |
---|
323 | initialized = true; |
---|
324 | } |
---|
325 | void resize(int extent1, int extent2) |
---|
326 | { |
---|
327 | Array<T_numtype,N_rank>::resize(extent1, extent2); |
---|
328 | initialized = true; |
---|
329 | } |
---|
330 | void resize(int extent1, int extent2, int extent3) |
---|
331 | { |
---|
332 | Array<T_numtype,N_rank>::resize(extent1, extent2, extent3); |
---|
333 | initialized = true; |
---|
334 | } |
---|
335 | void resize(int extent1, int extent2, int extent3, int extent4) |
---|
336 | { |
---|
337 | Array<T_numtype,N_rank>::resize(extent1, extent2, extent3, extent4); |
---|
338 | initialized = true; |
---|
339 | } |
---|
340 | void resize(int extent1, int extent2, int extent3, int extent4, int extent5) |
---|
341 | { |
---|
342 | Array<T_numtype,N_rank>::resize(extent1, extent2, extent3, extent4, extent5); |
---|
343 | initialized = true; |
---|
344 | } |
---|
345 | void resize(int extent1, int extent2, int extent3, int extent4, int extent5, int extent6) |
---|
346 | { |
---|
347 | Array<T_numtype,N_rank>::resize(extent1, extent2, extent3, extent4, extent5, extent6); |
---|
348 | initialized = true; |
---|
349 | } |
---|
350 | void resize(int extent1, int extent2, int extent3, int extent4, int extent5, |
---|
351 | int extent6, int extent7) |
---|
352 | { |
---|
353 | Array<T_numtype,N_rank>::resize(extent1, extent2, extent3, extent4, extent5, |
---|
354 | extent6, extent7); |
---|
355 | initialized = true; |
---|
356 | } |
---|
357 | void resize(int extent1, int extent2, int extent3, int extent4, int extent5, |
---|
358 | int extent6, int extent7, int extent8) |
---|
359 | { |
---|
360 | Array<T_numtype,N_rank>::resize(extent1, extent2, extent3, extent4, extent5, |
---|
361 | extent6, extent7, extent8); |
---|
362 | initialized = true; |
---|
363 | } |
---|
364 | void resize(int extent1, int extent2, int extent3, int extent4, int extent5, |
---|
365 | int extent6, int extent7, int extent8, int extent9) |
---|
366 | { |
---|
367 | Array<T_numtype,N_rank>::resize(extent1, extent2, extent3, extent4, extent5, |
---|
368 | extent6, extent7, extent8, extent9); |
---|
369 | initialized = true; |
---|
370 | } |
---|
371 | void resize(int extent1, int extent2, int extent3, int extent4, int extent5, |
---|
372 | int extent6, int extent7, int extent8, int extent9, int extent10) |
---|
373 | { |
---|
374 | Array<T_numtype,N_rank>::resize(extent1, extent2, extent3, extent4, extent5, |
---|
375 | extent6, extent7, extent8, extent9, extent10); |
---|
376 | initialized = true; |
---|
377 | } |
---|
378 | void resize(int extent1, int extent2, int extent3, int extent4, int extent5, int extent6, |
---|
379 | int extent7, int extent8, int extent9, int extent10, int extent11) |
---|
380 | { |
---|
381 | Array<T_numtype,N_rank>::resize(extent1, extent2, extent3, extent4, extent5, extent6, |
---|
382 | extent7, extent8, extent9, extent10, extent11); |
---|
383 | initialized = true; |
---|
384 | } |
---|
385 | |
---|
386 | void resize(Range r1) |
---|
387 | { |
---|
388 | Array<T_numtype,N_rank>::resize(r1); |
---|
389 | initialized = true; |
---|
390 | } |
---|
391 | void resize(Range r1, Range r2) |
---|
392 | { |
---|
393 | Array<T_numtype,N_rank>::resize(r1, r2); |
---|
394 | initialized = true; |
---|
395 | } |
---|
396 | void resize(Range r1, Range r2, Range r3) |
---|
397 | { |
---|
398 | Array<T_numtype,N_rank>::resize(r1, r2, r3); |
---|
399 | initialized = true; |
---|
400 | } |
---|
401 | void resize(Range r1, Range r2, Range r3, Range r4) |
---|
402 | { |
---|
403 | Array<T_numtype,N_rank>::resize(r1, r2, r3, r4); |
---|
404 | initialized = true; |
---|
405 | } |
---|
406 | void resize(Range r1, Range r2, Range r3, Range r4, Range r5) |
---|
407 | { |
---|
408 | Array<T_numtype,N_rank>::resize(r1, r2, r3, r4, r5); |
---|
409 | initialized = true; |
---|
410 | } |
---|
411 | void resize(Range r1, Range r2, Range r3, Range r4, Range r5, Range r6) |
---|
412 | { |
---|
413 | Array<T_numtype,N_rank>::resize(r1, r2, r3, r4, r5, r6); |
---|
414 | initialized = true; |
---|
415 | } |
---|
416 | void resize(Range r1, Range r2, Range r3, Range r4, Range r5, |
---|
417 | Range r6, Range r7) |
---|
418 | { |
---|
419 | Array<T_numtype,N_rank>::resize(r1, r2, r3, r4, r5, |
---|
420 | r6, r7); |
---|
421 | initialized = true; |
---|
422 | } |
---|
423 | void resize(Range r1, Range r2, Range r3, Range r4, Range r5, |
---|
424 | Range r6, Range r7, Range r8) |
---|
425 | { |
---|
426 | Array<T_numtype,N_rank>::resize(r1, r2, r3, r4, r5, |
---|
427 | r6, r7, r8); |
---|
428 | initialized = true; |
---|
429 | } |
---|
430 | void resize(Range r1, Range r2, Range r3, Range r4, Range r5, |
---|
431 | Range r6, Range r7, Range r8, Range r9) |
---|
432 | { |
---|
433 | Array<T_numtype,N_rank>::resize(r1, r2, r3, r4, r5, |
---|
434 | r6, r7, r8, r9); |
---|
435 | initialized = true; |
---|
436 | } |
---|
437 | void resize(Range r1, Range r2, Range r3, Range r4, Range r5, |
---|
438 | Range r6, Range r7, Range r8, Range r9, Range r10) |
---|
439 | { |
---|
440 | Array<T_numtype,N_rank>::resize(r1, r2, r3, r4, r5, |
---|
441 | r6, r7, r8, r9, r10); |
---|
442 | initialized = true; |
---|
443 | } |
---|
444 | void resize(Range r1, Range r2, Range r3, Range r4, Range r5, Range r6, |
---|
445 | Range r7, Range r8, Range r9, Range r10, Range r11) |
---|
446 | { |
---|
447 | Array<T_numtype,N_rank>::resize(r1, r2, r3, r4, r5, r6, |
---|
448 | r7, r8, r9, r10, r11); |
---|
449 | initialized = true; |
---|
450 | } |
---|
451 | |
---|
452 | void resize(const TinyVector<int,N_rank>& extent) |
---|
453 | { |
---|
454 | Array<T_numtype,N_rank>::resize(extent); |
---|
455 | initialized = true; |
---|
456 | } |
---|
457 | |
---|
458 | void resizeAndPreserve(const TinyVector<int,N_rank>& extent) |
---|
459 | { |
---|
460 | Array<T_numtype,N_rank>::resizeAndPreserve(extent); |
---|
461 | initialized = true; |
---|
462 | } |
---|
463 | |
---|
464 | void resizeAndPreserve(int extent) |
---|
465 | { |
---|
466 | Array<T_numtype,N_rank>::resizeAndPreserve(extent); |
---|
467 | initialized = true; |
---|
468 | } |
---|
469 | void resizeAndPreserve(int extent1, int extent2) |
---|
470 | { |
---|
471 | Array<T_numtype,N_rank>::resizeAndPreserve(extent1, extent2); |
---|
472 | initialized = true; |
---|
473 | } |
---|
474 | void resizeAndPreserve(int extent1, int extent2, int extent3) |
---|
475 | { |
---|
476 | Array<T_numtype,N_rank>::resizeAndPreserve(extent1, extent2, extent3); |
---|
477 | initialized = true; |
---|
478 | } |
---|
479 | void resizeAndPreserve(int extent1, int extent2, int extent3, int extent4) |
---|
480 | { |
---|
481 | Array<T_numtype,N_rank>::resizeAndPreserve(extent1, extent2, extent3, extent4); |
---|
482 | initialized = true; |
---|
483 | } |
---|
484 | void resizeAndPreserve(int extent1, int extent2, int extent3, int extent4, int extent5) |
---|
485 | { |
---|
486 | Array<T_numtype,N_rank>::resizeAndPreserve(extent1, extent2, extent3, extent4, extent5); |
---|
487 | initialized = true; |
---|
488 | } |
---|
489 | void resizeAndPreserve(int extent1, int extent2, int extent3, int extent4, |
---|
490 | int extent5, int extent6) |
---|
491 | { |
---|
492 | Array<T_numtype,N_rank>::resizeAndPreserve(extent1, extent2, extent3, extent4, |
---|
493 | extent5, extent6); |
---|
494 | initialized = true; |
---|
495 | } |
---|
496 | void resizeAndPreserve(int extent1, int extent2, int extent3, int extent4, |
---|
497 | int extent5, int extent6, int extent7) |
---|
498 | { |
---|
499 | Array<T_numtype,N_rank>::resizeAndPreserve(extent1, extent2, extent3, extent4, |
---|
500 | extent5, extent6, extent7); |
---|
501 | initialized = true; |
---|
502 | } |
---|
503 | void resizeAndPreserve(int extent1, int extent2, int extent3, int extent4, |
---|
504 | int extent5, int extent6, int extent7, int extent8) |
---|
505 | { |
---|
506 | Array<T_numtype,N_rank>::resizeAndPreserve(extent1, extent2, extent3, extent4, |
---|
507 | extent5, extent6, extent7, extent8); |
---|
508 | initialized = true; |
---|
509 | } |
---|
510 | void resizeAndPreserve(int extent1, int extent2, int extent3, int extent4, int extent5, |
---|
511 | int extent6, int extent7, int extent8, int extent9) |
---|
512 | { |
---|
513 | Array<T_numtype,N_rank>::resizeAndPreserve(extent1, extent2, extent3, extent4, extent5, |
---|
514 | extent6, extent7, extent8, extent9); |
---|
515 | initialized = true; |
---|
516 | } |
---|
517 | void resizeAndPreserve(int extent1, int extent2, int extent3, int extent4, int extent5, |
---|
518 | int extent6, int extent7, int extent8, int extent9, int extent10) |
---|
519 | { |
---|
520 | Array<T_numtype,N_rank>::resizeAndPreserve(extent1, extent2, extent3, extent4, extent5, |
---|
521 | extent6, extent7, extent8, extent9, extent10); |
---|
522 | initialized = true; |
---|
523 | } |
---|
524 | void resizeAndPreserve(int extent1, int extent2, int extent3, int extent4, int extent5, int extent6, |
---|
525 | int extent7, int extent8, int extent9, int extent10, int extent11) |
---|
526 | { |
---|
527 | Array<T_numtype,N_rank>::resizeAndPreserve(extent1, extent2, extent3, extent4, extent5, extent6, |
---|
528 | extent7, extent8, extent9, extent10, extent11); |
---|
529 | initialized = true; |
---|
530 | } |
---|
531 | |
---|
532 | virtual void fromString(const string& str) { istringstream iss(str); iss >> *this; initialized = true; } |
---|
533 | virtual string toString(void) const { ostringstream oss; oss << *this; return oss.str(); } |
---|
534 | |
---|
535 | virtual string dump(void) const |
---|
536 | { |
---|
537 | ostringstream oss; |
---|
538 | oss << this->shape()<<" "; |
---|
539 | if (this->shape().numElements() == 1 && this->shape().dataFirst()[0] == 1) |
---|
540 | oss << this->dataFirst()[0]; |
---|
541 | else |
---|
542 | oss << this->dataFirst()[0] <<" ... "<< this->dataFirst()[this->numElements()-1]; |
---|
543 | return oss.str(); |
---|
544 | } |
---|
545 | |
---|
546 | virtual void reset(void) { this->free(); initialized = false; } |
---|
547 | virtual bool isEmpty(void) const { return !initialized; } |
---|
548 | virtual size_t size(void) const { return size(this->numElements()); } |
---|
549 | static size_t size(sizeType numElements) { return (N_rank + 1) * sizeof(int) + sizeof(size_t) + numElements * sizeof(T_numtype); } |
---|
550 | |
---|
551 | virtual CBaseType* clone(void) const { return new CArray(*this); } |
---|
552 | |
---|
553 | virtual bool toBuffer(CBufferOut& buffer) const |
---|
554 | { |
---|
555 | bool ret; |
---|
556 | ret = buffer.put(this->dimensions()); |
---|
557 | ret &= buffer.put(this->shape().data(), this->dimensions()); |
---|
558 | ret &= buffer.put(this->numElements()); |
---|
559 | ret &= buffer.put(this->dataFirst(), this->numElements()); |
---|
560 | return ret; |
---|
561 | } |
---|
562 | |
---|
563 | virtual bool fromBuffer(CBufferIn& buffer) |
---|
564 | { |
---|
565 | bool ret; |
---|
566 | int numDim; |
---|
567 | TinyVector<int,N_rank> vect; |
---|
568 | size_t ne; |
---|
569 | |
---|
570 | ret = buffer.get(numDim); |
---|
571 | ret &= buffer.get(vect.data(), N_rank); |
---|
572 | this->resize(vect); |
---|
573 | ret &= buffer.get(ne); |
---|
574 | ret &= buffer.get(this->dataFirst(), ne); |
---|
575 | |
---|
576 | initialized = true; |
---|
577 | |
---|
578 | return ret; |
---|
579 | } |
---|
580 | }; |
---|
581 | |
---|
582 | |
---|
583 | #define macro(NRANK)\ |
---|
584 | \ |
---|
585 | template <>\ |
---|
586 | inline size_t CArray<StdString,NRANK>::size(void) const\ |
---|
587 | {\ |
---|
588 | size_t size=(1 + NRANK) * sizeof(int) ;\ |
---|
589 | Array<StdString,NRANK>::const_iterator it, itb=this->begin(), ite=this->end() ;\ |
---|
590 | \ |
---|
591 | for(it=itb;it!=ite;++it)\ |
---|
592 | {\ |
---|
593 | size+= sizeof(size_t) ;\ |
---|
594 | size+= (*it).size();\ |
---|
595 | } \ |
---|
596 | return size ;\ |
---|
597 | }\ |
---|
598 | \ |
---|
599 | /* for array string this function is an evaluation of maximum size of the array, considering stringArrayLen is the maximum size of the strings*/ \ |
---|
600 | template <>\ |
---|
601 | inline size_t CArray<StdString,NRANK>::size(sizeType numElements)\ |
---|
602 | {\ |
---|
603 | return (NRANK + 1) * sizeof(int) + numElements * stringArrayLen;\ |
---|
604 | }\ |
---|
605 | \ |
---|
606 | template <>\ |
---|
607 | inline bool CArray<StdString,NRANK>::toBuffer(CBufferOut& buffer) const\ |
---|
608 | {\ |
---|
609 | bool ret;\ |
---|
610 | ret = buffer.put(this->dimensions());\ |
---|
611 | ret &= buffer.put(this->shape().data(), this->dimensions());\ |
---|
612 | \ |
---|
613 | Array<StdString,NRANK>::const_iterator it, itb=this->begin(), ite=this->end() ;\ |
---|
614 | \ |
---|
615 | for(it=itb;it!=ite;++it)\ |
---|
616 | {\ |
---|
617 | ret &= buffer.put((*it).size()) ;\ |
---|
618 | ret &= buffer.put((*it).data(),(*it).size());\ |
---|
619 | } \ |
---|
620 | return ret;\ |
---|
621 | }\ |
---|
622 | \ |
---|
623 | template <>\ |
---|
624 | inline bool CArray<StdString,NRANK>::fromBuffer(CBufferIn& buffer)\ |
---|
625 | {\ |
---|
626 | bool ret;\ |
---|
627 | int numDim;\ |
---|
628 | TinyVector<int,NRANK> vect;\ |
---|
629 | size_t ne;\ |
---|
630 | \ |
---|
631 | ret = buffer.get(numDim);\ |
---|
632 | ret &= buffer.get(vect.data(), NRANK);\ |
---|
633 | this->resize(vect);\ |
---|
634 | \ |
---|
635 | Array<StdString,NRANK>::iterator it, itb=this->begin(), ite=this->end() ;\ |
---|
636 | for(it=itb;it!=ite;++it)\ |
---|
637 | {\ |
---|
638 | ret &= buffer.get(ne) ;\ |
---|
639 | char* str = new char[ne] ;\ |
---|
640 | ret &= buffer.get(str, ne);\ |
---|
641 | *it = string(str,ne) ;\ |
---|
642 | delete [] str ;\ |
---|
643 | }\ |
---|
644 | initialized = true;\ |
---|
645 | return ret;\ |
---|
646 | } |
---|
647 | macro(1) |
---|
648 | macro(2) |
---|
649 | macro(3) |
---|
650 | macro(4) |
---|
651 | macro(5) |
---|
652 | macro(6) |
---|
653 | macro(7) |
---|
654 | |
---|
655 | #undef macro |
---|
656 | |
---|
657 | template <typename T_numtype,int N_rank> inline CBufferOut& operator<<(CBufferOut& buffer, const CArray<T_numtype,N_rank>& array) |
---|
658 | { |
---|
659 | if (!array.toBuffer(buffer)) ERROR("template <typename T_numtype,int N_rank> inline CBufferOut& operator<<(CBufferOut& buffer, const CArray& array)", |
---|
660 | << "Not enough free space in buffer to queue the array."); |
---|
661 | return buffer; |
---|
662 | } |
---|
663 | |
---|
664 | template <typename T_numtype,int N_rank> inline CBufferIn& operator>>(CBufferIn& buffer, CArray<T_numtype, N_rank>& array) |
---|
665 | { |
---|
666 | if (!array.fromBuffer(buffer)) ERROR("template <typename T_numtype,int N_rank> inline CBufferIn& operator>>(CBufferIn& buffer, CArray& array)", |
---|
667 | << "Not enough data in buffer to unqueue the array."); |
---|
668 | return buffer; |
---|
669 | } |
---|
670 | |
---|
671 | template <typename T_numtype,int N_rank> inline CMessage& operator<<(CMessage& msg, const CArray<T_numtype, N_rank>& array) |
---|
672 | { |
---|
673 | msg.push(array); |
---|
674 | return msg; |
---|
675 | } |
---|
676 | |
---|
677 | template <typename T_numtype,int N_rank> inline CMessage& operator<<(CMessage& msg, CArray<T_numtype, N_rank>& array) |
---|
678 | { |
---|
679 | msg.push(array); |
---|
680 | return msg; |
---|
681 | } |
---|
682 | } |
---|
683 | |
---|
684 | #endif |
---|