1993
|
1 // Template array classes with like-type math ops |
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 |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
1988
|
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 |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
1988
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_MDiagArray2_h) |
|
25 #define octave_MDiagArray2_h 1 |
|
26 |
|
27 #include "DiagArray2.h" |
|
28 #include "MArray2.h" |
|
29 |
3580
|
30 // Two dimensional diagonal array with math ops. |
3107
|
31 |
3580
|
32 // But first, some preprocessor abuse... |
3107
|
33 |
3580
|
34 #include "MArray-defs.h" |
3107
|
35 |
6708
|
36 MDIAGARRAY2_OPS_FORWARD_DECLS (MDiagArray2, ) |
1988
|
37 |
|
38 template <class T> |
3585
|
39 class |
|
40 MDiagArray2 : public DiagArray2<T> |
1988
|
41 { |
|
42 protected: |
|
43 |
5275
|
44 MDiagArray2 (T *d, octave_idx_type r, octave_idx_type c) : DiagArray2<T> (d, r, c) { } |
1988
|
45 |
|
46 public: |
|
47 |
|
48 MDiagArray2 (void) : DiagArray2<T> () { } |
3585
|
49 |
5275
|
50 MDiagArray2 (octave_idx_type r, octave_idx_type c) : DiagArray2<T> (r, c) { } |
3585
|
51 |
5275
|
52 MDiagArray2 (octave_idx_type r, octave_idx_type c, const T& val) : DiagArray2<T> (r, c, val) { } |
3585
|
53 |
|
54 MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { } |
|
55 |
1988
|
56 MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { } |
3585
|
57 |
|
58 explicit MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { } |
1988
|
59 |
|
60 ~MDiagArray2 (void) { } |
|
61 |
|
62 MDiagArray2<T>& operator = (const MDiagArray2<T>& a) |
|
63 { |
|
64 DiagArray2<T>::operator = (a); |
|
65 return *this; |
|
66 } |
|
67 |
|
68 operator MArray2<T> () const |
|
69 { |
5275
|
70 octave_idx_type nr = DiagArray2<T>::dim1 (); |
|
71 octave_idx_type nc = DiagArray2<T>::dim2 (); |
1988
|
72 |
4513
|
73 MArray2<T> retval (nr, nc, T (0)); |
|
74 |
5275
|
75 octave_idx_type len = nr < nc ? nr : nc; |
1988
|
76 |
5275
|
77 for (octave_idx_type i = 0; i < len; i++) |
4645
|
78 retval.xelem (i, i) = this->xelem (i, i); |
1988
|
79 |
|
80 return retval; |
|
81 } |
|
82 |
4187
|
83 static MDiagArray2<T> nil_array; |
|
84 |
3580
|
85 // Currently, the OPS functions don't need to be friends, but that |
|
86 // may change. |
1988
|
87 |
3610
|
88 // MDIAGARRAY2_OPS_FRIEND_DECLS (MDiagArray2) |
3580
|
89 |
|
90 }; |
1988
|
91 |
|
92 #endif |
|
93 |
|
94 /* |
|
95 ;;; Local Variables: *** |
|
96 ;;; mode: C++ *** |
|
97 ;;; End: *** |
|
98 */ |