Use visitor instead of pulling values directly
Sensor thresholds pull out an int64_t and immediately
assign it to a double. Use a visitor instead to avoid
the intermediate and add flexibility / saftey to type
readings.
Tested-By: Verifed sensor list still worked.
Change-Id: If49bf54ec1c0636b3549d433b86ecdbd1ea99b0d
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/utils.hpp b/utils.hpp
index 75a3252..535ea66 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -208,6 +208,27 @@
const std::string& path,
InterfaceList&& interfaces);
+/** @struct VariantToDoubleVisitor
+ * @brief Visitor to convert variants to doubles
+ * @details Performs a static cast on the underlying type
+ */
+struct VariantToDoubleVisitor
+{
+ template <typename T>
+ std::enable_if_t<std::is_arithmetic<T>::value, double>
+ operator()(const T &t) const
+ {
+ return static_cast<double>(t);
+ }
+
+ template <typename T>
+ std::enable_if_t<!std::is_arithmetic<T>::value, double>
+ operator()(const T &t) const
+ {
+ throw std::invalid_argument("Cannot translate type to double");
+ }
+};
+
namespace method_no_args
{