summaryrefslogtreecommitdiff
path: root/core/src/Model/EvaluatedValue.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-04-16 16:49:28 -0700
committerrtk0c <[email protected]>2021-04-16 16:49:28 -0700
commit4e5730e1fcef150ce2f13f52a278890589ca96ad (patch)
tree0fe4002349047c7c770754e273d6a1d1ed666cbb /core/src/Model/EvaluatedValue.cpp
parent80d8ae5a6fef6c9a34e81e240539cb655dd99851 (diff)
More work on workflows
- WorkflowStep -> WorkflowNode - Added initial kinds of WorkflowNode's
Diffstat (limited to 'core/src/Model/EvaluatedValue.cpp')
-rw-r--r--core/src/Model/EvaluatedValue.cpp49
1 files changed, 42 insertions, 7 deletions
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 <charconv>
+
+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 "<err>";
+ }
}
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<std::chrono::system_clock>& DateTimeValue::GetValue() const {