00001 //# RefRows.h: Class holding the row numbers in a RefTable 00002 //# Copyright (C) 1998 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 00028 #ifndef TABLES_REFROWS_H 00029 #define TABLES_REFROWS_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/casa/Arrays/Vector.h> 00034 00035 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00036 00037 //# Forward Declarations 00038 class Slicer; 00039 00040 00041 // <summary> 00042 // Class holding the row numbers in a RefTable 00043 // </summary> 00044 00045 // <use visibility=local> 00046 00047 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tRefRows.cc"> 00048 // </reviewed> 00049 00050 // <prerequisite> 00051 //# Classes you should understand before using this one. 00052 // <li> <linkto class=Vector>Vector</linkto> 00053 // </prerequisite> 00054 00055 // <synopsis> 00056 // RefRows is used to hold the row numbers forming a view on another 00057 // table. It contains a vector which can hold the row numbers in 2 ways: 00058 // <ol> 00059 // <li> As a normal series of row numbers. This is used by e.g. class 00060 // <linkto class=RefTable>RefTable</linkto> 00061 // <li> As a series of Slices. In this case 3 subsequent entries 00062 // in the vector are used to represent start, end, and increment. 00063 // This is used by a function like <src>ScalarColumn::getColumnRange</src>. 00064 // </ol> 00065 // Class <linkto class=RefRowsSliceIter>RefRowsSliceIter</linkto> can be 00066 // used to iterate through a RefRows object. Each step in the iteration 00067 // goes to the next a slice. If the RefRows objct contains a simple series 00068 // of row numbers, each slice contains only one row number. 00069 // This can degrade performance, so it is possible to use shortcuts by 00070 // testing if the object contains slices (using <src>isSliced()</src>) 00071 // and getting the row number vector directly (using <src>rowVector()</src>). 00072 // </synopsis> 00073 00074 // <motivation> 00075 // RefRows is meant to have one class representing the various ways 00076 // of picking row numbers. This simplifies the interface of the table 00077 // and data manager classes dealing with getting/putting the data. 00078 // </motivation> 00079 00080 //# <todo asof="$DATE:$"> 00081 //# A List of bugs, limitations, extensions or planned refinements. 00082 //# </todo> 00083 00084 00085 class RefRows 00086 { 00087 public: 00088 00089 // Create the object from a Vector containing the row numbers. 00090 // When <src>isSliced==False</src>, the vector is treated as 00091 // containing individual row numbers, otherwise as containing 00092 // slices in the form start,end,incr. 00093 // When <src>collapse==True</src>, it will try to collapse the 00094 // individual row numbers to the slice form (to save memory). 00095 RefRows (const Vector<uInt>& rowNumbers, Bool isSliced = False, 00096 Bool collapse = False); 00097 00098 // Create the object from a single start,end,incr slice. 00099 RefRows (uInt start, uInt end, uInt incr=1); 00100 00101 // Copy constructor (reference semantics). 00102 RefRows (const RefRows& other); 00103 00104 // Assignment (copy semantics). 00105 RefRows& operator= (const RefRows& other); 00106 00107 ~RefRows(); 00108 00109 // Do this and the other object reference the same rows? 00110 Bool operator== (const RefRows& other) const; 00111 00112 // Convert this object to a Vector<uInt> by applying the given row numbers. 00113 // It is used to convert the RefRows object with row numbers in a 00114 // RefTable to row numbers in the original root table. 00115 Vector<uInt> convert (const Vector<uInt>& rootRownrs) const; 00116 00117 // Convert this object to a Vector<uInt> by de-slicing it. 00118 // I.e. it linearizes the row numbers. 00119 Vector<uInt> convert() const; 00120 00121 // Return the number of rows given by this object. 00122 // If the object contains slices, it counts the number of rows 00123 // represented by each slice. 00124 // <group> 00125 uInt nrows() const 00126 { return (itsNrows == 0 ? fillNrows() : itsNrows); } 00127 uInt nrow() const 00128 { return (itsNrows == 0 ? fillNrows() : itsNrows); } 00129 // </group> 00130 00131 // Return the first row in the object. 00132 uInt firstRow() const 00133 { return itsRows(0); } 00134 00135 // Represents the vector a slice? 00136 Bool isSliced() const 00137 { return itsSliced; } 00138 00139 // Get the row vector as is (thus sliced if the object contains slices). 00140 // It is mainly useful to get all row numbers when the object does not 00141 // contain slices. 00142 const Vector<uInt>& rowVector() const 00143 { return itsRows; } 00144 00145 private: 00146 // Fill the itsNrows variable. 00147 uInt fillNrows() const; 00148 00149 Vector<uInt> itsRows; 00150 uInt itsNrows; //# 0 = still unknown 00151 Bool itsSliced; //# True = vector contains slices 00152 }; 00153 00154 00155 00156 // <summary> 00157 // Class to iterate through a RefRows object. 00158 // </summary> 00159 00160 // <use visibility=local> 00161 00162 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tRefRows.cc"> 00163 // </reviewed> 00164 00165 // <prerequisite> 00166 //# Classes you should understand before using this one. 00167 // <li> <linkto class=RefRows>RefRows</linkto> 00168 // </prerequisite> 00169 00170 // <synopsis> 00171 // RefRowsSliceIter is useful to iterate through a 00172 // <linkto class=RefRows>RefRows</linkto> object, 00173 // especially if the RefRows object contains slices. 00174 // Each step in the iteration returns a Slice object containing 00175 // the next slice in the RefRows object. 00176 // <br> 00177 // It is used in Table and data manager classes (e.g. StManColumn). 00178 // </synopsis> 00179 00180 // <example> 00181 // This example shows how to iterate through a RefRows object 00182 // (giving a slice) and through each of the slices. 00183 // <srcblock> 00184 // void somefunc (const RefRows& rownrs) 00185 // // Iterate through all slices. 00186 // RefRowsSliceIter rowiter(rownrs); 00187 // while (! rowiter.pastEnd()) { 00188 // // Get start, end, and increment for this slice. 00189 // uInt rownr = rowiter.sliceStart(); 00190 // uInt end = rowiter.sliceEnd(); 00191 // uInt incr = rowiter.sliceIncr(); 00192 // // Iterate through the row numbers in the slice. 00193 // while (rownr <= end) { 00194 // rownr += incr; 00195 // } 00196 // // Go to next slice. 00197 // rowiter++; 00198 // } 00199 // } 00200 // </srcblock> 00201 // </example> 00202 00203 //# <todo asof="$DATE:$"> 00204 //# A List of bugs, limitations, extensions or planned refinements. 00205 //# </todo> 00206 00207 00208 class RefRowsSliceIter 00209 { 00210 public: 00211 // Construct the iterator on a RefRows object. 00212 // It is set to the beginning. 00213 RefRowsSliceIter (const RefRows&); 00214 00215 // Reset the iterator to the beginning. 00216 void reset(); 00217 00218 // Is the iterator past the end? 00219 Bool pastEnd() const 00220 { return itsPastEnd; } 00221 00222 // Go the next slice. 00223 // <group> 00224 void operator++() 00225 { next(); } 00226 void operator++(int) 00227 { next(); } 00228 void next(); 00229 // </group> 00230 00231 // Get the current slice start, end, or increment. 00232 // <group> 00233 uInt sliceStart() const 00234 { return itsStart; } 00235 uInt sliceEnd() const 00236 { return itsEnd; } 00237 uInt sliceIncr() const 00238 { return itsIncr; } 00239 // </group> 00240 00241 private: 00242 Vector<uInt> itsRows; 00243 Bool itsSliced; 00244 uInt itsStart; 00245 uInt itsEnd; 00246 uInt itsIncr; 00247 uInt itsPos; 00248 Bool itsPastEnd; 00249 }; 00250 00251 00252 00253 00254 } //# NAMESPACE CASACORE - END 00255 00256 #endif