aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Workflow/Workflow.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-04-26 14:07:28 -0700
committerrtk0c <[email protected]>2021-04-26 14:07:28 -0700
commitb7d5b514e7bffd3149a99bc7f1424f8251876d85 (patch)
tree42f2867875c0b367fab2a6db7be395f8c777eb41 /core/src/Model/Workflow/Workflow.hpp
parente7afe82857ac3ccc3e10b40cee60ea94cc59232b (diff)
Serialization for workflow stuff
Diffstat (limited to 'core/src/Model/Workflow/Workflow.hpp')
-rw-r--r--core/src/Model/Workflow/Workflow.hpp40
1 files changed, 35 insertions, 5 deletions
diff --git a/core/src/Model/Workflow/Workflow.hpp b/core/src/Model/Workflow/Workflow.hpp
index 9c02168..db341af 100644
--- a/core/src/Model/Workflow/Workflow.hpp
+++ b/core/src/Model/Workflow/Workflow.hpp
@@ -6,6 +6,7 @@
#include <cstddef>
#include <cstdint>
+#include <iosfwd>
#include <limits>
#include <memory>
#include <span>
@@ -41,6 +42,10 @@ public:
std::span<const ConnectionPoint> GetSourcePoints() const;
std::span<ConnectionPoint> GetDestinationPoints();
std::span<const ConnectionPoint> GetDestinationPoints() const;
+
+ void DrawDebugInfo() const;
+ void ReadFrom(std::istream& stream);
+ void WriteTo(std::ostream& stream);
};
class WorkflowNode {
@@ -71,7 +76,7 @@ public:
protected:
struct InputPin {
size_t Connection = WorkflowConnection::kInvalidId;
- BaseValue::Kind MatchingType = BaseValue::KindInvalid;
+ BaseValue::Kind MatchingType = BaseValue::InvalidKind;
bool ConnectionToConst = false;
bool AllowsMultipleConnections = false;
@@ -84,7 +89,7 @@ protected:
struct OutputPin {
size_t Connection = WorkflowConnection::kInvalidId;
- BaseValue::Kind MatchingType = BaseValue::KindInvalid;
+ BaseValue::Kind MatchingType = BaseValue::InvalidKind;
bool AllowsMultipleConnections = false;
bool IsConnected() const;
@@ -100,11 +105,14 @@ protected:
std::vector<InputPin> mInputs;
std::vector<OutputPin> mOutputs;
Vec2i mPosition;
- Type mType;
Kind mKind;
int mDepth;
public:
+ static const char* FormatKind(Kind kind);
+ static const char* FormatType(Type type);
+ static std::unique_ptr<WorkflowNode> CreateByKind(Kind kind);
+
WorkflowNode(Type type, Kind kind);
virtual ~WorkflowNode() = default;
@@ -113,14 +121,17 @@ public:
WorkflowNode(WorkflowNode&&) = default;
WorkflowNode& operator=(WorkflowNode&&) = default;
- Vec2i GetPosition() const;
void SetPosition(const Vec2i& position);
+ Vec2i GetPosition() const;
size_t GetId() const;
- Type GetType() const;
Kind GetKind() const;
int GetDepth() const;
+ Type GetType() const;
+ bool IsInputNode() const;
+ bool IsOutputNode() const;
+
void ConnectInput(int nodeId, WorkflowNode& output, int outputNodeId);
void DisconnectInput(int nodeId);
bool IsInputConnected(int nodeId) const;
@@ -131,6 +142,15 @@ public:
virtual void Evaluate(WorkflowEvaluationContext& ctx) = 0;
+ void Draw();
+ virtual void DrawExtra() {}
+
+ void DrawDebugInfo() const;
+ virtual void DrawExtraDebugInfo() const {}
+
+ virtual void ReadFrom(std::istream& istream);
+ virtual void WriteTo(std::ostream& ostream);
+
protected:
InputPin& InsertInputPin(int atIdx);
void RemoveInputPin(int pin);
@@ -153,6 +173,9 @@ private:
std::vector<std::unique_ptr<WorkflowNode>> mNodes;
std::vector<std::unique_ptr<BaseValue>> mConstants;
std::vector<std::vector<size_t>> mDepthGroups;
+ int mConnectionCount;
+ int mNodeCount;
+ int mConstantCount;
bool mDepthsDirty = true;
public:
@@ -190,6 +213,13 @@ public:
/// When `getInfo == false, the corresponding error code is returned but without/with empty payloads.
GraphUpdateResult UpdateGraph(bool getInfo = true);
+ enum ReadResult {
+ ReadSuccess,
+ ReadInvalidVersion,
+ };
+ ReadResult ReadFrom(std::istream& stream);
+ void WriteTo(std::ostream& stream);
+
private:
std::pair<WorkflowConnection&, size_t> AllocWorkflowConnection();
std::pair<std::unique_ptr<WorkflowNode>&, size_t> AllocWorkflowStep();