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