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