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