OpenCurves  0.9
binding Namespace Reference

Contains utility functions for binding expression tree branches. More...

Functions

BindResult bindMultiple (const QList< PlotInstance * > &curves, PlotBindingTracker &bindTracker, BindInfo &head, BindInfo *tail, unsigned tailLength, bool repeatLast)
 Bind multiple expressions, ensuring exhaustive binding combinations. More...
 

Detailed Description

Contains utility functions for binding expression tree branches.

Tree based PlotExpression objects may require binding on multiple branches. Each branch may in turn require binding multiple times. For example, consider the following expression:

1 r'speed.*' - r'speed.*'

This creates the following expression tree:

1  PlotSubtract
2  / \
3 PlotSample PlotSample

Both PlotSample nodes are using regular expressions. Now, if the available curves are: [ 'speed_measured', 'speed_reported' ], then the resulting bindings should result in a comparison of 'speed_measured' against 'speed_reported'. The bindMultiple() functions handle this sort of exhaustive binding, resulting in four bindings in this case:

  • 'speed_measured' - 'speed_measured'
  • 'speed_reported' - 'speed_reported'
  • 'speed_measured' - 'speed_reported'
  • 'speed_reported' - 'speed_measured'

While this is excessive, it ensures all required bindings are made.

The bindMultiple() functions should be used by any PlotExpression which has two or more child expressions. For such an expresison, the bind() method should look somewhat as follows:

BindResult bind(const QList<PlotInstance *> &curves, PlotBindingTracker &bindTracker, PlotExpressionBindDomain &domain, bool repeatLastBinding)
{
if (!_left || !_right)
{
return BindError;
}
BindInfo bindings[2];
bindings[0].expression = _left;
bindings[1].expression = _right;
repeatLastBinding = repeatLastBinding || bindTracker.isHeld(this);
BindResult bindResult = binding::bindMultiple(curves, bindTracker, bindings[0], &bindings[1], 1, repeatLastBinding);
domainUnion(domain, bindings[0].domain, bindings[1].domain);
return bindResult;
}

This is a binary binding. A ternary binding would have additional elements in bindings.

Function Documentation

BindResult binding::bindMultiple ( const QList< PlotInstance * > &  curves,
PlotBindingTracker bindTracker,
BindInfo head,
BindInfo tail,
unsigned  tailLength,
bool  repeatLast 
)

Bind multiple expressions, ensuring exhaustive binding combinations.

This binds the expression at head, then recurses to bind the remaining items in tail. The overall bind result is a combination of the head and tail results as follows:

Head Result Tail Result Final Result
Any BindError BindError
Any BindFailure BindFailure
BindError Any BindError
BindFailure Any BindFailure
Bound Bound Bound
Bound BoundMaybeMore BoundMaybeMore
BoundMaybeMore Bound BoundMaybeMore
BoundMaybeMore BoundMaybeMore BoundMaybeMore
Parameters
curvesThe curves available for binding.
bindTrackerTracks bind state for later bindings.
headThe head of the list of items to bind.
tailA list of remaining expression requiring binding.
tailLengthNumber of elements in tail.
repeatLastTrue to remake the last binding if possible (as defined in bindTracker).
Returns
The overall binding result as described in the table above.