adamdebreceni commented on a change in pull request #1032:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1032#discussion_r600354264



##########
File path: libminifi/include/core/state/Value.h
##########
@@ -380,9 +411,59 @@ class Int64Value : public Value {
     return false;
   }
 
+  virtual bool getValue(double& /*ref*/) {
+    return false;
+  }
+
   int64_t value;
 };
 
+class DoubleValue : public Value {
+ public:
+  explicit DoubleValue(double value)
+      : Value(std::to_string(value)),
+      value(value) {
+    setTypeId<double>();
+  }
+  explicit DoubleValue(const std::string &strvalue)
+      : Value(strvalue) {
+    utils::internal::ValueParser(strvalue).parse(value).parseEnd();
+    setTypeId<double>();
+  }
+
+  double getValue() {
+    return value;
+  }
+
+ protected:
+  virtual bool getValue(int&) {
+    return false;
+  }
+
+  virtual bool getValue(uint32_t&) {
+    return false;
+  }
+
+  virtual bool getValue(int64_t&) {
+    return false;

Review comment:
       why disable all casts? others like `IntValue` check the range (quite 
badly) and cast if possible, should we provide a helper like this, and thread 
all these `Value::getValue(*)` methods body through it? 
   ```
   template<T, U>
   bool utils::cast_if_in_range(T in, U& out) {
     U result = static_cast<U>(in);
     if (static_cast<T>(result) != in) {
       return false;
     }
     out = result;
     return true;
      
   }
   ```
   
   edit: this is an insufficient implementation, see `gsl::narrow` for a proper 
implementation (it would be great if we could use that instead of writing our 
own, but that throws (or calls terminate))




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to