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// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/lattices/LEL/LELInterface.h>
32#include <casacore/lattices/LEL/LELBinaryEnums.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// # Forward Declarations
37
38// <summary> This LEL class handles numerical binary operators </summary>
39//
40// <use visibility=local>
41//
42// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
43// </reviewed>
44//
45// <prerequisite>
46// <li> <linkto class="Lattice"> Lattice</linkto>
47// <li> <linkto class="LatticeExpr"> LatticeExpr</linkto>
48// <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto>
49// <li> <linkto class="LELInterface"> LELInterface</linkto>
50// <li> <linkto class="LELBinaryEnums"> LELBinaryEnums</linkto>
51// </prerequisite>
52//
53// <etymology>
54// This derived LEL letter class handles numerical binary
55// operators
56// </etymology>
57//
58// <synopsis>
59// This LEL letter class is derived from LELInterface. It
60// is used to construct LEL objects that apply numerical binary
61// operators to Lattice expressions. They operate on numerical
62// Lattice (Float,Double,Complex,DComplex) expressions and return the
63// same numerical type. The available C++ operators
64// are <src>+,-,*,/</src> with equivalents in the enum
65// of ADD, SUBTRACT, MULTIPLY, and DIVIDE.
66//
67// A description of the implementation details of the LEL classes can
68// be found in
69// <a href="../notes/216.html">Note 216</a>
70//
71// </synopsis>
72//
73// <example>
74// Examples are not very useful as the user would never use
75// these classes directly. Look in LatticeExprNode.cc to see
76// how it invokes these classes. Examples of how the user
77// would indirectly use this class (through the envelope) are:
78// <srcblock>
79// IPosition shape(2,5,10);
80// ArrayLattice<Float> x(shape); x.set(1.0);
81// ArrayLattice<Float> y(shape); y.set(2.0);
82// ArrayLattice<Float> z(shape);
83// z.copyData(x+y); // z = x + y;
84// z.copyData(x-y); // z = x - y;
85// z.copyData(x*y); // z = x * y;
86// z.copyData(x/y); // z = x / y;
87// </srcblock>
88// </example>
89//
90// <motivation>
91// Numerical binary operations are a basic mathematical expression.
92// </motivation>
93//
94// <todo asof="1998/01/20">
95// </todo>
96
97template <class T>
98class LELBinary : public LELInterface<T> {
99 // # Make members of parent class known.
100 protected:
101 using LELInterface<T>::setAttr;
102
103 public:
104 // Constructor takes operation and left and right expressions
105 // to be operated upon
106 LELBinary(const LELBinaryEnums::Operation op, const std::shared_ptr<LELInterface<T>>& pLeftExpr,
107 const std::shared_ptr<LELInterface<T>>& pRightExpr);
108
109 // Destructor
111
112 // Recursively evaluate the expression
113 virtual void eval(LELArray<T>& result, const Slicer& section) const;
114
115 // Recursively efvaluate the scalar expression
116 virtual LELScalar<T> getScalar() const;
117
118 // Do further preparations (e.g. optimization) on the expression.
120
121 // Get class name
122 virtual String className() const;
123
124 // Handle locking/syncing of a lattice in a lattice expression.
125 // <group>
126 virtual Bool lock(FileLocker::LockType, uInt nattempts);
127 virtual void unlock();
129 virtual void resync();
130 // </group>
131
132 private:
134 std::shared_ptr<LELInterface<T>> pLeftExpr_p;
135 std::shared_ptr<LELInterface<T>> pRightExpr_p;
136};
137
138// <summary> This LEL class handles relational binary numerical operators </summary>
139//
140// <use visibility=local>
141//
142// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
143// </reviewed>
144//
145// <prerequisite>
146// <li> <linkto class="Lattice"> Lattice</linkto>
147// <li> <linkto class="LatticeExpr"> LatticeExpr</linkto>
148// <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto>
149// <li> <linkto class="LELInterface"> LELInterface</linkto>
150// <li> <linkto class="LELBinaryEnums"> LELBinaryEnums</linkto>
151// </prerequisite>
152//
153// <etymology>
154// This derived LEL letter class handles relational numerical binary
155// operators
156// </etymology>
157//
158// <synopsis>
159// This LEL letter class is derived from LELInterface. It
160// is used to construct LEL objects that apply relational numerical
161// binary operators to Lattice expressions. They operate on numerical
162// (Float,Double,Complex,DComplex) Lattice expressions and result
163// in a Bool. The available C++ operators are
164// <src>==,!=>,>=,<,<=,</src> with equivalents in the enum of
165// EQ, NE, GT, GE, LT, and LE
166//
167// A description of the implementation details of the LEL classes can
168// be found in
169// <a href="../notes/216.html">Note 216</a>
170//
171// </synopsis>
172//
173// <example>
174// Examples are not very useful as the user would never use
175// these classes directly. Look in LatticeExprNode.cc to see
176// how it invokes these classes. Examples of how the user
177// would indirectly use this class (through the envelope) are:
178// <srcblock>
179// IPosition shape(2,5,10);
180// ArrayLattice<Float> x(shape); x.set(1.0);
181// ArrayLattice<Float> y(shape); y.set(2.0);
182// ArrayLattice<Bool> z(shape);
183// z.copyData(x==y); // z = x == y;
184// z.copyData(x!=y); // z = x != y;
185// z.copyData(x>y); // z = x > y;
186// z.copyData(x>=y); // z = x >= y;
187// z.copyData(x<y); // z = x < y;
188// z.copyData(x<=y); // z = x <= y;
189// </srcblock>
190// </example>
191//
192// <motivation>
193// Numerical relational binary operations are a basic mathematical expression.
194// </motivation>
195//
196// <todo asof="1998/01/20">
197// </todo>
198
199template <class T>
200class LELBinaryCmp : public LELInterface<Bool> {
201 public:
202 // Constructor takes operation and left and right expressions
203 // to be operated upon. It can only handle the comparison operators.
205 const std::shared_ptr<LELInterface<T>>& pLeftExpr,
206 const std::shared_ptr<LELInterface<T>>& pRightExpr);
207
208 // Destructor
210
211 // Recursively evaluate the expression
212 virtual void eval(LELArray<Bool>& result, const Slicer& section) const;
213
214 // Recursively evaluate the scalar expression
215 virtual LELScalar<Bool> getScalar() const;
216
217 // Do further preparations (e.g. optimization) on the expression.
219
220 // Get class name
221 virtual String className() const;
222
223 // Handle locking/syncing of a lattice in a lattice expression.
224 // <group>
225 virtual Bool lock(FileLocker::LockType, uInt nattempts);
226 virtual void unlock();
228 virtual void resync();
229 // </group>
230
231 private:
233 std::shared_ptr<LELInterface<T>> pLeftExpr_p;
234 std::shared_ptr<LELInterface<T>> pRightExpr_p;
235};
236
237// <summary> This LEL class handles logical binary operators </summary>
238//
239// <use visibility=local>
240//
241// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
242// </reviewed>
243//
244// <prerequisite>
245// <li> <linkto class="Lattice"> Lattice</linkto>
246// <li> <linkto class="LatticeExpr"> LatticeExpr</linkto>
247// <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto>
248// <li> <linkto class="LELInterface"> LELInterface</linkto>
249// <li> <linkto class="LELBinaryEnums"> LELBinaryEnums</linkto>
250// </prerequisite>
251
252// <etymology>
253// This derived LEL letter class handles logical binary operators
254// </etymology>
255//
256// <synopsis>
257// This LEL letter class is derived from LELInterface. It
258// is used to construct LEL objects that apply logical
259// binary operators to Lattice expressions. They apply only
260// to Bool Lattice expressions and result in a Bool. The
261// available C++ operators are <src>&&,||,==,!=</src> with
262// equivalents in the enum of AND, OR, EQ, and NE
263//
264// A description of the implementation details of the LEL classes can
265// be found in
266// <a href="../notes/216.html">Note 216</a>
267//
268// </synopsis>
269//
270// <example>
271// Examples are not very useful as the user would never use
272// these classes directly. Look in LatticeExprNode.cc to see
273// how it invokes these classes. Examples of how the user
274// would indirectly use this class (through the envelope) are:
275// <srcblock>
276// IPosition shape(2,5,10);
277// ArrayLattice<Bool> x(shape); x.set(False);
278// ArrayLattice<Bool> y(shape); y.set(True);
279// ArrayLattice<Bool> z(shape); z.set(False);
280// z.copyData(x&&y); // z = x && y;
281// z.copyData(x||y); // z = x || y;
282// z.copyData(x==y); // z = x == y;
283// z.copyData(x!=y); // z = x != y;
284// </srcblock>
285// </example>
286//
287// <motivation>
288// Logical binary operations are a basic mathematical expression.
289// </motivation>
290//
291// <todo asof="1998/01/20">
292// </todo>
293
294class LELBinaryBool : public LELInterface<Bool> {
295 public:
296 // Constructor takes operation and left and right expressions
297 // to be operated upon.
299 const std::shared_ptr<LELInterface<Bool>>& pLeftExpr,
300 const std::shared_ptr<LELInterface<Bool>>& pRightExpr);
301
302 // Destructor
304
305 // Recursively evaluate the expression
306 virtual void eval(LELArray<Bool>& result, const Slicer& section) const;
307
308 // Recursively evaluate the scalar expression
309 virtual LELScalar<Bool> getScalar() const;
310
311 // Do further preparations (e.g. optimization) on the expression.
313
314 // Get class name
315 virtual String className() const;
316
317 // Handle locking/syncing of a lattice in a lattice expression.
318 // <group>
319 virtual Bool lock(FileLocker::LockType, uInt nattempts);
320 virtual void unlock();
322 virtual void resync();
323 // </group>
324
325 private:
327 std::shared_ptr<LELInterface<Bool>> pLeftExpr_p;
328 std::shared_ptr<LELInterface<Bool>> pRightExpr_p;
329};
330
331} // namespace casacore
332
333#ifndef CASACORE_NO_AUTO_TEMPLATES
334#include <casacore/lattices/LEL/LELBinary.tcc>
335#endif // # CASACORE_NO_AUTO_TEMPLATES
336#endif
LockType
Define the possible lock types.
Definition FileLocker.h:89
~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:327
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:328
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:326
virtual Bool prepareScalarExpr()
Do further preparations (e.g.
virtual void unlock()
~LELBinaryCmp()
Destructor.
std::shared_ptr< LELInterface< T > > pRightExpr_p
Definition LELBinary.h:234
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:233
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:232
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:133
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:135
virtual void unlock()
std::shared_ptr< LELInterface< T > > pLeftExpr_p
Definition LELBinary.h:134
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:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40