From 701e76c381432c376afa20cc30f39b52e3f6cce5 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 8 Sep 2015 14:32:17 +1000 Subject: [PATCH] colour: move json deserialisation into cpp --- colour.cpp | 31 ++++++++++++++----------------- colour.hpp | 5 ----- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/colour.cpp b/colour.cpp index c26674d0..d501c28b 100644 --- a/colour.cpp +++ b/colour.cpp @@ -20,6 +20,7 @@ #include "random.hpp" #include "stream.hpp" +#include //----------------------------------------------------------------------------- using util::colour; @@ -341,26 +342,22 @@ util::hsv_to_rgb (colour3f hsv) } - ///---------------------------------------------------------------------------- -//! Extract a colour object from a JSON node. -//! -//! Data must be an array or 3 or 4 numbers. Guarantees success, or throws a -//! json::tree::type_error. -const json::tree::node& -operator>> (const json::tree::node &node, util::colour4f &c) { - c.r = static_cast (node[0].as_number ()); - c.g = static_cast (node[1].as_number ()); - c.b = static_cast (node[2].as_number ()); +/// Extract a colour object from a JSON node. +#include "json/tree.hpp" - try { - c.a = static_cast (node[3].as_number ()); - } catch (...) { - c.a = 1; +namespace json { namespace tree { + template <> + util::colour4f + io::deserialise (const node &root) { + return { + root[0].as (), + root[1].as (), + root[2].as (), + root[3].as (), + }; } - - return node; -} +} } //----------------------------------------------------------------------------- diff --git a/colour.hpp b/colour.hpp index 2cbfa071..df491a3a 100644 --- a/colour.hpp +++ b/colour.hpp @@ -19,8 +19,6 @@ #include "coord.hpp" -#include "json/tree.hpp" - #include namespace util { @@ -61,9 +59,6 @@ namespace util { colour3f rgb_to_hsv (colour3f); colour3f hsv_to_rgb (colour3f); - // Serialisation - const json::tree::node& operator>> (const json::tree::node&, util::colour4f&); - template std::ostream& operator<< (std::ostream&, util::colour); }