double value support

This commit is contained in:
Daniel Sipka 2015-04-29 10:53:01 +02:00
parent 9e541031fd
commit 105e708d42
6 changed files with 18 additions and 4 deletions

View File

@ -84,7 +84,7 @@ class lambda {
}; };
using node = boost::make_recursive_variant< 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<internal::object_t<boost::recursive_variant_>>, std::shared_ptr<internal::object_t<boost::recursive_variant_>>,
std::map<const std::string, boost::recursive_variant_>, std::map<const std::string, boost::recursive_variant_>,
std::vector<boost::recursive_variant_>>::type; std::vector<boost::recursive_variant_>>::type;

View File

@ -24,6 +24,11 @@ inline bool is_node_empty::operator()(const int& value) const {
return value == 0; return value == 0;
} }
template<>
inline bool is_node_empty::operator()(const double& value) const {
return value == 0;
}
template<> template<>
inline bool is_node_empty::operator()(const bool& value) const { inline bool is_node_empty::operator()(const bool& value) const {
return !value; return !value;

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <sstream>
#include <boost/variant/static_visitor.hpp> #include <boost/variant/static_visitor.hpp>
#include "mstch/mstch.hpp" #include "mstch/mstch.hpp"
@ -27,6 +28,13 @@ inline std::string render_node::operator()(const int& value) const {
return std::to_string(value); 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<> template<>
inline std::string render_node::operator()(const bool& value) const { inline std::string render_node::operator()(const bool& value) const {
return value?"true":"false"; return value?"true":"false";

View File

@ -17,7 +17,7 @@ public:
} }
mstch::node vat() { mstch::node vat() {
return static_cast<int>(m_value * 0.2); return m_value * 0.2;
} }
mstch::node currency() { mstch::node currency() {

View File

@ -1,6 +1,7 @@
class partial_view: public mstch::object { class partial_view: public mstch::object {
private: private:
int m_value; int m_value;
public: public:
partial_view(): m_value{10000} { partial_view(): m_value{10000} {
register_methods(this, { register_methods(this, {
@ -30,7 +31,7 @@ public:
} }
mstch::node taxed_value() { mstch::node taxed_value() {
return static_cast<int>(m_value - (m_value * 0.4)); return m_value - (m_value * 0.4);
} }
mstch::node in_ca() { mstch::node in_ca() {

View File

@ -21,7 +21,7 @@ public:
} }
mstch::node taxed_value() { mstch::node taxed_value() {
return static_cast<int>(m_value - (m_value * 0.4)); return m_value - (m_value * 0.4);
} }
mstch::node in_ca() { mstch::node in_ca() {