casacore
Loading...
Searching...
No Matches
RefRows.h
Go to the documentation of this file.
1//# RefRows.h: Class holding the row numbers in a RefTable
2//# Copyright (C) 1998
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 TABLES_REFROWS_H
27#define TABLES_REFROWS_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/Tables/RowNumbers.h>
32
33namespace casacore { //# NAMESPACE CASACORE - BEGIN
34
35//# Forward Declarations
36class Slicer;
37
38
39// <summary>
40// Class holding the row numbers in a RefTable
41// </summary>
42
43// <use visibility=local>
44
45// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tRefRows.cc">
46// </reviewed>
47
48// <prerequisite>
49//# Classes you should understand before using this one.
50// <li> <linkto class=Vector>Vector</linkto>
51// </prerequisite>
52
53// <synopsis>
54// RefRows is used to hold the row numbers forming a view on another
55// table. It contains a vector which can hold the row numbers in 2 ways:
56// <ol>
57// <li> As a normal series of row numbers. This is used by e.g. class
58// <linkto class=RefTable>RefTable</linkto>
59// <li> As a series of Slices. In this case 3 subsequent entries
60// in the vector are used to represent start, end, and increment.
61// This is used by a function like <src>ScalarColumn::getColumnRange</src>.
62// </ol>
63// Class <linkto class=RefRowsSliceIter>RefRowsSliceIter</linkto> can be
64// used to iterate through a RefRows object. Each step in the iteration
65// goes to the next a slice. If the RefRows objct contains a simple series
66// of row numbers, each slice contains only one row number.
67// This can degrade performance, so it is possible to use shortcuts by
68// testing if the object contains slices (using <src>isSliced()</src>)
69// and getting the row number vector directly (using <src>rowVector()</src>).
70// </synopsis>
71
72// <motivation>
73// RefRows is meant to have one class representing the various ways
74// of picking row numbers. This simplifies the interface of the table
75// and data manager classes dealing with getting/putting the data.
76// </motivation>
77
78//# <todo asof="$DATE:$">
79//# A List of bugs, limitations, extensions or planned refinements.
80//# </todo>
81
82
84{
85public:
86
87 // Create the object from a Vector containing the row numbers.
88 // When <src>isSliced==False</src>, the vector is treated as
89 // containing individual row numbers, otherwise as containing
90 // (possibly multiple) slices in the form start,end,incr.
91 // When <src>collapse==True</src>, it will try to collapse the
92 // individual row numbers to the slice form (to save memory).
93 RefRows (const Vector<rownr_t>& rowNumbers, Bool isSliced = False,
94 Bool collapse = False);
95#ifdef IMPLICIT_CTDS_32BIT
96 RefRows (const Vector<uInt>& rowNumbers, Bool isSliced = False,
97 Bool collapse = False);
98#else
99 explicit RefRows (const Vector<uInt>& rowNumbers, Bool isSliced = False,
100 Bool collapse = False);
101#endif
102
103 // Create the object from a single start,end,incr slice.
104 RefRows (rownr_t start, rownr_t end, rownr_t incr=1);
105
106 // Copy constructor (reference semantics).
107 RefRows (const RefRows& other);
108
109 // Assignment (copy semantics).
110 RefRows& operator= (const RefRows& other);
111
113
114 // Do this and the other object reference the same rows?
115 Bool operator== (const RefRows& other) const;
116
117 // Convert this object to a RowNumbers object by applying the given row numbers.
118 // It is used to convert the RefRows object with row numbers in a
119 // RefTable to row numbers in the original root table.
120 RowNumbers convert (const RowNumbers& rootRownrs) const;
121
122 // Convert this object to a RowNumbers object by de-slicing it.
123 // I.e. it linearizes the row numbers.
125
126 // Return the number of rows given by this object.
127 // If the object contains slices, it counts the number of rows
128 // represented by each slice. // <group>
130 { return (itsNrows == 0 ? fillNrows() : itsNrows); }
131 rownr_t nrow() const
132 { return (itsNrows == 0 ? fillNrows() : itsNrows); }
133 // </group>
134
135 // Return the first row in the object.
137 { return itsRows(0); }
138
139 // Represents the vector a slice?
141 { return itsSliced; }
142
143 // Get the row vector as is (thus sliced if the object contains slices).
144 // It is mainly useful to get all row numbers when the object does not
145 // contain slices.
147 { return itsRows; }
148
149private:
150 // Initialize the object.
151 void init (const Vector<rownr_t>& rowNumbers, Bool isSliced,
152 Bool collapse);
153
154 // Fill the itsNrows variable.
156
158 rownr_t itsNrows; //# 0 = still unknown
159 Bool itsSliced; //# True = vector contains slices
160};
161
162
163
164// <summary>
165// Class to iterate through a RefRows object.
166// </summary>
167
168// <use visibility=local>
169
170// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tRefRows.cc">
171// </reviewed>
172
173// <prerequisite>
174//# Classes you should understand before using this one.
175// <li> <linkto class=RefRows>RefRows</linkto>
176// </prerequisite>
177
178// <synopsis>
179// RefRowsSliceIter is useful to iterate through a
180// <linkto class=RefRows>RefRows</linkto> object,
181// especially if the RefRows object contains slices.
182// Each step in the iteration returns a Slice object containing
183// the next slice in the RefRows object.
184// <br>
185// It is used in Table and data manager classes (e.g. StManColumn).
186// </synopsis>
187
188// <example>
189// This example shows how to iterate through a RefRows object
190// (giving a slice) and through each of the slices.
191// <srcblock>
192// void somefunc (const RefRows& rownrs)
193// // Iterate through all slices.
194// RefRowsSliceIter rowiter(rownrs);
195// while (! rowiter.pastEnd()) {
196// // Get start, end, and increment for this slice.
197// rownr_t rownr = rowiter.sliceStart();
198// rownr_t end = rowiter.sliceEnd();
199// rownr_t incr = rowiter.sliceIncr();
200// // Iterate through the row numbers in the slice.
201// while (rownr <= end) {
202// rownr += incr;
203// }
204// // Go to next slice.
205// rowiter++;
206// }
207// }
208// </srcblock>
209// </example>
210
211//# <todo asof="$DATE:$">
212//# A List of bugs, limitations, extensions or planned refinements.
213//# </todo>
214
215
217{
218public:
219 // Construct the iterator on a RefRows object.
220 // It is set to the beginning.
222
223 // Reset the iterator to the beginning.
224 void reset();
225
226 // Is the iterator past the end?
227 Bool pastEnd() const
228 { return itsPastEnd; }
229
230 // Go the next slice.
231 // <group>
233 { next(); }
234 void operator++(int)
235 { next(); }
236 void next();
237 // </group>
238
239 // Get the current slice start, end, or increment.
240 // <group>
242 { return itsStart; }
244 { return itsEnd; }
246 { return itsIncr; }
247 // </group>
248
249private:
257};
258
259
260
261
262} //# NAMESPACE CASACORE - END
263
264#endif
Class to iterate through a RefRows object.
Definition RefRows.h:217
void operator++()
Go the next slice.
Definition RefRows.h:232
rownr_t sliceIncr() const
Definition RefRows.h:245
rownr_t sliceEnd() const
Definition RefRows.h:243
Vector< rownr_t > itsRows
Definition RefRows.h:250
Bool pastEnd() const
Is the iterator past the end?
Definition RefRows.h:227
rownr_t sliceStart() const
Get the current slice start, end, or increment.
Definition RefRows.h:241
void reset()
Reset the iterator to the beginning.
RefRowsSliceIter(const RefRows &)
Construct the iterator on a RefRows object.
RowNumbers convert(const RowNumbers &rootRownrs) const
Convert this object to a RowNumbers object by applying the given row numbers.
RefRows(rownr_t start, rownr_t end, rownr_t incr=1)
Create the object from a single start,end,incr slice.
Bool isSliced() const
Represents the vector a slice?
Definition RefRows.h:140
RefRows(const Vector< rownr_t > &rowNumbers, Bool isSliced=False, Bool collapse=False)
Create the object from a Vector containing the row numbers.
rownr_t nrow() const
Definition RefRows.h:131
rownr_t fillNrows() const
Fill the itsNrows variable.
RefRows(const RefRows &other)
Copy constructor (reference semantics).
void init(const Vector< rownr_t > &rowNumbers, Bool isSliced, Bool collapse)
Initialize the object.
Vector< rownr_t > itsRows
Definition RefRows.h:157
Bool operator==(const RefRows &other) const
Do this and the other object reference the same rows?
RowNumbers convert() const
Convert this object to a RowNumbers object by de-slicing it.
RefRows(const Vector< uInt > &rowNumbers, Bool isSliced=False, Bool collapse=False)
RefRows & operator=(const RefRows &other)
Assignment (copy semantics).
rownr_t nrows() const
Return the number of rows given by this object.
Definition RefRows.h:129
const Vector< rownr_t > & rowVector() const
Get the row vector as is (thus sliced if the object contains slices).
Definition RefRows.h:146
rownr_t itsNrows
Definition RefRows.h:158
rownr_t firstRow() const
Return the first row in the object.
Definition RefRows.h:136
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44