00001 //# LELUnary.h: LELUnary.h 00002 //# Copyright (C) 1997,1998,1999,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 //# $Id$ 00027 00028 #ifndef LATTICES_LELUNARY_H 00029 #define LATTICES_LELUNARY_H 00030 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/lattices/LEL/LELInterface.h> 00035 #include <casacore/lattices/LEL/LELScalar.h> 00036 #include <casacore/lattices/LEL/LELUnaryEnums.h> 00037 00038 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00039 00040 //# Forward Declarations 00041 00042 00043 // <summary> This LEL class handles scalar (unary) constants </summary> 00044 // 00045 // <use visibility=local> 00046 // 00047 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00048 // </reviewed> 00049 // 00050 // <prerequisite> 00051 // <li> <linkto class="Lattice"> Lattice</linkto> 00052 // <li> <linkto class="LatticeExpr"> LatticeExpr</linkto> 00053 // <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto> 00054 // <li> <linkto class="LELInterface"> LELInterface</linkto> 00055 // <li> <linkto class="LELUnaryEnums"> LELUnaryEnums</linkto> 00056 // </prerequisite> 00057 // 00058 // <etymology> 00059 // This derived LEL letter class handles scalar (unary) constants 00060 // </etymology> 00061 // 00062 // <synopsis> 00063 // This LEL letter class is derived from LELInterface. It 00064 // is used to construct LEL objects that represent scalars 00065 // constants. They can be of type Float,Double,Complex,DComplex 00066 // and Bool. 00067 // 00068 // A description of the implementation details of the LEL classes can 00069 // be found in 00070 // <a href="../notes/216.html">Note 216</a> 00071 // </synopsis> 00072 // 00073 // <example> 00074 // Examples are not very useful as the user would never use 00075 // these classes directly. Look in LatticeExprNode.cc to see 00076 // how it invokes these classes. Examples of how the user 00077 // would indirectly use this class (through the envelope) are: 00078 // <srcblock> 00079 // IPosition shape(2,5,10); 00080 // ArrayLattice<Float> x(shape); x.set(1.0); 00081 // ArrayLattice<Float> y(shape); 00082 // ArrayLattice<Float> z(shape); 00083 // y.copyData(x+2.0); // y = x + 2.0 00084 // z.copyData(True); // z = True 00085 // </srcblock> 00086 // </example> 00087 // 00088 // <motivation> 00089 // Constants are a basic mathematical expression. 00090 // </motivation> 00091 // 00092 // <todo asof="1998/01/20"> 00093 // </todo> 00094 00095 00096 template <class T> class LELUnaryConst : public LELInterface<T> 00097 { 00098 //# Make members of parent class known. 00099 protected: 00100 using LELInterface<T>::setAttr; 00101 00102 public: 00103 // Default constructor creates a scalar with a false mask. 00104 LELUnaryConst(); 00105 00106 // Constructor takes a scalar. 00107 LELUnaryConst(const T val); 00108 00109 // Destructor does nothing 00110 ~LELUnaryConst(); 00111 00112 // Evaluate the expression. 00113 // This throws an exception, since only a scalar can be returned. 00114 virtual void eval (LELArray<T>& result, 00115 const Slicer& section) const; 00116 00117 // Evaluate the scalar expression (get the constant) 00118 virtual LELScalar<T> getScalar() const; 00119 00120 // Do further preparations (e.g. optimization) on the expression. 00121 virtual Bool prepareScalarExpr(); 00122 00123 // Get class name 00124 virtual String className() const; 00125 00126 private: 00127 LELScalar<T> val_p; 00128 }; 00129 00130 00131 00132 // <summary> This LEL class handles numerical unary operators </summary> 00133 // 00134 // <use visibility=local> 00135 // 00136 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00137 // </reviewed> 00138 // 00139 // <prerequisite> 00140 // <li> <linkto class="Lattice"> Lattice</linkto> 00141 // <li> <linkto class="LatticeExpr"> LatticeExpr</linkto> 00142 // <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto> 00143 // <li> <linkto class="LELInterface"> LELInterface</linkto> 00144 // <li> <linkto class="LELUnaryEnums"> LELUnaryEnums</linkto> 00145 // </prerequisite> 00146 // 00147 // <etymology> 00148 // This derived LEL letter class handles numerical unary 00149 // operators 00150 // </etymology> 00151 // 00152 // <synopsis> 00153 // This LEL letter class is derived from LELInterface. It 00154 // is used to construct LEL objects that apply numerical unary 00155 // operators to Lattice expressions. They operate on numerical 00156 // Lattice (Float,Double,Complex,DComplex) expressions and return the 00157 // same numerical type. The available C++ operators 00158 // are <src>+,-</src> with equivalents in the enum 00159 // of PLUS and MINUS. 00160 // 00161 // A description of the implementation details of the LEL classes can 00162 // be found in 00163 // <a href="../notes/216.html">Note 216</a> 00164 // </synopsis> 00165 // 00166 // <example> 00167 // Examples are not very useful as the user would never use 00168 // these classes directly. Look in LatticeExprNode.cc to see 00169 // how it invokes these classes. An example of how the user 00170 // would indirectly use this class (through the envelope) is: 00171 // <srcblock> 00172 // IPosition shape(2,5,10); 00173 // ArrayLattice<Float> x(shape); x.set(1.0); 00174 // ArrayLattice<Float> y(shape); 00175 // y.copyData(-x); // y = -x 00176 // </srcblock> 00177 // </example> 00178 // 00179 // <motivation> 00180 // Numerical unary operations are a basic mathematical expression. 00181 // </motivation> 00182 // 00183 // <todo asof="1998/01/20"> 00184 // </todo> 00185 00186 template <class T> class LELUnary : public LELInterface<T> 00187 { 00188 public: 00189 00190 // Constructor takes operation and expression 00191 // to be operated upon 00192 LELUnary(const LELUnaryEnums::Operation op, 00193 const CountedPtr<LELInterface<T> >& pExpr); 00194 00195 // Destructor does nothing 00196 ~LELUnary(); 00197 00198 // Recursively evaluate the expression. 00199 virtual void eval (LELArray<T>& result, 00200 const Slicer& section) const; 00201 00202 // Recursively evaluate the scalar expression. 00203 virtual LELScalar<T> getScalar() const; 00204 00205 // Do further preparations (e.g. optimization) on the expression. 00206 virtual Bool prepareScalarExpr(); 00207 00208 // Get class name 00209 virtual String className() const; 00210 00211 // Handle locking/syncing of a lattice in a lattice expression. 00212 // <group> 00213 virtual Bool lock (FileLocker::LockType, uInt nattempts); 00214 virtual void unlock(); 00215 virtual Bool hasLock (FileLocker::LockType) const; 00216 virtual void resync(); 00217 // </group> 00218 00219 private: 00220 LELUnaryEnums::Operation op_p; 00221 CountedPtr<LELInterface<T> > pExpr_p; 00222 }; 00223 00224 00225 00226 00227 // <summary> This LEL class handles logical unary operators </summary> 00228 // 00229 // <use visibility=local> 00230 // 00231 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00232 // </reviewed> 00233 // 00234 // <prerequisite> 00235 // <li> <linkto class="Lattice"> Lattice</linkto> 00236 // <li> <linkto class="LatticeExpr"> LatticeExpr</linkto> 00237 // <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto> 00238 // <li> <linkto class="LELInterface"> LELInterface</linkto> 00239 // <li> <linkto class="LELUnaryEnums"> LELUnaryEnums</linkto> 00240 // </prerequisite> 00241 // 00242 // <etymology> 00243 // This derived LEL letter class handles logical unary 00244 // operators 00245 // </etymology> 00246 // 00247 // <synopsis> 00248 // This LEL letter class is derived from LELInterface. It 00249 // is used to construct LEL objects that apply logical unary 00250 // operators to Lattice expressions. They operate on Bool 00251 // Lattice expressions only and return a Bool. 00252 // The available C++ operator is <src>!</src> with the equivalent 00253 // in the enum of NOT. 00254 // 00255 // A description of the implementation details of the LEL classes can 00256 // be found in 00257 // <a href="../notes/216.html">Note 216</a> 00258 // </synopsis> 00259 // 00260 // <example> 00261 // Examples are not very useful as the user would never use 00262 // these classes directly. Look in LatticeExprNode.cc to see 00263 // how it invokes these classes. An example of how the user 00264 // would indirectly use this class (through the envelope) is: 00265 // <srcblock> 00266 // IPosition shape(2,5,10); 00267 // ArrayLattice<Bool> x(shape); x.set(True); 00268 // ArrayLattice<Bool> y(shape); 00269 // y.copyData(!x); // y = !x 00270 // </srcblock> 00271 // </example> 00272 // 00273 // <motivation> 00274 // Logical unary operations are a basic mathematical expression. 00275 // </motivation> 00276 // 00277 // <todo asof="1998/01/20"> 00278 // </todo> 00279 00280 00281 class LELUnaryBool : public LELInterface<Bool> 00282 { 00283 public: 00284 00285 // Constructor takes operation and expression 00286 // to be operated upon 00287 LELUnaryBool(const LELUnaryEnums::Operation op, 00288 const CountedPtr<LELInterface<Bool> >& pExpr); 00289 00290 // Destructor does nothing 00291 ~LELUnaryBool(); 00292 00293 // Recursively evaluate the expression. 00294 virtual void eval (LELArray<Bool>& result, 00295 const Slicer& section) const; 00296 00297 // Recursively evaluate the scalar expression. 00298 virtual LELScalar<Bool> getScalar() const; 00299 00300 // Do further preparations (e.g. optimization) on the expression. 00301 virtual Bool prepareScalarExpr(); 00302 00303 // Get class name 00304 virtual String className() const; 00305 00306 // Handle locking/syncing of a lattice in a lattice expression. 00307 // <group> 00308 virtual Bool lock (FileLocker::LockType, uInt nattempts); 00309 virtual void unlock(); 00310 virtual Bool hasLock (FileLocker::LockType) const; 00311 virtual void resync(); 00312 // </group> 00313 00314 private: 00315 LELUnaryEnums::Operation op_p; 00316 CountedPtr<LELInterface<Bool> > pExpr_p; 00317 }; 00318 00319 00320 00321 00322 } //# NAMESPACE CASACORE - END 00323 00324 //# See comments in LELInterface why LELInterface.tcc is included here. 00325 #ifndef CASACORE_NO_AUTO_TEMPLATES 00326 #include <casacore/lattices/LEL/LELInterface.tcc> 00327 #include <casacore/lattices/LEL/LELUnary.tcc> 00328 #endif //# CASACORE_NO_AUTO_TEMPLATES 00329 #endif