comparison liboctave/MDiagArray2.h @ 1988:7b56630a1e05

[project @ 1996-03-02 00:33:22 by jwe] Initial revision
author jwe
date Sat, 02 Mar 1996 00:33:22 +0000
parents
children 5668c00f9c7a
comparison
equal deleted inserted replaced
1987:6df7b42db205 1988:7b56630a1e05
1 // Template array classes with like-type math ops -*- C++ -*-
2 /*
3
4 Copyright (C) 1996 John W. Eaton
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_MDiagArray2_h)
29 #define octave_MDiagArray2_h 1
30
31 #include "DiagArray2.h"
32 #include "MArray2.h"
33
34 // Two dimensional diagonal array with math ops.
35
36 template <class T>
37 class MDiagArray2 : public DiagArray2<T>
38 {
39 protected:
40
41 MDiagArray2 (T *d, int r, int c) : DiagArray2<T> (d, r, c) { }
42
43 public:
44
45 MDiagArray2 (void) : DiagArray2<T> () { }
46 MDiagArray2 (int r, int c) : DiagArray2<T> (r, c) { }
47 MDiagArray2 (int r, int c, const T& val) : DiagArray2<T> (r, c, val) { }
48 MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { }
49 MDiagArray2 (const MArray<T>& a) : DiagArray2<T> (a) { }
50 MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { }
51 MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { }
52
53 ~MDiagArray2 (void) { }
54
55 MDiagArray2<T>& operator = (const MDiagArray2<T>& a)
56 {
57 DiagArray2<T>::operator = (a);
58 return *this;
59 }
60
61 operator MArray2<T> () const
62 {
63 MArray2<T> retval (nr, nc, T (0));
64
65 int len = nr < nc ? nr : nc;
66
67 for (int i = 0; i < len; i++)
68 retval.xelem (i, i) = xelem (i, i);
69
70 return retval;
71 }
72
73 // element by element MDiagArray2 by MDiagArray2 ops
74
75 friend MDiagArray2<T>&
76 operator += (MDiagArray2<T>& a, const MDiagArray2<T>& b);
77
78 friend MDiagArray2<T>&
79 operator -= (MDiagArray2<T>& a, const MDiagArray2<T>& b);
80
81 // element by element MDiagArray2 by scalar ops
82
83 friend MDiagArray2<T> operator * (const MDiagArray2<T>& a, const T& s);
84 friend MDiagArray2<T> operator / (const MDiagArray2<T>& a, const T& s);
85
86 // element by element scalar by MDiagArray2 ops
87
88 friend MDiagArray2<T> operator * (const T& s, const MDiagArray2<T>& a);
89
90 // element by element MDiagArray2 by MDiagArray2 ops
91
92 friend MDiagArray2<T>
93 operator + (const MDiagArray2<T>& a, const MDiagArray2<T>& b);
94
95 friend MDiagArray2<T>
96 operator - (const MDiagArray2<T>& a, const MDiagArray2<T>& b);
97
98 friend MDiagArray2<T>
99 product (const MDiagArray2<T>& a, const MDiagArray2<T>& b);
100
101 friend MDiagArray2<T> operator - (const MDiagArray2<T>& a);
102 };
103
104 #define INSTANTIATE_MDIAGARRAY_FRIENDS(T) \
105 template MDiagArray2<T> operator * (const MDiagArray2<T>& a, const T& s); \
106 template MDiagArray2<T> operator / (const MDiagArray2<T>& a, const T& s); \
107 template MDiagArray2<T> operator * (const T& s, const MDiagArray2<T>& a); \
108 template MDiagArray2<T> operator + (const MDiagArray2<T>& a, const MDiagArray2<T>& b); \
109 template MDiagArray2<T> operator - (const MDiagArray2<T>& a, const MDiagArray2<T>& b); \
110 template MDiagArray2<T> product (const MDiagArray2<T>& a, const MDiagArray2<T>& b); \
111 template MDiagArray2<T> operator - (const MDiagArray2<T>& a);
112
113 #endif
114
115 /*
116 ;;; Local Variables: ***
117 ;;; mode: C++ ***
118 ;;; page-delimiter: "^/\\*" ***
119 ;;; End: ***
120 */