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 |
|
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 |
4192
|
24 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1988
|
25 #pragma interface |
|
26 #endif |
|
27 |
|
28 #if !defined (octave_MDiagArray2_h) |
|
29 #define octave_MDiagArray2_h 1 |
|
30 |
|
31 #include "DiagArray2.h" |
|
32 #include "MArray2.h" |
|
33 |
3580
|
34 // Two dimensional diagonal array with math ops. |
3107
|
35 |
3580
|
36 // But first, some preprocessor abuse... |
3107
|
37 |
3580
|
38 #include "MArray-defs.h" |
3107
|
39 |
3580
|
40 MDIAGARRAY2_OPS_FORWARD_DECLS (MDiagArray2) |
1988
|
41 |
|
42 template <class T> |
3585
|
43 class |
|
44 MDiagArray2 : public DiagArray2<T> |
1988
|
45 { |
|
46 protected: |
|
47 |
|
48 MDiagArray2 (T *d, int r, int c) : DiagArray2<T> (d, r, c) { } |
|
49 |
|
50 public: |
|
51 |
|
52 MDiagArray2 (void) : DiagArray2<T> () { } |
3585
|
53 |
1988
|
54 MDiagArray2 (int r, int c) : DiagArray2<T> (r, c) { } |
3585
|
55 |
1988
|
56 MDiagArray2 (int r, int c, const T& val) : DiagArray2<T> (r, c, val) { } |
3585
|
57 |
|
58 MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { } |
|
59 |
1988
|
60 MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { } |
3585
|
61 |
|
62 explicit MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { } |
1988
|
63 |
|
64 ~MDiagArray2 (void) { } |
|
65 |
|
66 MDiagArray2<T>& operator = (const MDiagArray2<T>& a) |
|
67 { |
|
68 DiagArray2<T>::operator = (a); |
|
69 return *this; |
|
70 } |
|
71 |
|
72 operator MArray2<T> () const |
|
73 { |
4513
|
74 int nr = DiagArray2<T>::dim1 (); |
|
75 int nc = DiagArray2<T>::dim2 (); |
1988
|
76 |
4513
|
77 MArray2<T> retval (nr, nc, T (0)); |
|
78 |
|
79 int len = nr < nc ? nr : nc; |
1988
|
80 |
|
81 for (int i = 0; i < len; i++) |
|
82 retval.xelem (i, i) = xelem (i, i); |
|
83 |
|
84 return retval; |
|
85 } |
|
86 |
4187
|
87 static MDiagArray2<T> nil_array; |
|
88 |
3580
|
89 // Currently, the OPS functions don't need to be friends, but that |
|
90 // may change. |
1988
|
91 |
3610
|
92 // MDIAGARRAY2_OPS_FRIEND_DECLS (MDiagArray2) |
3580
|
93 |
|
94 }; |
1988
|
95 |
|
96 #endif |
|
97 |
|
98 /* |
|
99 ;;; Local Variables: *** |
|
100 ;;; mode: C++ *** |
|
101 ;;; End: *** |
|
102 */ |