casacore
Loading...
Searching...
No Matches
LatticeIterInterface.h
Go to the documentation of this file.
1// # LatticeIterInterface.h: A base class for Lattice iterators
2// # Copyright (C) 1994,1995,1996,1997,1998,1999,2003
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 LATTICES_LATTICEITERINTERFACE_H
27#define LATTICES_LATTICEITERINTERFACE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/IPosition.h>
32#include <casacore/casa/Arrays/Array.h>
33#include <casacore/lattices/Lattices/LatticeNavigator.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// # Forward Declarations
38template <class T>
39class Lattice;
40template <class T>
41class LatticeIterator;
42template <class T>
44
45// <summary>
46// A base class for Lattice iterators
47// </summary>
48
49// <use visibility=local>
50
51// <reviewed reviewer="Peter Barnes" date="1999/10/30" tests="tLatticeIterator.cc" demos="">
52// </reviewed>
53
54// <prerequisite>
55// <li> letter/envelope schemes - see Coplien, "Advanced C++", ch 5.5
56// <li> <linkto class="Lattice">Lattice</linkto>
57// <li> <linkto class="LatticeIterator">LatticeIterator</linkto>
58// </prerequisite>
59
60// <etymology>
61// The LatticeIterInterface class name reflects its role as the abstract
62// base class for concrete read-write LatticeIterators
63// </etymology>
64
65// <synopsis>
66// This class is only for authors of Lattice letters for the LatticeIterator
67// envelope. General users should see LatticeIterator.
68//
69// The LatticeIterInterface class defines an abstract base for the standard
70// methods of iteration required by Lattices. Declaring an Iterator that is
71// derived from this class forces it to meet the virtual requirements.
72//
73// The author of a Lattice derived class should consider the following:
74// <ul>
75// <li> The LatticeStepper class has strong effects on how the cursor is
76// filled. A non-integral shape of the cursor may allow a step of
77// iteration to be only partially "touching" the Lattice. We have dubbed
78// this "hangover."
79// <li> If the cursor has "hangover" it should be filled with a value that
80// indicates the cursor is in undefined space.
81// <li> The cursor cannot be a reference to a part of the Lattice since
82// hangover would imply a reference to undefined memory. To enclose the
83// Lattice with a zero valued hangover buffer would be inefficient. The
84// method thus forced upon the programmer is to "update" the cursor with
85// Lattice values after each move or iteration and to "write" the possibly
86// changed cursor values back into the Lattice before each iteration. An
87// algorithm which does the cursor update/write actions (and is independent
88// of Lattice dimensionality) may be copied from ArrLatticeIter::cursorUpdate()
89// and ArrLatticeIter::cursorWrite(), respectively.
90// <li> The majority of the code in a new letter for LatticeIterator may be
91// cut and pasted from other implementations of letters. See ArrLatticeIter
92// or PagedArrIter.
93// </ul>
94// </synopsis>
95
96// <example>
97// For an example see <linkto class=LatticeIterator>LatticeIterator</linkto>.
98// </example>
99
100// <motivation>
101// The is class provides a tidy base for letter/envelope techniques of
102// iteration.
103// </motivation>
104
105// <todo asof="1997/01/12">
106// <li> IPositions are returned by value. This a reflection of the
107// LatticeNavigator base class' inability to predict the
108// availibility of data members for references.
109// </todo>
110
111template <class T>
113 friend class Lattice<T>;
114 friend class LatticeIterator<T>;
115 friend class RO_LatticeIterator<T>;
116
117 public:
118 // Construct with the given navigator.
120
121 // A virtual destructor. A virtual is needed to ensure that derived
122 // classes declared as pointers to a LatticeIterInterface will scope their
123 // destructor to the derived class destructor.
125
126 protected:
127 // Default constructor (for derived classes).
129
130 // Copy constructor (copy semantics).
132
133 // Assignment (copy semantics).
135
136 // Clone the object.
138
139 // Return the underlying lattice.
141
142 // Increment operator - increment the cursor to the next position. The
143 // implementation of the prefix operator calls the postfix one.
144 // <group>
147 // </group>
148
149 // Decrement operator - decrement the cursor to the previous position. The
150 // implementation of the prefix operator calls the postfix one.
151 // <group>
154 // </group>
155
156 // Function which resets the cursor to the beginning of the Lattice and
157 // resets the number of steps taken to zero.
158 void reset();
159
160 // Function which returns a value of "True" if the cursor is at the
161 // beginning of the Lattice, otherwise, returns "False"
162 Bool atStart() const;
163
164 // Function which returns "True" if the cursor has been incremented to
165 // the end of the lattice, otherwise, returns "False"
166 Bool atEnd() const;
167
168 // Function to return the number of steps (increments or decrements) taken
169 // since construction (or since last reset). This is a running count of
170 // all cursor movement since doing N increments followed by N decrements
171 // does not necessarily put the cursor back at the origin of the Lattice.
172 uInt nsteps() const;
173
174 // Function which returns the current position of the beginning of the
175 // cursor within the Lattice. The returned IPosition will have the same
176 // number of axes as the underlying Lattice.
177 IPosition position() const;
178
179 // Function which returns the current position of the end of the
180 // cursor. The returned IPosition will have the same number of axes as the
181 // underlying Lattice.
182 IPosition endPosition() const;
183
184 // Function which returns the shape of the Lattice being iterated through.
185 // The returned IPosition will always have the same number of axes as the
186 // underlying Lattice.
187 IPosition latticeShape() const;
188
189 // Function which returns the shape of the cursor which is iterating
190 // through the Lattice. The cursor will always have as many dimensions as
191 // the Lattice.
192 IPosition cursorShape() const;
193
194 // Functions which returns a window to the data in the Lattice. These are
195 // used to read the data within the Lattice. Use the function
196 // that is appropriate to the current cursor dimension, AFTER REMOVING
197 // DEGENERATE AXES, or use the <src>cursor</src> function which works with
198 // any number of dimensions in the cursor. A call of the function whose
199 // return value is inappropriate with respect to the current cursor
200 // dimension will throw an exception (AipsError).
201 // <br>The <src>doRead</src> flag indicates if the data need to be read or
202 // if only a cursor with the correct shape has to be returned.
203 // <br>The <src>autoRewrite</src> flag indicates if the data has to be
204 // rewritten when the iterator state changes (e.g. moved, destructed).
205 // <group>
206 virtual Vector<T>& vectorCursor(Bool doRead, Bool autoRewrite);
207 virtual Matrix<T>& matrixCursor(Bool doRead, Bool autoRewrite);
208 virtual Cube<T>& cubeCursor(Bool doRead, Bool autoRewrite);
209 virtual Array<T>& cursor(Bool doRead, Bool autoRewrite);
210 //</group>
211
212 // Function which checks the internals of the class for consistency.
213 // Returns True if everything is fine otherwise returns False. The default
214 // implementation of this function always returns True.
215 Bool ok() const;
216
217 protected:
218 // Do the actual read of the data.
219 virtual void readData(Bool doRead);
220
221 // Rewrite the cursor data and clear the rewrite flag.
222 virtual void rewriteData();
223
224 // Update the cursor for the next chunk of data (resize if needed).
225 virtual void cursorUpdate();
226
227 // Allocate the internal buffer.
229
230 // Allocate the nondegenerate array with the correct type.
232
233 // Synchronise the storage of itsCurPtr with itsCursor.
235
236 // Copy the base data of the other object.
238
239 // Pointer to the method of Lattice transversal
241 // Pointer to the Lattice
243 // A buffer to hold the data. Usually itsCursor shares the data
244 // with this buffer, but for an ArrayLattice itsCursor might reference
245 // the lattice directly instead of making a copy in the buffer.
247 // Polymorphic pointer to the data in itsCursor.
249 // An Array which references the same data as the itsCurPtr, but has all
250 // the degenerate axes. This is an optimization to avoid the overhead of
251 // having to add the degenerate axes for each iteration.
253 // Keep a reference to the data (if possible).
255 // Is the cursor a reference to the lattice?
257 // Have the data been read after a cursor update? (False=not read)
259 // Rewrite the cursor data before moving or destructing?
261 // The axes forming the cursor.
263};
264
265template <class T>
269
270template <class T>
274
275template <class T>
277 return itsNavPtr->atStart();
278}
279
280template <class T>
282 return itsNavPtr->atEnd();
283}
284
285template <class T>
287 return itsNavPtr->nsteps();
288}
289
290template <class T>
292 return itsNavPtr->position();
293}
294
295template <class T>
297 return itsNavPtr->endPosition();
298}
299
300template <class T>
302 return itsNavPtr->latticeShape();
303}
304
305template <class T>
307 return itsNavPtr->cursorShape();
308}
309
310// # Declare extern templates for often used types.
311extern template class LatticeIterInterface<Float>;
312
313} // namespace casacore
314
315#ifndef CASACORE_NO_AUTO_TEMPLATES
316#include <casacore/lattices/Lattices/LatticeIterInterface.tcc>
317#endif // # CASACORE_NO_AUTO_TEMPLATES
318#endif
Bool atEnd() const
Function which returns "True" if the cursor has been incremented to the end of the lattice,...
LatticeIterInterface()
Default constructor (for derived classes).
virtual LatticeIterInterface< T > * clone() const
Clone the object.
Bool itsRewrite
Rewrite the cursor data before moving or destructing?
void setCurPtr2Cursor()
Synchronise the storage of itsCurPtr with itsCursor.
uInt nsteps() const
Function to return the number of steps (increments or decrements) taken since construction (or since ...
IPosition endPosition() const
Function which returns the current position of the end of the cursor.
LatticeIterInterface & operator=(const LatticeIterInterface< T > &other)
Assignment (copy semantics).
LatticeNavigator * itsNavPtr
Pointer to the method of Lattice transversal.
virtual void cursorUpdate()
Update the cursor for the next chunk of data (resize if needed).
Bool itsIsRef
Is the cursor a reference to the lattice?
Array< T > itsCursor
An Array which references the same data as the itsCurPtr, but has all the degenerate axes.
void allocateCurPtr()
Allocate the nondegenerate array with the correct type.
void allocateBuffer()
Allocate the internal buffer.
IPosition latticeShape() const
Function which returns the shape of the Lattice being iterated through.
Lattice< T > & lattice()
Return the underlying lattice.
virtual Matrix< T > & matrixCursor(Bool doRead, Bool autoRewrite)
virtual void rewriteData()
Rewrite the cursor data and clear the rewrite flag.
Bool operator--()
Decrement operator - decrement the cursor to the previous position.
Bool atStart() const
Function which returns a value of "True" if the cursor is at the beginning of the Lattice,...
virtual Vector< T > & vectorCursor(Bool doRead, Bool autoRewrite)
Functions which returns a window to the data in the Lattice.
Bool itsUseRef
Keep a reference to the data (if possible).
Bool itsHaveRead
Have the data been read after a cursor update?
Bool operator++()
Increment operator - increment the cursor to the next position.
LatticeIterInterface(const LatticeIterInterface< T > &other)
Copy constructor (copy semantics).
virtual Array< T > & cursor(Bool doRead, Bool autoRewrite)
void reset()
Function which resets the cursor to the beginning of the Lattice and resets the number of steps taken...
Array< T > itsBuffer
A buffer to hold the data.
Bool ok() const
Function which checks the internals of the class for consistency.
Lattice< T > * itsLattPtr
Pointer to the Lattice.
Array< T > * itsCurPtr
Polymorphic pointer to the data in itsCursor.
LatticeIterInterface(const Lattice< T > &lattice, const LatticeNavigator &navigator, Bool useRef)
Construct with the given navigator.
IPosition cursorShape() const
Function which returns the shape of the cursor which is iterating through the Lattice.
void copyBase(const LatticeIterInterface< T > &other)
Copy the base data of the other object.
IPosition itsCursorAxes
The axes forming the cursor.
IPosition position() const
Function which returns the current position of the beginning of the cursor within the Lattice.
virtual Cube< T > & cubeCursor(Bool doRead, Bool autoRewrite)
virtual ~LatticeIterInterface()
A virtual destructor.
virtual void readData(Bool doRead)
Do the actual read of the data.
A read/write lattice iterator.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40