Remove explict json constructor from range

This commit is contained in:
Danny Robson 2014-03-06 15:22:47 +11:00
parent 7404973415
commit 03a95ac05b
4 changed files with 28 additions and 21 deletions

View File

@ -20,6 +20,8 @@
#ifndef __NET_SOCKET_HPP #ifndef __NET_SOCKET_HPP
#define __NET_SOCKET_HPP #define __NET_SOCKET_HPP
#include <memory>
#include "types.hpp" #include "types.hpp"
#include "address.hpp" #include "address.hpp"

View File

@ -23,6 +23,7 @@
#include "range.hpp" #include "range.hpp"
#include <iostream> #include <iostream>
#include <limits>
void void
util::noise::image2d (uint8_t *restrict pixels, util::noise::image2d (uint8_t *restrict pixels,

View File

@ -21,9 +21,11 @@
#include "range.hpp" #include "range.hpp"
#include "debug.hpp" #include "debug.hpp"
#include "json.hpp"
#include "maths.hpp" #include "maths.hpp"
#include <limits> #include <limits>
#include <cmath>
#include <cstdint> #include <cstdint>
@ -33,25 +35,6 @@ using namespace util;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T>
range<T>::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 <typename T> template <typename T>
range<T>::range (T _min, T _max): range<T>::range (T _min, T _max):
min (_min), min (_min),
@ -200,3 +183,24 @@ namespace util {
template struct range<uint32_t>; template struct range<uint32_t>;
template struct range<uint64_t>; template struct range<uint64_t>;
} }
//-----------------------------------------------------------------------------
namespace json {
template <>
util::range<double>
io<util::range<double>>::deserialise (const json::node &node) {
if (node.is_string () && (node == "UNIT" ||
node == "unit")) {
return util::range<double>::UNIT;
} else if (node.is_string () && (node == "UNLIMITED" ||
node == "unlimited")) {
return util::range<double>::UNLIMITED;
} else {
return {
node[0].as_number (),
node[1].as_number ()
};
}
}
}

View File

@ -21,7 +21,8 @@
#ifndef __UTIL_RANGE_HPP #ifndef __UTIL_RANGE_HPP
#define __UTIL_RANGE_HPP #define __UTIL_RANGE_HPP
#include "json.hpp" #include <iostream>
namespace util { namespace util {
/** /**
@ -33,7 +34,6 @@ namespace util {
T min; T min;
T max; T max;
range (const json::node &node);
range (T _min, T _max); range (T _min, T _max);
/// Check whether value falls within this range (inclusive) /// Check whether value falls within this range (inclusive)