casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ExprRange.h
Go to the documentation of this file.
00001 //# ExprRange.h: Select range of a column in an select expression
00002 //# Copyright (C) 1994,1995,1999
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: ExprRange.h 21298 2012-12-07 14:53:03Z gervandiepen $
00027 
00028 #ifndef TABLES_EXPRRANGE_H
00029 #define TABLES_EXPRRANGE_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Vector.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 //# Forward Declarations
00038 class TableColumn;
00039 
00040 
00041 // <summary>
00042 // Select range of a column in an select expression
00043 // </summary>
00044 
00045 // <use visibility=local>
00046 
00047 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00048 // </reviewed>
00049 
00050 // <prerequisite>
00051 //# Classes you should understand before using this one.
00052 //   <li> TableExprNode
00053 // </prerequisite>
00054 
00055 // <etymology>
00056 // TableExprRange represents the ranges of a column as specified in
00057 // a table select expression.
00058 // </etymology>
00059 
00060 // <synopsis> 
00061 // TableExprRange holds the ranges of values for a column as specified
00062 // in a table select expression.
00063 // It traverses the expression tree and composes the hull of the values.
00064 // Only double values are taken into account.
00065 // It can handle operators &&, ||, ==, >, >=, <, <=, !.
00066 // It can handle a comparison operator only for a column with a constant.
00067 // Other operators and expressions are non-convertable.
00068 //
00069 // The ranges function in class TableExprNode returns a Block
00070 // of TableExprRange objects which contains the ranges for each
00071 // (applicable) column used in the expression.
00072 // </synopsis> 
00073 
00074 // <motivation>
00075 // TableExprRange gives great possibilities in optimizing a table
00076 // selection. It allows to get a rough estimate of the values needed
00077 // for a column which can be used to do a fast preselect using an index.
00078 // </motivation>
00079 
00080 // <todo asof="$DATE:$">
00081 //# A List of bugs, limitations, extensions or planned refinements.
00082 //   <li> Support other data types than double
00083 //   <li> Recognize that 2*COL<3 is equal to COL<3/2
00084 // </todo>
00085 
00086 
00087 class TableExprRange
00088 {
00089 public:
00090     // Default constructor (needed for Block<TableExprRange>).
00091     TableExprRange();
00092 
00093     // Construct from a column and a single constant range.
00094     TableExprRange (const TableColumn&, double stval, double endval);
00095 
00096     // Copy constructor.
00097     TableExprRange (const TableExprRange&);
00098 
00099     ~TableExprRange ();
00100 
00101     // Assignment operator (copy semantics).
00102     TableExprRange& operator= (const TableExprRange&);
00103 
00104     // Return the vector of start values.
00105     // Together with the equally sized vector of end values, this forms
00106     // the ranges for the column (which can be acquired using getColumn).
00107     const Vector<double>& start() const;
00108 
00109     // Return the vector of end values.
00110     // Together with the equally sized vector of start values, this forms
00111     // the ranges for the column (which can be acquired using getColumn).
00112     const Vector<double>& end() const;
00113 
00114     // Return the column object.
00115     const TableColumn& getColumn() const;
00116 
00117     //*display 4
00118     // Mix with another range for an AND expression.
00119     void mixAnd (const TableExprRange&);
00120 
00121     //*display 4
00122     // Mix with another range for an OR expression.
00123     void mixOr (const TableExprRange&);
00124 
00125 private:
00126     Vector<double>    sval_p;                 //# start values
00127     Vector<double>    eval_p;                 //# end values
00128     TableColumn*      tabColPtr_p;            //# pointer to column
00129 };
00130 
00131 
00132 inline const Vector<double>& TableExprRange::start() const
00133     { return sval_p; }
00134 inline const Vector<double>& TableExprRange::end() const
00135     { return eval_p; }
00136 
00137 
00138 
00139 } //# NAMESPACE CASA - END
00140 
00141 #endif