From 03a95ac05b08277bcc87e42180485b5be81ff7a2 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 6 Mar 2014 15:22:47 +1100 Subject: [PATCH] Remove explict json constructor from range --- net/socket.hpp | 2 ++ noise.cpp | 1 + range.cpp | 42 +++++++++++++++++++++++------------------- range.hpp | 4 ++-- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/net/socket.hpp b/net/socket.hpp index 8c971909..04861d94 100644 --- a/net/socket.hpp +++ b/net/socket.hpp @@ -20,6 +20,8 @@ #ifndef __NET_SOCKET_HPP #define __NET_SOCKET_HPP +#include + #include "types.hpp" #include "address.hpp" diff --git a/noise.cpp b/noise.cpp index 17099969..da627b1e 100644 --- a/noise.cpp +++ b/noise.cpp @@ -23,6 +23,7 @@ #include "range.hpp" #include +#include void util::noise::image2d (uint8_t *restrict pixels, diff --git a/range.cpp b/range.cpp index f0c74195..688d5e78 100644 --- a/range.cpp +++ b/range.cpp @@ -21,9 +21,11 @@ #include "range.hpp" #include "debug.hpp" +#include "json.hpp" #include "maths.hpp" #include +#include #include @@ -33,25 +35,6 @@ using namespace util; //----------------------------------------------------------------------------- -template -range::range (const json::node &node) { - if (node.is_string () && (node == "UNIT" || - node == "unit")) { - min = UNIT.min; - max = UNIT.max; - } else if (node.is_string () && (node == "UNLIMITED" || - node == "unlimited")) { - min = UNLIMITED.min; - max = UNLIMITED.max; - } else { - min = node[0].as_number (); - max = node[1].as_number (); - } - - sanity (); -} - - template range::range (T _min, T _max): min (_min), @@ -200,3 +183,24 @@ namespace util { template struct range; template struct range; } + + +//----------------------------------------------------------------------------- +namespace json { + template <> + util::range + io>::deserialise (const json::node &node) { + if (node.is_string () && (node == "UNIT" || + node == "unit")) { + return util::range::UNIT; + } else if (node.is_string () && (node == "UNLIMITED" || + node == "unlimited")) { + return util::range::UNLIMITED; + } else { + return { + node[0].as_number (), + node[1].as_number () + }; + } + } +} diff --git a/range.hpp b/range.hpp index e1ab4169..e2ba47fa 100644 --- a/range.hpp +++ b/range.hpp @@ -21,7 +21,8 @@ #ifndef __UTIL_RANGE_HPP #define __UTIL_RANGE_HPP -#include "json.hpp" +#include + namespace util { /** @@ -33,7 +34,6 @@ namespace util { T min; T max; - range (const json::node &node); range (T _min, T _max); /// Check whether value falls within this range (inclusive)