OpenCurves  0.9
plotunaryoperator.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) CSIRO 2015
5 //
6 #ifndef PLOTUNARYOPERATOR_H_
7 #define PLOTUNARYOPERATOR_H_
8 
9 #include "plotsconfig.h"
10 
11 #include "plotexpression.h"
12 
13 #include <QTextStream>
14 
21 {
22 public:
25  inline PlotUnaryOperator(PlotExpression *operand) : _operand(operand) {}
26 
29 
32  inline void setOperand(PlotExpression *operand) { _operand = operand; }
33 
36  inline const PlotExpression *operand() const { return _operand; }
37 
39  virtual BindResult bind(const QList<PlotInstance *> &curves, PlotBindingTracker &bindTracker, PlotExpressionBindDomain &domain, bool repeatLastBinding = false);
40 
42  virtual void unbind();
43 
46  bool explicitTime() const override;
47 
48 private:
49  PlotExpression *_operand;
50 };
51 
52 
67 template <class Operator>
69 {
70 public:
73 
77 
85  virtual inline double sample(double sampleTime) const
86  {
87  return Operator()(operand()->sample(sampleTime));
88  }
89 
92  inline const QString &opStr() const { return _opStr; }
93 
96  inline void setOpStr(const QString &str) { _opStr = str; }
97 
99  virtual PlotExpression *clone() const
100  {
102  op->setOpStr(_opStr);
103  return op;
104  }
105 
106 private:
109  virtual QString stringExpression() const
110  {
111  QString str;
112  QTextStream stream(&str);
113  stream << _opStr << operand()->toString();
114  return str;
115  }
116 
117  QString _opStr;
118 };
119 
120 #endif // PLOTUNARYOPERATOR_H_
void setOperand(PlotExpression *operand)
Set the operand expression.
Definition: plotunaryoperator.h:32
PlotUnaryOperatorT()
Default constructor: operand is null.
Definition: plotunaryoperator.h:72
virtual void unbind()
Unbind the operand.
virtual PlotExpression * clone() const
Deep clone.
Definition: plotunaryoperator.h:99
An extension of PlotExpression defining a unary operation.
Definition: plotunaryoperator.h:20
Supports multiple bindings of the same expression to different curves.
Definition: plotbindingtracker.h:34
const QString & opStr() const
Return the string used to prefix the operand.
Definition: plotunaryoperator.h:92
const PlotExpression * operand() const
Get the operand expression.
Definition: plotunaryoperator.h:36
Core data for binding a PlotExpression.
Definition: plotexpressionbinddomain.h:49
virtual PlotExpression * clone() const =0
Performs a deep clone of the PlotExpression.
BindResult
Return values for the PlotExpression::bind() method.
Definition: plotexpressionbinddomain.h:15
PlotUnaryOperator(PlotExpression *operand)
Create a binary operator on the given left and right expressions.
Definition: plotunaryoperator.h:25
void setOpStr(const QString &str)
Sets the string used to prefix the operand.
Definition: plotunaryoperator.h:96
virtual double sample(double sampleTime) const
Sample the operand and evaluate the Operator.
Definition: plotunaryoperator.h:85
bool explicitTime() const override
Is the generated expression sensitive to changes in the time domain?
QString toString() const
Converts the PlotExpression into a parseable string form.
Definition: plotexpression.h:147
PlotUnaryOperatorT(PlotExpression *operand)
Constructor.
Definition: plotunaryoperator.h:76
~PlotUnaryOperator()
Destructor, destroying the child.
A template unary operator, using a functional object to evaluate the expression.
Definition: plotunaryoperator.h:68
virtual double sample(double sampleTime) const =0
Called to generate a sample at sampleTime.
A PlotExpression represents an operation in a plot equation.
Definition: plotexpression.h:91
virtual BindResult bind(const QList< PlotInstance * > &curves, PlotBindingTracker &bindTracker, PlotExpressionBindDomain &domain, bool repeatLastBinding=false)
Binds the operand expression.