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 |
5307
|
20 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
21 02110-1301, USA. |
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 |
4513
|
59 Array2 (const Array2<T>& a) : Array<T> (a, a.dims ()) { } |
1988
|
60 |
5275
|
61 Array2 (const Array<T>& a, octave_idx_type r, octave_idx_type c) |
4513
|
62 : Array<T> (a, dim_vector (r, c)) { } |
1988
|
63 |
|
64 ~Array2 (void) { } |
|
65 |
|
66 Array2<T>& operator = (const Array2<T>& a) |
|
67 { |
3832
|
68 if (this != &a) |
4645
|
69 Array<T>::operator = (a); |
1988
|
70 |
|
71 return *this; |
|
72 } |
|
73 |
5275
|
74 void resize (octave_idx_type r, octave_idx_type c) { this->resize_no_fill (r, c); } |
3665
|
75 |
5275
|
76 void resize (octave_idx_type r, octave_idx_type c, const T& val) |
4645
|
77 { this->resize_and_fill (r, c, val); } |
2109
|
78 |
5275
|
79 Array2<T>& insert (const Array2<T>& a, octave_idx_type r, octave_idx_type c) |
2006
|
80 { |
4513
|
81 Array<T>::insert (a, r, c); |
|
82 return *this; |
2006
|
83 } |
1988
|
84 |
4513
|
85 Array2<T> transpose (void) const |
|
86 { |
|
87 Array<T> tmp = Array<T>::transpose (); |
|
88 return Array2<T> (tmp, tmp.rows (), tmp.columns ()); |
|
89 } |
2382
|
90 |
3933
|
91 Array2<T> index (idx_vector& i, int resize_ok = 0, |
4513
|
92 const T& rfv = resize_fill_value (T ())) const |
|
93 { |
|
94 Array<T> tmp = Array<T>::index (i, resize_ok, rfv); |
|
95 return Array2<T> (tmp, tmp.rows (), tmp.columns ()); |
|
96 } |
2382
|
97 |
3933
|
98 Array2<T> index (idx_vector& i, idx_vector& j, int resize_ok = 0, |
4513
|
99 const T& rfv = resize_fill_value (T ())) const |
|
100 { |
|
101 Array<T> tmp = Array<T>::index (i, j, resize_ok, rfv); |
|
102 return Array2<T> (tmp, tmp.rows (), tmp.columns ()); |
|
103 } |
1988
|
104 }; |
|
105 |
|
106 #endif |
|
107 |
|
108 /* |
|
109 ;;; Local Variables: *** |
|
110 ;;; mode: C++ *** |
|
111 ;;; End: *** |
|
112 */ |