From 7fe47a9d5b1727a61dc724523b530762f6d6ba19 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Thu, 30 Jun 2022 21:38:53 -0700 Subject: Restructure project --- app/source/Cplt/Model/Workflow/Values/Basic.cpp | 111 ++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 app/source/Cplt/Model/Workflow/Values/Basic.cpp (limited to 'app/source/Cplt/Model/Workflow/Values/Basic.cpp') diff --git a/app/source/Cplt/Model/Workflow/Values/Basic.cpp b/app/source/Cplt/Model/Workflow/Values/Basic.cpp new file mode 100644 index 0000000..198387c --- /dev/null +++ b/app/source/Cplt/Model/Workflow/Values/Basic.cpp @@ -0,0 +1,111 @@ +#include "Basic.hpp" + +#include +#include +#include + +bool NumericValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_Numeric; +} + +NumericValue::NumericValue() + : BaseValue(BaseValue::KD_Numeric) +{ +} + +template +static std::string NumberToString(T value) +{ + char buf[kMaxSize]; + auto res = std::to_chars(buf, buf + kMaxSize, value); + if (res.ec == std::errc()) { + return std::string(buf, res.ptr); + } else { + return ""; + } +} + +std::string NumericValue::GetTruncatedString() const +{ + constexpr auto kMaxSize = std::numeric_limits::digits10; + return ::NumberToString((int64_t)mValue); +} + +std::string NumericValue::GetRoundedString() const +{ + constexpr auto kMaxSize = std::numeric_limits::digits10; + return ::NumberToString((int64_t)std::round(mValue)); +} + +std::string NumericValue::GetString() const +{ + constexpr auto kMaxSize = std::numeric_limits::max_digits10; + return ::NumberToString(mValue); +} + +int64_t NumericValue::GetInt() const +{ + return static_cast(mValue); +} + +double NumericValue::GetValue() const +{ + return mValue; +} + +void NumericValue::SetValue(double value) +{ + mValue = value; +} + +bool TextValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_Text; +} + +TextValue::TextValue() + : BaseValue(BaseValue::KD_Text) +{ +} + +const std::string& TextValue::GetValue() const +{ + return mValue; +} + +void TextValue::SetValue(const std::string& value) +{ + mValue = value; +} + +bool DateTimeValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_DateTime; +} + +DateTimeValue::DateTimeValue() + : 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 +{ + return mValue; +} + +void DateTimeValue::SetValue(const std::chrono::time_point& value) +{ + mValue = value; +} -- cgit v1.2.3-70-g09d2