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 |
|
24 #if defined (__GNUG__) |
|
25 #pragma interface |
|
26 #endif |
|
27 |
|
28 #if !defined (octave_MArray2_h) |
|
29 #define octave_MArray2_h 1 |
|
30 |
|
31 #include "Array2.h" |
|
32 |
3107
|
33 #if defined (LTGT) |
|
34 #undef LTGT |
|
35 #endif |
|
36 |
|
37 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
|
38 #define LTGT |
|
39 #else |
|
40 |
|
41 #define LTGT <> |
|
42 |
|
43 template <class T> |
|
44 class MArray2; |
|
45 |
|
46 template <typename T> MArray2<T>& |
|
47 operator += (MArray2<T>& a, const T& s); |
|
48 |
|
49 template <typename T> MArray2<T>& |
|
50 operator -= (MArray2<T>& a, const T& s); |
|
51 |
|
52 template <typename T> MArray2<T>& |
|
53 operator += (MArray2<T>& a, const MArray2<T>& b); |
|
54 |
|
55 template <typename T> MArray2<T>& |
|
56 operator -= (MArray2<T>& a, const MArray2<T>& b); |
|
57 |
|
58 template <typename T> MArray2<T> |
|
59 operator + (const MArray2<T>& a, const T& s); |
|
60 |
|
61 template <typename T> MArray2<T> |
|
62 operator - (const MArray2<T>& a, const T& s); |
|
63 |
|
64 template <typename T> MArray2<T> |
|
65 operator * (const MArray2<T>& a, const T& s); |
|
66 |
|
67 template <typename T> MArray2<T> |
|
68 operator / (const MArray2<T>& a, const T& s); |
|
69 |
|
70 template <typename T> MArray2<T> |
|
71 operator + (const T& s, const MArray2<T>& a); |
|
72 |
|
73 template <typename T> MArray2<T> |
|
74 operator - (const T& s, const MArray2<T>& a); |
|
75 |
|
76 template <typename T> MArray2<T> |
|
77 operator * (const T& s, const MArray2<T>& a); |
|
78 |
|
79 template <typename T> MArray2<T> |
|
80 operator / (const T& s, const MArray2<T>& a); |
|
81 |
|
82 template <typename T> MArray2<T> |
|
83 operator + (const MArray2<T>& a, const MArray2<T>& b); |
|
84 |
|
85 template <typename T> MArray2<T> |
|
86 operator - (const MArray2<T>& a, const MArray2<T>& b); |
|
87 |
|
88 template <typename T> MArray2<T> |
|
89 product (const MArray2<T>& a, const MArray2<T>& b); |
|
90 |
|
91 template <typename T> MArray2<T> |
|
92 quotient (const MArray2<T>& a, const MArray2<T>& b); |
|
93 |
|
94 template <typename T> MArray2<T> |
|
95 operator - (const MArray2<T>& a); |
|
96 #endif |
|
97 |
1988
|
98 // Two dimensional array with math ops. |
|
99 |
|
100 template <class T> |
|
101 class MArray2 : public Array2<T> |
|
102 { |
|
103 protected: |
|
104 |
|
105 MArray2 (T *d, int n, int m) : Array2<T> (d, n, m) { } |
|
106 |
|
107 public: |
|
108 |
|
109 MArray2 (void) : Array2<T> () { } |
|
110 MArray2 (int n, int m) : Array2<T> (n, m) { } |
|
111 MArray2 (int n, int m, const T& val) : Array2<T> (n, m, val) { } |
|
112 MArray2 (const Array2<T>& a) : Array2<T> (a) { } |
|
113 MArray2 (const MArray2<T>& a) : Array2<T> (a) { } |
|
114 |
|
115 ~MArray2 (void) { } |
|
116 |
|
117 MArray2<T>& operator = (const MArray2<T>& a) |
|
118 { |
|
119 Array2<T>::operator = (a); |
|
120 return *this; |
|
121 } |
|
122 |
3225
|
123 MArray2<T>& insert (const Array2<T>& a, int r, int c) |
|
124 { |
|
125 Array2<T>::insert (a, r, c); |
|
126 return *this; |
|
127 } |
|
128 |
|
129 MArray2<T> transpose (void) const { return Array2<T>::transpose (); } |
|
130 |
1988
|
131 // element by element MArray2 by scalar ops |
|
132 |
3107
|
133 friend MArray2<T>& operator += LTGT (MArray2<T>& a, const T& s); |
|
134 friend MArray2<T>& operator -= LTGT (MArray2<T>& a, const T& s); |
1988
|
135 |
|
136 // element by element MArray2 by MArray2 ops |
|
137 |
3107
|
138 friend MArray2<T>& operator += LTGT (MArray2<T>& a, const MArray2<T>& b); |
|
139 friend MArray2<T>& operator -= LTGT (MArray2<T>& a, const MArray2<T>& b); |
1988
|
140 |
|
141 // element by element MArray2 by scalar ops |
|
142 |
3107
|
143 friend MArray2<T> operator + LTGT (const MArray2<T>& a, const T& s); |
|
144 friend MArray2<T> operator - LTGT (const MArray2<T>& a, const T& s); |
|
145 friend MArray2<T> operator * LTGT (const MArray2<T>& a, const T& s); |
|
146 friend MArray2<T> operator / LTGT (const MArray2<T>& a, const T& s); |
1988
|
147 |
|
148 // element by element scalar by MArray2 ops |
|
149 |
3107
|
150 friend MArray2<T> operator + LTGT (const T& s, const MArray2<T>& a); |
|
151 friend MArray2<T> operator - LTGT (const T& s, const MArray2<T>& a); |
|
152 friend MArray2<T> operator * LTGT (const T& s, const MArray2<T>& a); |
|
153 friend MArray2<T> operator / LTGT (const T& s, const MArray2<T>& a); |
1988
|
154 |
|
155 // element by element MArray2 by MArray2 ops |
|
156 |
3107
|
157 friend MArray2<T> operator + LTGT (const MArray2<T>& a, const MArray2<T>& b); |
|
158 friend MArray2<T> operator - LTGT (const MArray2<T>& a, const MArray2<T>& b); |
1988
|
159 |
3107
|
160 friend MArray2<T> product LTGT (const MArray2<T>& a, const MArray2<T>& b); |
|
161 friend MArray2<T> quotient LTGT (const MArray2<T>& a, const MArray2<T>& b); |
1988
|
162 |
3107
|
163 friend MArray2<T> operator - LTGT (const MArray2<T>& a); |
1988
|
164 }; |
|
165 |
3107
|
166 #undef LTGT |
|
167 |
2391
|
168 extern void |
|
169 gripe_nonconformant (const char *op, int op1_nr, int op1_nc, |
|
170 int op2_nr, int op2_nc); |
|
171 |
1988
|
172 #define INSTANTIATE_MARRAY2_FRIENDS(T) \ |
1992
|
173 template MArray2<T>& operator += (MArray2<T>& a, const T& s); \ |
|
174 template MArray2<T>& operator -= (MArray2<T>& a, const T& s); \ |
|
175 template MArray2<T>& operator += (MArray2<T>& a, const MArray2<T>& b); \ |
|
176 template MArray2<T>& operator -= (MArray2<T>& a, const MArray2<T>& b); \ |
1988
|
177 template MArray2<T> operator + (const MArray2<T>& a, const T& s); \ |
|
178 template MArray2<T> operator - (const MArray2<T>& a, const T& s); \ |
|
179 template MArray2<T> operator * (const MArray2<T>& a, const T& s); \ |
|
180 template MArray2<T> operator / (const MArray2<T>& a, const T& s); \ |
|
181 template MArray2<T> operator + (const T& s, const MArray2<T>& a); \ |
|
182 template MArray2<T> operator - (const T& s, const MArray2<T>& a); \ |
|
183 template MArray2<T> operator * (const T& s, const MArray2<T>& a); \ |
|
184 template MArray2<T> operator / (const T& s, const MArray2<T>& a); \ |
|
185 template MArray2<T> operator + (const MArray2<T>& a, const MArray2<T>& b); \ |
|
186 template MArray2<T> operator - (const MArray2<T>& a, const MArray2<T>& b); \ |
|
187 template MArray2<T> product (const MArray2<T>& a, const MArray2<T>& b); \ |
|
188 template MArray2<T> quotient (const MArray2<T>& a, const MArray2<T>& b); \ |
|
189 template MArray2<T> operator - (const MArray2<T>& a); |
|
190 |
|
191 #endif |
|
192 |
|
193 /* |
|
194 ;;; Local Variables: *** |
|
195 ;;; mode: C++ *** |
|
196 ;;; End: *** |
|
197 */ |