casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConcatRows.h
Go to the documentation of this file.
1 //# ConcatRows.h: Class holding the row numbers in a ConcatTable
2 //# Copyright (C) 2008
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_CONCATROWS_H
29 #define TABLES_CONCATROWS_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38  // <summary>
39  // Class holding the row numbers in a ConcatTable
40  // </summary>
41 
42  // <use visibility=local>
43 
44  // <reviewed reviewer="UNKNOWN" date="" tests="tConcatRows.cc">
45  // </reviewed>
46 
47  // <prerequisite>
48  //# Classes you should understand before using this one.
49  // <li> <linkto class=Block>Block</linkto>
50  // </prerequisite>
51 
52  // <synopsis>
53  // ConcatRows is used to hold the row numbers forming the concatenation
54  // of oher tables.
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=ConcatTable>ConcatTable</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=ConcatRowsIter>ConcatRowsIter</linkto> can be
64  // used to iterate through a ConcatRows object. Each step in the iteration
65  // goes to the next slice. If the ConcatRows object 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  // ConcatRows 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 concatinements.
80  //# </todo>
81 
82 
83  class ConcatRows
84  {
85  public:
86  // Construct an empty block.
88  : itsRows (1,0),
89  itsNTable (0),
90  itsLastStRow (1),
91  itsLastEndRow (0)
92  {}
93 
94  // Reserve the block for the given nr of tables.
96  { itsRows.resize (ntable+1); }
97 
98  // Add a table with the given nr of rows.
99  void add (uInt nrow);
100 
101  // Give the nr of tables.
102  uInt ntable() const
103  { return itsNTable; }
104 
105  // Get the total nr of rows.
106  uInt nrow() const
107  { return itsRows[itsNTable]; }
108 
109  // Give the nr of rows for the i-th table.
111  { return itsRows[i+1]; }
112 
113  // Give the offset for the i-th table.
114  uInt offset (uInt i) const
115  { return itsRows[i]; }
116 
117  // Map an overall row number to a table and row number.
118  void mapRownr (uInt& tableNr, uInt& tabRownr, uInt rownr) const
119  {
120  if (rownr < itsLastStRow || rownr >= itsLastEndRow) {
121  findRownr (rownr);
122  }
123  tableNr = itsLastTableNr;
124  tabRownr = rownr - itsLastStRow;
125  }
126 
127  private:
128  // Find the row number and fill in the lastXX_p values.
129  void findRownr (uInt rownr) const;
130 
131  //# Data members.
134  mutable uInt itsLastStRow; //# Cached variables to spped up
135  mutable uInt itsLastEndRow; //# function mapRownr().
137  };
138 
139 
140 
141  // <summary>
142  // Class to iterate through a ConcatRows object.
143  // </summary>
144 
145  // <use visibility=local>
146 
147  // <reviewed reviewer="UNKNOWN" date="" tests="tConcatRows.cc">
148  // </reviewed>
149 
150  // <prerequisite>
151  //# Classes you should understand before using this one.
152  // <li> <linkto class=ConcatRows>ConcatRows</linkto>
153  // </prerequisite>
154 
155  // <synopsis>
156  // ConcatRowsSliceIter is useful to iterate through a
157  // <linkto class=ConcatRows>ConcatRows</linkto> object.
158  // It is possible to define for which row
159 // especially if the ConcatRows object contains slices.
160 // Each step in the iteration returns a Slice object containing
161 // the next slice in the ConcatRows object.
162 // <br>
163 // It is used in Table and data manager classes (e.g. StManColumn).
164 // </synopsis>
165 
166 // <example>
167 // This example shows how to iterate through a ConcatRows object
168 // (giving a slice) and through each of the slices.
169 // <srcblock>
170 // void somefunc (const ConcatRows& rownrs)
171 // // Iterate through all slices.
172 // ConcatRowsSliceIter rowiter(rownrs);
173 // while (! rowiter.pastEnd()) {
174 // // Get start, end, and increment for this slice.
175 // uInt rownr = rowiter.sliceStart();
176 // uInt end = rowiter.sliceEnd();
177 // uInt incr = rowiter.sliceIncr();
178 // // Iterate through the row numbers in the slice.
179 // while (rownr <= end) {
180 // rownr += incr;
181 // }
182 // // Go to next slice.
183 // rowiter++;
184 // }
185 // }
186 // </srcblock>
187 // </example>
188 
189 //# <todo asof="$DATE:$">
190 //# A List of bugs, limitations, extensions or planned concatinements.
191 //# </todo>
192 
193 
195  {
196  public:
197  // Construct the iterator on a ConcatRows object.
198  // It is set to the full range.
199  explicit ConcatRowsIter (const ConcatRows&);
200 
201  // Construct the iterator on a ConcatRows object for the given row range.
202  ConcatRowsIter (const ConcatRows&, uInt start, uInt end, uInt incr=1);
203 
204  // Is the iterator past the end?
205  Bool pastEnd() const
206  { return itsPastEnd; }
207 
208  // Go the next chunk.
209  // <group>
210  void operator++()
211  { next(); }
212  void operator++(int)
213  { next(); }
214  void next();
215  // </group>
216 
217  // Get the current chunk.
219  { return RefRows(itsChunk, True); }
220 
221  // Get the nr of the table the current chunk is in.
222  uInt tableNr() const
223  { return itsPos; }
224 
225  private:
233  };
234 
235 
236 } //# NAMESPACE CASACORE - END
237 
238 #endif
uInt ntable() const
Give the nr of tables.
Definition: ConcatRows.h:102
uInt offset(uInt i) const
Give the offset for the i-th table.
Definition: ConcatRows.h:114
RefRows getChunk() const
Get the current chunk.
Definition: ConcatRows.h:218
Class holding the row numbers in a ConcatTable.
Definition: ConcatRows.h:83
const ConcatRows * itsRows
Definition: ConcatRows.h:226
uInt operator[](uInt i) const
Give the nr of rows for the i-th table.
Definition: ConcatRows.h:110
uInt tableNr() const
Get the nr of the table the current chunk is in.
Definition: ConcatRows.h:222
Bool pastEnd() const
Is the iterator past the end?
Definition: ConcatRows.h:205
void mapRownr(uInt &tableNr, uInt &tabRownr, uInt rownr) const
Map an overall row number to a table and row number.
Definition: ConcatRows.h:118
void resize(size_t n, Bool forceSmaller=False, Bool copyElements=True)
Resizes the Block.
Definition: Block.h:377
const_iterator end() const
Vector< uInt > itsChunk
Definition: ConcatRows.h:227
ConcatRowsIter(const ConcatRows &)
Construct the iterator on a ConcatRows object.
uInt nrow() const
Get the total nr of rows.
Definition: ConcatRows.h:106
Block< uInt > itsRows
Definition: ConcatRows.h:132
Class holding the row numbers in a RefTable.
Definition: RefRows.h:85
void reserve(uInt ntable)
Reserve the block for the given nr of tables.
Definition: ConcatRows.h:95
void operator++()
Go the next chunk.
Definition: ConcatRows.h:210
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void add(uInt nrow)
Add a table with the given nr of rows.
Class to iterate through a ConcatRows object.
Definition: ConcatRows.h:194
const Bool True
Definition: aipstype.h:43
ConcatRows()
Construct an empty block.
Definition: ConcatRows.h:87
void findRownr(uInt rownr) const
Find the row number and fill in the lastXX_p values.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42