casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ExprFuncNodeArray.h
Go to the documentation of this file.
00001 //# ExprFuncNodeArray.h: Class representing an array function in table select expression
00002 //# Copyright (C) 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: ExprFuncNodeArray.h 21168 2012-01-04 08:11:03Z gervandiepen $
00027 
00028 #ifndef TABLES_EXPRFUNCNODEARRAY_H
00029 #define TABLES_EXPRFUNCNODEARRAY_H
00030 
00031 //# Includes
00032 #include <tables/Tables/ExprNodeArray.h>
00033 #include <tables/Tables/ExprFuncNode.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 //# Forward Declarations
00038 
00039 
00040 // <summary>
00041 // Class representing an array function in table select expression
00042 // </summary>
00043 
00044 // <use visibility=local>
00045 
00046 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00047 // </reviewed>
00048 // <prerequisite>
00049 //# Classes you should understand before using this one.
00050 //   <li> <linkto class=TableExprFuncNode>TableExprFuncNode</linkto>
00051 //   <li> <linkto class=TableExprNodeArray>TableExprNodeArray</linkto>
00052 // </prerequisite>
00053 
00054 // <synopsis> 
00055 // This class can be seen as a specialization of TableExprFuncNode
00056 // for functions returning arrays.
00057 // However, it is derived from TableExprNodeArray to make it possible
00058 // that the ExprNode classes use all array functionality offered by
00059 // that base class.
00060 // <br>Internally an TableExprFuncNode object is used.
00061 // <p>
00062 // When a TaQL function is used, TableExprFuncNode::checkOperands
00063 // determines whether the result is a scalar or an array.
00064 // Thereafter TableExprNode::newFunctionNode creates a TableExprFuncNode
00065 // for scalars or a TableExprFuncNodeArray for arrays.
00066 // </synopsis> 
00067 
00068 
00069 class TableExprFuncNodeArray : public TableExprNodeArray
00070 {
00071 public:
00072     // Constructor
00073     TableExprFuncNodeArray (TableExprFuncNode::FunctionType,
00074                             NodeDataType, ValueType,
00075                             const TableExprNodeSet& source,
00076                             const TaQLStyle&);
00077 
00078     // Destructor
00079     ~TableExprFuncNodeArray();
00080 
00081     // 'get' Functions to get the desired result of a function
00082     // <group>
00083     virtual Array<Bool> getArrayBool (const TableExprId& id);
00084     virtual Array<Int64> getArrayInt (const TableExprId& id);
00085     virtual Array<Double> getArrayDouble (const TableExprId& id);
00086     virtual Array<DComplex> getArrayDComplex (const TableExprId& id);
00087     virtual Array<String> getArrayString (const TableExprId& id);
00088     virtual Array<MVTime> getArrayDate (const TableExprId& id);
00089     // </group>
00090 
00091     // Get the function node.
00092     const TableExprFuncNode* getChild() const
00093       { return &node_p; }
00094 
00095     // Link the children to the node and convert the children
00096     // to constants if possible. Also convert the node to
00097     // constant if possible.
00098     static TableExprNodeRep* fillNode (TableExprFuncNodeArray* thisNode,
00099                                        PtrBlock<TableExprNodeRep*>& nodes,
00100                                        const Block<Int>& dtypeOper);
00101 
00102 private:
00103     // Try if the function gives a constant result.
00104     // If so, set the expression type to Constant.
00105     void tryToConst();
00106 
00107     // Some functions to be used by TableExprNodeFuncArray.
00108     // <group>
00109     const PtrBlock<TableExprNodeRep*>& operands() const
00110         { return node_p.operands(); }
00111     PtrBlock<TableExprNodeRep*>& rwOperands()
00112         { return node_p.rwOperands(); }
00113     TableExprFuncNode::FunctionType funcType() const
00114         { return node_p.funcType(); }
00115     NodeDataType argDataType() const
00116         { return node_p.argDataType(); }
00117     // </group>
00118 
00119     // Set unit scale factor (needed for sqrt).
00120     void setScale (Double scale)
00121         { node_p.setScale (scale); }
00122 
00123     // Get the collapse axes for the partial functions.
00124     // It compares the values with the #dim and removes them if too high.
00125     // axarg gives the argument nr of the axes.
00126     IPosition getAxes (const TableExprId& id,
00127                        Int ndim, uInt axarg=1, Bool swapRemove=True);
00128 
00129     // Remove axes exceeding ndim.
00130     IPosition removeAxes (const IPosition& axes, Int ndim) const;
00131 
00132     // Get the shape for the array function.
00133     // axarg gives the argument nr of the shape.
00134     const IPosition& getArrayShape (const TableExprId& id, uInt axarg=1);
00135 
00136     // Get the transpose order of the array axes.
00137     IPosition getOrder (const TableExprId& id, Int ndim);
00138 
00139     TableExprFuncNode node_p;
00140     Int               origin_p;        //# axes origin
00141     Bool              isCOrder_p;      //# axes order
00142     Bool              constAxes_p;     //# True = collapse axes are constant
00143     IPosition         ipos_p;          //# the (maybe constant) axes or shape
00144     IPosition         iposN_p;         //# the non-reversed axes or shape
00145 };
00146 
00147 
00148 
00149 
00150 } //# NAMESPACE CASA - END
00151 
00152 #endif