ExprNodeRep.h

Go to the documentation of this file.
00001 //# ExprNodeRep.h: Abstract base class for a node in a table column expression tree
00002 //# Copyright (C) 1994,1995,1996,1997,1998,2000,2001,2003
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: ExprNodeRep.h 21262 2012-09-07 12:38:36Z gervandiepen $
00027 
00028 #ifndef TABLES_EXPRNODEREP_H
00029 #define TABLES_EXPRNODEREP_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/tables/Tables/Table.h>
00034 #include <casacore/tables/TaQL/TableExprId.h>
00035 #include <casacore/tables/TaQL/ExprRange.h>
00036 #include <casacore/tables/TaQL/MArray.h>
00037 #include <casacore/casa/BasicSL/Complex.h>
00038 #include <casacore/casa/Quanta/MVTime.h>
00039 #include <casacore/casa/Quanta/Unit.h>
00040 #include <casacore/casa/Utilities/DataType.h>
00041 #include <casacore/casa/Utilities/Regex.h>
00042 #include <casacore/casa/Utilities/StringDistance.h>
00043 #include <casacore/casa/iosfwd.h>
00044 
00045 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00046 
00047 //# Forward Declarations
00048 class TableExprNode;
00049 class TableExprNodeColumn;
00050 class TableExprGroupFuncBase;
00051 template<class T> class Block;
00052 
00053 
00054 // <summary>
00055 // Class to handle a Regex or StringDistance.
00056 // </summary>
00057 
00058 // <use visibility=local>
00059 
00060 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00061 // </reviewed>
00062 
00063 // <prerequisite>
00064 //# Classes you should understand before using this one.
00065 //   <li> <linkto class=Regex>Regex</linkto>
00066 //   <li> <linkto class=StringDistance>StringDistance</linkto>
00067 // </prerequisite>
00068 
00069 // <synopsis> 
00070 // A StringDistance (Levensthein distance) in TaQL is given in the same way
00071 // as a Regex. This class is needed to have a single object in the parse tree
00072 // objects containing them (in class TableExprNodeConstRegex).
00073 // </synopsis> 
00074 
00075 class TaqlRegex
00076 {
00077 public:
00078     // Construct from a regex.
00079   explicit TaqlRegex (const Regex& regex)
00080     : itsRegex(regex)
00081   {}
00082 
00083   // Construct from a StringDistance.
00084   explicit TaqlRegex (const StringDistance& dist)
00085     : itsDist(dist)
00086   {}
00087 
00088   // Does the regex or maximum string distance match?
00089   Bool match (const String& str) const
00090     { return itsRegex.regexp().empty()  ?
00091         itsDist.match(str) : str.matches(itsRegex);
00092     }
00093 
00094   // Return the regular expression.
00095   const Regex& regex() const
00096     { return itsRegex; }
00097 
00098 private:
00099   Regex          itsRegex;
00100   StringDistance itsDist;
00101 };
00102 
00103 
00104 
00105 // <summary>
00106 // Abstract base class for a node in a table column expression tree
00107 // </summary>
00108 
00109 // <use visibility=local>
00110 
00111 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00112 // </reviewed>
00113 
00114 // <prerequisite>
00115 //# Classes you should understand before using this one.
00116 //   <li> <linkto class=TableExprNode>TableExprNode</linkto>
00117 // </prerequisite>
00118 
00119 // <etymology>
00120 // TableExprNodeRep is the (abstract) REPresentation of a node in a table
00121 // expression tree.
00122 // </etymology>
00123 
00124 // <synopsis> 
00125 // TableExprNodeRep is the base class for all nodes in a table
00126 // expression tree. It is used by the handle class TableExprNode.
00127 // <p>
00128 // The objects of this class are reference-counted to make it possible
00129 // that the same object is reused.
00130 // </synopsis> 
00131 
00132 // <motivation>
00133 // TableExprNodeRep and its derivations store a table select expression
00134 // before actually evaluating it. It is also possible that the classes
00135 // are used by the table expression parser defined in TableParse and
00136 // TableGram.
00137 // <br>
00138 // For each operator a special derived class is implemented.
00139 // Another approach could have been to store the operator as
00140 // a flag and switch on that. However, that causes extra overhead
00141 // and the C++ virtual function mechanism is designed for
00142 // these purposes.
00143 // </motivation>
00144 
00145 // <todo asof="$DATE:$">
00146 //# A List of bugs, limitations, extensions or planned refinements.
00147 //   <li> add selection by comparing with a set of values
00148 // </todo>
00149 
00150 
00151 class TableExprNodeRep
00152 {
00153 public:
00154     // Define the data types of a node.
00155     enum NodeDataType {
00156         NTBool,
00157         NTInt,
00158         NTDouble,
00159         NTComplex,
00160         NTString,
00161         NTRegex,
00162         NTDate,
00163         NTReal,                //# NTInt or NTDouble
00164         NTDouCom,              //# NTDouble or NTComplex
00165         NTNumeric,             //# NTInt, NTDouble, or NTComplex
00166         NTAny                  //# Any data type
00167     };
00168 
00169     // Define the value types.
00170     enum ValueType {
00171         VTScalar,
00172         VTArray,
00173         VTRecord,
00174         VTSetElem,
00175         VTSet,
00176         VTIndex
00177     };
00178 
00179     // Define the operator types.
00180     // LE and LT are handled as GE and GT with swapped operands.
00181     enum OperType {OtPlus, OtMinus, OtTimes, OtDivide, OtModulo,
00182                    OtBitAnd, OtBitOr, OtBitXor, OtBitNegate,
00183                    OtEQ, OtGE, OtGT, OtNE, OtIN,
00184                    OtAND, OtOR, OtNOT, OtMIN,
00185                    OtColumn, OtField, OtLiteral, OtFunc, OtSlice, OtUndef,
00186                    OtRownr, OtRandom
00187     };
00188 
00189     // Define the value types of the 2 arguments when arrays are involved.
00190     enum ArgType {
00191         NoArr, ArrArr, ArrSca, ScaArr
00192     };
00193 
00194     // Define (sub-)expression type
00195     enum ExprType {
00196         // A constant subexpression which can be evaluated immediately.
00197         Constant,
00198         // A variable (i.e. row dependent) subexpression which
00199         // has to be evaluated for each table row.
00200         Variable
00201         // An expensive constant subexpression which should only be
00202         // evaluated when needed (e.g. a subquery).
00203 //      Lazy
00204     };
00205 
00206     // Construct a node.
00207     TableExprNodeRep (NodeDataType, ValueType, OperType, ArgType, ExprType,
00208                       Int ndim, const IPosition& shape,
00209                       const Table& table);
00210 
00211     // This constructor is called from the derived TableExprNodeRep.
00212     TableExprNodeRep (NodeDataType, ValueType, OperType, const Table&);
00213 
00214     // Copy constructor.
00215     TableExprNodeRep (const TableExprNodeRep&);
00216 
00217     // The destructor deletes all the underlying TableExprNode objects.
00218     virtual ~TableExprNodeRep();
00219 
00220     // Link to this object, i.e. increase its reference count.
00221     TableExprNodeRep* link();
00222 
00223     // Unlink from the given object.
00224     // If its reference count is zero, delete it.
00225     static void unlink (TableExprNodeRep*);
00226 
00227     // Do not apply the selection.
00228     virtual void disableApplySelection();
00229 
00230     // Re-create the column object for a selection of rows.
00231     // The default implementation does nothing.
00232     virtual void applySelection (const Vector<uInt>& rownrs);
00233 
00234     // Get the unit conversion factor.
00235     // Default 1 is returned.
00236     virtual Double getUnitFactor() const;
00237 
00238     // Throw an exception if an aggregate function is used in
00239     // the expression node.
00240     static void checkAggrFuncs (const TableExprNodeRep* node);
00241 
00242     // Get the nodes representing an aggregate function.
00243     virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr);
00244   
00245     // Get the nodes representing a table column.
00246     virtual void getColumnNodes (vector<TableExprNodeRep*>& cols);
00247   
00248     // Create the correct immediate aggregate function object.
00249     // The default implementation throws an exception, because it should
00250     // only be called for TableExprAggrNode(Array).
00251     virtual CountedPtr<TableExprGroupFuncBase> makeGroupAggrFunc();
00252 
00253     // Is the aggregate function a lazy or an immediate one?
00254     // The default implementation returns True
00255     // (because all UDF aggregate functions have to be lazy).
00256     virtual Bool isLazyAggregate() const;
00257 
00258     // Get a scalar value for this node in the given row.
00259     // The appropriate functions are implemented in the derived classes and
00260     // will usually invoke the get in their children and apply the
00261     // operator on the resulting values.
00262     // <group>
00263     virtual Bool getBool         (const TableExprId& id);
00264     virtual Int64 getInt         (const TableExprId& id);
00265     virtual Double getDouble     (const TableExprId& id);
00266     virtual DComplex getDComplex (const TableExprId& id);
00267     virtual String getString     (const TableExprId& id);
00268     virtual TaqlRegex getRegex   (const TableExprId& id);
00269     virtual MVTime getDate       (const TableExprId& id);
00270     // </group>
00271 
00272     // Get an array value for this node in the given row.
00273     // The appropriate functions are implemented in the derived classes and
00274     // will usually invoke the get in their children and apply the
00275     // operator on the resulting values.
00276     // <group>
00277     virtual MArray<Bool> getArrayBool         (const TableExprId& id);
00278     virtual MArray<Int64> getArrayInt         (const TableExprId& id);
00279     virtual MArray<Double> getArrayDouble     (const TableExprId& id);
00280     virtual MArray<DComplex> getArrayDComplex (const TableExprId& id);
00281     virtual MArray<String> getArrayString     (const TableExprId& id);
00282     virtual MArray<MVTime> getArrayDate       (const TableExprId& id);
00283     // </group>
00284 
00285     // General get functions for template purposes.
00286     // <group>
00287     void get (const TableExprId& id, Bool& value)
00288       { value = getBool (id); }
00289     void get (const TableExprId& id, Int64& value)
00290       { value = getInt (id); }
00291     void get (const TableExprId& id, Double& value)
00292       { value = getDouble (id); }
00293     void get (const TableExprId& id, DComplex& value)
00294       { value = getDComplex (id); }
00295     void get (const TableExprId& id, MVTime& value)
00296       { value = getDate (id); }
00297     void get (const TableExprId& id, String& value)
00298       { value = getString (id); }
00299     void get (const TableExprId& id, MArray<Bool>& value)
00300       { value = getArrayBool (id); }
00301     void get (const TableExprId& id, MArray<Int64>& value)
00302       { value = getArrayInt (id); }
00303     void get (const TableExprId& id, MArray<Double>& value)
00304       { value = getArrayDouble (id); }
00305     void get (const TableExprId& id, MArray<DComplex>& value)
00306       { value = getArrayDComplex (id); }
00307     void get (const TableExprId& id, MArray<MVTime>& value)
00308       { value = getArrayDate (id); }
00309     void get (const TableExprId& id, MArray<String>& value)
00310       { value = getArrayString (id); }
00311     // </group>
00312 
00313     // Get a value as an array, even it it is a scalar.
00314     // This is useful if one could give an argument as scalar or array.
00315     // <group>
00316     MArray<Bool> getBoolAS         (const TableExprId& id);
00317     MArray<Int64> getIntAS         (const TableExprId& id);
00318     MArray<Double> getDoubleAS     (const TableExprId& id);
00319     MArray<DComplex> getDComplexAS (const TableExprId& id);
00320     MArray<String> getStringAS     (const TableExprId& id);
00321     MArray<MVTime> getDateAS       (const TableExprId& id);
00322     // </group>
00323 
00324     // Does a value occur in an array or set?
00325     // The default implementation tests if it is in an array.
00326     // <group>
00327     virtual Bool hasBool     (const TableExprId& id, Bool value);
00328     virtual Bool hasInt      (const TableExprId& id, Int64 value);
00329     virtual Bool hasDouble   (const TableExprId& id, Double value);
00330     virtual Bool hasDComplex (const TableExprId& id, const DComplex& value);
00331     virtual Bool hasString   (const TableExprId& id, const String& value);
00332     virtual Bool hasDate     (const TableExprId& id, const MVTime& value);
00333     virtual MArray<Bool> hasArrayBool     (const TableExprId& id,
00334                                            const MArray<Bool>& value);
00335     virtual MArray<Bool> hasArrayInt      (const TableExprId& id,
00336                                            const MArray<Int64>& value);
00337     virtual MArray<Bool> hasArrayDouble   (const TableExprId& id,
00338                                            const MArray<Double>& value);
00339     virtual MArray<Bool> hasArrayDComplex (const TableExprId& id,
00340                                            const MArray<DComplex>& value);
00341     virtual MArray<Bool> hasArrayString   (const TableExprId& id,
00342                                            const MArray<String>& value);
00343     virtual MArray<Bool> hasArrayDate     (const TableExprId& id,
00344                                            const MArray<MVTime>& value);
00345     // </group>
00346 
00347     // Get the number of rows in the table associated with this expression.
00348     // One is returned if the expression is a constant.
00349     // Zero is returned if no table is associated with it.
00350     uInt nrow() const;
00351 
00352     // Get the data type of the column.
00353     // It returns True when it could set the data type (which it can
00354     // if the expression is a scalar column or a constant array column pixel).
00355     // Otherwise it returns False.
00356     virtual Bool getColumnDataType (DataType&) const;
00357 
00358     // Get the value of the expression evaluated for the entire column.
00359     // The data of function called should match the data type as
00360     // returned by function <src>getColumnDataType</src>.
00361     // <group>
00362     virtual Array<Bool>     getColumnBool (const Vector<uInt>& rownrs);
00363     virtual Array<uChar>    getColumnuChar (const Vector<uInt>& rownrs);
00364     virtual Array<Short>    getColumnShort (const Vector<uInt>& rownrs);
00365     virtual Array<uShort>   getColumnuShort (const Vector<uInt>& rownrs);
00366     virtual Array<Int>      getColumnInt (const Vector<uInt>& rownrs);
00367     virtual Array<uInt>     getColumnuInt (const Vector<uInt>& rownrs);
00368     virtual Array<Float>    getColumnFloat (const Vector<uInt>& rownrs);
00369     virtual Array<Double>   getColumnDouble (const Vector<uInt>& rownrs);
00370     virtual Array<Complex>  getColumnComplex (const Vector<uInt>& rownrs);
00371     virtual Array<DComplex> getColumnDComplex (const Vector<uInt>& rownrs);
00372     virtual Array<String>   getColumnString (const Vector<uInt>& rownrs);
00373     // </group>
00374 
00375     // Convert the tree to a number of range vectors which at least
00376     // select the same things.
00377     // This function is very useful to convert the expression to
00378     // some intervals covering the select expression. This can
00379     // be used to do a rough fast selection via an index and do the
00380     // the slower final selection on that much smaller subset.
00381     // The function can only convert direct comparisons of columns
00382     // with constants (via ==, !=, >, >=, < or <=) and their combinations
00383     // using && or ||.
00384     virtual void ranges (Block<TableExprRange>&);
00385 
00386     // Get the data type of the derived TableExprNode object.
00387     // This is the data type of the resulting value. E.g. a compare
00388     // of 2 numeric values results in a Bool, thus the data type
00389     // of, say, TableExprNodeEQ<T> is always Bool.
00390     // Function getInternalDT gives the internal data type, thus in
00391     // the example above the data type of T.
00392     NodeDataType dataType() const;
00393 
00394     // Is the data type real (i.e., integer or double)?
00395     Bool isReal() const;
00396 
00397     // Get the value type.
00398     ValueType valueType() const;
00399 
00400     // Set the value type.
00401     void setValueType (ValueType vtype);
00402 
00403     // Get the operator type.
00404     OperType operType() const;
00405 
00406     // Get the expression type.
00407     ExprType exprType() const;
00408 
00409     // Is the expression a constant?
00410     Bool isConstant() const;
00411 
00412     // Get the unit.
00413     const Unit& unit() const;
00414 
00415     // Set the unit.
00416     // It also sets the datatype to NTDouble if it is NTInt.
00417     void setUnit (const Unit& unit);
00418 
00419     // Get the fixed dimensionality (same for all rows).
00420     Int ndim() const;
00421 
00422     // Get the fixed shape (same for all rows).
00423     const IPosition& shape() const;
00424 
00425     // Get the shape for the given row.
00426     // It returns the fixed shape if defined, otherwise getShape(id).
00427     const IPosition& shape (const TableExprId& id);
00428 
00429     // Is the value in the given row defined?
00430     // The default implementation returns True.
00431     virtual Bool isDefined (const TableExprId& id);
00432 
00433     // Show the expression tree.
00434     virtual void show (ostream&, uInt indent) const;
00435 
00436     // Get table. This gets the Table object to which a
00437     // TableExprNode belongs. A TableExprNode belongs to the Table to
00438     // which the first column used in an expression belongs.
00439     // <group>
00440     Table& table();
00441     const Table& table() const;
00442     // </group>
00443 
00444     // Let a set node convert itself to the given unit.
00445     // The default implementation does nothing.
00446     virtual void adaptSetUnits (const Unit&);
00447 
00448     // Create a range object from a column and an interval.
00449     static void createRange (Block<TableExprRange>&,
00450                              TableExprNodeColumn*, Double start, Double end);
00451 
00452     // Create a empty range object.
00453     static void createRange (Block<TableExprRange>&);
00454 
00455     // Convert a NodeDataType to a string.
00456     static String typeString (NodeDataType);
00457 
00458     // Convert a ValueType to a string.
00459     static String typeString (ValueType);
00460 
00461 protected:
00462     uInt              count_p;       //# Reference count
00463     Table             table_p;       //# Table from which node is "derived"
00464     NodeDataType      dtype_p;       //# data type of the operation
00465     ValueType         vtype_p;       //# value type of the result
00466     OperType          optype_p;      //# operator type
00467     ArgType           argtype_p;     //# argument types
00468     ExprType          exprtype_p;    //# Constant or Variable
00469     Int               ndim_p;        //# Fixed dimensionality of node values
00470                                      //# -1 = variable dimensionality
00471     IPosition         shape_p;       //# Fixed shape of node values
00472     Unit              unit_p;        //# Unit of the values
00473 
00474     // Get the shape for the given row.
00475     virtual const IPosition& getShape (const TableExprId& id);
00476 
00477     // Get pointer to REPresentation object.
00478     // This is used by derived classes.
00479     static TableExprNodeRep* getRep (TableExprNode&);
00480 
00481     // When one of the children is a constant, convert its data type
00482     // to that of the other operand. This avoids that conversions are
00483     // done for each get.
00484     // The default implementation does nothing.
00485     virtual void convertConstChild();
00486 
00487     // Check if this node uses the same table pointer.
00488     // Fill the Table object if it is still null.
00489     // <group>
00490     void checkTablePtr (const TableExprNodeRep* node);
00491     static void checkTablePtr (Table& table,
00492                                const TableExprNodeRep* node);
00493     // </group>
00494 
00495     // Set expression type to Variable if node is Variable.
00496     // <group>
00497     void fillExprType (const TableExprNodeRep* node);
00498     static void fillExprType (ExprType&, const TableExprNodeRep* node);
00499     // </group>
00500 
00501     // When the node is constant, it is evaluated and replaced by
00502     // the appropriate TableExprNodeConst object.
00503     // If not constant, it calls the virtual ConvertConstChild function
00504     // which can convert a constant child when appropriate.
00505     static TableExprNodeRep* convertNode (TableExprNodeRep* thisNode,
00506                                           Bool convertConstType);
00507 
00508 private:
00509     // A copy of a TableExprNodeRep cannot be made.
00510     TableExprNodeRep& operator= (const TableExprNodeRep&);
00511 };
00512 
00513 
00514 
00515 
00516 // <summary>
00517 // Abstract base class for a node having 0, 1, or 2 child nodes.
00518 // </summary>
00519 
00520 // <use visibility=local>
00521 
00522 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00523 // </reviewed>
00524 
00525 // <prerequisite>
00526 //# Classes you should understand before using this one.
00527 //   <li> <linkto class=TableExprNodeRep>TableExprNodeRep</linkto>
00528 // </prerequisite>
00529 
00530 // <etymology>
00531 // TableExprNodeBinary is a node in the table expression tree
00532 // representing a binary node (i.e. having 2 operands).
00533 // </etymology>
00534 
00535 // <synopsis> 
00536 // TableExprNodeBinary is the abstract base class for all nodes in a table
00537 // expression tree using up to 2 operands.
00538 // It is used as the base class for the node classes representing
00539 // operator +, -, etc..
00540 // </synopsis> 
00541 
00542 // <motivation>
00543 // This class contains the common functionality for the classes
00544 // representing a binary (or unary) operator.
00545 // </motivation>
00546 
00547 //# <todo asof="$DATE:$">
00548 //# A List of bugs, limitations, extensions or planned refinements.
00549 //#   <li> to be filled in
00550 //# </todo>
00551 
00552 
00553 class TableExprNodeBinary : public TableExprNodeRep
00554 {
00555 public:
00556     // Constructor
00557     TableExprNodeBinary (NodeDataType, ValueType, OperType, const Table&);
00558     TableExprNodeBinary (NodeDataType, const TableExprNodeRep&, OperType);
00559 
00560     // Destructor
00561     virtual ~TableExprNodeBinary();
00562     
00563     // Show the expression tree.
00564     virtual void show (ostream&, uInt indent) const;
00565 
00566     // Get the nodes representing an aggregate function.
00567     virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr);
00568   
00569     // Get the nodes representing a table column.
00570     virtual void getColumnNodes (vector<TableExprNodeRep*>& cols);
00571   
00572     // Check the data types and get the common one.
00573     static NodeDataType getDT (NodeDataType leftDtype,
00574                                NodeDataType rightDype,
00575                                OperType operType);
00576 
00577     // Check the data and value types and get the common one.
00578     static TableExprNodeRep getTypes (const TableExprNodeRep& left,
00579                                       const TableExprNodeRep& right,
00580                                       OperType operType);
00581 
00582     // Link the children to the node and convert the children
00583     // to constants if needed and possible. Also convert the node to
00584     // constant if possible.
00585     // The operand data types can be adapted as needed.
00586     static TableExprNodeRep* fillNode (TableExprNodeBinary* thisNode,
00587                                        TableExprNodeRep* left,
00588                                        TableExprNodeRep* right,
00589                                        Bool convertConstType,
00590                                        Bool adaptDataType=True);
00591 
00592     // Handle the units of the children and possibly set the parent's unit.
00593     // The default implementation make the units of the children equal and
00594     // set the parent unit to that unit if the parent is not a Bool value.
00595     virtual void handleUnits();
00596 
00597     // When one of the children is a constant, convert its data type
00598     // to that of the other operand. This avoids that conversions are
00599     // done for each get.
00600     void convertConstChild();
00601 
00602     // Get the child nodes.
00603     // <group>
00604     const TableExprNodeRep* getLeftChild() const
00605         { return lnode_p; }
00606     const TableExprNodeRep* getRightChild() const
00607         { return rnode_p; }
00608     // </group>
00609 
00610 protected:
00611     // Make the units equal.
00612     // Replace the right node if needed.
00613     static const Unit& makeEqualUnits (TableExprNodeRep* left,
00614                                        TableExprNodeRep*& right);
00615 
00616     TableExprNodeRep* lnode_p;     //# left operand
00617     TableExprNodeRep* rnode_p;     //# right operand
00618 };
00619 
00620 
00621 
00622 
00623 // <summary>
00624 // Abstract base class for a node having multiple child nodes.
00625 // </summary>
00626 
00627 // <use visibility=local>
00628 
00629 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00630 // </reviewed>
00631 
00632 // <prerequisite>
00633 //# Classes you should understand before using this one.
00634 //   <li> <linkto class=TableExprNodeRep>TableExprNodeRep</linkto>
00635 // </prerequisite>
00636 
00637 // <etymology>
00638 // TableExprNodeMulti is a node in the table expression tree
00639 // which can have MULTIple child nodes.
00640 // </etymology>
00641 
00642 // <synopsis> 
00643 // TableExprNodeMulti is the abstract base class for all nodes in a table
00644 // expression tree using multiple operands.
00645 // It is used as the base class for the node classes representing
00646 // functions, sets, indices, etc..
00647 // </synopsis> 
00648 
00649 // <motivation>
00650 // This class contains the common functionality for the classes
00651 // representing a node with multiple operands.
00652 // </motivation>
00653 
00654 //# <todo asof="$DATE:$">
00655 //# A List of bugs, limitations, extensions or planned refinements.
00656 //#   <li> to be filled in
00657 //# </todo>
00658 
00659 
00660 class TableExprNodeMulti : public TableExprNodeRep
00661 {
00662 public:
00663     // Constructor
00664     TableExprNodeMulti (NodeDataType, ValueType, OperType,
00665                         const TableExprNodeRep& source);
00666 
00667     // Destructor
00668     virtual ~TableExprNodeMulti();
00669 
00670     // Show the expression tree.
00671     virtual void show (ostream&, uInt indent) const;
00672 
00673     // Get the nodes representing an aggregate function.
00674     virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr);
00675 
00676     // Get the nodes representing a table column.
00677     virtual void getColumnNodes (vector<TableExprNodeRep*>& cols);
00678   
00679     // Check number of arguments
00680     // low <= number_of_args <= high
00681     // It throws an exception if wrong number of arguments.
00682     static uInt checkNumOfArg (uInt low, uInt high,
00683                                const PtrBlock<TableExprNodeRep*>& nodes);
00684     
00685     // Get the child nodes.
00686     const PtrBlock<TableExprNodeRep*>& getChildren() const
00687       { return operands_p; }
00688 
00689     // Check datatype of nodes and return output type.
00690     // It also sets the expected data type of the operands (from dtIn).
00691     static NodeDataType checkDT (Block<Int>& dtypeOper,
00692                                  NodeDataType dtIn, NodeDataType dtOut,
00693                                  const PtrBlock<TableExprNodeRep*>& nodes);
00694 
00695 protected:
00696     PtrBlock<TableExprNodeRep*> operands_p;
00697 };
00698 
00699 
00700 
00701 //# Get the data type of the node.
00702 inline TableExprNodeRep::NodeDataType TableExprNodeRep::dataType() const
00703     { return dtype_p; }
00704 
00705 inline Bool TableExprNodeRep::isReal() const
00706     { return dtype_p==NTInt || dtype_p==NTDouble; }
00707 
00708 //# Get the value type of the node.
00709 inline TableExprNodeRep::ValueType TableExprNodeRep::valueType() const
00710     { return vtype_p; }
00711 
00712 //# Set the value type of the node.
00713 inline void TableExprNodeRep::setValueType (TableExprNodeRep::ValueType vtype)
00714     { vtype_p = vtype; }
00715 
00716 //# Get the operator type of the node.
00717 inline TableExprNodeRep::OperType TableExprNodeRep::operType() const
00718     { return optype_p; }
00719 
00720 //# Get the expression type of the node.
00721 inline TableExprNodeRep::ExprType TableExprNodeRep::exprType() const
00722     { return exprtype_p; }
00723 
00724 //# Is the expression a constant?
00725 inline Bool TableExprNodeRep::isConstant() const
00726     { return  (exprtype_p == Constant); }
00727 
00728 //# Get the unit of the node.
00729 inline const Unit& TableExprNodeRep::unit() const
00730     { return unit_p; }
00731 
00732 //# Get the fixed dimensionality of the node.
00733 inline Int TableExprNodeRep::ndim() const
00734     { return ndim_p; }
00735 
00736 //# Get the fixed shape of the node.
00737 inline const IPosition& TableExprNodeRep::shape() const
00738     { return shape_p; }
00739 
00740 //# Get the table from which the node is derived.
00741 inline Table& TableExprNodeRep::table()
00742     { return table_p; }
00743 inline const Table& TableExprNodeRep::table() const
00744     { return table_p; }
00745 
00746 inline void TableExprNodeRep::checkTablePtr (const TableExprNodeRep* node)
00747     { checkTablePtr (table_p, node); }
00748 inline void TableExprNodeRep::fillExprType (const TableExprNodeRep* node)
00749     { fillExprType (exprtype_p, node); }
00750 
00751 //# Link to the node.
00752 inline TableExprNodeRep* TableExprNodeRep::link()
00753 {
00754     count_p++;
00755     return this;
00756 }
00757 
00758 
00759 } //# NAMESPACE CASACORE - END
00760 
00761 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1