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 |
4513
|
52 static int get_size (const dim_vector& dims) |
|
53 { return Array<T>::get_size (dims); } |
4323
|
54 |
4513
|
55 ArrayN (T *d, const dim_vector& dims) : Array<T> (d, dims) { } |
3665
|
56 |
|
57 public: |
|
58 |
|
59 // These really need to be protected (and they will be in the |
|
60 // future, so don't depend on them being here!), but they can't be |
|
61 // until template friends work correctly in g++. |
|
62 |
|
63 ArrayN (void) : Array<T> () { } |
|
64 |
4513
|
65 ArrayN (const dim_vector& dims) : Array<T> (dims) { } |
3665
|
66 |
4513
|
67 ArrayN (const dim_vector& dims, const T& val) |
|
68 : Array<T> (dims) { fill (val); } |
3665
|
69 |
4513
|
70 ArrayN (const Array2<T>& a) : Array<T> (a, a.dims ()) { } |
4504
|
71 |
4513
|
72 ArrayN (const ArrayN<T>& a) : Array<T> (a, a.dims ()) { } |
4504
|
73 |
4532
|
74 ArrayN (const Array<T>& a) : Array<T> (a) { } |
|
75 |
4513
|
76 ArrayN (const Array<T>& a, const dim_vector& dims) : Array<T> (a, dims) { } |
4504
|
77 |
3665
|
78 ~ArrayN (void) { } |
|
79 |
|
80 ArrayN<T>& operator = (const ArrayN<T>& a) |
|
81 { |
4513
|
82 if (this != &a) |
|
83 Array<T>::operator = (a); |
3665
|
84 |
|
85 return *this; |
|
86 } |
|
87 |
4513
|
88 void resize (const dim_vector& dims) |
4543
|
89 { Array<T>::resize_no_fill (dims); } |
3665
|
90 |
4513
|
91 void resize (const dim_vector& dims, const T& val) |
|
92 { Array<T>::resize (dims, val); } |
3665
|
93 |
4532
|
94 ArrayN<T> squeeze (void) const { return Array<T>::squeeze (); } |
|
95 |
4513
|
96 ArrayN<T>& insert (const ArrayN<T>& a, const dim_vector& dims) |
3665
|
97 { |
4513
|
98 Array<T>::insert (a, dims); |
|
99 return *this; |
3665
|
100 } |
|
101 |
4513
|
102 ArrayN<T> index (idx_vector& i, int resize_ok = 0, |
|
103 const T& rfv = resize_fill_value (T ())) const |
3665
|
104 { |
4513
|
105 Array<T> tmp = Array<T>::index (i, resize_ok, rfv); |
|
106 return ArrayN<T> (tmp, tmp.dims ()); |
3665
|
107 } |
|
108 |
4513
|
109 ArrayN<T> index (idx_vector& i, idx_vector& j, int resize_ok = 0, |
|
110 const T& rfv = resize_fill_value (T ())) const |
|
111 { |
|
112 Array<T> tmp = Array<T>::index (i, j, resize_ok, rfv); |
|
113 return ArrayN<T> (tmp, tmp.dims ()); |
|
114 } |
3665
|
115 |
4273
|
116 ArrayN<T> index (Array<idx_vector>& ra_idx, int resize_ok = 0, |
4513
|
117 const T& rfv = resize_fill_value (T ())) const |
|
118 { |
|
119 Array<T> tmp = Array<T>::index (ra_idx, resize_ok, rfv); |
|
120 return ArrayN<T> (tmp, tmp.dims ()); |
|
121 } |
3665
|
122 }; |
|
123 |
|
124 template <class T> |
|
125 std::ostream& |
|
126 operator << (std::ostream&, const ArrayN<T>&); |
|
127 |
|
128 #endif |
|
129 |
|
130 /* |
|
131 ;;; Local Variables: *** |
|
132 ;;; mode: C++ *** |
|
133 ;;; End: *** |
|
134 */ |