1993
|
1 // Template array classes with like-type math ops |
237
|
2 /* |
|
3 |
1882
|
4 Copyright (C) 1996 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 |
1359
|
33 // One dimensional array with math ops. |
237
|
34 |
|
35 template <class T> |
|
36 class MArray : public Array<T> |
|
37 { |
|
38 protected: |
|
39 |
|
40 MArray (T *d, int l) : Array<T> (d, l) { } |
|
41 |
|
42 public: |
|
43 |
|
44 MArray (void) : Array<T> () { } |
|
45 MArray (int n) : Array<T> (n) { } |
|
46 MArray (int n, const T& val) : Array<T> (n, val) { } |
1989
|
47 // MArray (const Array<T>& a) : Array<T> (a) { } |
237
|
48 MArray (const MArray<T>& a) : Array<T> (a) { } |
|
49 |
1230
|
50 ~MArray (void) { } |
|
51 |
237
|
52 MArray<T>& operator = (const MArray<T>& a) |
1213
|
53 { |
|
54 Array<T>::operator = (a); |
|
55 return *this; |
|
56 } |
237
|
57 |
1359
|
58 // element by element MArray by scalar ops |
237
|
59 |
1230
|
60 friend MArray<T>& operator += (MArray<T>& a, const T& s); |
|
61 friend MArray<T>& operator -= (MArray<T>& a, const T& s); |
237
|
62 |
1359
|
63 // element by element MArray by MArray ops |
237
|
64 |
1230
|
65 friend MArray<T>& operator += (MArray<T>& a, const MArray<T>& b); |
|
66 friend MArray<T>& operator -= (MArray<T>& a, const MArray<T>& b); |
237
|
67 |
1359
|
68 // element by element MArray by scalar ops |
237
|
69 |
|
70 friend MArray<T> operator + (const MArray<T>& a, const T& s); |
|
71 friend MArray<T> operator - (const MArray<T>& a, const T& s); |
|
72 friend MArray<T> operator * (const MArray<T>& a, const T& s); |
|
73 friend MArray<T> operator / (const MArray<T>& a, const T& s); |
|
74 |
1359
|
75 // element by element scalar by MArray ops |
237
|
76 |
|
77 friend MArray<T> operator + (const T& s, const MArray<T>& a); |
|
78 friend MArray<T> operator - (const T& s, const MArray<T>& a); |
|
79 friend MArray<T> operator * (const T& s, const MArray<T>& a); |
|
80 friend MArray<T> operator / (const T& s, const MArray<T>& a); |
|
81 |
1359
|
82 // element by element MArray by MArray ops |
237
|
83 |
|
84 friend MArray<T> operator + (const MArray<T>& a, const MArray<T>& b); |
|
85 |
|
86 friend MArray<T> operator - (const MArray<T>& a, const MArray<T>& b); |
|
87 |
|
88 friend MArray<T> product (const MArray<T>& a, const MArray<T>& b); |
|
89 friend MArray<T> quotient (const MArray<T>& a, const MArray<T>& b); |
|
90 |
|
91 friend MArray<T> operator - (const MArray<T>& a); |
|
92 }; |
|
93 |
1989
|
94 #define INSTANTIATE_MARRAY_FRIENDS(T) \ |
1992
|
95 template MArray<T>& operator += (MArray<T>& a, const T& s); \ |
|
96 template MArray<T>& operator -= (MArray<T>& a, const T& s); \ |
|
97 template MArray<T>& operator += (MArray<T>& a, const MArray<T>& b); \ |
|
98 template MArray<T>& operator -= (MArray<T>& a, const MArray<T>& b); \ |
1989
|
99 template MArray<T> operator + (const MArray<T>& a, const T& s); \ |
|
100 template MArray<T> operator - (const MArray<T>& a, const T& s); \ |
|
101 template MArray<T> operator * (const MArray<T>& a, const T& s); \ |
|
102 template MArray<T> operator / (const MArray<T>& a, const T& s); \ |
|
103 template MArray<T> operator + (const T& s, const MArray<T>& a); \ |
|
104 template MArray<T> operator - (const T& s, const MArray<T>& a); \ |
|
105 template MArray<T> operator * (const T& s, const MArray<T>& a); \ |
|
106 template MArray<T> operator / (const T& s, const MArray<T>& a); \ |
|
107 template MArray<T> operator + (const MArray<T>& a, const MArray<T>& b); \ |
|
108 template MArray<T> operator - (const MArray<T>& a, const MArray<T>& b); \ |
|
109 template MArray<T> product (const MArray<T>& a, const MArray<T>& b); \ |
|
110 template MArray<T> quotient (const MArray<T>& a, const MArray<T>& b); \ |
|
111 template MArray<T> operator - (const MArray<T>& a); |
237
|
112 |
|
113 #endif |
|
114 |
|
115 /* |
|
116 ;;; Local Variables: *** |
|
117 ;;; mode: C++ *** |
|
118 ;;; End: *** |
|
119 */ |