casa
$Rev:20696$
|
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: RefRows.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00027 00028 #ifndef TABLES_REFROWS_H 00029 #define TABLES_REFROWS_H 00030 00031 //# Includes 00032 #include <casa/Arrays/Vector.h> 00033 00034 namespace casa { //# NAMESPACE CASA - BEGIN 00035 00036 //# Forward Declarations 00037 class Slicer; 00038 00039 00040 // <summary> 00041 // Class holding the row numbers in a RefTable 00042 // </summary> 00043 00044 // <use visibility=local> 00045 00046 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tRefRows.cc"> 00047 // </reviewed> 00048 00049 // <prerequisite> 00050 //# Classes you should understand before using this one. 00051 // <li> <linkto class=Vector>Vector</linkto> 00052 // </prerequisite> 00053 00054 // <synopsis> 00055 // RefRows is used to hold the row numbers forming a view on another 00056 // table. It contains a vector which can hold the row numbers in 2 ways: 00057 // <ol> 00058 // <li> As a normal series of row numbers. This is used by e.g. class 00059 // <linkto class=RefTable>RefTable</linkto> 00060 // <li> As a series of Slices. In this case 3 subsequent entries 00061 // in the vector are used to represent start, end, and increment. 00062 // This is used by a function like <src>ScalarColumn::getColumnRange</src>. 00063 // </ol> 00064 // Class <linkto class=RefRowsSliceIter>RefRowsSliceIter</linkto> can be 00065 // used to iterate through a RefRows object. Each step in the iteration 00066 // goes to the next a slice. If the RefRows objct contains a simple series 00067 // of row numbers, each slice contains only one row number. 00068 // This can degrade performance, so it is possible to use shortcuts by 00069 // testing if the object contains slices (using <src>isSliced()</src>) 00070 // and getting the row number vector directly (using <src>rowVector()</src>). 00071 // </synopsis> 00072 00073 // <motivation> 00074 // RefRows is meant to have one class representing the various ways 00075 // of picking row numbers. This simplifies the interface of the table 00076 // and data manager classes dealing with getting/putting the data. 00077 // </motivation> 00078 00079 //# <todo asof="$DATE:$"> 00080 //# A List of bugs, limitations, extensions or planned refinements. 00081 //# </todo> 00082 00083 00084 class RefRows 00085 { 00086 public: 00087 00088 // Create the object from a Vector containing the row numbers. 00089 // When <src>isSliced==False</src>, the vector is treated as 00090 // containing individual row numbers, otherwise as containing 00091 // slices in the form start,end,incr. 00092 // When <src>collapse==True</src>, it will try to collapse the 00093 // individual row numbers to the slice form (to save memory). 00094 RefRows (const Vector<uInt>& rowNumbers, Bool isSliced = False, 00095 Bool collapse = False); 00096 00097 // Create the object from a single start,end,incr slice. 00098 RefRows (uInt start, uInt end, uInt incr=1); 00099 00100 // Copy constructor (reference semantics). 00101 RefRows (const RefRows& other); 00102 00103 // Assignment (copy semantics). 00104 RefRows& operator= (const RefRows& other); 00105 00106 ~RefRows(); 00107 00108 // Do this and the other object reference the same rows? 00109 Bool operator== (const RefRows& other) const; 00110 00111 // Convert this object to a Vector<uInt> by applying the given row numbers. 00112 // It is used to convert the RefRows object with row numbers in a 00113 // RefTable to row numbers in the original root table. 00114 Vector<uInt> convert (const Vector<uInt>& rootRownrs) const; 00115 00116 // Convert this object to a Vector<uInt> by de-slicing it. 00117 // I.e. it linearizes the row numbers. 00118 Vector<uInt> convert() const; 00119 00120 // Return the number of rows given by this object. 00121 // If the object contains slices, it counts the number of rows 00122 // represented by each slice. 00123 // <group> 00124 uInt nrows() const 00125 { return (itsNrows == 0 ? fillNrows() : itsNrows); } 00126 uInt nrow() const 00127 { return (itsNrows == 0 ? fillNrows() : itsNrows); } 00128 // </group> 00129 00130 // Return the first row in the object. 00131 uInt firstRow() const 00132 { return itsRows(0); } 00133 00134 // Represents the vector a slice? 00135 Bool isSliced() const 00136 { return itsSliced; } 00137 00138 // Get the row vector as is (thus sliced if the object contains slices). 00139 // It is mainly useful to get all row numbers when the object does not 00140 // contain slices. 00141 const Vector<uInt>& rowVector() const 00142 { return itsRows; } 00143 00144 private: 00145 // Fill the itsNrows variable. 00146 uInt fillNrows() const; 00147 00148 Vector<uInt> itsRows; 00149 uInt itsNrows; //# 0 = still unknown 00150 Bool itsSliced; //# True = vector contains slices 00151 }; 00152 00153 00154 00155 // <summary> 00156 // Class to iterate through a RefRows object. 00157 // </summary> 00158 00159 // <use visibility=local> 00160 00161 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tRefRows.cc"> 00162 // </reviewed> 00163 00164 // <prerequisite> 00165 //# Classes you should understand before using this one. 00166 // <li> <linkto class=RefRows>RefRows</linkto> 00167 // </prerequisite> 00168 00169 // <synopsis> 00170 // RefRowsSliceIter is useful to iterate through a 00171 // <linkto class=RefRows>RefRows</linkto> object, 00172 // especially if the RefRows object contains slices. 00173 // Each step in the iteration returns a Slice object containing 00174 // the next slice in the RefRows object. 00175 // <br> 00176 // It is used in Table and data manager classes (e.g. StManColumn). 00177 // </synopsis> 00178 00179 // <example> 00180 // This example shows how to iterate through a RefRows object 00181 // (giving a slice) and through each of the slices. 00182 // <srcblock> 00183 // void somefunc (const RefRows& rownrs) 00184 // // Iterate through all slices. 00185 // RefRowsSliceIter rowiter(rownrs); 00186 // while (! rowiter.pastEnd()) { 00187 // // Get start, end, and increment for this slice. 00188 // uInt rownr = rowiter.sliceStart(); 00189 // uInt end = rowiter.sliceEnd(); 00190 // uInt incr = rowiter.sliceIncr(); 00191 // // Iterate through the row numbers in the slice. 00192 // while (rownr <= end) { 00193 // rownr += incr; 00194 // } 00195 // // Go to next slice. 00196 // rowiter++; 00197 // } 00198 // } 00199 // </srcblock> 00200 // </example> 00201 00202 //# <todo asof="$DATE:$"> 00203 //# A List of bugs, limitations, extensions or planned refinements. 00204 //# </todo> 00205 00206 00207 class RefRowsSliceIter 00208 { 00209 public: 00210 // Construct the iterator on a RefRows object. 00211 // It is set to the beginning. 00212 RefRowsSliceIter (const RefRows&); 00213 00214 // Reset the iterator to the beginning. 00215 void reset(); 00216 00217 // Is the iterator past the end? 00218 Bool pastEnd() const 00219 { return itsPastEnd; } 00220 00221 // Go the next slice. 00222 // <group> 00223 void operator++() 00224 { next(); } 00225 void operator++(int) 00226 { next(); } 00227 void next(); 00228 // </group> 00229 00230 // Get the current slice start, end, or increment. 00231 // <group> 00232 uInt sliceStart() const 00233 { return itsStart; } 00234 uInt sliceEnd() const 00235 { return itsEnd; } 00236 uInt sliceIncr() const 00237 { return itsIncr; } 00238 // </group> 00239 00240 private: 00241 Vector<uInt> itsRows; 00242 Bool itsSliced; 00243 uInt itsStart; 00244 uInt itsEnd; 00245 uInt itsIncr; 00246 uInt itsPos; 00247 Bool itsPastEnd; 00248 }; 00249 00250 00251 00252 00253 } //# NAMESPACE CASA - END 00254 00255 #endif