casacore
Loading...
Searching...
No Matches
LELBinary.h
Go to the documentation of this file.
1//# LELBinary.h: LELBinary.h
2//# Copyright (C) 1997,1998,1999,2000
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef LATTICES_LELBINARY_H
27#define LATTICES_LELBINARY_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/lattices/LEL/LELInterface.h>
33#include <casacore/lattices/LEL/LELBinaryEnums.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37//# Forward Declarations
38
39
40// <summary> This LEL class handles numerical binary operators </summary>
41//
42// <use visibility=local>
43//
44// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
45// </reviewed>
46//
47// <prerequisite>
48// <li> <linkto class="Lattice"> Lattice</linkto>
49// <li> <linkto class="LatticeExpr"> LatticeExpr</linkto>
50// <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto>
51// <li> <linkto class="LELInterface"> LELInterface</linkto>
52// <li> <linkto class="LELBinaryEnums"> LELBinaryEnums</linkto>
53// </prerequisite>
54//
55// <etymology>
56// This derived LEL letter class handles numerical binary
57// operators
58// </etymology>
59//
60// <synopsis>
61// This LEL letter class is derived from LELInterface. It
62// is used to construct LEL objects that apply numerical binary
63// operators to Lattice expressions. They operate on numerical
64// Lattice (Float,Double,Complex,DComplex) expressions and return the
65// same numerical type. The available C++ operators
66// are <src>+,-,*,/</src> with equivalents in the enum
67// of ADD, SUBTRACT, MULTIPLY, and DIVIDE.
68//
69// A description of the implementation details of the LEL classes can
70// be found in
71// <a href="../notes/216.html">Note 216</a>
72//
73// </synopsis>
74//
75// <example>
76// Examples are not very useful as the user would never use
77// these classes directly. Look in LatticeExprNode.cc to see
78// how it invokes these classes. Examples of how the user
79// would indirectly use this class (through the envelope) are:
80// <srcblock>
81// IPosition shape(2,5,10);
82// ArrayLattice<Float> x(shape); x.set(1.0);
83// ArrayLattice<Float> y(shape); y.set(2.0);
84// ArrayLattice<Float> z(shape);
85// z.copyData(x+y); // z = x + y;
86// z.copyData(x-y); // z = x - y;
87// z.copyData(x*y); // z = x * y;
88// z.copyData(x/y); // z = x / y;
89// </srcblock>
90// </example>
91//
92// <motivation>
93// Numerical binary operations are a basic mathematical expression.
94// </motivation>
95//
96// <todo asof="1998/01/20">
97// </todo>
98
99
100template <class T> class LELBinary : public LELInterface<T>
101{
102 //# Make members of parent class known.
103protected:
104 using LELInterface<T>::setAttr;
105
106public:
107// Constructor takes operation and left and right expressions
108// to be operated upon
110 const std::shared_ptr<LELInterface<T>>& pLeftExpr,
111 const std::shared_ptr<LELInterface<T>>& pRightExpr);
112
113// Destructor
115
116// Recursively evaluate the expression
117 virtual void eval (LELArray<T>& result,
118 const Slicer& section) const;
119
120// Recursively efvaluate the scalar expression
121 virtual LELScalar<T> getScalar() const;
122
123// Do further preparations (e.g. optimization) on the expression.
125
126// Get class name
127 virtual String className() const;
128
129 // Handle locking/syncing of a lattice in a lattice expression.
130 // <group>
131 virtual Bool lock (FileLocker::LockType, uInt nattempts);
132 virtual void unlock();
134 virtual void resync();
135 // </group>
136
137private:
139 std::shared_ptr<LELInterface<T>> pLeftExpr_p;
140 std::shared_ptr<LELInterface<T>> pRightExpr_p;
141};
142
143
144
145
146// <summary> This LEL class handles relational binary numerical operators </summary>
147//
148// <use visibility=local>
149//
150// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
151// </reviewed>
152//
153// <prerequisite>
154// <li> <linkto class="Lattice"> Lattice</linkto>
155// <li> <linkto class="LatticeExpr"> LatticeExpr</linkto>
156// <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto>
157// <li> <linkto class="LELInterface"> LELInterface</linkto>
158// <li> <linkto class="LELBinaryEnums"> LELBinaryEnums</linkto>
159// </prerequisite>
160//
161// <etymology>
162// This derived LEL letter class handles relational numerical binary
163// operators
164// </etymology>
165//
166// <synopsis>
167// This LEL letter class is derived from LELInterface. It
168// is used to construct LEL objects that apply relational numerical
169// binary operators to Lattice expressions. They operate on numerical
170// (Float,Double,Complex,DComplex) Lattice expressions and result
171// in a Bool. The available C++ operators are
172// <src>==,!=>,>=,<,<=,</src> with equivalents in the enum of
173// EQ, NE, GT, GE, LT, and LE
174//
175// A description of the implementation details of the LEL classes can
176// be found in
177// <a href="../notes/216.html">Note 216</a>
178//
179// </synopsis>
180//
181// <example>
182// Examples are not very useful as the user would never use
183// these classes directly. Look in LatticeExprNode.cc to see
184// how it invokes these classes. Examples of how the user
185// would indirectly use this class (through the envelope) are:
186// <srcblock>
187// IPosition shape(2,5,10);
188// ArrayLattice<Float> x(shape); x.set(1.0);
189// ArrayLattice<Float> y(shape); y.set(2.0);
190// ArrayLattice<Bool> z(shape);
191// z.copyData(x==y); // z = x == y;
192// z.copyData(x!=y); // z = x != y;
193// z.copyData(x>y); // z = x > y;
194// z.copyData(x>=y); // z = x >= y;
195// z.copyData(x<y); // z = x < y;
196// z.copyData(x<=y); // z = x <= y;
197// </srcblock>
198// </example>
199//
200// <motivation>
201// Numerical relational binary operations are a basic mathematical expression.
202// </motivation>
203//
204// <todo asof="1998/01/20">
205// </todo>
206
207
208template<class T> class LELBinaryCmp : public LELInterface<Bool>
209{
210public:
211
212// Constructor takes operation and left and right expressions
213// to be operated upon. It can only handle the comparison operators.
215 const std::shared_ptr<LELInterface<T>>& pLeftExpr,
216 const std::shared_ptr<LELInterface<T>>& pRightExpr);
217
218// Destructor
220
221// Recursively evaluate the expression
222 virtual void eval (LELArray<Bool>& result,
223 const Slicer& section) const;
224
225// Recursively evaluate the scalar expression
226 virtual LELScalar<Bool> getScalar() const;
227
228// Do further preparations (e.g. optimization) on the expression.
230
231// Get class name
232 virtual String className() const;
233
234 // Handle locking/syncing of a lattice in a lattice expression.
235 // <group>
236 virtual Bool lock (FileLocker::LockType, uInt nattempts);
237 virtual void unlock();
239 virtual void resync();
240 // </group>
241
242private:
244 std::shared_ptr<LELInterface<T>> pLeftExpr_p;
245 std::shared_ptr<LELInterface<T>> pRightExpr_p;
246};
247
248
249
250
251// <summary> This LEL class handles logical binary operators </summary>
252//
253// <use visibility=local>
254//
255// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
256// </reviewed>
257//
258// <prerequisite>
259// <li> <linkto class="Lattice"> Lattice</linkto>
260// <li> <linkto class="LatticeExpr"> LatticeExpr</linkto>
261// <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto>
262// <li> <linkto class="LELInterface"> LELInterface</linkto>
263// <li> <linkto class="LELBinaryEnums"> LELBinaryEnums</linkto>
264// </prerequisite>
265
266// <etymology>
267// This derived LEL letter class handles logical binary operators
268// </etymology>
269//
270// <synopsis>
271// This LEL letter class is derived from LELInterface. It
272// is used to construct LEL objects that apply logical
273// binary operators to Lattice expressions. They apply only
274// to Bool Lattice expressions and result in a Bool. The
275// available C++ operators are <src>&&,||,==,!=</src> with
276// equivalents in the enum of AND, OR, EQ, and NE
277//
278// A description of the implementation details of the LEL classes can
279// be found in
280// <a href="../notes/216.html">Note 216</a>
281//
282// </synopsis>
283//
284// <example>
285// Examples are not very useful as the user would never use
286// these classes directly. Look in LatticeExprNode.cc to see
287// how it invokes these classes. Examples of how the user
288// would indirectly use this class (through the envelope) are:
289// <srcblock>
290// IPosition shape(2,5,10);
291// ArrayLattice<Bool> x(shape); x.set(False);
292// ArrayLattice<Bool> y(shape); y.set(True);
293// ArrayLattice<Bool> z(shape); z.set(False);
294// z.copyData(x&&y); // z = x && y;
295// z.copyData(x||y); // z = x || y;
296// z.copyData(x==y); // z = x == y;
297// z.copyData(x!=y); // z = x != y;
298// </srcblock>
299// </example>
300//
301// <motivation>
302// Logical binary operations are a basic mathematical expression.
303// </motivation>
304//
305// <todo asof="1998/01/20">
306// </todo>
307
308
309class LELBinaryBool : public LELInterface<Bool>
310{
311public:
312
313// Constructor takes operation and left and right expressions
314// to be operated upon.
316 const std::shared_ptr<LELInterface<Bool>>& pLeftExpr,
317 const std::shared_ptr<LELInterface<Bool>>& pRightExpr);
318
319// Destructor
321
322// Recursively evaluate the expression
323 virtual void eval (LELArray<Bool>& result,
324 const Slicer& section) const;
325
326// Recursively evaluate the scalar expression
327 virtual LELScalar<Bool> getScalar() const;
328
329// Do further preparations (e.g. optimization) on the expression.
331
332// Get class name
333 virtual String className() const;
334
335 // Handle locking/syncing of a lattice in a lattice expression.
336 // <group>
337 virtual Bool lock (FileLocker::LockType, uInt nattempts);
338 virtual void unlock();
340 virtual void resync();
341 // </group>
342
343private:
345 std::shared_ptr<LELInterface<Bool>> pLeftExpr_p;
346 std::shared_ptr<LELInterface<Bool>> pRightExpr_p;
347};
348
349
350
351
352} //# NAMESPACE CASACORE - END
353
354#ifndef CASACORE_NO_AUTO_TEMPLATES
355#include <casacore/lattices/LEL/LELBinary.tcc>
356#endif //# CASACORE_NO_AUTO_TEMPLATES
357#endif
LockType
Define the possible lock types.
Definition FileLocker.h:93
This LEL class handles logical binary operators.
Definition LELBinary.h:310
~LELBinaryBool()
Destructor
virtual Bool hasLock(FileLocker::LockType) const
virtual String className() const
Get class name.
std::shared_ptr< LELInterface< Bool > > pLeftExpr_p
Definition LELBinary.h:345
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle locking/syncing of a lattice in a lattice expression.
virtual LELScalar< Bool > getScalar() const
Recursively evaluate the scalar expression
std::shared_ptr< LELInterface< Bool > > pRightExpr_p
Definition LELBinary.h:346
LELBinaryBool(const LELBinaryEnums::Operation op, const std::shared_ptr< LELInterface< Bool > > &pLeftExpr, const std::shared_ptr< LELInterface< Bool > > &pRightExpr)
Constructor takes operation and left and right expressions to be operated upon.
virtual void resync()
virtual void eval(LELArray< Bool > &result, const Slicer &section) const
Recursively evaluate the expression
LELBinaryEnums::Operation op_p
Definition LELBinary.h:344
virtual Bool prepareScalarExpr()
Do further preparations (e.g.
virtual void unlock()
This LEL class handles relational binary numerical operators.
Definition LELBinary.h:209
~LELBinaryCmp()
Destructor
std::shared_ptr< LELInterface< T > > pRightExpr_p
Definition LELBinary.h:245
virtual void unlock()
virtual Bool prepareScalarExpr()
Do further preparations (e.g.
LELBinaryCmp(const LELBinaryEnums::Operation op, const std::shared_ptr< LELInterface< T > > &pLeftExpr, const std::shared_ptr< LELInterface< T > > &pRightExpr)
Constructor takes operation and left and right expressions to be operated upon.
std::shared_ptr< LELInterface< T > > pLeftExpr_p
Definition LELBinary.h:244
virtual void resync()
virtual void eval(LELArray< Bool > &result, const Slicer &section) const
Recursively evaluate the expression
virtual String className() const
Get class name.
virtual LELScalar< Bool > getScalar() const
Recursively evaluate the scalar expression
LELBinaryEnums::Operation op_p
Definition LELBinary.h:243
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle locking/syncing of a lattice in a lattice expression.
virtual Bool hasLock(FileLocker::LockType) const
virtual void eval(LELArray< T > &result, const Slicer &section) const
Recursively evaluate the expression
virtual Bool prepareScalarExpr()
Do further preparations (e.g.
virtual Bool hasLock(FileLocker::LockType) const
virtual String className() const
Get class name.
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle locking/syncing of a lattice in a lattice expression.
~LELBinary()
Destructor
LELBinaryEnums::Operation op_p
Definition LELBinary.h:138
virtual LELScalar< T > getScalar() const
Recursively efvaluate the scalar expression
virtual void resync()
LELBinary(const LELBinaryEnums::Operation op, const std::shared_ptr< LELInterface< T > > &pLeftExpr, const std::shared_ptr< LELInterface< T > > &pRightExpr)
Constructor takes operation and left and right expressions to be operated upon.
std::shared_ptr< LELInterface< T > > pRightExpr_p
Definition LELBinary.h:140
virtual void unlock()
std::shared_ptr< LELInterface< T > > pLeftExpr_p
Definition LELBinary.h:139
void setAttr(const LELAttribute &attrib)
Set the expression attributes of this object.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40