00001 //# TableExprId.h: The identification of a TaQL selection subject 00002 //# Copyright (C) 2000 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 //# 00027 //# $Id$ 00028 00029 00030 #ifndef TABLES_TABLEEXPRID_H 00031 #define TABLES_TABLEEXPRID_H 00032 00033 //# Includes 00034 #include <casacore/casa/aips.h> 00035 #include <casacore/casa/stdvector.h> 00036 00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00038 00039 //# Forward Declarations 00040 class RecordInterface; 00041 class TableExprData; 00042 00043 // <summary> 00044 // The identification of a TaQL selection subject. 00045 // </summary> 00046 00047 // <use visibility=export> 00048 00049 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00050 // </reviewed> 00051 00052 // <prerequisite> 00053 // <li> <linkto class="TableExprNode">TableExprNode</linkto>. 00054 // </prerequisite> 00055 00056 // <synopsis> 00057 // This class provides the user the ability to identify the data objects 00058 // to test in a TaQL expression. In this way a TaQL expression is not 00059 // limited to tables, but can be used for any set of data. 00060 // Three types are available: 00061 // <ol> 00062 // <li> A row number giving the row to test in a table. 00063 // It also contains a sequence number (0..n) which is used to get the 00064 // result calculated by aggregate functions. 00065 // <li> A <linkto class=RecordInterface>RecordInterface</linkto> 00066 // object giving the record to test. 00067 // <li> A <linkto class=TableExprData>TableExprData</linkto> 00068 // object giving the abstract base class of an object holding 00069 // the data to test. In this way any data can be used. 00070 // </ol> 00071 // The TaQL expression must be setup with this in mind by constructing 00072 // the appropriate <linkto class=TableExprNode>TableExprNode</linkto> 00073 // leaf objects. 00074 // <br> 00075 // When used for tables, the function <linkto class=Table>Table::col</linkto> 00076 // should be used to create the <src>TableExprNode</src> objects for the 00077 // table columns to be used in the expression. 00078 // <br> 00079 // For the other cases class 00080 // <linkto class=TableExprNodeRecordField>TableExprNodeRecordField</linkto> 00081 // has to be used to know the index of the fields in the expression. 00082 // It uses a record (description) for this purpose. 00083 // </synopsis> 00084 00085 // <example> 00086 // <srcblock> 00087 // </srcBlock> 00088 // </example> 00089 00090 // <motivation> 00091 // This class makes it possible that TaQL can be used in a very versatile way. 00092 // </motivation> 00093 00094 //# <todo asof="1996/03/12"> 00095 //# </todo> 00096 00097 00098 class TableExprId 00099 { 00100 public: 00101 // Default constructor sets rownr to -1. 00102 TableExprId(); 00103 00104 // Construct it from a row number. 00105 TableExprId (uInt rowNumber); 00106 00107 // Construct it from a Record object. 00108 TableExprId (const RecordInterface&); 00109 00110 // Construct it from pointers to data. 00111 TableExprId (const TableExprData& data); 00112 00113 ~TableExprId() 00114 {} 00115 00116 // Is the id given by row number? 00117 Bool byRow() const; 00118 00119 // Is the id given as a RecordInterface? 00120 Bool byRecord() const; 00121 00122 // Is the id given as a TableExprData? 00123 Bool byData() const; 00124 00125 // Get the row number. 00126 Int64 rownr() const; 00127 00128 // Get the Record reference. 00129 const RecordInterface& record() const; 00130 00131 // Get the data reference. 00132 const TableExprData& data() const; 00133 // Set the row number. 00134 00135 void setRownr (uInt rownr); 00136 00137 // Set the record. 00138 void setRecord (const RecordInterface&); 00139 00140 private: 00141 Int type_p; 00142 union { 00143 Int64 row_p; 00144 const RecordInterface* record_p; 00145 const TableExprData* data_p; 00146 }; 00147 }; 00148 00149 00150 00151 inline TableExprId::TableExprId() 00152 : type_p (0), 00153 row_p (-1) 00154 {} 00155 00156 inline TableExprId::TableExprId (uInt rowNumber) 00157 : type_p (0), 00158 row_p (rowNumber) 00159 {} 00160 00161 inline TableExprId::TableExprId (const RecordInterface& record) 00162 : type_p (-1), 00163 record_p (&record) 00164 {} 00165 00166 inline TableExprId::TableExprId (const TableExprData& data) 00167 : type_p (-2), 00168 data_p (&data) 00169 {} 00170 00171 inline Int64 TableExprId::rownr() const 00172 { 00173 return row_p; 00174 } 00175 00176 inline const RecordInterface& TableExprId::record() const 00177 { 00178 return *record_p; 00179 } 00180 00181 inline const TableExprData& TableExprId::data() const 00182 { 00183 return *data_p; 00184 } 00185 00186 inline void TableExprId::setRownr (uInt rownr) 00187 { 00188 row_p = rownr; 00189 } 00190 00191 inline void TableExprId::setRecord (const RecordInterface& record) 00192 { 00193 record_p = &record; 00194 } 00195 00196 inline Bool TableExprId::byRow() const 00197 { 00198 return type_p >= 0; 00199 } 00200 00201 inline Bool TableExprId::byRecord() const 00202 { 00203 return type_p == -1; 00204 } 00205 00206 inline Bool TableExprId::byData() const 00207 { 00208 return type_p == -2; 00209 } 00210 00211 00212 } //# NAMESPACE CASACORE - END 00213 00214 #endif