diff options
Diffstat (limited to 'core/src/Model/Workflow/Values')
-rw-r--r-- | core/src/Model/Workflow/Values/BasicValues.cpp | 76 | ||||
-rw-r--r-- | core/src/Model/Workflow/Values/BasicValues.hpp | 46 | ||||
-rw-r--r-- | core/src/Model/Workflow/Values/fwd.hpp | 6 |
3 files changed, 128 insertions, 0 deletions
diff --git a/core/src/Model/Workflow/Values/BasicValues.cpp b/core/src/Model/Workflow/Values/BasicValues.cpp new file mode 100644 index 0000000..fd70acd --- /dev/null +++ b/core/src/Model/Workflow/Values/BasicValues.cpp @@ -0,0 +1,76 @@ +#include "BasicValues.hpp" + +#include <charconv> + +bool NumericValue::IsInstance(const BaseValue* value) { + return value->GetKind() == KD_Numeric; +} + +NumericValue::NumericValue() + : 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 "<err>"; + } +} + +int64_t NumericValue::GetInt() const { + return static_cast<int64_t>(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<std::chrono::system_clock>& DateTimeValue::GetValue() const { + return mValue; +} + +void DateTimeValue::SetValue(const std::chrono::time_point<std::chrono::system_clock>& value) { + mValue = value; +} diff --git a/core/src/Model/Workflow/Values/BasicValues.hpp b/core/src/Model/Workflow/Values/BasicValues.hpp new file mode 100644 index 0000000..a116c8c --- /dev/null +++ b/core/src/Model/Workflow/Values/BasicValues.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include "Model/Workflow/Value.hpp" + +#include <chrono> +#include <cstdint> +#include <string> + +class NumericValue : public BaseValue { +private: + double mValue; + +public: + static bool IsInstance(const BaseValue* value); + NumericValue(); + + std::string GetString() const; + int64_t GetInt() const; + double GetValue() const; + void SetValue(double value); +}; + +class TextValue : public BaseValue { +private: + std::string mValue; + +public: + static bool IsInstance(const BaseValue* value); + TextValue(); + + const std::string& GetValue() const; + void SetValue(const std::string& value); +}; + +class DateTimeValue : public BaseValue { +private: + std::chrono::time_point<std::chrono::system_clock> mValue; + +public: + static bool IsInstance(const BaseValue* value); + DateTimeValue(); + + std::string GetString() const; + const std::chrono::time_point<std::chrono::system_clock>& GetValue() const; + void SetValue(const std::chrono::time_point<std::chrono::system_clock>& value); +}; diff --git a/core/src/Model/Workflow/Values/fwd.hpp b/core/src/Model/Workflow/Values/fwd.hpp new file mode 100644 index 0000000..24f8119 --- /dev/null +++ b/core/src/Model/Workflow/Values/fwd.hpp @@ -0,0 +1,6 @@ +#pragma once + +// BasicValues.hpp +class NumericValue; +class TextValue; +class DateTimeValue; |