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 |
4192
|
27 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1988
|
28 #pragma interface |
|
29 #endif |
|
30 |
|
31 #include <cassert> |
3473
|
32 #include <climits> |
|
33 #include <cmath> |
1988
|
34 #include <cstdlib> |
|
35 |
|
36 #include "Array.h" |
|
37 #include "lo-error.h" |
|
38 |
|
39 class idx_vector; |
|
40 |
|
41 // Two dimensional array class. |
|
42 |
|
43 template <class T> |
3585
|
44 class |
|
45 Array2 : public Array<T> |
1988
|
46 { |
3492
|
47 protected: |
3473
|
48 |
4513
|
49 static int get_size (int r, int c) { return Array<T>::get_size (r, c); } |
3473
|
50 |
4513
|
51 Array2 (T *d, int r, int c) : Array<T> (d, dim_vector (r, c)) { } |
1988
|
52 |
|
53 public: |
|
54 |
4513
|
55 Array2 (void) : Array<T> (dim_vector (0, 0)) { } |
1988
|
56 |
4513
|
57 Array2 (int r, int c) : Array<T> (dim_vector (r, c)) { } |
1988
|
58 |
4513
|
59 Array2 (int r, int c, const T& val) |
|
60 : Array<T> (dim_vector (r, c), val) { } |
1988
|
61 |
4513
|
62 Array2 (const Array2<T>& a) : Array<T> (a, a.dims ()) { } |
1988
|
63 |
4513
|
64 Array2 (const Array<T>& a, int r, int c) |
|
65 : Array<T> (a, dim_vector (r, c)) { } |
1988
|
66 |
|
67 ~Array2 (void) { } |
|
68 |
|
69 Array2<T>& operator = (const Array2<T>& a) |
|
70 { |
3832
|
71 if (this != &a) |
1988
|
72 { |
|
73 Array<T>::operator = (a); |
4513
|
74 |
|
75 dimensions = a.dimensions; |
1988
|
76 } |
|
77 |
|
78 return *this; |
|
79 } |
|
80 |
4513
|
81 void resize (int r, int c) { resize_no_fill (r, c); } |
3665
|
82 |
4513
|
83 void resize (int r, int c, const T& val) { resize_and_fill (r, c, val); } |
2109
|
84 |
4513
|
85 Array2<T>& insert (const Array2<T>& a, int r, int c) |
2006
|
86 { |
4513
|
87 Array<T>::insert (a, r, c); |
|
88 return *this; |
2006
|
89 } |
1988
|
90 |
4513
|
91 Array2<T> transpose (void) const |
|
92 { |
|
93 Array<T> tmp = Array<T>::transpose (); |
|
94 return Array2<T> (tmp, tmp.rows (), tmp.columns ()); |
|
95 } |
2382
|
96 |
3933
|
97 Array2<T> index (idx_vector& i, int resize_ok = 0, |
4513
|
98 const T& rfv = resize_fill_value (T ())) const |
|
99 { |
|
100 Array<T> tmp = Array<T>::index (i, resize_ok, rfv); |
|
101 return Array2<T> (tmp, tmp.rows (), tmp.columns ()); |
|
102 } |
2382
|
103 |
3933
|
104 Array2<T> index (idx_vector& i, idx_vector& j, int resize_ok = 0, |
4513
|
105 const T& rfv = resize_fill_value (T ())) const |
|
106 { |
|
107 Array<T> tmp = Array<T>::index (i, j, resize_ok, rfv); |
|
108 return Array2<T> (tmp, tmp.rows (), tmp.columns ()); |
|
109 } |
1988
|
110 }; |
|
111 |
|
112 #endif |
|
113 |
|
114 /* |
|
115 ;;; Local Variables: *** |
|
116 ;;; mode: C++ *** |
|
117 ;;; End: *** |
|
118 */ |