aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Model/Workflow/Workflow_RTTI.cpp
blob: 6b8f76e21dc3ff8fd3185a2efec8b2133478191b (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "Workflow.hpp"

#include <Cplt/Model/Workflow/Nodes/DocumentNodes.hpp>
#include <Cplt/Model/Workflow/Nodes/NumericNodes.hpp>
#include <Cplt/Model/Workflow/Nodes/TextNodes.hpp>
#include <Cplt/Model/Workflow/Nodes/UserInputNodes.hpp>
#include <Cplt/Utils/I18n.hpp>
#include <Cplt/Utils/Macros.hpp>

#include <memory>

const char* WorkflowNode::FormatKind(Kind kind) {
	switch (kind) {
		case KD_NumericAddition: return I18N_TEXT("Add", L10N_WORKFLOW_ADD);
		case KD_NumericSubtraction: return I18N_TEXT("Subtract", L10N_WORKFLOW_SUB);
		case KD_NumericMultiplication: return I18N_TEXT("Multiply", L10N_WORKFLOW_MUL);
		case KD_NumericDivision: return I18N_TEXT("Divide", L10N_WORKFLOW_DIV);
		case KD_NumericExpression: return I18N_TEXT("Evaluate expression", L10N_WORKFLOW_EVAL);
		case KD_TextFormatting: return I18N_TEXT("Format text", L10N_WORKFLOW_FMT);
		case KD_DocumentTemplateExpansion: return I18N_TEXT("Expand template", L10N_WORKFLOW_INSTANTIATE_TEMPLATE);
		case KD_FormInput: return I18N_TEXT("Form input", L10N_WORKFLOW_FORM_INPUT);
		case KD_DatabaseRowsInput: return I18N_TEXT("Database input", L10N_WORKFLOW_DB_INPUT);

		case InvalidKind: break;
	}
	return "";
}

const char* WorkflowNode::FormatCategory(WorkflowNode::Category category) {
	switch (category) {
		case CG_Numeric: return I18N_TEXT("Numeric", L10N_WORKFLOW_CATEGORY_NUMERIC);
		case CG_Text: return I18N_TEXT("Text", L10N_WORKFLOW_CATEGORY_TEXT);
		case CG_Document: return I18N_TEXT("Document", L10N_WORKFLOW_CATEGORY_DOCUMENT);
		case CG_UserInput: return I18N_TEXT("User input", L10N_WORKFLOW_CATEGORY_USER_INPUT);
		case CG_SystemInput: return I18N_TEXT("System input", L10N_WORKFLOW_CATEGORY_SYS_INPUT);
		case CG_Output: return I18N_TEXT("Output", L10N_WORKFLOW_CATEGORY_OUTPUT);

		case InvalidCategory: break;
	}
	return "";
}

const char* WorkflowNode::FormatType(Type type) {
	switch (type) {
		case InputType: return I18N_TEXT("Input", L10N_WORKFLOW_KIND_INPUT);
		case TransformType: return I18N_TEXT("Transform", L10N_WORKFLOW_KIND_TRANSFORM);
		case OutputType: return I18N_TEXT("Output", L10N_WORKFLOW_KIND_OUTPUT);
	}
	return "";
}

WorkflowNode::Category WorkflowNode::QueryCategory(Kind kind) {
	switch (kind) {
		case KD_NumericAddition:
		case KD_NumericSubtraction:
		case KD_NumericMultiplication:
		case KD_NumericDivision:
		case KD_NumericExpression:
			return CG_Numeric;
		case KD_TextFormatting:
			return CG_Text;
		case KD_DocumentTemplateExpansion:
			return CG_Document;
		case KD_FormInput:
		case KD_DatabaseRowsInput:
			return CG_UserInput;

		case InvalidKind: break;
	}
	return InvalidCategory;
}

std::span<const WorkflowNode::Kind> WorkflowNode::QueryCategoryMembers(Category category) {
	constexpr WorkflowNode::Kind kNumeric[] = {
		KD_NumericAddition,
		KD_NumericSubtraction,
		KD_NumericMultiplication,
		KD_NumericDivision,
		KD_NumericExpression,
	};

	constexpr WorkflowNode::Kind kText[] = {
		KD_TextFormatting,
	};

	constexpr WorkflowNode::Kind kDocument[] = {
		KD_DocumentTemplateExpansion,
	};

	constexpr WorkflowNode::Kind kUserInput[] = {
		KD_FormInput,
		KD_DatabaseRowsInput,
	};

	// TODO remove invalid kinds after we have nodes of these categories
	constexpr WorkflowNode::Kind kSystemInput[] = {
		InvalidKind,
	};

	constexpr WorkflowNode::Kind kOutput[] = {
		InvalidKind,
	};

	switch (category) {
		case CG_Numeric: return kNumeric;
		case CG_Text: return kText;
		case CG_Document: return kDocument;
		case CG_UserInput: return kUserInput;
		case CG_SystemInput: return kSystemInput;
		case CG_Output: return kOutput;

		case InvalidCategory: break;
	}
	return {};
}

std::unique_ptr<WorkflowNode> WorkflowNode::CreateByKind(WorkflowNode::Kind kind) {
	switch (kind) {
		case KD_NumericAddition: return std::make_unique<NumericOperationNode>(NumericOperationNode::Addition);
		case KD_NumericSubtraction: return std::make_unique<NumericOperationNode>(NumericOperationNode::Subtraction);
		case KD_NumericMultiplication: return std::make_unique<NumericOperationNode>(NumericOperationNode::Multiplication);
		case KD_NumericDivision: return std::make_unique<NumericOperationNode>(NumericOperationNode::Division);
		case KD_NumericExpression: return std::make_unique<NumericExpressionNode>();
		case KD_TextFormatting: return std::make_unique<TextFormatterNode>();
		case KD_DocumentTemplateExpansion: return std::make_unique<DocumentTemplateExpansionNode>();
		case KD_FormInput: return std::make_unique<FormInputNode>();
		case KD_DatabaseRowsInput: return std::make_unique<DatabaseRowsInputNode>();

		case InvalidKind: break;
	}
	return nullptr;
}

bool WorkflowNode::IsInstance(const WorkflowNode* node) {
	return true;
}