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