Go to the documentation of this file.
28 #ifndef CASA_FUNCTORS_H
29 #define CASA_FUNCTORS_H
31 #include <casacore/casa/aips.h>
32 #include <casacore/casa/BasicMath/Math.h>
33 #include <casacore/casa/BasicSL/Complex.h>
34 #include <casacore/casa/BasicSL/String.h>
43 template<
typename InputIterator1,
typename InputIterator2,
typename BinaryOperator>
45 InputIterator2 first2, BinaryOperator op)
47 for (; first1!=last1; ++first1, ++first2) {
48 *first1 = op(*first1, *first2);
55 template<
typename InputIterator1,
typename UnaryOperator>
59 for (; first1!=last1; ++first1) {
60 *first1 = op(*first1);
67 template<
typename InputIterator,
typename MaskIterator,
typename Accum,
typename BinaryOperator>
69 MaskIterator
mask, Accum acc,
70 BinaryOperator op = std::plus<Accum>())
81 template<
typename InputIterator,
typename MaskIterator,
typename Accum,
typename BinaryOperator>
83 MaskIterator
mask, Accum acc,
84 BinaryOperator op = std::plus<Accum>())
96 template<
typename InputIterator1,
typename InputIterator2,
typename CompareOperator>
97 inline bool compareAll (InputIterator1 first1, InputIterator1 last1,
98 InputIterator2 first2, CompareOperator op)
100 for (; first1!=last1; ++first1, ++first2) {
101 if (!op(*first1, *first2))
return false;
108 template<
typename InputIterator1,
typename T,
typename CompareOperator>
110 T left, CompareOperator op)
112 for (; first1!=last1; ++first1) {
113 if (!op(left, *first1))
return false;
120 template<
typename InputIterator1,
typename T,
typename CompareOperator>
122 T right, CompareOperator op)
124 for (; first1!=last1; ++first1) {
125 if (!op(*first1, right))
return false;
135 template<
typename InputIterator1,
typename InputIterator2,
typename CompareOperator>
136 inline bool compareAny (InputIterator1 first1, InputIterator1 last1,
137 InputIterator2 first2, CompareOperator op)
139 for (; first1!=last1; ++first1, ++first2) {
140 if (op(*first1, *first2))
return true;
147 template<
typename InputIterator1,
typename T,
typename CompareOperator>
149 T left, CompareOperator op)
151 for (; first1!=last1; ++first1) {
152 if (op(left, *first1))
return true;
159 template<
typename InputIterator1,
typename T,
typename CompareOperator>
161 T right, CompareOperator op)
163 for (; first1!=last1; ++first1) {
164 if (op(*first1, right))
return true;
174 template <
typename L,
typename R=L,
typename RES=L>
175 struct Plus :
public std::binary_function<L,R,RES>
183 template <
typename L,
typename R=L,
typename RES=L>
184 struct Minus :
public std::binary_function<L,R,RES>
192 template <
typename L,
typename R=L,
typename RES=L>
201 template <
typename L,
typename R=L,
typename RES=L>
202 struct Divides :
public std::binary_function<L,R,RES>
211 template <
typename L,
typename R=L,
typename RES=L>
212 struct Modulo :
public std::binary_function<L,R,RES>
220 template <
typename L,
typename R=L,
typename RES=L>
221 struct FloorMod :
public std::binary_function<L,R,RES>
224 {
return floormod (RES(x), RES(y)); }
228 template <
typename T>
229 struct BitAnd :
public std::binary_function<T,T,T>
236 template <
typename T>
237 struct BitOr :
public std::binary_function<T,T,T>
244 template <
typename T>
245 struct BitXor :
public std::binary_function<T,T,T>
252 template <
typename T>
266 struct IsNaN :
public std::unary_function<T,bool>
274 struct IsInf :
public std::unary_function<T,bool>
282 struct IsFinite :
public std::unary_function<T,bool>
294 template<
typename L,
typename R=L>
295 struct Near :
public std::binary_function<L,R,bool>
297 explicit Near (
double tolerance=1
e-5)
307 template<
typename L,
typename R=L>
308 struct NearAbs :
public std::binary_function<L,R,bool>
321 template<
typename T,
typename RES=T>
322 struct Sin :
public std::unary_function<T,RES>
329 template<
typename T,
typename RES=T>
330 struct Sinh :
public std::unary_function<T,RES>
337 template<
typename T,
typename RES=T>
338 struct Asin :
public std::unary_function<T,RES>
345 template<
typename T,
typename RES=T>
346 struct Cos :
public std::unary_function<T,RES>
353 template<
typename T,
typename RES=T>
354 struct Cosh :
public std::unary_function<T,RES>
361 template<
typename T,
typename RES=T>
362 struct Acos :
public std::unary_function<T,RES>
369 template<
typename T,
typename RES=T>
370 struct Tan :
public std::unary_function<T,RES>
377 template<
typename T,
typename RES=T>
378 struct Tanh :
public std::unary_function<T,RES>
385 template<
typename T,
typename RES=T>
386 struct Atan :
public std::unary_function<T,RES>
393 template<
typename L,
typename R=L,
typename RES=L>
394 struct Atan2 :
public std::binary_function<L,R,RES>
397 {
return RES(
atan2 (left, L(right))); }
401 template<
typename T,
typename RES=T>
402 struct Sqr :
public std::unary_function<T,RES>
409 template<
typename T,
typename RES=T>
410 struct Pow3 :
public std::unary_function<T,RES>
417 template<
typename T,
typename RES=T>
418 struct Sqrt :
public std::unary_function<T,RES>
425 template<
typename T,
typename RES=T>
426 struct Exp :
public std::unary_function<T,RES>
433 template<
typename T,
typename RES=T>
434 struct Log :
public std::unary_function<T,RES>
441 template<
typename T,
typename RES=T>
442 struct Log10 :
public std::unary_function<T,RES>
449 template<
typename T,
typename RES=T>
450 struct Abs :
public std::unary_function<T,RES>
457 template<
typename T,
typename RES=T>
458 struct Floor :
public std::unary_function<T,RES>
465 template<
typename T,
typename RES=T>
466 struct Ceil :
public std::unary_function<T,RES>
473 template<
typename T,
typename RES=T>
474 struct Round :
public std::unary_function<T,RES>
481 template<
typename T,
typename RES=T>
482 struct Sign :
public std::unary_function<T,RES>
489 template<
typename L,
typename R,
typename RES>
493 {
return RES(l, r); }
498 template<
typename L,
typename R,
typename RES>
502 {
return RES(
real(l), r); }
507 template<
typename L,
typename R,
typename RES>
511 {
return RES(l,
imag(r)); }
516 template<
typename L,
typename R,
typename RES>
524 template<
typename T,
typename RES=T>
525 struct Conj :
public std::unary_function<T,RES>
532 template<
typename T,
typename RES>
533 struct Real :
public std::unary_function<T,RES>
540 template<
typename T,
typename RES>
541 struct Imag :
public std::unary_function<T,RES>
548 template<
typename T,
typename RES>
549 struct CArg :
public std::unary_function<T,RES>
556 template<
typename T,
typename RES>
557 struct CAbs :
public std::unary_function<T,RES>
560 {
return RES(fabs (
value)); }
564 template<
typename T,
typename E=T,
typename RES=T>
565 struct Pow :
public std::binary_function<T,E,RES>
568 {
return RES(
pow (left, exponent)); }
572 template<
typename L,
typename R=L,
typename RES=L>
573 struct Fmod :
public std::binary_function<L,R,RES>
576 {
return RES(
fmod (left, L(right))); }
580 template<
typename L,
typename R=L,
typename RES=L>
581 struct Min :
public std::binary_function<L,R,RES>
584 {
return RES(left<right ? left : right); }
588 template<
typename L,
typename R=L,
typename RES=L>
589 struct Max :
public std::binary_function<L,R,RES>
592 {
return RES(left<right ? right : left); }
596 template<
typename T,
typename Accum=T>
597 struct SumSqr :
public std::binary_function<Accum,T,Accum>
600 {
return left + Accum(right)*Accum(right); }
606 template<
typename T,
typename Accum=T>
607 struct SumSqrDiff :
public std::binary_function<Accum,T,Accum>
622 struct SumSqrDiff<
std::complex<T>> :
public std::binary_function<std::complex<T>,std::complex<T>,std::complex<T>>
625 std::complex<T>
operator() (std::complex<T> left, std::complex<T> right)
const
626 {
return left + ((right.real() -
itsBase.real()) * (right.real() -
itsBase.real()) +
627 (right.imag() -
itsBase.imag()) * (right.imag() -
itsBase.imag())); }
634 template<
typename T,
typename Accum=T>
635 struct SumAbsDiff :
public std::binary_function<Accum,T,Accum>
645 struct Downcase :
public std::unary_function<std::string,String>
652 struct Upcase :
public std::unary_function<std::string,String>
659 struct Capitalize :
public std::unary_function<std::string,String>
667 struct Trim :
public std::unary_function<std::string,String>
RES operator()(T value) const
Functor to take modulo of (integer) variables of possibly different types in the C way.
LatticeExprNode acos(const LatticeExprNode &expr)
RES operator()(T left, E exponent) const
bool compareAllLeft(InputIterator1 first1, InputIterator1 last1, T left, CompareOperator op)
For use with a constant left value.
void transformInPlace(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryOperator op)
Define a function to do a binary transform in place.
Functor to apply complex function real.
Functor to add absolute diff of right and base value to left.
RES operator()(T value) const
RES operator()(T value) const
RES operator()(R left, L right) const
RES operator()(L l, R r) const
Functor to subtract variables of possibly different types.
Functor to get maximum of two values.
Functor to add square of right to left.
T operator()(const T &x, const T &y) const
Functor to form a complex number from the left value and the imaginary part of the right value.
bool operator()(L left, R right) const
Functor to take modulo of variables of possibly different types using the floor modulo (% as used in ...
LatticeExprNode log(const LatticeExprNode &expr)
Near(double tolerance=1e-5)
bool operator()(T value) const
RES operator()(T value) const
RES operator()(T value) const
bool compareAnyRight(InputIterator1 first1, InputIterator1 last1, T right, CompareOperator op)
For use with a constant right value.
LatticeExprNode real(const LatticeExprNode &expr)
TableExprNode isFinite(const TableExprNode &node)
Function to test if a scalar or array is finite.
LatticeExprNode log10(const LatticeExprNode &expr)
bool compareAny(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, CompareOperator op)
Define a function to compare all elements of two sequences.
Functor to apply sign (result is -1, 0, or 1).
Accum accumulateTrue(InputIterator first, InputIterator last, MaskIterator mask, Accum acc, BinaryOperator op=std::plus< Accum >())
Define a function (similar to std::accumulate) to do accumulation of elements for which the correspon...
LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
bool operator()(T value) const
Functor to apply complex function arg.
LatticeExprNode abs(const LatticeExprNode &expr)
Numerical 1-argument functions which result in a real number regardless of input expression type.
RES operator()(T value) const
RES operator()(L l, R r) const
Functor to apply sqr (power of 2).
RES operator()(L left, R right) const
T operator()(const T &x, const T &y) const
Accum operator()(Accum left, T right) const
RES operator()(T value) const
Functor for bitwise xor of (integer) values.
Functor to form a complex number from the real part of the left value and the right value.
RES operator()(T value) const
bool operator()(L left, R right) const
Functor for bitwise negate of (integer) values.
Functor to test for finiteness.
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
String operator()(const std::string &value) const
Functor to downcase a std::string.
RES operator()(T value) const
Functor to form a complex number from the left and right value.
LatticeExprNode atan(const LatticeExprNode &expr)
RES operator()(T value) const
Functor to get minimum of two values.
LatticeExprNode conj(const LatticeExprNode &expr)
LatticeExprNode sqrt(const LatticeExprNode &expr)
TableExprNode isInf(const TableExprNode &node)
LatticeExprNode tan(const LatticeExprNode &expr)
T operator()(const T &x) const
RES operator()(const L &x, const R &y) const
RES operator()(T value) const
RES operator()(T value) const
LatticeExprNode cos(const LatticeExprNode &expr)
std::complex< T > itsBase
RES operator()(const L &x, const R &y) const
String operator()(const std::string &value) const
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
bool compareAnyLeft(InputIterator1 first1, InputIterator1 last1, T left, CompareOperator op)
For use with a constant left value.
TableExprNode upcase(const TableExprNode &node)
LatticeExprNode cosh(const LatticeExprNode &expr)
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
Bool near(const GaussianBeam &left, const GaussianBeam &other, const Double relWidthTol, const Quantity &absPaTol)
Functor to apply a power of 3.
RES operator()(T value) const
LatticeExprNode ceil(const LatticeExprNode &expr)
Functor to upcase a std::string.
RES operator()(T value) const
RES operator()(T value) const
bool compareAll(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, CompareOperator op)
Define a function to compare all elements of two sequences.
RES operator()(T value) const
NearAbs(double tolerance=1e-13)
LatticeExprNode asin(const LatticeExprNode &expr)
this file contains all the compiler specific defines
Functor to multiply variables of possibly different types.
String operator()(const std::string &value) const
RES operator()(L left, R right) const
Functor to apply complex function fabs.
RES operator()(T value) const
LatticeExprNode imag(const LatticeExprNode &expr)
TableExprNode capitalize(const TableExprNode &node)
Functor to trim a std::string.
RES operator()(L l, R r) const
RES operator()(T value) const
Functor for bitwise and of (integer) values.
Functor to test if two values are relatively near each other.
Functor to form a complex number from the real part of the left value and the imaginary part of the r...
Functor to test for infinity.
bool operator()(T value) const
RES operator()(L left, R right) const
Functor to apply complex function imag.
Functor to add squared diff of right and base value to left.
const Double e
e and functions thereof:
RES operator()(T value) const
String operator()(const std::string &value) const
Functor to apply round (e.g.
LatticeExprNode isNaN(const LatticeExprNode &expr)
Test if a value is a NaN.
Define real & complex conjugation for non-complex types and put comparisons into std namespace.
bool compareAllRight(InputIterator1 first1, InputIterator1 last1, T right, CompareOperator op)
For use with a constant right value.
Functor to test for if two values are absolutely near each other.
TableExprNode downcase(const TableExprNode &node)
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
RES operator()(const L &x, const R &y) const
LatticeExprNode arg(const LatticeExprNode &expr)
RES operator()(const L &x, const R &y) const
RES operator()(T value) const
RES operator()(L l, R r) const
LatticeExprNode tanh(const LatticeExprNode &expr)
RES operator()(T value) const
Functor to divide variables of possibly different types.
String: the storage and methods of handling collections of characters.
RES operator()(T value) const
LatticeExprNode floor(const LatticeExprNode &expr)
Functor to add variables of possibly different types.
Accum operator()(Accum left, T right) const
TableExprNode trim(const TableExprNode &node)
Accum accumulateFalse(InputIterator first, InputIterator last, MaskIterator mask, Accum acc, BinaryOperator op=std::plus< Accum >())
Define a function (similar to std::accumulate) to do accumulation of elements for which the correspon...
RES operator()(const L &x, const R &y) const
Functor to apply complex function conj.
RES operator()(const L &x, const R &y) const
Accum operator()(Accum left, T right) const
LatticeExprNode sinh(const LatticeExprNode &expr)
RES operator()(T value) const
Functor to capitalize a std::string.
LatticeExprNode exp(const LatticeExprNode &expr)
RES operator()(T value) const
SumSqrDiff(std::complex< T > base)
RES operator()(T value) const
TableExprNode nearAbs(const TableExprNode &left, const TableExprNode &right)
T operator()(const T &x, const T &y) const
Functor for bitwise or of (integer) values.