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) { } |
3419
|
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 }; |
|
123 |
3107
|
124 #undef LTGT |
|
125 |
2391
|
126 extern void |
|
127 gripe_nonconformant (const char *op, int op1_len, int op2_len); |
|
128 |
1989
|
129 #define INSTANTIATE_MARRAY_FRIENDS(T) \ |
1992
|
130 template MArray<T>& operator += (MArray<T>& a, const T& s); \ |
|
131 template MArray<T>& operator -= (MArray<T>& a, const T& s); \ |
|
132 template MArray<T>& operator += (MArray<T>& a, const MArray<T>& b); \ |
|
133 template MArray<T>& operator -= (MArray<T>& a, const MArray<T>& b); \ |
1989
|
134 template MArray<T> operator + (const MArray<T>& a, const T& s); \ |
|
135 template MArray<T> operator - (const MArray<T>& a, const T& s); \ |
|
136 template MArray<T> operator * (const MArray<T>& a, const T& s); \ |
|
137 template MArray<T> operator / (const MArray<T>& a, const T& s); \ |
|
138 template MArray<T> operator + (const T& s, const MArray<T>& a); \ |
|
139 template MArray<T> operator - (const T& s, const MArray<T>& a); \ |
|
140 template MArray<T> operator * (const T& s, const MArray<T>& a); \ |
|
141 template MArray<T> operator / (const T& s, const MArray<T>& a); \ |
|
142 template MArray<T> operator + (const MArray<T>& a, const MArray<T>& b); \ |
|
143 template MArray<T> operator - (const MArray<T>& a, const MArray<T>& b); \ |
|
144 template MArray<T> product (const MArray<T>& a, const MArray<T>& b); \ |
|
145 template MArray<T> quotient (const MArray<T>& a, const MArray<T>& b); \ |
|
146 template MArray<T> operator - (const MArray<T>& a); |
237
|
147 |
|
148 #endif |
|
149 |
|
150 /* |
|
151 ;;; Local Variables: *** |
|
152 ;;; mode: C++ *** |
|
153 ;;; End: *** |
|
154 */ |