Workspace 6.21.5
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
IteratingOperationBase Class Referenceabstract

Base class for operations that iterate over a workflow one or more times. More...

#include <Workspace/DataExecution/Operations/Builtin/iteratingoperationbase.h>

Inheritance diagram for IteratingOperationBase:
[legend]

Public Types

enum  ExecutionResult { Abort , Success , Retry }
 Result of an iteration's execution. More...
 

Public Member Functions

 IteratingOperationBase ()
 
virtual ~IteratingOperationBase ()=default
 

Protected Member Functions

virtual bool atEndCondition ()=0
 
virtual ExecutionResult executeIteration (Workspace *workspaceToExecute) noexcept(false)=0
 
WorkspacegetWorkspaceToExecute ()
 
bool isExecuting () const
 
virtual bool isLoopConditionValid () const =0
 
virtual void performCleanup (Workspace *workspaceToExecute, bool forceStop) noexcept(false)=0
 
virtual bool performInitialisation (Workspace *workspaceToExecute) noexcept(false)=0
 
virtual bool postIterationExecute ()
 
virtual bool preIterations ()=0
 
virtual void setNonIterationControlInputsNotUpToDate ()
 
void setWorkspaceToExecute (Workspace *workspace)
 
virtual bool updateInputsForIteration ()=0
 
virtual void updateProgress ()=0
 

Protected Attributes

bool executing_
 
bool reset_
 

Detailed Description

Derived classes are advised not to derive from this directly, but rather used the classes WorkspaceBasedParallelIterator or OperationBasedParallelIterator.

This class does not inherit from either Operation or Workspace, as it leaves this option up to the derived class as to how they want the iteration to be implemented. Instead, derived classes should pass a reference of themselves to the base class constructor. If the WorkspaceBasedParallelIterator or OperationBasedParallelIterator classes are used, this is automatically handled for the developer.

Member Enumeration Documentation

◆ ExecutionResult

Enumerator
Abort 
Success 
Retry 

Constructor & Destructor Documentation

◆ IteratingOperationBase()

◆ ~IteratingOperationBase()

virtual ~IteratingOperationBase ( )
virtualdefault

Member Function Documentation

◆ atEndCondition()

virtual bool atEndCondition ( )
protectedpure virtual

Invoked to test the end condition after each loop iteration.

Returns
true if the loop is at its end condition, false otherwise. Returning true will cause the loop to terminate without completing any further iterations.

Implemented in ParallelIteratingOperation< Derived >, and ParallelIteratingOperation< CountedLoop >.

◆ executeIteration()

virtual ExecutionResult executeIteration ( Workspace workspaceToExecute)
protectedpure virtual
Parameters
workspaceToExecuteThe workspace of which to execute an iteration. This will be provided as 'null' if the derived class does not ensure that setWorkspaceToExecute() is invoked prior to execution. It's up to derived classes whether or not this is an error.

Invoked for each iteration of the workspace under execution. Derived classes can override this to control exactly how this execution occurs. For example, it could execute immediately, or it could be scheduled for future execution.

Returns
true if the execution succeeded, false otherwise.

Implemented in ParallelIteratingOperation< Derived >, and ParallelIteratingOperation< CountedLoop >.

◆ getWorkspaceToExecute()

Workspace * getWorkspaceToExecute ( )
protected
Returns
The workspace that this iterator is to execute repeatedly.

◆ isExecuting()

bool isExecuting ( ) const
protected
Returns
true if the iterator is currently iterating, false otherwise.

◆ isLoopConditionValid()

virtual bool isLoopConditionValid ( ) const
protectedpure virtual

Derived classes must override this method to specify when a loop termination condition is infinite. Workspace can then terminate the loop with an error if this is achieved. To allow infinite loops, simply return false from this method always.

Returns
true if the loop condition is infinite, false otherwise.

Implemented in ParallelIteratingOperation< Derived >, and ParallelIteratingOperation< CountedLoop >.

◆ performCleanup()

virtual void performCleanup ( Workspace workspaceToExecute,
bool  forceStop 
)
protectedpure virtual
Parameters
workspaceToExecuteThe specific workspace that has been executed for a given iteration.
forceStopIf true, will force the loop to stop iterating.

Cleanup opportunity following the attempted execution of iterations. Regardless of how the execution terminates (aborted or successful), this method is invoked. Must not throw exceptions.

Implemented in IteratingOperation< Derived >, IteratingOperation< CountedLoop >, ParallelIteratingOperation< Derived >, and ParallelIteratingOperation< CountedLoop >.

◆ performInitialisation()

virtual bool performInitialisation ( Workspace workspaceToExecute)
protectedpure virtual
Parameters
workspaceToExecuteThe template workspace of which to execute an iteration. This will be provided as 'null' if the derived class does not ensure that setWorkspaceToExecute() is invoked prior to execution. This may or may not be an error for the specific workspace involved.

Initialises the loop prior to execution of any iterations.

Implemented in IteratingOperation< Derived >, IteratingOperation< CountedLoop >, ParallelIteratingOperation< Derived >, and ParallelIteratingOperation< CountedLoop >.

◆ postIterationExecute()

bool postIterationExecute ( )
protectedvirtual
Returns
true if the method executed successfully, false otherwise.

Invoked immediately following the successful execution of an iteration. Default implementation does nothing, returning true.

Reimplemented in ParallelIteratingOperation< Derived >, and ParallelIteratingOperation< CountedLoop >.

◆ preIterations()

virtual bool preIterations ( )
protectedpure virtual

Invoked immediately prior to the commencement of any iterations. If 'wrap' is enabled, this will be invoked prior to each set of iterations.

Returns
false if an error occurs and the loop should be terminated, true otherwise.

Implemented in IteratingOperation< Derived >, IteratingOperation< CountedLoop >, ParallelIteratingOperation< Derived >, and ParallelIteratingOperation< CountedLoop >.

◆ setNonIterationControlInputsNotUpToDate()

void setNonIterationControlInputsNotUpToDate ( )
protectedvirtual

Sets the non-iteration-control inputs to not-up-to-date at the beginning of each iteration. Derived classes must override this and may choose to not avail of the functionality or perform it differently depending on the need of the specific derived class.

Invoked immediately following preIterations(). Default implementation does nothing. Override if needed.

Reimplemented in IteratingOperation< Derived >, IteratingOperation< CountedLoop >, ParallelIteratingOperation< Derived >, and ParallelIteratingOperation< CountedLoop >.

◆ setWorkspaceToExecute()

void setWorkspaceToExecute ( Workspace workspace)
protected
Parameters
workspaceThe workspace that this iterator should execute repeatedly. Can be null if the derived class supports executing sub-setions of a workflow.

◆ updateInputsForIteration()

virtual bool updateInputsForIteration ( )
protectedpure virtual

Forces derived classes to specify how the iteration's input values are updated for each iteration of the loop. For most operations, this will be as simple as assigning a value to an input or an output (for operation-based iterators) and then flipping its up-to-date status to false, then back to true.

For example, in the counted loop:

*outputCounterValue_ = counterValue;
outputCounterValue_.setUpToDate(false);
outputCounterValue_.setUpToDate(true);
Returns
true if the inputs were able to be updated successfully, false otherwise.

Implemented in CountedLoop, IteratingOperation< Derived >, and IteratingOperation< CountedLoop >.

◆ updateProgress()

virtual void updateProgress ( )
protectedpure virtual

Updates its parent operation's progress at the start of each iteration. Derived classes must override this to specify how progress is indicated, as it will change depending on how iteration is computed.

Implemented in ParallelIteratingOperation< Derived >, and ParallelIteratingOperation< CountedLoop >.

Member Data Documentation

◆ executing_

bool executing_
protected

◆ reset_

bool reset_
protected