1993
|
1 // Template array classes |
228
|
2 /* |
|
3 |
7017
|
4 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003, |
|
5 2004, 2005, 2006, 2007 John W. Eaton |
228
|
6 |
|
7 This file is part of Octave. |
|
8 |
|
9 Octave is free software; you can redistribute it and/or modify it |
|
10 under the terms of the GNU General Public License as published by the |
7016
|
11 Free Software Foundation; either version 3 of the License, or (at your |
|
12 option) any later version. |
228
|
13 |
|
14 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
17 for more details. |
|
18 |
|
19 You should have received a copy of the GNU General Public License |
7016
|
20 along with Octave; see the file COPYING. If not, see |
|
21 <http://www.gnu.org/licenses/>. |
228
|
22 |
|
23 */ |
|
24 |
382
|
25 #if !defined (octave_Array_h) |
|
26 #define octave_Array_h 1 |
|
27 |
1366
|
28 #include <cassert> |
4152
|
29 #include <cstddef> |
3613
|
30 |
3933
|
31 #include <iostream> |
|
32 |
4513
|
33 #include "dim-vector.h" |
3613
|
34 #include "lo-utils.h" |
228
|
35 |
1560
|
36 class idx_vector; |
|
37 |
1359
|
38 // One dimensional array class. Handles the reference counting for |
|
39 // all the derived classes. |
238
|
40 |
228
|
41 template <class T> |
4459
|
42 T |
|
43 resize_fill_value (const T& x) |
|
44 { |
|
45 return x; |
|
46 } |
|
47 |
|
48 template <class T> |
3585
|
49 class |
|
50 Array |
228
|
51 { |
3504
|
52 protected: |
1619
|
53 |
4513
|
54 //-------------------------------------------------------------------- |
|
55 // The real representation of all arrays. |
|
56 //-------------------------------------------------------------------- |
1735
|
57 |
|
58 class ArrayRep |
|
59 { |
|
60 public: |
|
61 |
|
62 T *data; |
5275
|
63 octave_idx_type len; |
1735
|
64 int count; |
|
65 |
5275
|
66 ArrayRep (T *d, octave_idx_type l) : data (d), len (l), count (1) { } |
1735
|
67 |
|
68 ArrayRep (void) : data (0), len (0), count (1) { } |
|
69 |
5275
|
70 explicit ArrayRep (octave_idx_type n) : data (new T [n]), len (n), count (1) { } |
1735
|
71 |
5275
|
72 explicit ArrayRep (octave_idx_type n, const T& val) |
4513
|
73 : data (new T [n]), len (n), count (1) |
|
74 { |
|
75 fill (val); |
|
76 } |
|
77 |
1735
|
78 ArrayRep (const ArrayRep& a) |
|
79 : data (new T [a.len]), len (a.len), count (1) |
4513
|
80 { |
5275
|
81 for (octave_idx_type i = 0; i < len; i++) |
4513
|
82 data[i] = a.data[i]; |
|
83 } |
4517
|
84 |
1735
|
85 ~ArrayRep (void) { delete [] data; } |
|
86 |
5275
|
87 octave_idx_type length (void) const { return len; } |
1735
|
88 |
4513
|
89 void fill (const T& val) |
|
90 { |
5275
|
91 for (octave_idx_type i = 0; i < len; i++) |
4513
|
92 data[i] = val; |
|
93 } |
|
94 |
5275
|
95 T& elem (octave_idx_type n) { return data[n]; } |
1735
|
96 |
5275
|
97 T elem (octave_idx_type n) const { return data[n]; } |
1756
|
98 |
|
99 void qsort (int (*compare) (const void *, const void *)) |
|
100 { |
3613
|
101 octave_qsort (data, static_cast<size_t> (len), sizeof (T), compare); |
1756
|
102 } |
4517
|
103 |
|
104 private: |
|
105 |
|
106 // No assignment! |
|
107 |
|
108 ArrayRep& operator = (const ArrayRep& a); |
1735
|
109 }; |
|
110 |
4513
|
111 //-------------------------------------------------------------------- |
|
112 |
6884
|
113 public: |
|
114 |
|
115 // !!! WARNING !!! -- these should be protected, not public. You |
|
116 // should not access these methods directly! |
|
117 |
2006
|
118 void make_unique (void) |
|
119 { |
|
120 if (rep->count > 1) |
|
121 { |
|
122 --rep->count; |
|
123 rep = new ArrayRep (*rep); |
|
124 } |
|
125 } |
|
126 |
4513
|
127 void make_unique (const T& val) |
|
128 { |
|
129 if (rep->count > 1) |
|
130 { |
|
131 --rep->count; |
|
132 rep = new ArrayRep (rep->length (), val); |
|
133 } |
|
134 else |
|
135 rep->fill (val); |
|
136 } |
238
|
137 |
5900
|
138 typedef T element_type; |
|
139 |
4902
|
140 // !!! WARNING !!! -- these should be protected, not public. You |
|
141 // should not access these data members directly! |
|
142 |
|
143 typename Array<T>::ArrayRep *rep; |
4518
|
144 |
4513
|
145 dim_vector dimensions; |
|
146 |
4518
|
147 protected: |
|
148 |
6881
|
149 mutable idx_vector *idx; |
|
150 mutable int idx_count; |
4513
|
151 |
5275
|
152 Array (T *d, octave_idx_type n) |
4513
|
153 : rep (new typename Array<T>::ArrayRep (d, n)), dimensions (n), |
|
154 idx (0), idx_count (0) { } |
1619
|
155 |
4587
|
156 Array (T *d, const dim_vector& dv) |
|
157 : rep (new typename Array<T>::ArrayRep (d, get_size (dv))), |
|
158 dimensions (dv), idx (0), idx_count (0) { } |
4513
|
159 |
|
160 private: |
|
161 |
4585
|
162 typename Array<T>::ArrayRep *nil_rep (void) const |
4513
|
163 { |
|
164 static typename Array<T>::ArrayRep *nr |
|
165 = new typename Array<T>::ArrayRep (); |
|
166 |
|
167 return nr; |
1550
|
168 } |
238
|
169 |
4902
|
170 template <class U> |
|
171 T * |
|
172 coerce (const U *a, int len) |
|
173 { |
|
174 T *retval = new T [len]; |
|
175 |
|
176 for (int i = 0; i < len; i++) |
|
177 retval[i] = T (a[i]); |
|
178 |
|
179 return retval; |
|
180 } |
|
181 |
228
|
182 public: |
238
|
183 |
1550
|
184 Array (void) |
4513
|
185 : rep (nil_rep ()), dimensions (), |
|
186 idx (0), idx_count (0) { rep->count++; } |
1550
|
187 |
5275
|
188 explicit Array (octave_idx_type n) |
4513
|
189 : rep (new typename Array<T>::ArrayRep (n)), dimensions (n), |
|
190 idx (0), idx_count (0) { } |
1619
|
191 |
5275
|
192 explicit Array (octave_idx_type n, const T& val) |
4513
|
193 : rep (new typename Array<T>::ArrayRep (n)), dimensions (n), |
|
194 idx (0), idx_count (0) |
|
195 { |
|
196 fill (val); |
|
197 } |
|
198 |
4902
|
199 // Type conversion case. |
|
200 template <class U> |
|
201 Array (const Array<U>& a) |
|
202 : rep (new typename Array<T>::ArrayRep (coerce (a.data (), a.length ()), a.length ())), |
|
203 dimensions (a.dimensions), idx (0), idx_count (0) |
|
204 { |
|
205 } |
|
206 |
|
207 // No type conversion case. |
4513
|
208 Array (const Array<T>& a) |
|
209 : rep (a.rep), dimensions (a.dimensions), idx (0), idx_count (0) |
|
210 { |
|
211 rep->count++; |
1550
|
212 } |
|
213 |
4513
|
214 public: |
|
215 |
4587
|
216 Array (const dim_vector& dv) |
|
217 : rep (new typename Array<T>::ArrayRep (get_size (dv))), |
|
218 dimensions (dv), idx (0), idx_count (0) { } |
238
|
219 |
4587
|
220 Array (const dim_vector& dv, const T& val) |
|
221 : rep (new typename Array<T>::ArrayRep (get_size (dv))), |
|
222 dimensions (dv), idx (0), idx_count (0) |
1550
|
223 { |
4513
|
224 fill (val); |
|
225 } |
|
226 |
4834
|
227 Array (const Array<T>& a, const dim_vector& dv); |
228
|
228 |
4979
|
229 virtual ~Array (void); |
228
|
230 |
4513
|
231 Array<T>& operator = (const Array<T>& a) |
|
232 { |
|
233 if (this != &a) |
|
234 { |
|
235 if (--rep->count <= 0) |
|
236 delete rep; |
|
237 |
|
238 rep = a.rep; |
|
239 rep->count++; |
|
240 |
|
241 dimensions = a.dimensions; |
5632
|
242 |
|
243 idx_count = 0; |
|
244 idx = 0; |
4513
|
245 } |
|
246 |
|
247 return *this; |
|
248 } |
|
249 |
|
250 void fill (const T& val) { make_unique (val); } |
238
|
251 |
5275
|
252 octave_idx_type capacity (void) const { return rep->length (); } |
|
253 octave_idx_type length (void) const { return capacity (); } |
|
254 octave_idx_type nelem (void) const { return capacity (); } |
|
255 octave_idx_type numel (void) const { return nelem (); } |
4513
|
256 |
5275
|
257 octave_idx_type dim1 (void) const { return dimensions(0); } |
|
258 octave_idx_type dim2 (void) const { return dimensions(1); } |
|
259 octave_idx_type dim3 (void) const { return dimensions(2); } |
4513
|
260 |
5275
|
261 octave_idx_type rows (void) const { return dim1 (); } |
|
262 octave_idx_type cols (void) const { return dim2 (); } |
|
263 octave_idx_type columns (void) const { return dim2 (); } |
|
264 octave_idx_type pages (void) const { return dim3 (); } |
4513
|
265 |
4902
|
266 size_t byte_size (void) const { return numel () * sizeof (T); } |
|
267 |
4513
|
268 dim_vector dims (void) const { return dimensions; } |
|
269 |
4532
|
270 Array<T> squeeze (void) const; |
4703
|
271 |
|
272 void chop_trailing_singletons (void) |
|
273 { dimensions.chop_trailing_singletons (); } |
|
274 |
5275
|
275 static octave_idx_type get_size (octave_idx_type r, octave_idx_type c); |
|
276 static octave_idx_type get_size (octave_idx_type r, octave_idx_type c, octave_idx_type p); |
|
277 static octave_idx_type get_size (const dim_vector& dv); |
228
|
278 |
5275
|
279 octave_idx_type compute_index (const Array<octave_idx_type>& ra_idx) const; |
4517
|
280 |
5275
|
281 T range_error (const char *fcn, octave_idx_type n) const; |
|
282 T& range_error (const char *fcn, octave_idx_type n); |
3665
|
283 |
5275
|
284 T range_error (const char *fcn, octave_idx_type i, octave_idx_type j) const; |
|
285 T& range_error (const char *fcn, octave_idx_type i, octave_idx_type j); |
4513
|
286 |
5275
|
287 T range_error (const char *fcn, octave_idx_type i, octave_idx_type j, octave_idx_type k) const; |
|
288 T& range_error (const char *fcn, octave_idx_type i, octave_idx_type j, octave_idx_type k); |
4513
|
289 |
6867
|
290 T range_error (const char *fcn, const Array<octave_idx_type>& ra_idx) const; |
|
291 T& range_error (const char *fcn, const Array<octave_idx_type>& ra_idx); |
4513
|
292 |
2108
|
293 // No checking, even for multiple references, ever. |
|
294 |
5275
|
295 T& xelem (octave_idx_type n) { return rep->elem (n); } |
|
296 T xelem (octave_idx_type n) const { return rep->elem (n); } |
2108
|
297 |
5275
|
298 T& xelem (octave_idx_type i, octave_idx_type j) { return xelem (dim1()*j+i); } |
|
299 T xelem (octave_idx_type i, octave_idx_type j) const { return xelem (dim1()*j+i); } |
4513
|
300 |
5275
|
301 T& xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return xelem (i, dim2()*k+j); } |
|
302 T xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const { return xelem (i, dim2()*k+j); } |
4513
|
303 |
6867
|
304 T& xelem (const Array<octave_idx_type>& ra_idx) |
4513
|
305 { return xelem (compute_index (ra_idx)); } |
|
306 |
6867
|
307 T xelem (const Array<octave_idx_type>& ra_idx) const |
4513
|
308 { return xelem (compute_index (ra_idx)); } |
|
309 |
5775
|
310 // FIXME -- would be nice to fix this so that we don't |
2006
|
311 // unnecessarily force a copy, but that is not so easy, and I see no |
|
312 // clean way to do it. |
|
313 |
5275
|
314 T& checkelem (octave_idx_type n) |
2006
|
315 { |
|
316 if (n < 0 || n >= rep->length ()) |
2109
|
317 return range_error ("T& Array<T>::checkelem", n); |
2006
|
318 else |
2108
|
319 { |
|
320 make_unique (); |
|
321 return xelem (n); |
|
322 } |
2006
|
323 } |
|
324 |
5275
|
325 T& checkelem (octave_idx_type i, octave_idx_type j) |
4513
|
326 { |
|
327 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ()) |
|
328 return range_error ("T& Array<T>::checkelem", i, j); |
|
329 else |
|
330 return elem (dim1()*j+i); |
|
331 } |
|
332 |
5275
|
333 T& checkelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) |
4513
|
334 { |
|
335 if (i < 0 || j < 0 || k < 0 || i >= dim1 () || j >= dim2 () || k >= dim3 ()) |
|
336 return range_error ("T& Array<T>::checkelem", i, j, k); |
|
337 else |
|
338 return elem (i, dim2()*k+j); |
|
339 } |
|
340 |
6867
|
341 T& checkelem (const Array<octave_idx_type>& ra_idx) |
4513
|
342 { |
5275
|
343 octave_idx_type i = compute_index (ra_idx); |
4513
|
344 |
|
345 if (i < 0) |
|
346 return range_error ("T& Array<T>::checkelem", ra_idx); |
|
347 else |
|
348 return elem (i); |
|
349 } |
|
350 |
5275
|
351 T& elem (octave_idx_type n) |
2108
|
352 { |
|
353 make_unique (); |
2109
|
354 return xelem (n); |
2108
|
355 } |
2306
|
356 |
5275
|
357 T& elem (octave_idx_type i, octave_idx_type j) { return elem (dim1()*j+i); } |
4513
|
358 |
5275
|
359 T& elem (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return elem (i, dim2()*k+j); } |
4513
|
360 |
6867
|
361 T& elem (const Array<octave_idx_type>& ra_idx) |
4513
|
362 { return Array<T>::elem (compute_index (ra_idx)); } |
|
363 |
2306
|
364 #if defined (BOUNDS_CHECKING) |
5275
|
365 T& operator () (octave_idx_type n) { return checkelem (n); } |
|
366 T& operator () (octave_idx_type i, octave_idx_type j) { return checkelem (i, j); } |
|
367 T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return checkelem (i, j, k); } |
6867
|
368 T& operator () (const Array<octave_idx_type>& ra_idx) { return checkelem (ra_idx); } |
2306
|
369 #else |
5275
|
370 T& operator () (octave_idx_type n) { return elem (n); } |
|
371 T& operator () (octave_idx_type i, octave_idx_type j) { return elem (i, j); } |
|
372 T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return elem (i, j, k); } |
6867
|
373 T& operator () (const Array<octave_idx_type>& ra_idx) { return elem (ra_idx); } |
2006
|
374 #endif |
|
375 |
5275
|
376 T checkelem (octave_idx_type n) const |
2006
|
377 { |
|
378 if (n < 0 || n >= rep->length ()) |
2109
|
379 return range_error ("T Array<T>::checkelem", n); |
2049
|
380 else |
2108
|
381 return xelem (n); |
2006
|
382 } |
1989
|
383 |
5275
|
384 T checkelem (octave_idx_type i, octave_idx_type j) const |
4513
|
385 { |
|
386 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ()) |
|
387 return range_error ("T Array<T>::checkelem", i, j); |
|
388 else |
|
389 return elem (dim1()*j+i); |
|
390 } |
|
391 |
5275
|
392 T checkelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const |
4513
|
393 { |
|
394 if (i < 0 || j < 0 || k < 0 || i >= dim1 () || j >= dim2 () || k >= dim3 ()) |
|
395 return range_error ("T Array<T>::checkelem", i, j, k); |
|
396 else |
|
397 return Array<T>::elem (i, Array<T>::dim1()*k+j); |
|
398 } |
|
399 |
6867
|
400 T checkelem (const Array<octave_idx_type>& ra_idx) const |
4513
|
401 { |
5275
|
402 octave_idx_type i = compute_index (ra_idx); |
4513
|
403 |
|
404 if (i < 0) |
|
405 return range_error ("T Array<T>::checkelem", ra_idx); |
|
406 else |
|
407 return Array<T>::elem (i); |
|
408 } |
|
409 |
5275
|
410 T elem (octave_idx_type n) const { return xelem (n); } |
2306
|
411 |
5275
|
412 T elem (octave_idx_type i, octave_idx_type j) const { return elem (dim1()*j+i); } |
4513
|
413 |
5275
|
414 T elem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const { return elem (i, dim2()*k+j); } |
4513
|
415 |
6867
|
416 T elem (const Array<octave_idx_type>& ra_idx) const |
4513
|
417 { return Array<T>::elem (compute_index (ra_idx)); } |
|
418 |
2108
|
419 #if defined (BOUNDS_CHECKING) |
5275
|
420 T operator () (octave_idx_type n) const { return checkelem (n); } |
|
421 T operator () (octave_idx_type i, octave_idx_type j) const { return checkelem (i, j); } |
|
422 T operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) const { return checkelem (i, j, k); } |
6867
|
423 T operator () (const Array<octave_idx_type>& ra_idx) const { return checkelem (ra_idx); } |
2006
|
424 #else |
5275
|
425 T operator () (octave_idx_type n) const { return elem (n); } |
|
426 T operator () (octave_idx_type i, octave_idx_type j) const { return elem (i, j); } |
|
427 T operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) const { return elem (i, j, k); } |
6867
|
428 T operator () (const Array<octave_idx_type>& ra_idx) const { return elem (ra_idx); } |
2006
|
429 #endif |
|
430 |
4567
|
431 Array<T> reshape (const dim_vector& new_dims) const; |
|
432 |
5275
|
433 Array<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const; |
|
434 Array<T> ipermute (const Array<octave_idx_type>& vec) const |
4593
|
435 { return permute (vec, true); } |
|
436 |
5275
|
437 void resize_no_fill (octave_idx_type n); |
|
438 void resize_and_fill (octave_idx_type n, const T& val); |
4548
|
439 |
4518
|
440 // !!! WARNING !!! -- the following resize_no_fill and |
|
441 // resize_and_fill functions are public because template friends |
|
442 // don't work properly with versions of gcc earlier than 3.3. You |
|
443 // should use these functions only in classes that are derived |
|
444 // from Array<T>. |
|
445 |
|
446 // protected: |
4513
|
447 |
5275
|
448 void resize_no_fill (octave_idx_type r, octave_idx_type c); |
|
449 void resize_and_fill (octave_idx_type r, octave_idx_type c, const T& val); |
4513
|
450 |
5275
|
451 void resize_no_fill (octave_idx_type r, octave_idx_type c, octave_idx_type p); |
|
452 void resize_and_fill (octave_idx_type r, octave_idx_type c, octave_idx_type p, const T& val); |
4513
|
453 |
4587
|
454 void resize_no_fill (const dim_vector& dv); |
|
455 void resize_and_fill (const dim_vector& dv, const T& val); |
4513
|
456 |
|
457 public: |
|
458 |
5392
|
459 void resize (octave_idx_type n) { resize_no_fill (n); } |
4513
|
460 |
5392
|
461 void resize (octave_idx_type n, const T& val) { resize_and_fill (n, val); } |
4513
|
462 |
4587
|
463 void resize (const dim_vector& dv) { resize_no_fill (dv); } |
4513
|
464 |
4587
|
465 void resize (const dim_vector& dv, const T& val) |
|
466 { resize_and_fill (dv, val); } |
4513
|
467 |
5275
|
468 Array<T>& insert (const Array<T>& a, octave_idx_type r, octave_idx_type c); |
|
469 Array<T>& insert2 (const Array<T>& a, octave_idx_type r, octave_idx_type c); |
|
470 Array<T>& insertN (const Array<T>& a, octave_idx_type r, octave_idx_type c); |
4513
|
471 |
5275
|
472 Array<T>& insert (const Array<T>& a, const Array<octave_idx_type>& idx); |
4513
|
473 |
|
474 bool is_square (void) const { return (dim1 () == dim2 ()); } |
|
475 |
4559
|
476 bool is_empty (void) const { return numel () == 0; } |
|
477 |
4513
|
478 Array<T> transpose (void) const; |
238
|
479 |
1550
|
480 const T *data (void) const { return rep->data; } |
228
|
481 |
3952
|
482 const T *fortran_vec (void) const { return data (); } |
|
483 |
238
|
484 T *fortran_vec (void); |
1560
|
485 |
1781
|
486 Array<T>& qsort (int (*compare) (const void *, const void *)) |
1756
|
487 { |
2347
|
488 make_unique (); |
1756
|
489 |
|
490 rep->qsort (compare); |
1781
|
491 |
|
492 return *this; |
1756
|
493 } |
|
494 |
4513
|
495 int ndims (void) const { return dimensions.length (); } |
1560
|
496 |
4517
|
497 void maybe_delete_dims (void); |
|
498 |
6881
|
499 void clear_index (void) const; |
1560
|
500 |
6881
|
501 void set_index (const idx_vector& i) const; |
1560
|
502 |
1619
|
503 int index_count (void) const { return idx_count; } |
1560
|
504 |
1619
|
505 idx_vector *get_idx (void) const { return idx; } |
1560
|
506 |
|
507 void maybe_delete_elements (idx_vector& i); |
|
508 |
4513
|
509 void maybe_delete_elements_1 (idx_vector& i); |
|
510 |
|
511 void maybe_delete_elements_2 (idx_vector& i); |
|
512 |
|
513 void maybe_delete_elements (idx_vector& i, idx_vector& j); |
|
514 |
|
515 void maybe_delete_elements (idx_vector& i, idx_vector& j, idx_vector& k); |
|
516 |
|
517 void maybe_delete_elements (Array<idx_vector>& ra_idx, const T& rfv); |
|
518 |
6881
|
519 Array<T> value (void) const; |
2382
|
520 |
3933
|
521 Array<T> index (idx_vector& i, int resize_ok = 0, |
4459
|
522 const T& rfv = resize_fill_value (T ())) const; |
3933
|
523 |
4513
|
524 Array<T> index1 (idx_vector& i, int resize_ok = 0, |
|
525 const T& rfv = resize_fill_value (T ())) const; |
|
526 |
|
527 Array<T> index2 (idx_vector& i, int resize_ok = 0, |
|
528 const T& rfv = resize_fill_value (T ())) const; |
|
529 |
4530
|
530 Array<T> indexN (idx_vector& i, int resize_ok = 0, |
|
531 const T& rfv = resize_fill_value (T ())) const; |
|
532 |
4513
|
533 Array<T> index (idx_vector& i, idx_vector& j, int resize_ok = 0, |
|
534 const T& rfv = resize_fill_value (T ())) const; |
|
535 |
|
536 Array<T> index (Array<idx_vector>& ra_idx, int resize_ok = 0, |
|
537 const T& rfv = resize_fill_value (T ())) const; |
3928
|
538 |
4459
|
539 // static T resize_fill_value (void) { return T (); } |
3933
|
540 |
4517
|
541 void print_info (std::ostream& os, const std::string& prefix) const; |
5900
|
542 |
|
543 // Unsafe. This function exists to support the MEX interface. |
|
544 // You should not use it anywhere else. |
|
545 void *mex_get_data (void) const { return const_cast<T *> (data ()); } |
4513
|
546 }; |
4459
|
547 |
4518
|
548 // NOTE: these functions should be friends of the Array<T> class and |
|
549 // Array<T>::dimensions should be protected, not public, but we can't |
|
550 // do that because of bugs in gcc prior to 3.3. |
|
551 |
|
552 template <class LT, class RT> |
|
553 /* friend */ int |
|
554 assign (Array<LT>& lhs, const Array<RT>& rhs, const LT& rfv); |
|
555 |
|
556 template <class LT, class RT> |
|
557 /* friend */ int |
|
558 assign1 (Array<LT>& lhs, const Array<RT>& rhs, const LT& rfv); |
|
559 |
|
560 template <class LT, class RT> |
|
561 /* friend */ int |
|
562 assign2 (Array<LT>& lhs, const Array<RT>& rhs, const LT& rfv); |
|
563 |
|
564 template <class LT, class RT> |
|
565 /* friend */ int |
|
566 assignN (Array<LT>& lhs, const Array<RT>& rhs, const LT& rfv); |
|
567 |
3836
|
568 template <class LT, class RT> |
|
569 int |
|
570 assign (Array<LT>& lhs, const Array<RT>& rhs) |
|
571 { |
4459
|
572 return assign (lhs, rhs, resize_fill_value (LT ())); |
3836
|
573 } |
1560
|
574 |
6708
|
575 #define INSTANTIATE_ARRAY_ASSIGN(LT, RT, API) \ |
|
576 template API int assign (Array<LT>&, const Array<RT>&, const LT&); \ |
|
577 template API int assign1 (Array<LT>&, const Array<RT>&, const LT&); \ |
|
578 template API int assign2 (Array<LT>&, const Array<RT>&, const LT&); \ |
|
579 template API int assignN (Array<LT>&, const Array<RT>&, const LT&); \ |
|
580 template API int assign (Array<LT>&, const Array<RT>&) |
4594
|
581 |
4762
|
582 |
6708
|
583 #define INSTANTIATE_ARRAY(T, API) \ |
|
584 template class API Array<T>; \ |
|
585 template API T resize_fill_value (const T&); \ |
4762
|
586 |
6708
|
587 #define INSTANTIATE_ARRAY_AND_ASSIGN(T, API) \ |
|
588 INSTANTIATE_ARRAY (T, API); \ |
|
589 INSTANTIATE_ARRAY_ASSIGN (T, T, API) |
4594
|
590 |
228
|
591 #endif |
|
592 |
|
593 /* |
|
594 ;;; Local Variables: *** |
|
595 ;;; mode: C++ *** |
|
596 ;;; End: *** |
|
597 */ |