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