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