1993
|
1 // Template array classes |
1988
|
2 /* |
|
3 |
2847
|
4 Copyright (C) 1996, 1997 John W. Eaton |
1988
|
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 |
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_Array2_h) |
|
25 #define octave_Array2_h 1 |
|
26 |
|
27 #include <cassert> |
3473
|
28 #include <climits> |
|
29 #include <cmath> |
1988
|
30 #include <cstdlib> |
|
31 |
|
32 #include "Array.h" |
|
33 #include "lo-error.h" |
|
34 |
|
35 class idx_vector; |
|
36 |
|
37 // Two dimensional array class. |
|
38 |
|
39 template <class T> |
3585
|
40 class |
|
41 Array2 : public Array<T> |
1988
|
42 { |
3492
|
43 protected: |
3473
|
44 |
5275
|
45 static octave_idx_type get_size (octave_idx_type r, octave_idx_type c) { return Array<T>::get_size (r, c); } |
3473
|
46 |
5275
|
47 Array2 (T *d, octave_idx_type r, octave_idx_type c) : Array<T> (d, dim_vector (r, c)) { } |
1988
|
48 |
|
49 public: |
|
50 |
4513
|
51 Array2 (void) : Array<T> (dim_vector (0, 0)) { } |
1988
|
52 |
5275
|
53 Array2 (octave_idx_type r, octave_idx_type c) : Array<T> (dim_vector (r, c)) { } |
1988
|
54 |
5275
|
55 Array2 (octave_idx_type r, octave_idx_type c, const T& val) |
4513
|
56 : Array<T> (dim_vector (r, c), val) { } |
1988
|
57 |
4513
|
58 Array2 (const Array2<T>& a) : Array<T> (a, a.dims ()) { } |
1988
|
59 |
5275
|
60 Array2 (const Array<T>& a, octave_idx_type r, octave_idx_type c) |
4513
|
61 : Array<T> (a, dim_vector (r, c)) { } |
1988
|
62 |
|
63 ~Array2 (void) { } |
|
64 |
|
65 Array2<T>& operator = (const Array2<T>& a) |
|
66 { |
3832
|
67 if (this != &a) |
4645
|
68 Array<T>::operator = (a); |
1988
|
69 |
|
70 return *this; |
|
71 } |
|
72 |
5275
|
73 void resize (octave_idx_type r, octave_idx_type c) { this->resize_no_fill (r, c); } |
3665
|
74 |
5275
|
75 void resize (octave_idx_type r, octave_idx_type c, const T& val) |
4645
|
76 { this->resize_and_fill (r, c, val); } |
2109
|
77 |
5275
|
78 Array2<T>& insert (const Array2<T>& a, octave_idx_type r, octave_idx_type c) |
2006
|
79 { |
4513
|
80 Array<T>::insert (a, r, c); |
|
81 return *this; |
2006
|
82 } |
1988
|
83 |
4513
|
84 Array2<T> transpose (void) const |
|
85 { |
|
86 Array<T> tmp = Array<T>::transpose (); |
|
87 return Array2<T> (tmp, tmp.rows (), tmp.columns ()); |
|
88 } |
2382
|
89 |
3933
|
90 Array2<T> index (idx_vector& i, int resize_ok = 0, |
4513
|
91 const T& rfv = resize_fill_value (T ())) const |
|
92 { |
|
93 Array<T> tmp = Array<T>::index (i, resize_ok, rfv); |
|
94 return Array2<T> (tmp, tmp.rows (), tmp.columns ()); |
|
95 } |
2382
|
96 |
3933
|
97 Array2<T> index (idx_vector& i, idx_vector& j, int resize_ok = 0, |
4513
|
98 const T& rfv = resize_fill_value (T ())) const |
|
99 { |
|
100 Array<T> tmp = Array<T>::index (i, j, resize_ok, rfv); |
|
101 return Array2<T> (tmp, tmp.rows (), tmp.columns ()); |
|
102 } |
1988
|
103 }; |
|
104 |
|
105 #endif |
|
106 |
|
107 /* |
|
108 ;;; Local Variables: *** |
|
109 ;;; mode: C++ *** |
|
110 ;;; End: *** |
|
111 */ |