diff --git a/include/mstch/mstch.hpp b/include/mstch/mstch.hpp index c35b5ac..f9b42d4 100644 --- a/include/mstch/mstch.hpp +++ b/include/mstch/mstch.hpp @@ -84,7 +84,7 @@ class lambda { }; using node = boost::make_recursive_variant< - std::nullptr_t, std::string, int, bool, lambda, + std::nullptr_t, std::string, int, double, bool, lambda, std::shared_ptr>, std::map, std::vector>::type; diff --git a/src/visitor/is_node_empty.hpp b/src/visitor/is_node_empty.hpp index 25b3c69..43b0756 100644 --- a/src/visitor/is_node_empty.hpp +++ b/src/visitor/is_node_empty.hpp @@ -24,6 +24,11 @@ inline bool is_node_empty::operator()(const int& value) const { return value == 0; } +template<> +inline bool is_node_empty::operator()(const double& value) const { + return value == 0; +} + template<> inline bool is_node_empty::operator()(const bool& value) const { return !value; diff --git a/src/visitor/render_node.hpp b/src/visitor/render_node.hpp index aefd22f..bc494c3 100644 --- a/src/visitor/render_node.hpp +++ b/src/visitor/render_node.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include "mstch/mstch.hpp" @@ -27,6 +28,13 @@ inline std::string render_node::operator()(const int& value) const { return std::to_string(value); } +template<> +inline std::string render_node::operator()(const double& value) const { + std::stringstream ss; + ss << value; + return ss.str(); +} + template<> inline std::string render_node::operator()(const bool& value) const { return value?"true":"false"; diff --git a/test/data/dot_notation.hpp b/test/data/dot_notation.hpp index d21ee50..9a6574d 100644 --- a/test/data/dot_notation.hpp +++ b/test/data/dot_notation.hpp @@ -17,7 +17,7 @@ public: } mstch::node vat() { - return static_cast(m_value * 0.2); + return m_value * 0.2; } mstch::node currency() { diff --git a/test/data/partial_view.hpp b/test/data/partial_view.hpp index b6341ef..09869a8 100644 --- a/test/data/partial_view.hpp +++ b/test/data/partial_view.hpp @@ -1,6 +1,7 @@ class partial_view: public mstch::object { private: int m_value; + public: partial_view(): m_value{10000} { register_methods(this, { @@ -30,7 +31,7 @@ public: } mstch::node taxed_value() { - return static_cast(m_value - (m_value * 0.4)); + return m_value - (m_value * 0.4); } mstch::node in_ca() { diff --git a/test/data/simple.hpp b/test/data/simple.hpp index e7e6088..a2a64c3 100644 --- a/test/data/simple.hpp +++ b/test/data/simple.hpp @@ -21,7 +21,7 @@ public: } mstch::node taxed_value() { - return static_cast(m_value - (m_value * 0.4)); + return m_value - (m_value * 0.4); } mstch::node in_ca() {