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>())
73 if (*mask) acc = op(acc, *first);
81 template<
typename InputIterator,
typename MaskIterator,
typename Accum,
typename BinaryOperator>
83 MaskIterator mask, Accum acc,
84 BinaryOperator op = std::plus<Accum>())
87 if (!*mask) acc = op(acc, *first);
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>
210 template <
typename L,
typename R=L,
typename RES=L>
211 struct Modulo :
public std::binary_function<L,R,RES>
218 template <
typename T>
219 struct BitAnd :
public std::binary_function<T,T,T>
226 template <
typename T>
227 struct BitOr :
public std::binary_function<T,T,T>
234 template <
typename T>
235 struct BitXor :
public std::binary_function<T,T,T>
242 template <
typename T>
256 struct IsNaN :
public std::unary_function<T,bool>
259 {
return isNaN (value); }
264 struct IsInf :
public std::unary_function<T,bool>
267 {
return isInf (value); }
272 struct IsFinite :
public std::unary_function<T,bool>
284 template<
typename L,
typename R=L>
285 struct Near :
public std::binary_function<L,R,bool>
287 explicit Near (
double tolerance=1
e-5)
288 : itsTolerance (tolerance)
291 {
return near (left, L(right), itsTolerance); }
297 template<
typename L,
typename R=L>
298 struct NearAbs :
public std::binary_function<L,R,bool>
301 : itsTolerance (tolerance)
304 {
return nearAbs (left, L(right), itsTolerance); }
311 template<
typename T,
typename RES=T>
312 struct Sin :
public std::unary_function<T,RES>
315 {
return RES(
sin (value)); }
319 template<
typename T,
typename RES=T>
320 struct Sinh :
public std::unary_function<T,RES>
323 {
return RES(
sinh (value)); }
327 template<
typename T,
typename RES=T>
328 struct Asin :
public std::unary_function<T,RES>
331 {
return RES(
asin (value)); }
335 template<
typename T,
typename RES=T>
336 struct Cos :
public std::unary_function<T,RES>
339 {
return RES(
cos (value)); }
343 template<
typename T,
typename RES=T>
344 struct Cosh :
public std::unary_function<T,RES>
347 {
return RES(
cosh (value)); }
351 template<
typename T,
typename RES=T>
352 struct Acos :
public std::unary_function<T,RES>
355 {
return RES(
acos (value)); }
359 template<
typename T,
typename RES=T>
360 struct Tan :
public std::unary_function<T,RES>
363 {
return RES(
tan (value)); }
367 template<
typename T,
typename RES=T>
368 struct Tanh :
public std::unary_function<T,RES>
371 {
return RES(
tanh (value)); }
375 template<
typename T,
typename RES=T>
376 struct Atan :
public std::unary_function<T,RES>
379 {
return RES(
atan (value)); }
383 template<
typename L,
typename R=L,
typename RES=L>
384 struct Atan2 :
public std::binary_function<L,R,RES>
387 {
return RES(
atan2 (left, L(right))); }
391 template<
typename T,
typename RES=T>
392 struct Sqr :
public std::unary_function<T,RES>
395 {
return RES(value*value); }
399 template<
typename T,
typename RES=T>
400 struct Pow3 :
public std::unary_function<T,RES>
403 {
return RES(value*value*value); }
407 template<
typename T,
typename RES=T>
408 struct Sqrt :
public std::unary_function<T,RES>
411 {
return RES(
sqrt (value)); }
415 template<
typename T,
typename RES=T>
416 struct Exp :
public std::unary_function<T,RES>
419 {
return RES(
exp (value)); }
423 template<
typename T,
typename RES=T>
424 struct Log :
public std::unary_function<T,RES>
427 {
return RES(
log (value)); }
431 template<
typename T,
typename RES=T>
432 struct Log10 :
public std::unary_function<T,RES>
435 {
return RES(
log10 (value)); }
439 template<
typename T,
typename RES=T>
440 struct Abs :
public std::unary_function<T,RES>
443 {
return RES(
abs (value)); }
447 template<
typename T,
typename RES=T>
448 struct Floor :
public std::unary_function<T,RES>
451 {
return RES(
floor (value)); }
455 template<
typename T,
typename RES=T>
456 struct Ceil :
public std::unary_function<T,RES>
459 {
return RES(
ceil (value)); }
463 template<
typename T,
typename RES=T>
464 struct Round :
public std::unary_function<T,RES>
467 {
return RES(value<0 ?
ceil(value-0.5) :
floor(value+0.5)); }
471 template<
typename T,
typename RES=T>
472 struct Sign :
public std::unary_function<T,RES>
475 {
return (value<0 ? -1 : (value>0 ? 1:0)); }
479 template<
typename L,
typename R,
typename RES>
483 {
return RES(l, r); }
488 template<
typename L,
typename R,
typename RES>
492 {
return RES(
real(l), r); }
497 template<
typename L,
typename R,
typename RES>
501 {
return RES(l,
imag(r)); }
506 template<
typename L,
typename R,
typename RES>
514 template<
typename T,
typename RES=T>
515 struct Conj :
public std::unary_function<T,RES>
518 {
return RES(
conj (value)); }
522 template<
typename T,
typename RES>
523 struct Real :
public std::unary_function<T,RES>
526 {
return RES(
real (value)); }
530 template<
typename T,
typename RES>
531 struct Imag :
public std::unary_function<T,RES>
534 {
return RES(
imag (value)); }
538 template<
typename T,
typename RES>
539 struct CArg :
public std::unary_function<T,RES>
542 {
return RES(
arg (value)); }
546 template<
typename T,
typename RES>
547 struct CAbs :
public std::unary_function<T,RES>
550 {
return RES(fabs (value)); }
554 template<
typename T,
typename E=T,
typename RES=T>
555 struct Pow :
public std::binary_function<T,E,RES>
558 {
return RES(
pow (left, exponent)); }
562 template<
typename L,
typename R=L,
typename RES=L>
563 struct Fmod :
public std::binary_function<L,R,RES>
566 {
return RES(
fmod (left, L(right))); }
570 template<
typename L,
typename R=L,
typename RES=L>
571 struct Min :
public std::binary_function<L,R,RES>
574 {
return RES(left<right ? left : right); }
578 template<
typename L,
typename R=L,
typename RES=L>
579 struct Max :
public std::binary_function<L,R,RES>
582 {
return RES(left<right ? right : left); }
586 template<
typename T,
typename Accum=T>
587 struct SumSqr :
public std::binary_function<Accum,T,Accum>
590 {
return left + Accum(right)*Accum(right); }
595 template<
typename T,
typename Accum=T>
596 struct SumSqrDiff :
public std::binary_function<Accum,T,Accum>
600 {
return left + (right-itsBase)*(right-itsBase); }
607 template<
typename T,
typename Accum=T>
608 struct SumAbsDiff :
public std::binary_function<Accum,T,Accum>
612 {
return left +
abs((right-itsBase)); }
618 struct Downcase :
public std::unary_function<std::string,String>
625 struct Upcase :
public std::unary_function<std::string,String>
632 struct Capitalize :
public std::unary_function<std::string,String>
640 struct Trim :
public std::unary_function<std::string,String>
643 {
return trim(value); }
LatticeExprNode log10(const LatticeExprNode &expr)
Functor to test for if two values are absolutely near each other.
Functor for bitwise and of (integer) values.
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 log(const LatticeExprNode &expr)
LatticeExprNode arg(const LatticeExprNode &expr)
TableExprNode downcase(const TableExprNode &node)
Functor to apply round (e.g.
Functor to add square of right to left.
Functor to add absolute diff of right and base value to left.
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
Functor to apply a power of 3.
LatticeExprNode imag(const LatticeExprNode &expr)
Functor to form a complex number from the real part of the left value and the imaginary part of the r...
Functor for bitwise negate of (integer) values.
Near(double tolerance=1e-5)
bool compareAllLeft(InputIterator1 first1, InputIterator1 last1, T left, CompareOperator op)
For use with a constant left value.
Functor to get maximum of two values.
Functor to downcase a std::string.
Functor to form a complex number from the left and right value.
Bool near(const GaussianBeam &left, const GaussianBeam &other, const Double relWidthTol, const Quantity &absPaTol)
Functor to test for finiteness.
Functor to trim a std::string.
Functor for bitwise or of (integer) values.
LatticeExprNode exp(const LatticeExprNode &expr)
Functor to subtract variables of possibly different types.
LatticeExprNode floor(const LatticeExprNode &expr)
LatticeExprNode cos(const LatticeExprNode &expr)
Functor to apply sqr (power of 2).
Functor to get minimum of two values.
LatticeExprNode conj(const LatticeExprNode &expr)
Functor to add variables of possibly different types.
Functor to apply complex function fabs.
Float pow(Float f1, Float f2)
LatticeExprNode tanh(const LatticeExprNode &expr)
void transformInPlace(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryOperator op)
Define a function to do a binary transform in place.
Functor to test if two values are relatively near each other.
TableExprNode isInf(const TableExprNode &node)
NearAbs(double tolerance=1e-13)
Functor to apply complex function imag.
Functor for bitwise xor of (integer) values.
LatticeExprNode abs(const LatticeExprNode &expr)
Numerical 1-argument functions which result in a real number regardless of input expression type...
TableExprNode trim(const TableExprNode &node)
Functor to test for infinity.
Functor to form a complex number from the real part of the left value and the right value...
LatticeExprNode sqrt(const LatticeExprNode &expr)
LatticeExprNode tan(const LatticeExprNode &expr)
TableExprNode isFinite(const TableExprNode &node)
Function to test if a scalar or array is finite.
LatticeExprNode atan(const LatticeExprNode &expr)
Functor to capitalize a std::string.
TableExprNode upcase(const TableExprNode &node)
bool compareAnyRight(InputIterator1 first1, InputIterator1 last1, T right, CompareOperator op)
For use with a constant right value.
Functor to apply complex function real.
bool compareAny(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, CompareOperator op)
Define a function to compare all elements of two sequences.
Functor to apply complex function conj.
Functor to multiply variables of possibly different types.
bool compareAllRight(InputIterator1 first1, InputIterator1 last1, T right, CompareOperator op)
For use with a constant right value.
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
bool compareAnyLeft(InputIterator1 first1, InputIterator1 last1, T left, CompareOperator op)
For use with a constant left value.
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
LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
Functor to apply sign (result is -1, 0, or 1).
LatticeExprNode asin(const LatticeExprNode &expr)
const Double e
e and functions thereof:
Functor to divide variables of possibly different types.
LatticeExprNode sinh(const LatticeExprNode &expr)
Functor to form a complex number from the left value and the imaginary part of the right value...
LatticeExprNode acos(const LatticeExprNode &expr)
TableExprNode capitalize(const TableExprNode &node)
String: the storage and methods of handling collections of characters.
TableExprNode nearAbs(const TableExprNode &left, const TableExprNode &right)
Functor to take modulo of (integer) variables of possibly different types.
LatticeExprNode isNaN(const LatticeExprNode &expr)
Test if a value is a NaN.
bool compareAll(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, CompareOperator op)
Define a function to compare all elements of two sequences.
Functor to upcase a std::string.
LatticeExprNode ceil(const LatticeExprNode &expr)
this file contains all the compiler specific defines
LatticeExprNode cosh(const LatticeExprNode &expr)
LatticeExprNode real(const LatticeExprNode &expr)
Functor to add squared diff of right and base value to left.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
Functor to apply complex function arg.