00001 //# TableIterProxy.h: Proxy for table iterator access 00002 //# Copyright (C) 1994,1995,1996,1999,2005 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_TABLEITERPROXY_H 00029 #define TABLES_TABLEITERPROXY_H 00030 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/tables/Tables/TableIter.h> 00035 #include <casacore/casa/Arrays/Vector.h> 00036 00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00038 00039 //# Forward Declarations 00040 class TableProxy; 00041 00042 00043 // <summary> 00044 // Proxy for table iterator access. 00045 // </summary> 00046 00047 // <use visibility=export> 00048 00049 // <reviewed reviewer="Paul Shannon" date="1995/09/15" tests="tgtable.g" demos=""> 00050 // </reviewed> 00051 00052 // <prerequisite> 00053 //# Classes you should understand before using this one. 00054 // <li> class TableIterator 00055 // </prerequisite> 00056 00057 // <etymology> 00058 // TableIterProxy holds a TableIterator object for the table 00059 // glish client. 00060 // </etymology> 00061 00062 // <synopsis> 00063 // TableIterProxy gives access to the table iterator functionality. 00064 // It is primarily meant to be used in classes that wrap access to it 00065 // from scripting languages (like Glish and Python). 00066 // However, it can also be used directly from other C++ code. 00067 // 00068 // A TableIterProxy object is usually created by class 00069 // <linkto class=TableProxy>TableProxy</linkto>. 00070 // </synopsis> 00071 00072 // <example> 00073 // <srcblock> 00074 // // Get a table proxy. 00075 // TableProxy proxy("sometable"); 00076 // Vector<String> columns(1, "SOMECOL"); 00077 // TableIterProxy tgi (proxy, columns, "a", "q"); 00078 // TableProxy subTable; 00079 // // Iterate through the table. 00080 // while (tgi.next (subTable)) { 00081 // ..use Table object subTable.table() 00082 // } 00083 // </srcblock> 00084 // </example> 00085 00086 class TableIterProxy 00087 { 00088 public: 00089 // Default constructor initializes to not open. 00090 // This constructor is only needed for the Block container. 00091 TableIterProxy(); 00092 00093 // Construct iterator for the given table column(s). 00094 // Order and sortType are case-insentive strings and only the first 00095 // character in it is important. 00096 // <br>order[0]=a means ascending; d means descending. 00097 // <br>sortType[0]=q means quicksort, i means insertion sort, 00098 // n means nosort, h means heapsort, otherwise parsort 00099 // <br>For each column an iteration interval can be given making it possible 00100 // to iterate in e.g. time chunks of 1 minute. Not given or zero means 00101 // no interval is given for that column, thus a normal comparison is done. 00102 // It can only be used for numerical columns (not complex). 00103 // However, if for a string column the interbval is set to non-zero, it 00104 // means that case-insensitive comparison will be used. 00105 TableIterProxy (const TableProxy& tab, const Vector<String>& columns, 00106 const String& order, const String& sortType, 00107 const Vector<Double>& intervals = Vector<Double>()); 00108 00109 // Copy constructor (copy semantics). 00110 TableIterProxy (const TableIterProxy&); 00111 00112 ~TableIterProxy(); 00113 00114 // Assignment (copy semantics). 00115 TableIterProxy& operator= (const TableIterProxy&); 00116 00117 // Is the internal iterator object null? 00118 Bool isNull() const 00119 { return iter_p.isNull(); } 00120 00121 // Get the TableIterator object. 00122 const TableIterator& iterator() const 00123 { return iter_p; } 00124 00125 // Get the next subtable and return it in the TableProxy argument. 00126 // When no more subtables are available, it returns False. 00127 Bool nextPart (TableProxy& table); 00128 00129 // Iterate to the next part (for Python use). 00130 // An IterError exception is thrown at the end of the loop. 00131 TableProxy next(); 00132 00133 // Reset the iterator (for Python use). 00134 void reset(); 00135 00136 00137 private: 00138 // Make an iterator where iteration intervals may have been given. 00139 void makeStepIter (const Table& tab, 00140 const Block<String>& columns, 00141 const Vector<Double>& iterSteps, 00142 TableIterator::Order order, 00143 TableIterator::Option sortType); 00144 00145 //# Data members 00146 TableIterator iter_p; 00147 Bool firstTime_p; //# True = first time 00148 }; 00149 00150 00151 } //# NAMESPACE CASACORE - END 00152 00153 00154 #endif