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 |
4513
|
74 ArrayN (const Array<T>& a, const dim_vector& dims) : Array<T> (a, dims) { } |
4504
|
75 |
3665
|
76 ~ArrayN (void) { } |
|
77 |
|
78 ArrayN<T>& operator = (const ArrayN<T>& a) |
|
79 { |
4513
|
80 if (this != &a) |
|
81 Array<T>::operator = (a); |
3665
|
82 |
|
83 return *this; |
|
84 } |
|
85 |
4513
|
86 void resize (const dim_vector& dims) |
|
87 { Array<T>resize_no_fill (dims); } |
3665
|
88 |
4513
|
89 void resize (const dim_vector& dims, const T& val) |
|
90 { Array<T>::resize (dims, val); } |
3665
|
91 |
4513
|
92 ArrayN<T>& insert (const ArrayN<T>& a, const dim_vector& dims) |
3665
|
93 { |
4513
|
94 Array<T>::insert (a, dims); |
|
95 return *this; |
3665
|
96 } |
|
97 |
4513
|
98 ArrayN<T> index (idx_vector& i, int resize_ok = 0, |
|
99 const T& rfv = resize_fill_value (T ())) const |
3665
|
100 { |
4513
|
101 Array<T> tmp = Array<T>::index (i, resize_ok, rfv); |
|
102 return ArrayN<T> (tmp, tmp.dims ()); |
3665
|
103 } |
|
104 |
4513
|
105 ArrayN<T> index (idx_vector& i, idx_vector& j, int resize_ok = 0, |
|
106 const T& rfv = resize_fill_value (T ())) const |
|
107 { |
|
108 Array<T> tmp = Array<T>::index (i, j, resize_ok, rfv); |
|
109 return ArrayN<T> (tmp, tmp.dims ()); |
|
110 } |
3665
|
111 |
4273
|
112 ArrayN<T> index (Array<idx_vector>& ra_idx, int resize_ok = 0, |
4513
|
113 const T& rfv = resize_fill_value (T ())) const |
|
114 { |
|
115 Array<T> tmp = Array<T>::index (ra_idx, resize_ok, rfv); |
|
116 return ArrayN<T> (tmp, tmp.dims ()); |
|
117 } |
3665
|
118 }; |
|
119 |
|
120 template <class T> |
|
121 std::ostream& |
|
122 operator << (std::ostream&, const ArrayN<T>&); |
|
123 |
|
124 #endif |
|
125 |
|
126 /* |
|
127 ;;; Local Variables: *** |
|
128 ;;; mode: C++ *** |
|
129 ;;; End: *** |
|
130 */ |