Mercurial > hg > octave-nkf
comparison liboctave/Array.h @ 228:ee01ac1c7acc
[project @ 1993-11-16 09:56:54 by jwe]
Initial revision
author | jwe |
---|---|
date | Tue, 16 Nov 1993 09:56:54 +0000 |
parents | |
children | 780cbbc57b7c |
comparison
equal
deleted
inserted
replaced
227:1a48a1b91489 | 228:ee01ac1c7acc |
---|---|
1 // Template array classes -*- C++ -*- | |
2 /* | |
3 | |
4 Copyright (C) 1993 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, 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | |
22 */ | |
23 | |
24 // Written by John C. Campbell <jcc@che.utexas.edu>. | |
25 | |
26 #if !defined (_Array_h) | |
27 #define _Array_h 1 | |
28 | |
29 #include <iostream.h> | |
30 #include <assert.h> | |
31 | |
32 template <class T> class Array; | |
33 | |
34 template <class T> | |
35 class ArrayRep | |
36 { | |
37 friend class Array<T>; | |
38 | |
39 public: | |
40 | |
41 ArrayRep (void); | |
42 ArrayRep (int); | |
43 ArrayRep (const ArrayRep<T>& a); | |
44 | |
45 ~ArrayRep (void); | |
46 | |
47 int length (void) const; | |
48 | |
49 T& elem (int n); | |
50 T& checkelem (int n); | |
51 T& operator () (int n); | |
52 | |
53 T elem (int n) const; | |
54 T checkelem (int n) const; | |
55 T operator () (int n) const; | |
56 | |
57 private: | |
58 | |
59 T *data; | |
60 int len; | |
61 int count; | |
62 }; | |
63 | |
64 template <class T> | |
65 class Array | |
66 { | |
67 public: | |
68 | |
69 Array (void); | |
70 Array (int); | |
71 Array (int n, T val); | |
72 Array (const Array<T>& a); | |
73 | |
74 ~Array (void); | |
75 | |
76 Array<T>& operator = (const Array<T>& a); | |
77 | |
78 int length (void) const; | |
79 | |
80 T& elem (int n); | |
81 T& checkelem (int n); | |
82 T& operator () (int n); | |
83 | |
84 T elem (int n) const; | |
85 T checkelem (int n) const; | |
86 T operator () (int n) const; | |
87 | |
88 protected: | |
89 | |
90 ArrayRep<T> *rep; | |
91 }; | |
92 | |
93 template <class T> | |
94 class Array2 : public Array<T> | |
95 { | |
96 public: | |
97 | |
98 Array2 (void); | |
99 Array2 (int n, int m); | |
100 Array2 (int n, int m, T val); | |
101 Array2 (const Array2<T>& a); | |
102 | |
103 Array2<T>& operator = (const Array2<T>& a); | |
104 | |
105 int dim1 (void) const; | |
106 int dim2 (void) const; | |
107 | |
108 T& elem (int i, int j); | |
109 T& checkelem (int i, int j); | |
110 T& operator () (int i, int j); | |
111 | |
112 T elem (int i, int j) const; | |
113 T checkelem (int i, int j) const; | |
114 T operator () (int i, int j) const; | |
115 | |
116 protected: | |
117 | |
118 int d1; | |
119 int d2; | |
120 }; | |
121 | |
122 template <class T> | |
123 class Array3 : public Array2<T> | |
124 { | |
125 public: | |
126 | |
127 Array3 (void); | |
128 Array3 (int n, int m, int k); | |
129 Array3 (int n, int m, int k, T val); | |
130 Array3 (const Array3<T>& a); | |
131 | |
132 Array3<T>& operator = (const Array3<T>& a); | |
133 | |
134 int dim3 (void) const; | |
135 | |
136 T& elem (int i, int j, int k); | |
137 T& checkelem (int i, int j, int k); | |
138 T& operator()(int i,int j,int k); | |
139 | |
140 T elem (int i, int j, int k) const; | |
141 T checkelem(int i,int j,int k)const; | |
142 T operator()(int i,int j,int k) const; | |
143 | |
144 protected: | |
145 | |
146 int d3; | |
147 }; | |
148 | |
149 template <class T> | |
150 class DiagArray : public Array<T> | |
151 { | |
152 public: | |
153 | |
154 DiagArray (void); | |
155 DiagArray (int n): Array<T> (n) {} | |
156 DiagArray (int r, int c); | |
157 DiagArray (int r, int c, T val); | |
158 DiagArray (const Array<T>& a); | |
159 DiagArray (const DiagArray<T>& a); | |
160 | |
161 DiagArray<T>& operator = (const DiagArray<T>& a); | |
162 | |
163 int rows (void) const; | |
164 int cols (void) const; | |
165 int columns (void) const; | |
166 | |
167 T& elem (int r, int c); | |
168 T& checkelem (int r, int c); | |
169 T& operator () (int r, int c); | |
170 | |
171 T elem (int r, int c) const; | |
172 T checkelem (int r, int c) const; | |
173 T operator () (int r, int c) const; | |
174 | |
175 protected: | |
176 | |
177 int nr; | |
178 int nc; | |
179 }; | |
180 | |
181 #ifdef __GNUG__ | |
182 #include "Array.cc" | |
183 #endif | |
184 | |
185 #endif | |
186 | |
187 /* | |
188 ;;; Local Variables: *** | |
189 ;;; mode: C++ *** | |
190 ;;; page-delimiter: "^/\\*" *** | |
191 ;;; End: *** | |
192 */ |