3665
|
1 // Template array classes |
|
2 /* |
|
3 |
|
4 Copyright (C) 2000 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 (octave_ArrayN_h) |
|
25 #define octave_ArrayN_h 1 |
|
26 |
4192
|
27 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
3665
|
28 #pragma interface |
|
29 #endif |
|
30 |
|
31 #include <iostream> |
|
32 |
|
33 #include <cassert> |
|
34 #include <climits> |
|
35 #include <cmath> |
|
36 #include <cstdlib> |
|
37 |
|
38 #include "Array.h" |
4513
|
39 #include "Array2.h" |
3665
|
40 #include "lo-error.h" |
|
41 |
|
42 class idx_vector; |
|
43 |
|
44 // N-dimensional array class. |
|
45 |
|
46 template <class T> |
|
47 class |
|
48 ArrayN : public Array<T> |
|
49 { |
|
50 protected: |
|
51 |
4587
|
52 ArrayN (T *d, const dim_vector& dv) : Array<T> (d, dv) { } |
3665
|
53 |
|
54 public: |
|
55 |
|
56 // These really need to be protected (and they will be in the |
|
57 // future, so don't depend on them being here!), but they can't be |
|
58 // until template friends work correctly in g++. |
|
59 |
|
60 ArrayN (void) : Array<T> () { } |
|
61 |
4587
|
62 ArrayN (const dim_vector& dv) : Array<T> (dv) { } |
3665
|
63 |
4587
|
64 ArrayN (const dim_vector& dv, const T& val) |
|
65 : Array<T> (dv) { fill (val); } |
3665
|
66 |
4513
|
67 ArrayN (const Array2<T>& a) : Array<T> (a, a.dims ()) { } |
4504
|
68 |
4513
|
69 ArrayN (const ArrayN<T>& a) : Array<T> (a, a.dims ()) { } |
4504
|
70 |
4532
|
71 ArrayN (const Array<T>& a) : Array<T> (a) { } |
|
72 |
4587
|
73 ArrayN (const Array<T>& a, const dim_vector& dv) : Array<T> (a, dv) { } |
4504
|
74 |
3665
|
75 ~ArrayN (void) { } |
|
76 |
|
77 ArrayN<T>& operator = (const ArrayN<T>& a) |
|
78 { |
4513
|
79 if (this != &a) |
|
80 Array<T>::operator = (a); |
3665
|
81 |
|
82 return *this; |
|
83 } |
|
84 |
4587
|
85 void resize (const dim_vector& dv) |
4645
|
86 { this->resize_no_fill (dv); } |
3665
|
87 |
4587
|
88 void resize (const dim_vector& dv, const T& val) |
|
89 { Array<T>::resize (dv, val); } |
3665
|
90 |
4532
|
91 ArrayN<T> squeeze (void) const { return Array<T>::squeeze (); } |
|
92 |
4587
|
93 ArrayN<T>& insert (const ArrayN<T>& a, const dim_vector& dv) |
3665
|
94 { |
4587
|
95 Array<T>::insert (a, dv); |
4513
|
96 return *this; |
3665
|
97 } |
|
98 |
4513
|
99 ArrayN<T> index (idx_vector& i, int resize_ok = 0, |
|
100 const T& rfv = resize_fill_value (T ())) const |
3665
|
101 { |
4513
|
102 Array<T> tmp = Array<T>::index (i, resize_ok, rfv); |
|
103 return ArrayN<T> (tmp, tmp.dims ()); |
3665
|
104 } |
|
105 |
4513
|
106 ArrayN<T> index (idx_vector& i, idx_vector& j, int resize_ok = 0, |
|
107 const T& rfv = resize_fill_value (T ())) const |
|
108 { |
|
109 Array<T> tmp = Array<T>::index (i, j, resize_ok, rfv); |
|
110 return ArrayN<T> (tmp, tmp.dims ()); |
|
111 } |
3665
|
112 |
4273
|
113 ArrayN<T> index (Array<idx_vector>& ra_idx, int resize_ok = 0, |
4513
|
114 const T& rfv = resize_fill_value (T ())) const |
|
115 { |
|
116 Array<T> tmp = Array<T>::index (ra_idx, resize_ok, rfv); |
|
117 return ArrayN<T> (tmp, tmp.dims ()); |
|
118 } |
3665
|
119 }; |
|
120 |
|
121 template <class T> |
|
122 std::ostream& |
|
123 operator << (std::ostream&, const ArrayN<T>&); |
|
124 |
|
125 #endif |
|
126 |
|
127 /* |
|
128 ;;; Local Variables: *** |
|
129 ;;; mode: C++ *** |
|
130 ;;; End: *** |
|
131 */ |