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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1