casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
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  // 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<uInt>& rowNumbers, Bool isSliced = False,
96  Bool collapse = False);
97 
98  // Create the object from a single start,end,incr slice.
99  RefRows (uInt start, uInt end, uInt incr=1);
100 
101  // Copy constructor (reference semantics).
102  RefRows (const RefRows& other);
103 
104  // Assignment (copy semantics).
105  RefRows& operator= (const RefRows& other);
106 
107  ~RefRows();
108 
109  // Do this and the other object reference the same rows?
110  Bool operator== (const RefRows& other) const;
111 
112  // Convert this object to a Vector<uInt> by applying the given row numbers.
113  // It is used to convert the RefRows object with row numbers in a
114  // RefTable to row numbers in the original root table.
115  Vector<uInt> convert (const Vector<uInt>& rootRownrs) const;
116 
117  // Convert this object to a Vector<uInt> by de-slicing it.
118  // I.e. it linearizes the row numbers.
119  Vector<uInt> convert() const;
120 
121  // Return the number of rows given by this object.
122  // If the object contains slices, it counts the number of rows
123  // represented by each slice.
124  // <group>
125  uInt nrows() const
126  { return (itsNrows == 0 ? fillNrows() : itsNrows); }
127  uInt nrow() const
128  { return (itsNrows == 0 ? fillNrows() : itsNrows); }
129  // </group>
130 
131  // Return the first row in the object.
132  uInt firstRow() const
133  { return itsRows(0); }
134 
135  // Represents the vector a slice?
136  Bool isSliced() const
137  { return itsSliced; }
138 
139  // Get the row vector as is (thus sliced if the object contains slices).
140  // It is mainly useful to get all row numbers when the object does not
141  // contain slices.
142  const Vector<uInt>& rowVector() const
143  { return itsRows; }
144 
145 private:
146  // Fill the itsNrows variable.
147  uInt fillNrows() const;
148 
150  uInt itsNrows; //# 0 = still unknown
151  Bool itsSliced; //# True = vector contains slices
152 };
153 
154 
155 
156 // <summary>
157 // Class to iterate through a RefRows object.
158 // </summary>
159 
160 // <use visibility=local>
161 
162 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tRefRows.cc">
163 // </reviewed>
164 
165 // <prerequisite>
166 //# Classes you should understand before using this one.
167 // <li> <linkto class=RefRows>RefRows</linkto>
168 // </prerequisite>
169 
170 // <synopsis>
171 // RefRowsSliceIter is useful to iterate through a
172 // <linkto class=RefRows>RefRows</linkto> object,
173 // especially if the RefRows object contains slices.
174 // Each step in the iteration returns a Slice object containing
175 // the next slice in the RefRows object.
176 // <br>
177 // It is used in Table and data manager classes (e.g. StManColumn).
178 // </synopsis>
179 
180 // <example>
181 // This example shows how to iterate through a RefRows object
182 // (giving a slice) and through each of the slices.
183 // <srcblock>
184 // void somefunc (const RefRows& rownrs)
185 // // Iterate through all slices.
186 // RefRowsSliceIter rowiter(rownrs);
187 // while (! rowiter.pastEnd()) {
188 // // Get start, end, and increment for this slice.
189 // uInt rownr = rowiter.sliceStart();
190 // uInt end = rowiter.sliceEnd();
191 // uInt incr = rowiter.sliceIncr();
192 // // Iterate through the row numbers in the slice.
193 // while (rownr <= end) {
194 // rownr += incr;
195 // }
196 // // Go to next slice.
197 // rowiter++;
198 // }
199 // }
200 // </srcblock>
201 // </example>
202 
203 //# <todo asof="$DATE:$">
204 //# A List of bugs, limitations, extensions or planned refinements.
205 //# </todo>
206 
207 
209 {
210 public:
211  // Construct the iterator on a RefRows object.
212  // It is set to the beginning.
213  RefRowsSliceIter (const RefRows&);
214 
215  // Reset the iterator to the beginning.
216  void reset();
217 
218  // Is the iterator past the end?
219  Bool pastEnd() const
220  { return itsPastEnd; }
221 
222  // Go the next slice.
223  // <group>
224  void operator++()
225  { next(); }
226  void operator++(int)
227  { next(); }
228  void next();
229  // </group>
230 
231  // Get the current slice start, end, or increment.
232  // <group>
233  uInt sliceStart() const
234  { return itsStart; }
235  uInt sliceEnd() const
236  { return itsEnd; }
237  uInt sliceIncr() const
238  { return itsIncr; }
239  // </group>
240 
241 private:
249 };
250 
251 
252 
253 
254 } //# NAMESPACE CASACORE - END
255 
256 #endif
Vector< uInt > convert() const
Convert this object to a Vector&lt;uInt&gt; by de-slicing it.
uInt nrow() const
Definition: RefRows.h:127
const_iterator end() const
uInt sliceStart() const
Get the current slice start, end, or increment.
Definition: RefRows.h:233
Bool pastEnd() const
Is the iterator past the end?
Definition: RefRows.h:219
void reset()
Reset the iterator to the beginning.
uInt fillNrows() const
Fill the itsNrows variable.
const Vector< uInt > & rowVector() const
Get the row vector as is (thus sliced if the object contains slices).
Definition: RefRows.h:142
Class holding the row numbers in a RefTable.
Definition: RefRows.h:85
RefRows & operator=(const RefRows &other)
Assignment (copy semantics).
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Vector< uInt > itsRows
Definition: RefRows.h:149
const Bool False
Definition: aipstype.h:44
void operator++()
Go the next slice.
Definition: RefRows.h:224
RefRows(const Vector< uInt > &rowNumbers, Bool isSliced=False, Bool collapse=False)
Create the object from a Vector containing the row numbers.
RefRowsSliceIter(const RefRows &)
Construct the iterator on a RefRows object.
Vector< uInt > itsRows
Definition: RefRows.h:242
uInt sliceIncr() const
Definition: RefRows.h:237
uInt sliceEnd() const
Definition: RefRows.h:235
Bool operator==(const RefRows &other) const
Do this and the other object reference the same rows?
Bool isSliced() const
Represents the vector a slice?
Definition: RefRows.h:136
Class to iterate through a RefRows object.
Definition: RefRows.h:208
uInt nrows() const
Return the number of rows given by this object.
Definition: RefRows.h:125
unsigned int uInt
Definition: aipstype.h:51
uInt firstRow() const
Return the first row in the object.
Definition: RefRows.h:132
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42