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