diff options
Diffstat (limited to 'core/src/Model/Workflow/Nodes/TextNodes.cpp')
-rw-r--r-- | core/src/Model/Workflow/Nodes/TextNodes.cpp | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/core/src/Model/Workflow/Nodes/TextNodes.cpp b/core/src/Model/Workflow/Nodes/TextNodes.cpp index 72bd666..944fc07 100644 --- a/core/src/Model/Workflow/Nodes/TextNodes.cpp +++ b/core/src/Model/Workflow/Nodes/TextNodes.cpp @@ -11,10 +11,12 @@ #include <variant> #include <vector> -class TextFormatterNode::Impl { +class TextFormatterNode::Impl +{ public: template <class TFunction> - static void ForArguments(std::vector<Element>::iterator begin, std::vector<Element>::iterator end, const TFunction& func) { + static void ForArguments(std::vector<Element>::iterator begin, std::vector<Element>::iterator end, const TFunction& func) + { for (auto it = begin; it != end; ++it) { auto& elm = *it; if (auto arg = std::get_if<Argument>(&elm)) { @@ -24,7 +26,8 @@ public: } /// Find the pin index that the \c elmIdx -th element should have, based on the elements coming before it. - static int FindPinForElement(const std::vector<Element>& vec, int elmIdx) { + static int FindPinForElement(const std::vector<Element>& vec, int elmIdx) + { for (int i = elmIdx; i >= 0; --i) { auto& elm = vec[i]; if (auto arg = std::get_if<Argument>(&elm)) { @@ -35,7 +38,8 @@ public: } }; -BaseValue::Kind TextFormatterNode::ArgumentTypeToValueKind(TextFormatterNode::ArgumentType arg) { +BaseValue::Kind TextFormatterNode::ArgumentTypeToValueKind(TextFormatterNode::ArgumentType arg) +{ switch (arg) { case NumericArgument: return BaseValue::KD_Numeric; case TextArgument: return BaseValue::KD_Text; @@ -44,23 +48,28 @@ BaseValue::Kind TextFormatterNode::ArgumentTypeToValueKind(TextFormatterNode::Ar } } -bool TextFormatterNode::IsInstance(const WorkflowNode* node) { +bool TextFormatterNode::IsInstance(const WorkflowNode* node) +{ return node->GetKind() == KD_TextFormatting; } TextFormatterNode::TextFormatterNode() - : WorkflowNode(KD_TextFormatting) { + : WorkflowNode(KD_TextFormatting) +{ } -int TextFormatterNode::GetElementCount() const { +int TextFormatterNode::GetElementCount() const +{ return mElements.size(); } -const TextFormatterNode::Element& TextFormatterNode::GetElement(int idx) const { +const TextFormatterNode::Element& TextFormatterNode::GetElement(int idx) const +{ return mElements[idx]; } -void TextFormatterNode::SetElement(int idx, std::string text) { +void TextFormatterNode::SetElement(int idx, std::string text) +{ assert(idx >= 0 && idx < mElements.size()); std::visit( @@ -74,7 +83,8 @@ void TextFormatterNode::SetElement(int idx, std::string text) { mElements[idx] = std::move(text); } -void TextFormatterNode::SetElement(int idx, ArgumentType argument) { +void TextFormatterNode::SetElement(int idx, ArgumentType argument) +{ assert(idx >= 0 && idx < mElements.size()); std::visit( @@ -106,7 +116,8 @@ void TextFormatterNode::SetElement(int idx, ArgumentType argument) { mElements[idx]); } -void TextFormatterNode::InsertElement(int idx, std::string text) { +void TextFormatterNode::InsertElement(int idx, std::string text) +{ assert(idx >= 0); if (idx >= mElements.size()) AppendElement(std::move(text)); @@ -114,7 +125,8 @@ void TextFormatterNode::InsertElement(int idx, std::string text) { mElements.insert(mElements.begin() + idx, std::move(text)); } -void TextFormatterNode::InsertElement(int idx, ArgumentType argument) { +void TextFormatterNode::InsertElement(int idx, ArgumentType argument) +{ assert(idx >= 0); if (idx >= mElements.size()) AppendElement(argument); @@ -133,12 +145,14 @@ void TextFormatterNode::InsertElement(int idx, ArgumentType argument) { }); } -void TextFormatterNode::AppendElement(std::string text) { +void TextFormatterNode::AppendElement(std::string text) +{ mMinOutputChars += text.size(); mElements.push_back(std::move(text)); } -void TextFormatterNode::AppendElement(ArgumentType argument) { +void TextFormatterNode::AppendElement(ArgumentType argument) +{ int pinIdx = mInputs.size(); // Create pin mInputs.push_back(InputPin{}); @@ -150,7 +164,8 @@ void TextFormatterNode::AppendElement(ArgumentType argument) { }); } -void TextFormatterNode::RemoveElement(int idx) { +void TextFormatterNode::RemoveElement(int idx) +{ assert(idx >= 0 && idx < mElements.size()); PreRemoveElement(idx); @@ -160,7 +175,8 @@ void TextFormatterNode::RemoveElement(int idx) { mElements.erase(mElements.begin() + idx); } -void TextFormatterNode::Evaluate(WorkflowEvaluationContext& ctx) { +void TextFormatterNode::Evaluate(WorkflowEvaluationContext& ctx) +{ std::string result; result.reserve((size_t)(mMinOutputChars * 1.5f)); @@ -201,7 +217,8 @@ void TextFormatterNode::Evaluate(WorkflowEvaluationContext& ctx) { } } -void TextFormatterNode::PreRemoveElement(int idx) { +void TextFormatterNode::PreRemoveElement(int idx) +{ auto& elm = mElements[idx]; if (auto arg = std::get_if<Argument>(&elm)) { RemoveInputPin(arg->PinIdx); |