casacore
Loading...
Searching...
No Matches
VectorIter.h
Go to the documentation of this file.
1// # VectorIter.h: Iterate a vector cursor through another array
2// # Copyright (C) 1993,1994,1995,1999
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_VECTORITER_2_H
27#define CASA_VECTORITER_2_H
28
29#include "ArrayIter.h"
30#include "Vector.h"
31
32namespace casacore { // # NAMESPACE CASACORE - BEGIN
33
34//
35// <summary> Iterate an Vector cursor through another Array. </summary>
36// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
37// </reviewed>
38//
39// VectorIterator steps a Vector (the "cursor") through an array for the
40// given axis.
41// The cursor "refers" to storage in the array, so that changing the
42// values in the cursor changes values in the original array.
43//
44// This class is derived from ArrayIterator; basically it only adds
45// the vector() member function which allows you to access the cursor
46// as a Vector.
47//
48// <note role=tip>
49// The origin of the cursor, i.e. the subarray that moves through the
50// larger array, is always zero.
51// </note>
52//
53// In this example we sum all the elements of an array; of course we already
54// have the "sum" function in ArrayMath.h that we should use instead.
55//
56// <srcblock>
57// Array<float> af;
58// // set af
59// VectorIterator vi(af);
60// float sum = 0.0;
61// size_t n = vi.vector().nelements();
62// while (! vi.pastEnd()) {
63// for (int i=0; i < n; i++) { // N.B.; cursor always 0 based.
64// sum += vi.vector()(i);
65// }
66// vi.next();
67// }
68// </srcblock>
69
70template <typename T>
71class VectorIterator : public ArrayIterator<T> {
72 public:
73 // Iterate by vector cursors through array "a".
74 // The vector cursor is taken for the given axis.
75 explicit VectorIterator(Array<T> &a, size_t axis = 0);
76
77 // Return a Vector at the current position.
78 Vector<T> &vector() { return *(Vector<T> *)this->ap_p.get(); }
79
80 private:
81 // Not implemented.
83 // Not implemented.
85};
86
87//
88// <summary> Iterate a Vector cursor through another Array. </summary>
89// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
90// </reviewed>
91//
92// ReadOnlyVectorIterator behaves exactly like VectorIterator (cf.) only
93// it should be used on const Arrays.
94//
95// <note role=tip> Note that the R/O VectorIterator is not derived from R/O
96// ArrayIterator.
97// </note>
98
99template <typename T>
101 public:
102 // <group>
103 explicit ReadOnlyVectorIterator(const Array<T> &a, size_t axis = 0)
104 : vi(const_cast<Array<T> &>(a), axis) {}
105
106 void next() { vi.next(); }
107 void reset() { vi.origin(); }
108 void origin() { vi.origin(); }
109
110 const Array<T> &array() { return vi.array(); }
111 const Vector<T> &vector() { return vi.vector(); }
112
113 bool atStart() const { return vi.atStart(); }
114 bool pastEnd() const { return vi.pastEnd(); }
115 const IPosition &pos() const { return vi.pos(); }
116 IPosition endPos() const { return vi.endPos(); }
117 size_t ndim() const { return vi.ndim(); }
118 // </group>
119 private:
120 // Not implemented.
122 // Not implemented.
124
126};
127
128} // namespace casacore
129
130#include "VectorIter.tcc"
131
132#endif
std::unique_ptr< Array< T > > ap_p
The cursor.
Definition ArrayIter.h:117
ArrayIterator(const Array< T > &arr, size_t byDim=1)
Step through array "arr" over the first byDim axes (using a cursor of dimensionality "byDim").
const Vector< T > & vector()
Definition VectorIter.h:111
const Array< T > & array()
Definition VectorIter.h:110
ReadOnlyVectorIterator(const ReadOnlyVectorIterator< T > &)=delete
Not implemented.
const IPosition & pos() const
Definition VectorIter.h:115
ReadOnlyVectorIterator< T > & operator=(const ReadOnlyVectorIterator< T > &)=delete
Not implemented.
ReadOnlyVectorIterator(const Array< T > &a, size_t axis=0)
Definition VectorIter.h:103
Vector< T > & vector()
Return a Vector at the current position.
Definition VectorIter.h:78
VectorIterator< T > & operator=(const VectorIterator< T > &)=delete
Not implemented.
VectorIterator(Array< T > &a, size_t axis=0)
Iterate by vector cursors through array "a".
VectorIterator(const VectorIterator< T > &)=delete
Not implemented.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28