OpenCurves  0.9
plotexpressionarithmetic.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) CSIRO 2013
5 //
6 #ifndef __PLOTEXPRESSIONARITHMETIC_H_
7 #define __PLOTEXPRESSIONARITHMETIC_H_
8 
9 #include "plotsconfig.h"
10 
11 #include "plotbinaryoperator.h"
12 #include "plotunaryoperator.h"
13 
14 #include <functional>
15 
18 class PlotAdd : public PlotBinaryOperatorT<std::plus<double> > { public: PlotAdd(PlotExpression *left, PlotExpression *right) { setLeft(left); setRight(right); setOpStr(" + "); } };
19 
22 class PlotSubtract : public PlotBinaryOperatorT<std::minus<double> > { public: PlotSubtract(PlotExpression *left, PlotExpression *right) { setLeft(left); setRight(right); setOpStr(" - "); } };
23 
26 class PlotMultiply : public PlotBinaryOperatorT<std::multiplies<double> > { public: PlotMultiply(PlotExpression *left, PlotExpression *right) { setLeft(left); setRight(right); setOpStr(" * "); } };
27 
30 class PlotDivide : public PlotBinaryOperatorT<std::divides<double> > { public: PlotDivide(PlotExpression *left, PlotExpression *right) { setLeft(left); setRight(right); setOpStr(" / "); } };
31 
34 class PlotNegate : public PlotUnaryOperatorT<std::negate<double> > { public: PlotNegate(PlotExpression *operand) { setOperand(operand); setOpStr(" -"); } };
35 
38 template<class T>
39 struct Power : public std::binary_function<T, T, T>
40 {
45  inline T operator()(const T &left, const T &right) const { return T(pow(left, right)); }
46 };
47 
50 class PlotPower : public PlotBinaryOperatorT<Power<double> > { public : PlotPower(PlotExpression *left, PlotExpression *right) { setLeft(left); setRight(right); setOpStr("^"); } };
51 
52 #endif // __PLOTEXPRESSIONARITHMETIC_H_
void setOperand(PlotExpression *operand)
Set the operand expression.
Definition: plotunaryoperator.h:32
A PlotExpression which raises the results of one PlotExpression object by another.
Definition: plotexpressionarithmetic.h:50
const PlotExpression * right() const
Get the right branch.
Definition: plotbinaryoperator.h:47
A PlotExpression which adds the results of two other PlotExpression objects.
Definition: plotexpressionarithmetic.h:34
void setLeft(PlotExpression *left)
Set the left branch.
Definition: plotbinaryoperator.h:35
const PlotExpression * operand() const
Get the operand expression.
Definition: plotunaryoperator.h:36
A PlotExpression which multiplies the results of two other PlotExpression objects.
Definition: plotexpressionarithmetic.h:26
A PlotExpression which adds the results of two other PlotExpression objects.
Definition: plotexpressionarithmetic.h:18
A PlotExpression which divides the results one PlotExpression object from another.
Definition: plotexpressionarithmetic.h:30
void setOpStr(const QString &str)
Sets the string used to prefix the operand.
Definition: plotunaryoperator.h:96
A PlotExpression which subtracts the results one PlotExpression object from another.
Definition: plotexpressionarithmetic.h:22
const PlotExpression * left() const
Get the left branch.
Definition: plotbinaryoperator.h:39
A template binary operator, using a functional object to evaluate the expression. ...
Definition: plotbinaryoperator.h:82
A template unary operator, using a functional object to evaluate the expression.
Definition: plotunaryoperator.h:68
void setOpStr(const QString &str)
Sets the string used to combine left and right branches.
Definition: plotbinaryoperator.h:114
A binary_function object which raises the one value to the power of another.
Definition: plotexpressionarithmetic.h:39
A PlotExpression represents an operation in a plot equation.
Definition: plotexpression.h:91
T operator()(const T &left, const T &right) const
Expression effector calculating left raised to the power of right.
Definition: plotexpressionarithmetic.h:45
void setRight(PlotExpression *right)
Set the right branch.
Definition: plotbinaryoperator.h:43