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