MArray.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef CASA_MARRAY_H
00029 #define CASA_MARRAY_H
00030
00031
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/tables/TaQL/MArrayBase.h>
00034
00035 namespace casacore {
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 template <typename T>
00069 class MArray: public MArrayBase
00070 {
00071 public:
00072
00073 MArray()
00074 : MArrayBase (True)
00075 {}
00076
00077
00078
00079 explicit MArray (const Array<T>& array)
00080 : MArrayBase (False),
00081 itsArray (array)
00082 {
00083 resizeBase (array, False);
00084 }
00085
00086
00087
00088
00089 MArray (const Array<T>& array, const Array<Bool>& mask, Bool isNull=False)
00090 : MArrayBase (array, mask, isNull),
00091 itsArray (array)
00092 {}
00093
00094
00095
00096
00097 MArray (const Array<T>& array, const MArrayBase& marray)
00098 : MArrayBase (array, marray),
00099 itsArray (array)
00100 {}
00101
00102
00103
00104 MArray (const MArray<T>& array, const MArray<Bool>& mask)
00105 : MArrayBase (array.isNull() || mask.isNull())
00106 {
00107 if (! isNull()) {
00108 itsArray.reference (array.array());
00109 setBase (itsArray, mask.array());
00110 }
00111 }
00112
00113
00114 void reference (const MArray<T>& other)
00115 {
00116 itsArray.reference (other.itsArray);
00117 referenceBase (other);
00118 }
00119
00120
00121
00122 void resize (const IPosition& shape, Bool useMask)
00123 {
00124 itsArray.resize (shape);
00125 resizeBase (itsArray, useMask);
00126 }
00127
00128
00129
00130
00131
00132 template <typename U>
00133 void fill (const MArray<U>& from)
00134 {
00135 itsArray.resize (from.shape());
00136 convertArray (itsArray, from.array());
00137 setBase (itsArray, from.mask());
00138 }
00139
00140
00141
00142
00143 template <typename U>
00144 void fill (const Array<U>& from)
00145 {
00146 itsArray.resize (from.shape());
00147 convertArray (itsArray, from);
00148 resizeBase (itsArray, False);
00149 }
00150
00151
00152
00153 const Array<T>& array() const
00154 { return itsArray; }
00155 Array<T>& array()
00156 { return itsArray; }
00157
00158
00159
00160 Vector<T> flatten() const;
00161
00162
00163
00164 size_t flatten (T* out, size_t size) const;
00165
00166
00167 MArray<T> operator() (const IPosition& start, const IPosition& end,
00168 const IPosition& stride)
00169 {
00170 if (hasMask()) {
00171 return MArray<T> (itsArray(start, end, stride),
00172 mask()(start, end, stride));
00173 }
00174 return MArray<T> (itsArray(start, end, stride));
00175 }
00176
00177 private:
00178 Array<T> itsArray;
00179 };
00180
00181
00182
00183 template<typename T>
00184 Vector<T> MArray<T>::flatten() const
00185 {
00186 Vector<T> vec(nvalid());
00187
00188 flatten (vec.data(), itsArray.size());
00189 return vec;
00190 }
00191
00192 template<typename T>
00193 size_t MArray<T>::flatten (T* out, size_t size) const
00194 {
00195 if (size < itsArray.size()) {
00196 throw ArrayError ("MArray::flatten - size " + String::toString(size) +
00197 " of output buffer is too small");
00198 }
00199 size_t nr = 0;
00200 if (!hasMask()) {
00201
00202 Array<T> arr(itsArray.shape(), out, SHARE);
00203 arr = itsArray;
00204 nr = arr.size();
00205 } else {
00206
00207 if (itsArray.contiguousStorage() && mask().contiguousStorage()) {
00208 typename Array<Bool>::const_contiter miter = mask().cbegin();
00209 typename Array<T>::const_contiter iterEnd = itsArray.cend();
00210 for (typename Array<T>::const_contiter iter=itsArray.cbegin();
00211 iter!=iterEnd; ++iter, ++miter) {
00212 if (!*miter) out[nr++] = *iter;
00213 }
00214 } else {
00215 typename Array<Bool>::const_iterator miter = mask().begin();
00216 typename Array<T>::const_iterator iterEnd = itsArray.end();
00217 for (typename Array<T>::const_iterator iter=itsArray.begin();
00218 iter!=iterEnd; ++iter, ++miter) {
00219 if (!*miter) out[nr++] = *iter;
00220 }
00221 }
00222 }
00223 return nr;
00224 }
00225
00226
00227 }
00228
00229 #endif