casacore
Loading...
Searching...
No Matches
LELUnary.h
Go to the documentation of this file.
1//# LELUnary.h: LELUnary.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_LELUNARY_H
27#define LATTICES_LELUNARY_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/lattices/LEL/LELInterface.h>
33#include <casacore/lattices/LEL/LELScalar.h>
34#include <casacore/lattices/LEL/LELUnaryEnums.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward Declarations
39
40
41// <summary> This LEL class handles scalar (unary) constants </summary>
42//
43// <use visibility=local>
44//
45// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
46// </reviewed>
47//
48// <prerequisite>
49// <li> <linkto class="Lattice"> Lattice</linkto>
50// <li> <linkto class="LatticeExpr"> LatticeExpr</linkto>
51// <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto>
52// <li> <linkto class="LELInterface"> LELInterface</linkto>
53// <li> <linkto class="LELUnaryEnums"> LELUnaryEnums</linkto>
54// </prerequisite>
55//
56// <etymology>
57// This derived LEL letter class handles scalar (unary) constants
58// </etymology>
59//
60// <synopsis>
61// This LEL letter class is derived from LELInterface. It
62// is used to construct LEL objects that represent scalars
63// constants. They can be of type Float,Double,Complex,DComplex
64// and Bool.
65//
66// A description of the implementation details of the LEL classes can
67// be found in
68// <a href="../notes/216.html">Note 216</a>
69// </synopsis>
70//
71// <example>
72// Examples are not very useful as the user would never use
73// these classes directly. Look in LatticeExprNode.cc to see
74// how it invokes these classes. Examples of how the user
75// would indirectly use this class (through the envelope) are:
76// <srcblock>
77// IPosition shape(2,5,10);
78// ArrayLattice<Float> x(shape); x.set(1.0);
79// ArrayLattice<Float> y(shape);
80// ArrayLattice<Float> z(shape);
81// y.copyData(x+2.0); // y = x + 2.0
82// z.copyData(True); // z = True
83// </srcblock>
84// </example>
85//
86// <motivation>
87// Constants are a basic mathematical expression.
88// </motivation>
89//
90// <todo asof="1998/01/20">
91// </todo>
92
93
94template <class T> class LELUnaryConst : public LELInterface<T>
95{
96 //# Make members of parent class known.
97protected:
98 using LELInterface<T>::setAttr;
99
100public:
101// Default constructor creates a scalar with a false mask.
103
104// Constructor takes a scalar.
105 LELUnaryConst(const T val);
106
107// Destructor does nothing
109
110// Evaluate the expression.
111// This throws an exception, since only a scalar can be returned.
112 virtual void eval (LELArray<T>& result,
113 const Slicer& section) const;
114
115// Evaluate the scalar expression (get the constant)
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
124private:
126};
127
128
129
130// <summary> This LEL class handles numerical unary operators </summary>
131//
132// <use visibility=local>
133//
134// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
135// </reviewed>
136//
137// <prerequisite>
138// <li> <linkto class="Lattice"> Lattice</linkto>
139// <li> <linkto class="LatticeExpr"> LatticeExpr</linkto>
140// <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto>
141// <li> <linkto class="LELInterface"> LELInterface</linkto>
142// <li> <linkto class="LELUnaryEnums"> LELUnaryEnums</linkto>
143// </prerequisite>
144//
145// <etymology>
146// This derived LEL letter class handles numerical unary
147// operators
148// </etymology>
149//
150// <synopsis>
151// This LEL letter class is derived from LELInterface. It
152// is used to construct LEL objects that apply numerical unary
153// operators to Lattice expressions. They operate on numerical
154// Lattice (Float,Double,Complex,DComplex) expressions and return the
155// same numerical type. The available C++ operators
156// are <src>+,-</src> with equivalents in the enum
157// of PLUS and MINUS.
158//
159// A description of the implementation details of the LEL classes can
160// be found in
161// <a href="../notes/216.html">Note 216</a>
162// </synopsis>
163//
164// <example>
165// Examples are not very useful as the user would never use
166// these classes directly. Look in LatticeExprNode.cc to see
167// how it invokes these classes. An example of how the user
168// would indirectly use this class (through the envelope) is:
169// <srcblock>
170// IPosition shape(2,5,10);
171// ArrayLattice<Float> x(shape); x.set(1.0);
172// ArrayLattice<Float> y(shape);
173// y.copyData(-x); // y = -x
174// </srcblock>
175// </example>
176//
177// <motivation>
178// Numerical unary operations are a basic mathematical expression.
179// </motivation>
180//
181// <todo asof="1998/01/20">
182// </todo>
183
184template <class T> class LELUnary : public LELInterface<T>
185{
186public:
187
188// Constructor takes operation and expression
189// to be operated upon
191 const std::shared_ptr<LELInterface<T>>& pExpr);
192
193// Destructor does nothing
195
196// Recursively evaluate the expression.
197 virtual void eval (LELArray<T>& result,
198 const Slicer& section) const;
199
200// Recursively evaluate the scalar expression.
201 virtual LELScalar<T> getScalar() const;
202
203// Do further preparations (e.g. optimization) on the expression.
205
206// Get class name
207 virtual String className() const;
208
209 // Handle locking/syncing of a lattice in a lattice expression.
210 // <group>
211 virtual Bool lock (FileLocker::LockType, uInt nattempts);
212 virtual void unlock();
214 virtual void resync();
215 // </group>
216
217private:
219 std::shared_ptr<LELInterface<T>> pExpr_p;
220};
221
222
223
224
225// <summary> This LEL class handles logical unary operators </summary>
226//
227// <use visibility=local>
228//
229// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
230// </reviewed>
231//
232// <prerequisite>
233// <li> <linkto class="Lattice"> Lattice</linkto>
234// <li> <linkto class="LatticeExpr"> LatticeExpr</linkto>
235// <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto>
236// <li> <linkto class="LELInterface"> LELInterface</linkto>
237// <li> <linkto class="LELUnaryEnums"> LELUnaryEnums</linkto>
238// </prerequisite>
239//
240// <etymology>
241// This derived LEL letter class handles logical unary
242// operators
243// </etymology>
244//
245// <synopsis>
246// This LEL letter class is derived from LELInterface. It
247// is used to construct LEL objects that apply logical unary
248// operators to Lattice expressions. They operate on Bool
249// Lattice expressions only and return a Bool.
250// The available C++ operator is <src>!</src> with the equivalent
251// in the enum of NOT.
252//
253// A description of the implementation details of the LEL classes can
254// be found in
255// <a href="../notes/216.html">Note 216</a>
256// </synopsis>
257//
258// <example>
259// Examples are not very useful as the user would never use
260// these classes directly. Look in LatticeExprNode.cc to see
261// how it invokes these classes. An example of how the user
262// would indirectly use this class (through the envelope) is:
263// <srcblock>
264// IPosition shape(2,5,10);
265// ArrayLattice<Bool> x(shape); x.set(True);
266// ArrayLattice<Bool> y(shape);
267// y.copyData(!x); // y = !x
268// </srcblock>
269// </example>
270//
271// <motivation>
272// Logical unary operations are a basic mathematical expression.
273// </motivation>
274//
275// <todo asof="1998/01/20">
276// </todo>
277
278
279class LELUnaryBool : public LELInterface<Bool>
280{
281public:
282
283// Constructor takes operation and expression
284// to be operated upon
286 const std::shared_ptr<LELInterface<Bool>>& pExpr);
287
288// Destructor does nothing
290
291// Recursively evaluate the expression.
292 virtual void eval (LELArray<Bool>& result,
293 const Slicer& section) const;
294
295// Recursively evaluate the scalar expression.
296 virtual LELScalar<Bool> getScalar() const;
297
298// Do further preparations (e.g. optimization) on the expression.
300
301// Get class name
302 virtual String className() const;
303
304 // Handle locking/syncing of a lattice in a lattice expression.
305 // <group>
306 virtual Bool lock (FileLocker::LockType, uInt nattempts);
307 virtual void unlock();
309 virtual void resync();
310 // </group>
311
312private:
314 std::shared_ptr<LELInterface<Bool>> pExpr_p;
315};
316
317
318
319
320} //# NAMESPACE CASACORE - END
321
322//# See comments in LELInterface why LELInterface.tcc is included here.
323#ifndef CASACORE_NO_AUTO_TEMPLATES
324#include <casacore/lattices/LEL/LELInterface.tcc>
325#include <casacore/lattices/LEL/LELUnary.tcc>
326#endif //# CASACORE_NO_AUTO_TEMPLATES
327#endif
LockType
Define the possible lock types.
Definition FileLocker.h:93
void setAttr(const LELAttribute &attrib)
Set the expression attributes of this object.
This LEL class handles logical unary operators.
Definition LELUnary.h:280
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle locking/syncing of a lattice in a lattice expression.
std::shared_ptr< LELInterface< Bool > > pExpr_p
Definition LELUnary.h:314
virtual LELScalar< Bool > getScalar() const
Recursively evaluate the scalar expression.
virtual String className() const
Get class name.
~LELUnaryBool()
Destructor does nothing.
virtual Bool hasLock(FileLocker::LockType) const
LELUnaryEnums::Operation op_p
Definition LELUnary.h:313
virtual Bool prepareScalarExpr()
Do further preparations (e.g.
virtual void unlock()
virtual void eval(LELArray< Bool > &result, const Slicer &section) const
Recursively evaluate the expression.
virtual void resync()
LELUnaryBool(const LELUnaryEnums::Operation op, const std::shared_ptr< LELInterface< Bool > > &pExpr)
Constructor takes operation and expression to be operated upon.
virtual Bool prepareScalarExpr()
Do further preparations (e.g.
LELScalar< T > val_p
Definition LELUnary.h:125
virtual String className() const
Get class name.
virtual LELScalar< T > getScalar() const
Evaluate the scalar expression (get the constant)
LELUnaryConst(const T val)
Constructor takes a scalar.
virtual void eval(LELArray< T > &result, const Slicer &section) const
Evaluate the expression.
LELUnaryConst()
Default constructor creates a scalar with a false mask.
~LELUnaryConst()
Destructor does nothing.
This LEL class handles numerical unary operators.
Definition LELUnary.h:185
virtual LELScalar< T > getScalar() const
Recursively evaluate the scalar expression.
virtual Bool hasLock(FileLocker::LockType) const
virtual void unlock()
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle locking/syncing of a lattice in a lattice expression.
virtual void resync()
std::shared_ptr< LELInterface< T > > pExpr_p
Definition LELUnary.h:219
LELUnaryEnums::Operation op_p
Definition LELUnary.h:218
LELUnary(const LELUnaryEnums::Operation op, const std::shared_ptr< LELInterface< T > > &pExpr)
Constructor takes operation and expression to be operated upon.
virtual void eval(LELArray< T > &result, const Slicer &section) const
Recursively evaluate the expression.
~LELUnary()
Destructor does nothing.
virtual Bool prepareScalarExpr()
Do further preparations (e.g.
virtual String className() const
Get class name.
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