#include "Workflow.hpp" #include #include #include #include #include #include #include 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 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::CreateByKind(WorkflowNode::Kind kind) { switch (kind) { case KD_NumericAddition: return std::make_unique(NumericOperationNode::Addition); case KD_NumericSubtraction: return std::make_unique(NumericOperationNode::Subtraction); case KD_NumericMultiplication: return std::make_unique(NumericOperationNode::Multiplication); case KD_NumericDivision: return std::make_unique(NumericOperationNode::Division); case KD_NumericExpression: return std::make_unique(); case KD_TextFormatting: return std::make_unique(); case KD_DocumentTemplateExpansion: return std::make_unique(); case KD_FormInput: return std::make_unique(); case KD_DatabaseRowsInput: return std::make_unique(); case InvalidKind: break; } return nullptr; } bool WorkflowNode::IsInstance(const WorkflowNode* node) { return true; }