aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Model/Workflow/Evaluation.hpp
blob: 5b8c6cc12c39ec67b6f214964e6c1d3d8dfdae91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once

#include <Cplt/Model/Workflow/Workflow.hpp>

#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>

class WorkflowEvaluationError
{
public:
	enum MessageType : int16_t
	{
		Error,
		Warning,
	};

	enum PinType : int16_t
	{
		NoPin,
		InputPin,
		OutputPin,
	};

public:
	std::string Message;
	size_t NodeId;
	int PinId;
	PinType PinType;
	MessageType Type;

public:
	static const char* FormatMessageType(enum MessageType messageType);
	static const char* FormatPinType(enum PinType pinType);

	std::string Format() const;
};

class WorkflowEvaluationContext
{
private:
	struct RuntimeNode;
	struct RuntimeConnection;

	Workflow* mWorkflow;
	std::vector<RuntimeNode> mRuntimeNodes;
	std::vector<RuntimeConnection> mRuntimeConnections;
	std::vector<WorkflowEvaluationError> mErrors;
	std::vector<WorkflowEvaluationError> mWarnings;

public:
	WorkflowEvaluationContext(Workflow& workflow);

	BaseValue* GetConnectionValue(size_t id, bool constant);
	BaseValue* GetConnectionValue(const WorkflowNode::InputPin& inputPin);
	void SetConnectionValue(size_t id, std::unique_ptr<BaseValue> value);
	void SetConnectionValue(const WorkflowNode::OutputPin& outputPin, std::unique_ptr<BaseValue> value);

	void ReportError(std::string message, const WorkflowNode& node, int pinId, bool inputPin);
	void ReportError(std::string message, const WorkflowNode& node);
	void ReportWarning(std::string message, const WorkflowNode& node, int pinId, bool inputPin);
	void ReportWarning(std::string message, const WorkflowNode& node);

	/// Run until all possible paths have been evaluated.
	void Run();
};