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