Initial commit
This commit is contained in:
Executable
+257
@@ -0,0 +1,257 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wfr/common/types/LwdTypes.h>
|
||||
#include <wfr/common/types/WfsTypes.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
namespace wfr {
|
||||
namespace wfs {
|
||||
|
||||
// forward declarations
|
||||
class Workflow;
|
||||
class WorkflowTemplate;
|
||||
class Activity;
|
||||
class AtomicActivityImplementation;
|
||||
class AtomicActivityType;
|
||||
|
||||
|
||||
class ActivityTemplate {
|
||||
friend class WorkflowTemplate;
|
||||
friend class Workflow;
|
||||
friend class Activity;
|
||||
// Mutable properties that need to be accessed via getter-/setter-functions.
|
||||
protected:
|
||||
/** Parent activity. **/
|
||||
ActivityTemplate* parentActivity = nullptr;
|
||||
|
||||
/** Parent workflow. **/
|
||||
WorkflowTemplate* parentWorkflow = nullptr;
|
||||
|
||||
// Successors
|
||||
std::initializer_list<wfr_id_t> succRawList;
|
||||
std::vector<ActivityTemplate*> successors;
|
||||
|
||||
// Predecessors
|
||||
std::initializer_list<wfr_id_t> predRawList;
|
||||
std::vector<ActivityTemplate*> predecessors;
|
||||
|
||||
// Invariant properties that can be accessed directly.
|
||||
public:
|
||||
/** Unique ID (>0).**/
|
||||
const wfr_id_t templateID;
|
||||
|
||||
const std::string activityName;
|
||||
|
||||
const ActivityType activityType;
|
||||
|
||||
const wfr_size_t parentActivityID;
|
||||
|
||||
/** BranchID of the parents execution branch (0 represents default branch). **/
|
||||
const wfr_id_t branchID;
|
||||
|
||||
const bool isCompositeActivity;
|
||||
|
||||
const bool isLoop;
|
||||
|
||||
const bool isConditional;
|
||||
|
||||
// Non-public functions.
|
||||
protected:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param id templateID of this template object.
|
||||
* @param type type of this template object.
|
||||
* @param branchID ID of the parents (structure-wise) execution branch this object belongs to.
|
||||
* @param succList list of templateIDs representing this objects successors (structure-wise).
|
||||
* @param predList list of templateIDs representing this objects predecessors (structure-wise).
|
||||
* @param name activity name of this object.
|
||||
**/
|
||||
ActivityTemplate( wfr_id_t id,
|
||||
ActivityType type,
|
||||
const std::string& name,
|
||||
wfr_id_t parentID,
|
||||
wfr_id_t branchID,
|
||||
const std::initializer_list<wfr_id_t>& succList,
|
||||
const std::initializer_list<wfr_id_t>& predList,
|
||||
bool isCompositeActivity,
|
||||
bool isLoop,
|
||||
bool isConditional ) noexcept;
|
||||
|
||||
void initActivityTemplate(WorkflowTemplate& parentWorkflow);
|
||||
|
||||
virtual void checkStructure();
|
||||
|
||||
Activity* createActivityFromTemplate(wfr::wfs::Workflow& workflow);
|
||||
|
||||
// Public functions.
|
||||
public:
|
||||
virtual ~ActivityTemplate() noexcept {}
|
||||
|
||||
ActivityTemplate* getParentActivity() const noexcept { return parentActivity;}
|
||||
|
||||
WorkflowTemplate* getParentWorkflow() const noexcept {
|
||||
assert(parentWorkflow != nullptr);
|
||||
return parentWorkflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of this objects successors.
|
||||
* @return number of successors.
|
||||
**/
|
||||
wfr_size_t getSuccessorCount() const noexcept { return successors.size(); }
|
||||
|
||||
/**
|
||||
* Returns all successors.
|
||||
* @return reference to vector with successors
|
||||
**/
|
||||
const std::vector<ActivityTemplate*>& getSuccessors() const noexcept { return successors; }
|
||||
|
||||
/**
|
||||
* Returns the successor with the given index.
|
||||
* @param index index of successor
|
||||
* @return successor with given index
|
||||
**/
|
||||
ActivityTemplate* getSuccessor(wfr_size_t index) const noexcept {
|
||||
if (index < successors.size()) {
|
||||
return successors[index];
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given activity is a successor of this object.
|
||||
* @param activity reference to test.
|
||||
* @return true if the given reference represents a successor, otherwise false.
|
||||
**/
|
||||
bool isSuccessor(const ActivityTemplate& activity) const noexcept {
|
||||
for (auto i : successors) {
|
||||
if (i == &activity) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of this objects predecessors.
|
||||
* @return number of predecessors.
|
||||
**/
|
||||
wfr_size_t getPredecessorCount() const noexcept { return predecessors.size(); }
|
||||
|
||||
/**
|
||||
* Returns all predecessors.
|
||||
* @return reference to vector with predecessors
|
||||
**/
|
||||
const std::vector<ActivityTemplate*>& getPredecessors() const noexcept { return predecessors; }
|
||||
|
||||
/**
|
||||
* Returns the predecessor with the given index.
|
||||
* @param index index of predecessor
|
||||
* @return predecessor with given index
|
||||
**/
|
||||
ActivityTemplate* getPredecessor(wfr_size_t index) const noexcept {
|
||||
if (index < predecessors.size()) {
|
||||
return predecessors[index];
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given activity is a successor of this object.
|
||||
* @param activity reference to test.
|
||||
* @return true if the given reference represents a successor, otherwise false.
|
||||
**/
|
||||
bool isPredecessor(const ActivityTemplate& activity) const noexcept {
|
||||
for (auto i : predecessors) {
|
||||
if (i == &activity) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& as() noexcept { return *static_cast<T*>(this); }
|
||||
|
||||
template<class T>
|
||||
const T& as() const noexcept { return *static_cast<const T*>(this); }
|
||||
|
||||
|
||||
/* ********************************************************** *
|
||||
* Convenience functions for activity template instantiation. *
|
||||
* ********************************************************** */
|
||||
public:
|
||||
|
||||
static ActivityTemplate* atomic( wfr_id_t id,
|
||||
const std::string& name,
|
||||
wfr_id_t parentID,
|
||||
wfr_id_t branchID,
|
||||
std::initializer_list<wfr_id_t> succList,
|
||||
std::initializer_list<wfr_id_t> predList,
|
||||
InputHookFunc inputHook,
|
||||
std::shared_ptr<AtomicActivityType> atomicActivityType );
|
||||
|
||||
static ActivityTemplate* assign( wfr_id_t id,
|
||||
const std::string& name,
|
||||
wfr_id_t parentID,
|
||||
wfr_id_t branchID,
|
||||
std::initializer_list<wfr_id_t> succList,
|
||||
std::initializer_list<wfr_id_t> predList,
|
||||
InputHookFunc inputHook,
|
||||
ExecutionHookFunc execHook );
|
||||
|
||||
static ActivityTemplate* container( wfr_id_t id,
|
||||
const std::string& name,
|
||||
wfr_id_t parentID,
|
||||
wfr_id_t branchID,
|
||||
std::initializer_list<wfr_id_t> succList,
|
||||
std::initializer_list<wfr_id_t> predList,
|
||||
InputHookFunc inputHook,
|
||||
OutputHookFunc outputHook );
|
||||
|
||||
static ActivityTemplate* forLoop( wfr_id_t id,
|
||||
const std::string& name,
|
||||
wfr_id_t parentID,
|
||||
wfr_id_t branchID,
|
||||
const std::initializer_list<wfr_id_t>& succList,
|
||||
const std::initializer_list<wfr_id_t>& predList,
|
||||
InputHookFunc inputFuncHook,
|
||||
OutputHookFunc outputFuncHook,
|
||||
ForCounterHookFunc counterFuncHook,
|
||||
LoopIterationHookFunc iterationFuncHook,
|
||||
bool isParallel );
|
||||
|
||||
static ActivityTemplate* whileLoop( wfr_id_t id,
|
||||
const std::string& name,
|
||||
wfr_id_t parentID,
|
||||
wfr_id_t branchID,
|
||||
const std::initializer_list<wfr_id_t>& succList,
|
||||
const std::initializer_list<wfr_id_t>& predList,
|
||||
InputHookFunc inputFuncHook,
|
||||
OutputHookFunc outputFuncHook,
|
||||
WhileConditionHookFunc conditionFuncHook,
|
||||
LoopIterationHookFunc iterationFuncHook );
|
||||
|
||||
static ActivityTemplate* conditional( wfr_id_t id,
|
||||
const std::string& name,
|
||||
wfr_id_t parentID,
|
||||
wfr_id_t branchID,
|
||||
const std::initializer_list<wfr_id_t>& succList,
|
||||
const std::initializer_list<wfr_id_t>& predList,
|
||||
InputHookFunc inputFuncHook,
|
||||
OutputHookFunc outputFuncHook,
|
||||
BranchConditionHookFunc branchFuncHook );
|
||||
};
|
||||
|
||||
|
||||
} /* namespace wfs */
|
||||
} /* namespace wfr */
|
||||
|
||||
Reference in New Issue
Block a user