1993
|
1 // Template array classes with like-type math ops |
237
|
2 /* |
|
3 |
2847
|
4 Copyright (C) 1996, 1997 John W. Eaton |
237
|
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 |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
237
|
21 |
|
22 */ |
|
23 |
1296
|
24 #if defined (__GNUG__) |
|
25 #pragma interface |
|
26 #endif |
|
27 |
382
|
28 #if !defined (octave_MArray_h) |
|
29 #define octave_MArray_h 1 |
|
30 |
237
|
31 #include "Array.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 MArray; |
|
45 |
|
46 template <typename T> MArray<T>& |
|
47 operator += (MArray<T>& a, const T& s); |
|
48 |
|
49 template <typename T> MArray<T>& |
|
50 operator -= (MArray<T>& a, const T& s); |
|
51 |
|
52 template <typename T> MArray<T>& |
|
53 operator += (MArray<T>& a, const MArray<T>& b); |
|
54 |
|
55 template <typename T> MArray<T>& |
|
56 operator -= (MArray<T>& a, const MArray<T>& b); |
|
57 |
|
58 template <typename T> MArray<T> |
|
59 operator + (const MArray<T>& a, const T& s); |
|
60 |
|
61 template <typename T> MArray<T> |
|
62 operator - (const MArray<T>& a, const T& s); |
|
63 |
|
64 template <typename T> MArray<T> |
|
65 operator * (const MArray<T>& a, const T& s); |
|
66 |
|
67 template <typename T> MArray<T> |
|
68 operator / (const MArray<T>& a, const T& s); |
|
69 |
|
70 template <typename T> MArray<T> |
|
71 operator + (const T& s, const MArray<T>& a); |
|
72 |
|
73 template <typename T> MArray<T> |
|
74 operator - (const T& s, const MArray<T>& a); |
|
75 |
|
76 template <typename T> MArray<T> |
|
77 operator * (const T& s, const MArray<T>& a); |
|
78 |
|
79 template <typename T> MArray<T> |
|
80 operator / (const T& s, const MArray<T>& a); |
|
81 |
|
82 template <typename T> MArray<T> |
|
83 operator + (const MArray<T>& a, const MArray<T>& b); |
|
84 |
|
85 template <typename T> MArray<T> |
|
86 operator - (const MArray<T>& a, const MArray<T>& b); |
|
87 |
|
88 template <class T> MArray<T> |
|
89 product (const MArray<T>& a, const MArray<T>& b); |
|
90 |
|
91 template <typename T> MArray<T> |
|
92 quotient (const MArray<T>& a, const MArray<T>& b); |
|
93 |
|
94 template <typename T> MArray<T> |
|
95 operator - (const MArray<T>& a); |
|
96 #endif |
|
97 |
1359
|
98 // One dimensional array with math ops. |
237
|
99 |
|
100 template <class T> |
|
101 class MArray : public Array<T> |
|
102 { |
|
103 protected: |
|
104 |
|
105 MArray (T *d, int l) : Array<T> (d, l) { } |
|
106 |
|
107 public: |
|
108 |
|
109 MArray (void) : Array<T> () { } |
|
110 MArray (int n) : Array<T> (n) { } |
|
111 MArray (int n, const T& val) : Array<T> (n, val) { } |
1989
|
112 // MArray (const Array<T>& a) : Array<T> (a) { } |
237
|
113 MArray (const MArray<T>& a) : Array<T> (a) { } |
|
114 |
1230
|
115 ~MArray (void) { } |
|
116 |
237
|
117 MArray<T>& operator = (const MArray<T>& a) |
1213
|
118 { |
|
119 Array<T>::operator = (a); |
|
120 return *this; |
|
121 } |
237
|
122 |
1359
|
123 // element by element MArray by scalar ops |
237
|
124 |
3107
|
125 friend MArray<T>& operator += LTGT (MArray<T>& a, const T& s); |
|
126 friend MArray<T>& operator -= LTGT (MArray<T>& a, const T& s); |
237
|
127 |
1359
|
128 // element by element MArray by MArray ops |
237
|
129 |
3107
|
130 friend MArray<T>& operator += LTGT (MArray<T>& a, const MArray<T>& b); |
|
131 friend MArray<T>& operator -= LTGT (MArray<T>& a, const MArray<T>& b); |
237
|
132 |
1359
|
133 // element by element MArray by scalar ops |
237
|
134 |
3107
|
135 friend MArray<T> operator + LTGT (const MArray<T>& a, const T& s); |
|
136 friend MArray<T> operator - LTGT (const MArray<T>& a, const T& s); |
|
137 friend MArray<T> operator * LTGT (const MArray<T>& a, const T& s); |
|
138 friend MArray<T> operator / LTGT (const MArray<T>& a, const T& s); |
237
|
139 |
1359
|
140 // element by element scalar by MArray ops |
237
|
141 |
3107
|
142 friend MArray<T> operator + LTGT (const T& s, const MArray<T>& a); |
|
143 friend MArray<T> operator - LTGT (const T& s, const MArray<T>& a); |
|
144 friend MArray<T> operator * LTGT (const T& s, const MArray<T>& a); |
|
145 friend MArray<T> operator / LTGT (const T& s, const MArray<T>& a); |
237
|
146 |
1359
|
147 // element by element MArray by MArray ops |
237
|
148 |
3107
|
149 friend MArray<T> operator + LTGT (const MArray<T>& a, const MArray<T>& b); |
237
|
150 |
3107
|
151 friend MArray<T> operator - LTGT (const MArray<T>& a, const MArray<T>& b); |
237
|
152 |
3107
|
153 friend MArray<T> product LTGT (const MArray<T>& a, const MArray<T>& b); |
|
154 friend MArray<T> quotient LTGT (const MArray<T>& a, const MArray<T>& b); |
237
|
155 |
3107
|
156 friend MArray<T> operator - LTGT (const MArray<T>& a); |
237
|
157 }; |
|
158 |
3107
|
159 #undef LTGT |
|
160 |
2391
|
161 extern void |
|
162 gripe_nonconformant (const char *op, int op1_len, int op2_len); |
|
163 |
1989
|
164 #define INSTANTIATE_MARRAY_FRIENDS(T) \ |
1992
|
165 template MArray<T>& operator += (MArray<T>& a, const T& s); \ |
|
166 template MArray<T>& operator -= (MArray<T>& a, const T& s); \ |
|
167 template MArray<T>& operator += (MArray<T>& a, const MArray<T>& b); \ |
|
168 template MArray<T>& operator -= (MArray<T>& a, const MArray<T>& b); \ |
1989
|
169 template MArray<T> operator + (const MArray<T>& a, const T& s); \ |
|
170 template MArray<T> operator - (const MArray<T>& a, const T& s); \ |
|
171 template MArray<T> operator * (const MArray<T>& a, const T& s); \ |
|
172 template MArray<T> operator / (const MArray<T>& a, const T& s); \ |
|
173 template MArray<T> operator + (const T& s, const MArray<T>& a); \ |
|
174 template MArray<T> operator - (const T& s, const MArray<T>& a); \ |
|
175 template MArray<T> operator * (const T& s, const MArray<T>& a); \ |
|
176 template MArray<T> operator / (const T& s, const MArray<T>& a); \ |
|
177 template MArray<T> operator + (const MArray<T>& a, const MArray<T>& b); \ |
|
178 template MArray<T> operator - (const MArray<T>& a, const MArray<T>& b); \ |
|
179 template MArray<T> product (const MArray<T>& a, const MArray<T>& b); \ |
|
180 template MArray<T> quotient (const MArray<T>& a, const MArray<T>& b); \ |
|
181 template MArray<T> operator - (const MArray<T>& a); |
237
|
182 |
|
183 #endif |
|
184 |
|
185 /* |
|
186 ;;; Local Variables: *** |
|
187 ;;; mode: C++ *** |
|
188 ;;; End: *** |
|
189 */ |