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