casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: aips2-request@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 //# $Id$
27 
28 #ifndef CASA_VECTORITER_H
29 #define CASA_VECTORITER_H
30 
31 
32 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //
39 // <summary> Iterate an Vector cursor through another Array. </summary>
40 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
41 // </reviewed>
42 //
43 // VectorIterator steps a Vector (the "cursor") through an array for the
44 // given axis.
45 // The cursor "refers" to storage in the array, so that changing the
46 // values in the cursor changes values in the original array.
47 //
48 // This class is derived from ArrayIterator; basically it only adds
49 // the vector() member function which allows you to access the cursor
50 // as a Vector.
51 //
52 // <note role=tip>
53 // The origin of the cursor, i.e. the subarray that moves through the
54 // larger array, is always zero.
55 // </note>
56 //
57 // In this example we sum all the elements of an array; of course we already
58 // have the "sum" function in ArrayMath.h that we should use instead.
59 //
60 // <srcblock>
61 // Array<Float> af;
62 // // set af
63 // VectorIterator vi(af);
64 // Float sum = 0.0;
65 // uInt n = vi.vector().nelements();
66 // while (! vi.pastEnd()) {
67 // for (Int i=0; i < n; i++) { // N.B.; cursor always 0 based.
68 // sum += vi.vector()(i);
69 // }
70 // vi.next();
71 // }
72 // </srcblock>
73 
74 template<class T> class VectorIterator : public ArrayIterator<T>
75 {
76 public:
77  // Iterate by vector cursors through array "a".
78  // The vector cursor is taken for the given axis.
79  explicit VectorIterator(Array<T> &a, uInt axis=0);
80 
81  // Return a Vector at the current position.
82  Vector<T> &vector() {return *(Vector<T> *)this->ap_p;}
83 
84 private:
85  // Not implemented.
87  // Not implemented.
89 };
90 
91 //
92 // <summary> Iterate a Vector cursor through another Array. </summary>
93 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
94 // </reviewed>
95 //
96 // ReadOnlyVectorIterator behaves exactly like VectorIterator (cf.) only
97 // it should be used on const Arrays.
98 //
99 // <note role=tip> Note that the R/O VectorIterator is not derived from R/O
100 // ArrayIterator.
101 // </note>
102 
103 template<class T> class ReadOnlyVectorIterator
104 {
105 public:
106  // <group>
107  explicit ReadOnlyVectorIterator(const Array<T> &a, uInt axis=0)
108  : vi(const_cast<Array<T>&>(a), axis) {}
109 
110  void next() {vi.next();}
111  void reset() {vi.origin();}
112  void origin() {vi.origin();}
113 
114  const Array<T> &array() {return vi.array();}
115  const Vector<T> &vector() {return vi.vector();}
116 
117  Bool atStart() const {return vi.atStart();}
118  Bool pastEnd() const {return vi.pastEnd();}
119  const IPosition &pos() const {return vi.pos();}
120  IPosition endPos() const {return vi.endPos();}
121  uInt ndim() const {return vi.ndim();}
122  // </group>
123 private:
124  // Not implemented.
126  // Not implemented.
128 
130 };
131 
132 
133 } //# NAMESPACE CASACORE - END
134 
135 #ifndef CASACORE_NO_AUTO_TEMPLATES
136 #include <casacore/casa/Arrays/VectorIter.tcc>
137 #endif //# CASACORE_NO_AUTO_TEMPLATES
138 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
A 1-D Specialization of the Array class.
ReadOnlyVectorIterator(const Array< T > &a, uInt axis=0)
Definition: VectorIter.h:107
const Array< T > & array()
Definition: VectorIter.h:114
Vector< T > & vector()
Return a Vector at the current position.
Definition: VectorIter.h:82
Iterate an Array cursor through another Array.
Definition: Array.h:51
Array< T > * ap_p
A pointer to the cursor.
Definition: ArrayIter.h:125
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
const Vector< T > & vector()
Definition: VectorIter.h:115
Iterate an Vector cursor through another Array.
Definition: VectorIter.h:74
Iterate a Vector cursor through another Array.
Definition: VectorIter.h:103
ReadOnlyVectorIterator< T > & operator=(const ReadOnlyVectorIterator< T > &)
Not implemented.
VectorIterator< T > & operator=(const VectorIterator< T > &)
Not implemented.
const IPosition & pos() const
Definition: VectorIter.h:119
unsigned int uInt
Definition: aipstype.h:51
VectorIterator(Array< T > &a, uInt axis=0)
Iterate by vector cursors through array &quot;a&quot;.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42