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>
72{
73public:
74 // Iterate by vector cursors through array "a".
75 // The vector cursor is taken for the given axis.
76 explicit VectorIterator(Array<T> &a, size_t axis=0);
77
78 // Return a Vector at the current position.
79 Vector<T> &vector() {return *(Vector<T> *)this->ap_p.get();}
80
81private:
82 // Not implemented.
84 // Not implemented.
86};
87
88//
89// <summary> Iterate a Vector cursor through another Array. </summary>
90// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
91// </reviewed>
92//
93// ReadOnlyVectorIterator behaves exactly like VectorIterator (cf.) only
94// it should be used on const Arrays.
95//
96// <note role=tip> Note that the R/O VectorIterator is not derived from R/O
97// ArrayIterator.
98// </note>
99
100template<typename T> class ReadOnlyVectorIterator
101{
102public:
103 // <group>
104 explicit ReadOnlyVectorIterator(const Array<T> &a, size_t axis=0)
105 : vi(const_cast<Array<T>&>(a), axis) {}
106
107 void next() {vi.next();}
108 void reset() {vi.origin();}
109 void origin() {vi.origin();}
110
111 const Array<T> &array() {return vi.array();}
112 const Vector<T> &vector() {return vi.vector();}
113
114 bool atStart() const {return vi.atStart();}
115 bool pastEnd() const {return vi.pastEnd();}
116 const IPosition &pos() const {return vi.pos();}
117 IPosition endPos() const {return vi.endPos();}
118 size_t ndim() const {return vi.ndim();}
119 // </group>
120private:
121 // Not implemented.
123 // Not implemented.
125
127};
128
129
130} //# NAMESPACE CASACORE - END
131
132#include "VectorIter.tcc"
133
134#endif
std::unique_ptr< Array< T > > ap_p
The cursor.
Definition ArrayIter.h:120
Iterate a Vector cursor through another Array.
Definition VectorIter.h:101
const Vector< T > & vector()
Definition VectorIter.h:112
const Array< T > & array()
Definition VectorIter.h:111
ReadOnlyVectorIterator(const ReadOnlyVectorIterator< T > &)=delete
Not implemented.
const IPosition & pos() const
Definition VectorIter.h:116
ReadOnlyVectorIterator< T > & operator=(const ReadOnlyVectorIterator< T > &)=delete
Not implemented.
ReadOnlyVectorIterator(const Array< T > &a, size_t axis=0)
Definition VectorIter.h:104
Vector< T > & vector()
Return a Vector at the current position.
Definition VectorIter.h:79
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.
this file contains all the compiler specific defines
Definition mainpage.dox:28