aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Workflow/Values/BasicValues.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-04-28 15:18:51 -0700
committerrtk0c <[email protected]>2021-04-28 15:18:51 -0700
commit00fd95526677d670d002ca81069636f0f74b91f7 (patch)
treea783f05be218a58c2b78175425f7576664c3f1a9 /core/src/Model/Workflow/Values/BasicValues.cpp
parentb7d5b514e7bffd3149a99bc7f1424f8251876d85 (diff)
Code cleanup, fix database view paging and selection
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);
}