aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Workflow/Values/BasicValues.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/Model/Workflow/Values/BasicValues.cpp')
-rw-r--r--core/src/Model/Workflow/Values/BasicValues.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/core/src/Model/Workflow/Values/BasicValues.cpp b/core/src/Model/Workflow/Values/BasicValues.cpp
index fd70acd..11d30b7 100644
--- a/core/src/Model/Workflow/Values/BasicValues.cpp
+++ b/core/src/Model/Workflow/Values/BasicValues.cpp
@@ -1,6 +1,7 @@
#include "BasicValues.hpp"
#include <charconv>
+#include <limits>
bool NumericValue::IsInstance(const BaseValue* value) {
return value->GetKind() == KD_Numeric;
@@ -10,17 +11,31 @@ 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);
+template <class T>
+static std::string NumberToString(T value) {
+ constexpr auto kSize = std::numeric_limits<T>::max_digits10;
+ char buf[kSize];
+
+ auto res = std::to_chars(buf, buf + kSize, value);
if (res.ec == std::errc()) {
return std::string(buf, res.ptr);
} else {
- // TODO larger buffer
return "<err>";
}
}
+std::string NumericValue::GetTruncatedString() const {
+ return ::NumberToString((int64_t)mValue);
+}
+
+std::string NumericValue::GetRoundedString() const {
+ return ::NumberToString((int64_t)std::round(mValue));
+}
+
+std::string NumericValue::GetString() const {
+ return ::NumberToString(mValue);
+}
+
int64_t NumericValue::GetInt() const {
return static_cast<int64_t>(mValue);
}