From 4e5730e1fcef150ce2f13f52a278890589ca96ad Mon Sep 17 00:00:00 2001 From: rtk0c Date: Fri, 16 Apr 2021 16:49:28 -0700 Subject: More work on workflows - WorkflowStep -> WorkflowNode - Added initial kinds of WorkflowNode's --- core/src/Model/EvaluatedValue.cpp | 49 +++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) (limited to 'core/src/Model/EvaluatedValue.cpp') diff --git a/core/src/Model/EvaluatedValue.cpp b/core/src/Model/EvaluatedValue.cpp index c86f00b..685d50f 100644 --- a/core/src/Model/EvaluatedValue.cpp +++ b/core/src/Model/EvaluatedValue.cpp @@ -1,15 +1,32 @@ #include "EvaluatedValue.hpp" -BaseValue::BaseValue(Type type) - : mType{ type } { +#include + +BaseValue::BaseValue(Kind kind) + : mKind{ kind } { +} + +BaseValue::Kind BaseValue::GetKind() const { + return mKind; } -BaseValue::Type BaseValue::GetType() const { - return mType; +bool NumericValue::IsInstance(const BaseValue* value) { + return value->GetKind() == KD_Numeric; } NumericValue::NumericValue() - : BaseValue(BaseValue::NumericType) { + : BaseValue(BaseValue::KD_Numeric) { +} + +std::string NumericValue::GetString() const { + char buf[64]; + auto res = std::to_chars(buf, buf + std::size(buf), mValue); + if (res.ec == std::errc()) { + return std::string(buf, res.ptr); + } else { + // TODO larger buffer + return ""; + } } int64_t NumericValue::GetInt() const { @@ -24,8 +41,12 @@ void NumericValue::SetValue(double value) { mValue = value; } +bool TextValue::IsInstance(const BaseValue* value) { + return value->GetKind() == KD_Text; +} + TextValue::TextValue() - : BaseValue(BaseValue::TextType) { + : BaseValue(BaseValue::KD_Text) { } const std::string& TextValue::GetValue() const { @@ -36,8 +57,22 @@ void TextValue::SetValue(const std::string& value) { mValue = value; } +bool DateTimeValue::IsInstance(const BaseValue* value) { + return value->GetKind() == KD_DateTime; +} + DateTimeValue::DateTimeValue() - : BaseValue(BaseValue::DateTimeType) { + : BaseValue(BaseValue::KD_DateTime) { +} + +std::string DateTimeValue::GetString() const { + namespace chrono = std::chrono; + auto t = chrono::system_clock::to_time_t(mValue); + + char data[32]; + std::strftime(data, sizeof(data), "%Y-%m-%d %H:%M:%S", std::localtime(&t)); + + return std::string(data); } const std::chrono::time_point& DateTimeValue::GetValue() const { -- cgit v1.2.3-70-g09d2