Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 23CFB200B70 for ; Sat, 13 Aug 2016 00:18:48 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 2292C160AB6; Fri, 12 Aug 2016 22:18:48 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 43C4E160AB0 for ; Sat, 13 Aug 2016 00:18:47 +0200 (CEST) Received: (qmail 4936 invoked by uid 500); 12 Aug 2016 22:18:46 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 4923 invoked by uid 99); 12 Aug 2016 22:18:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Aug 2016 22:18:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5C207E03E8; Fri, 12 Aug 2016 22:18:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: astitcher@apache.org To: commits@qpid.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: qpid-cpp git commit: QPID-7392: More judicious templates (stolen from c++11) to avoid warnings Date: Fri, 12 Aug 2016 22:18:46 +0000 (UTC) archived-at: Fri, 12 Aug 2016 22:18:48 -0000 Repository: qpid-cpp Updated Branches: refs/heads/master e65f39fe5 -> 2a9e20b68 QPID-7392: More judicious templates (stolen from c++11) to avoid warnings Project: http://git-wip-us.apache.org/repos/asf/qpid-cpp/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-cpp/commit/2a9e20b6 Tree: http://git-wip-us.apache.org/repos/asf/qpid-cpp/tree/2a9e20b6 Diff: http://git-wip-us.apache.org/repos/asf/qpid-cpp/diff/2a9e20b6 Branch: refs/heads/master Commit: 2a9e20b688d130b1e9cbddf1ee4ac9d24434bb4c Parents: e65f39f Author: Andrew Stitcher Authored: Fri Aug 12 17:59:24 2016 -0400 Committer: Andrew Stitcher Committed: Fri Aug 12 17:59:24 2016 -0400 ---------------------------------------------------------------------- src/qpid/framing/FieldValue.cpp | 28 ++++++++++----------- src/qpid/types/Variant.cpp | 49 ++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/2a9e20b6/src/qpid/framing/FieldValue.cpp ---------------------------------------------------------------------- diff --git a/src/qpid/framing/FieldValue.cpp b/src/qpid/framing/FieldValue.cpp index d2bfe89..56b0d0b 100644 --- a/src/qpid/framing/FieldValue.cpp +++ b/src/qpid/framing/FieldValue.cpp @@ -47,30 +47,30 @@ template struct FloatType{}; template<> struct FloatType<4> { typedef float Type; }; template<> struct FloatType<8> { typedef double Type; }; +// Stolen from C++11 +template struct enable_if {}; +template struct enable_if { typedef T type; }; + // Construct the right subclass of FixedWidthValue for numeric types using width and kind. // Kind 1=int, 2=unsigned int, 3=float -template FixedWidthValue* numericFixedWidthValue(uint8_t kind) { +template +typename enable_if<(W<3), FixedWidthValue*>::type +numericFixedWidthValue(uint8_t kind) { switch (kind) { case 1: return new FixedWidthIntValue::Type>(); case 2: return new FixedWidthIntValue::Type>(); - case 3: return new FixedWidthFloatValue::Type>(); default: return new FixedWidthValue(); } } -template<> FixedWidthValue<1>* numericFixedWidthValue<1>(uint8_t kind) { - switch (kind) { - case 1: return new FixedWidthIntValue::Type>(); - case 2: return new FixedWidthIntValue::Type>(); - default: return new FixedWidthValue<1>(); - } -} - -template<> FixedWidthValue<2>* numericFixedWidthValue<2>(uint8_t kind) { +template +typename enable_if<(W>=3), FixedWidthValue*>::type +numericFixedWidthValue(uint8_t kind) { switch (kind) { - case 1: return new FixedWidthIntValue::Type>(); - case 2: return new FixedWidthIntValue::Type>(); - default: return new FixedWidthValue<2>(); + case 1: return new FixedWidthIntValue::Type>(); + case 2: return new FixedWidthIntValue::Type>(); + case 3: return new FixedWidthFloatValue::Type>(); + default: return new FixedWidthValue(); } } http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/2a9e20b6/src/qpid/types/Variant.cpp ---------------------------------------------------------------------- diff --git a/src/qpid/types/Variant.cpp b/src/qpid/types/Variant.cpp index 26dbe0c..eb2ff42 100644 --- a/src/qpid/types/Variant.cpp +++ b/src/qpid/types/Variant.cpp @@ -31,6 +31,27 @@ namespace qpid { namespace types { +// Stolen from C++11 +template struct enable_if {}; +template struct enable_if { typedef T type; }; + +struct true_type { static const bool value = true; }; +struct false_type { static const bool value = false; }; + +template struct is_signed : public false_type {}; +template <> struct is_signed : public false_type {}; +template <> struct is_signed : public false_type {}; +template <> struct is_signed : public false_type {}; +template <> struct is_signed : public false_type {}; +template <> struct is_signed : public true_type {}; +template <> struct is_signed : public true_type {}; +template <> struct is_signed : public true_type {}; +template <> struct is_signed : public true_type {}; + +template <> struct is_signed : public true_type {}; +template <> struct is_signed : public true_type {}; + + namespace { const std::string EMPTY; const std::string PREFIX("invalid conversion: "); @@ -115,7 +136,8 @@ class VariantImpl } value; std::string encoding; // Optional encoding for variable length data. - template T convertFromString() const + template + typename enable_if::value, T>::type convertFromString() const { const std::string& s = *value.string; @@ -125,18 +147,31 @@ class VariantImpl if ( s[0] != '-' ) { return boost::lexical_cast(s); } else { - T r = boost::lexical_cast(s.substr(1)); - if (std::numeric_limits::is_signed) { - return -r; - } else { - if (r==0) return 0; - } + return -boost::lexical_cast(s.substr(1)); } } catch(const boost::bad_lexical_cast&) { } throw InvalidConversion(QPID_MSG("Cannot convert " << s)); } + template + typename enable_if::value, T>::type convertFromString() const + { + const std::string& s = *value.string; + + try { + // Extra shenanigans to work around negative zero + // conversion error in older GCC libs. + if ( s[0] != '-' ) { + return boost::lexical_cast(s); + } else { + T r = boost::lexical_cast(s.substr(1)); + if (r==0) return 0; + } + } catch(const boost::bad_lexical_cast&) { + } + throw InvalidConversion(QPID_MSG("Cannot convert " << s)); + } }; VariantImpl::VariantImpl() : type(VAR_VOID) {} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org