diff options
author | rtk0c <[email protected]> | 2021-04-14 15:09:13 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-04-14 15:09:13 -0700 |
commit | 80d8ae5a6fef6c9a34e81e240539cb655dd99851 (patch) | |
tree | 062bb1590eaf030b75aae75acecc5706e16d9b0c /core/src/Model/Workflow.hpp | |
parent | 568fcc1dfe40c37b57b7baa2dea93b291d3fa956 (diff) |
Initial work on workflows
Diffstat (limited to 'core/src/Model/Workflow.hpp')
-rw-r--r-- | core/src/Model/Workflow.hpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/core/src/Model/Workflow.hpp b/core/src/Model/Workflow.hpp new file mode 100644 index 0000000..a90ef21 --- /dev/null +++ b/core/src/Model/Workflow.hpp @@ -0,0 +1,101 @@ +#pragma once + +#include "EvaluatedValue.hpp" + +#include <cstddef> +#include <cstdint> +#include <limits> +#include <memory> +#include <vector> + +class WorkflowConnection { +public: + size_t Source; + size_t Destination; +}; + +class WorkflowStep { +public: + static constexpr auto kInvalidId = std::numeric_limits<size_t>::max(); + + // TODO do we even need this? + // enum Type { + // NumericAdditionType, + // NumericSubtractionType, + // NumericMultiplicationType, + // NumericDivisionType, + // NumericExpressionType, + // TextFormattingType, + // FormInputType, + // DatabaseRowsInputType, + // DocumentTemplateExpansionType, + // + // InvalidType, + // TypeCount = InvalidType, + // }; + +protected: + struct InputNode { + size_t ConnectedStep = kInvalidId; + int ConnectedNodeIndex = -1; + BaseValue::Type MatchingType = BaseValue::InvalidType; + + bool IsConnected() const; + }; + + struct OutputNode { + size_t ConnectedStep = kInvalidId; + int ConnectedNodeIndex = -1; + BaseValue::Type MatchingType = BaseValue::InvalidType; + + bool IsConnected() const; + }; + + friend class Workflow; + Workflow* mWorkflow; + size_t mId; + std::vector<InputNode> mInputs; + std::vector<OutputNode> mOutputs; + +public: + virtual ~WorkflowStep() = default; + + WorkflowStep(const WorkflowStep&) = delete; + WorkflowStep& operator=(const WorkflowStep&) = delete; + WorkflowStep(WorkflowStep&&) = default; + WorkflowStep& operator=(WorkflowStep&&) = default; + + size_t GetId() const; + + void ConnectInput(int nodeId, size_t outputId, int outputNodeId); + void DisconnectInput(int nodeId); + bool IsInputConnected(int nodeId) const; + + void ConnectOutput(int nodeId, size_t inputId, int inputNodeId); + void DisconnectOutput(int nodeId); + bool IsOutputConnected(int nodeId) const; + +protected: + /// Child classes should call this whenever \c mInputs and \c mOutputs are about to be modified (append or remove) + /// after invocation of the constructor. + void OnIOAboutToChange(); + void OnIOChanged(); +}; + +class Workflow { +private: + std::vector<WorkflowConnection> mConnections; + std::vector<std::unique_ptr<WorkflowStep>> mSteps; + +public: + WorkflowConnection* GetConnectionById(size_t id); + WorkflowStep* GetStepById(size_t id); + + void Connect(size_t source, int sourceNode, size_t destination, int destinationNode); + void DisconnectBySource(size_t source, int sourceNode); + void DisconnectByDestination(size_t destination, int destinationNode); +}; + +class WorkflowEvaluationContext { + +}; |