From f7fbbaaca375e0f7058eac71d3fd700827a7773d Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Wed, 25 Jan 2017 12:11:58 +0000 Subject: [PATCH] Compiles after merging --- lib/serialisation/BaseIO.h | 12 +++++++++++- lib/serialisation/JSON_IO.cc | 25 ++++++++++++++++--------- lib/serialisation/JSON_IO.h | 10 ++++++++++ lib/serialisation/XmlIO.h | 6 ++---- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/lib/serialisation/BaseIO.h b/lib/serialisation/BaseIO.h index 887f7a05..7eb7b229 100644 --- a/lib/serialisation/BaseIO.h +++ b/lib/serialisation/BaseIO.h @@ -8,6 +8,7 @@ Author: Antonin Portelli Author: Peter Boyle +Author: Guido Cossu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -182,6 +183,16 @@ namespace Grid { T *upcast; }; + // What is the vtype + template struct isReader { + static const bool value = false; + }; + template struct isWriter { + static const bool value = false; + }; + + + // Generic writer interface // serializable base class class Serializable @@ -326,7 +337,6 @@ namespace Grid { } // Generic writer interface ////////////////////////////////////////////////// ->>>>>>> develop template inline void push(Writer &w, const std::string &s) { w.push(s); diff --git a/lib/serialisation/JSON_IO.cc b/lib/serialisation/JSON_IO.cc index 168ad6ff..f6cb7871 100644 --- a/lib/serialisation/JSON_IO.cc +++ b/lib/serialisation/JSON_IO.cc @@ -68,15 +68,22 @@ void JSONWriter::delete_comma() ss_.str(dlast); } - -template<> -void JSONWriter::writeDefault(const std::string &s, const std::string &x){ - if (s.size()) - ss_ << "\""<< s << "\" : \"" << x << "\" ," ; - else - ss_ << "\"" << x << "\" ," ; -} - +// here we are hitting a g++ bug (Bug 56480) +// compiles fine with clang +// have to wrap in the Grid namespace +// annoying, but necessary for TravisCI +namespace Grid +{ + template<> + void JSONWriter::writeDefault(const std::string &s, + const std::string &x) + { + if (s.size()) + ss_ << "\""<< s << "\" : \"" << x << "\" ," ; + else + ss_ << "\"" << x << "\" ," ; + } +}// namespace Grid // Reader implementation /////////////////////////////////////////////////////// diff --git a/lib/serialisation/JSON_IO.h b/lib/serialisation/JSON_IO.h index b62cf318..0d9ed33c 100644 --- a/lib/serialisation/JSON_IO.h +++ b/lib/serialisation/JSON_IO.h @@ -87,6 +87,16 @@ namespace Grid json::iterator it_; json::iterator it_end_; }; + + template <> + struct isReader< JSONReader > { + static const bool value = true; + }; + + template <> + struct isWriter< JSONWriter > { + static const bool value = true; + }; // Writer template implementation //////////////////////////////////////////// template diff --git a/lib/serialisation/XmlIO.h b/lib/serialisation/XmlIO.h index 60fcad1f..f333b9aa 100644 --- a/lib/serialisation/XmlIO.h +++ b/lib/serialisation/XmlIO.h @@ -78,7 +78,7 @@ namespace Grid pugi::xml_node node_; std::string fileName_; }; - + template <> struct isReader< XmlReader > { static const bool value = true; @@ -88,9 +88,7 @@ namespace Grid struct isWriter { static const bool value = true; }; - - - + // Writer template implementation //////////////////////////////////////////// template void XmlWriter::writeDefault(const std::string &s, const U &x)