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 21277 2012-10-31 16:07:31Z gervandiepen $ 00027 00028 #ifndef TABLES_EXPRFUNCNODEARRAY_H 00029 #define TABLES_EXPRFUNCNODEARRAY_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/tables/TaQL/ExprNodeArray.h> 00034 #include <casacore/tables/TaQL/ExprFuncNode.h> 00035 00036 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00037 00038 //# Forward Declarations 00039 00040 00041 // <summary> 00042 // Class representing an array function in table select expression 00043 // </summary> 00044 00045 // <use visibility=local> 00046 00047 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00048 // </reviewed> 00049 // <prerequisite> 00050 //# Classes you should understand before using this one. 00051 // <li> <linkto class=TableExprFuncNode>TableExprFuncNode</linkto> 00052 // <li> <linkto class=TableExprNodeArray>TableExprNodeArray</linkto> 00053 // </prerequisite> 00054 00055 // <synopsis> 00056 // This class can be seen as a specialization of TableExprFuncNode 00057 // for functions returning arrays. 00058 // However, it is derived from TableExprNodeArray to make it possible 00059 // that the ExprNode classes use all array functionality offered by 00060 // that base class. 00061 // <br>Internally an TableExprFuncNode object is used. 00062 // <p> 00063 // When a TaQL function is used, TableExprFuncNode::checkOperands 00064 // determines whether the result is a scalar or an array. 00065 // Thereafter TableExprNode::newFunctionNode creates a TableExprFuncNode 00066 // for scalars or a TableExprFuncNodeArray for arrays. 00067 // </synopsis> 00068 00069 00070 class TableExprFuncNodeArray : public TableExprNodeArray 00071 { 00072 public: 00073 // Constructor 00074 TableExprFuncNodeArray (TableExprFuncNode::FunctionType, 00075 NodeDataType, ValueType, 00076 const TableExprNodeSet& source, 00077 const TaQLStyle&); 00078 00079 // Destructor 00080 ~TableExprFuncNodeArray(); 00081 00082 // Get the nodes representing an aggregate function. 00083 virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr); 00084 00085 // Get the nodes representing a table column. 00086 virtual void getColumnNodes (vector<TableExprNodeRep*>& cols); 00087 00088 // 'get' Functions to get the desired result of a function 00089 // <group> 00090 virtual MArray<Bool> getArrayBool (const TableExprId& id); 00091 virtual MArray<Int64> getArrayInt (const TableExprId& id); 00092 virtual MArray<Double> getArrayDouble (const TableExprId& id); 00093 virtual MArray<DComplex> getArrayDComplex (const TableExprId& id); 00094 virtual MArray<String> getArrayString (const TableExprId& id); 00095 virtual MArray<MVTime> getArrayDate (const TableExprId& id); 00096 // </group> 00097 00098 // Get the function node. 00099 TableExprFuncNode* getChild() 00100 { return &node_p; } 00101 const TableExprFuncNode* getChild() const 00102 { return &node_p; } 00103 00104 // Link the children to the node and convert the children 00105 // to constants if possible. Also convert the node to 00106 // constant if possible. 00107 static TableExprNodeRep* fillNode (TableExprFuncNodeArray* thisNode, 00108 PtrBlock<TableExprNodeRep*>& nodes, 00109 const Block<Int>& dtypeOper); 00110 00111 protected: 00112 // Try if the function gives a constant result. 00113 // If so, set the expression type to Constant. 00114 void tryToConst(); 00115 00116 // Some functions to be used by TableExprNodeFuncArray. 00117 // <group> 00118 const PtrBlock<TableExprNodeRep*>& operands() const 00119 { return node_p.operands(); } 00120 PtrBlock<TableExprNodeRep*>& rwOperands() 00121 { return node_p.rwOperands(); } 00122 TableExprFuncNode::FunctionType funcType() const 00123 { return node_p.funcType(); } 00124 NodeDataType argDataType() const 00125 { return node_p.argDataType(); } 00126 // </group> 00127 00128 private: 00129 // Set unit scale factor (needed for sqrt). 00130 void setScale (Double scale) 00131 { node_p.setScale (scale); } 00132 00133 // Get the collapse axes for the partial functions. 00134 // It compares the values with the #dim and removes them if too high. 00135 // axarg gives the argument nr of the axes. 00136 IPosition getAxes (const TableExprId& id, 00137 Int ndim, uInt axarg=1, Bool swapRemove=True); 00138 00139 // Remove axes exceeding ndim. 00140 IPosition removeAxes (const IPosition& axes, Int ndim) const; 00141 00142 // Get the shape for the array function. 00143 // axarg gives the argument nr of the shape. 00144 const IPosition& getArrayShape (const TableExprId& id, uInt axarg=1); 00145 00146 // Get the transpose order of the array axes. 00147 IPosition getOrder (const TableExprId& id, Int ndim); 00148 00149 // Get the arguments for the diagonals function. 00150 // They are checked and if needed adapted if the shape is not empty. 00151 const IPosition& getDiagonalArg (const TableExprId& id, 00152 const IPosition& shp); 00153 00154 // Set the alternate value expandAlt_p for array expand and return it. 00155 const IPosition& getAlternate (const TableExprId& id); 00156 00157 // Templated fucntion to resize/expand an array. 00158 template<typename T> 00159 MArray<T> TEFResize (const MArray<T>& arr, const TableExprId& id); 00160 00161 00162 //# Data members 00163 TableExprFuncNode node_p; 00164 Int origin_p; //# axes origin 00165 Bool isCOrder_p; //# axes order 00166 Bool constAxes_p; //# True = collapse axes are constant 00167 Bool constAlt_p; //# True = expandAlt_p is constant 00168 IPosition ipos_p; //# the (maybe constant) axes or shape 00169 IPosition iposN_p; //# the non-reversed axes or shape 00170 IPosition expandAlt_p; //# alternate for expand/resize 00171 }; 00172 00173 00174 00175 00176 } //# NAMESPACE CASACORE - END 00177 00178 #endif