qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject qpid-cpp git commit: QPID-7392: Judicious use of template specialisations to avoid code which generates warnings on instantiation
Date Fri, 12 Aug 2016 06:06:24 GMT
Repository: qpid-cpp
Updated Branches:
  refs/heads/master 484843fcf -> 868caf542


QPID-7392: Judicious use of template specialisations to avoid code which
generates warnings on instantiation


Project: http://git-wip-us.apache.org/repos/asf/qpid-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-cpp/commit/868caf54
Tree: http://git-wip-us.apache.org/repos/asf/qpid-cpp/tree/868caf54
Diff: http://git-wip-us.apache.org/repos/asf/qpid-cpp/diff/868caf54

Branch: refs/heads/master
Commit: 868caf5420653a5536a343f1745535dceb3461a0
Parents: 484843f
Author: Andrew Stitcher <astitcher@apache.org>
Authored: Fri Aug 12 01:52:17 2016 -0400
Committer: Andrew Stitcher <astitcher@apache.org>
Committed: Fri Aug 12 02:05:57 2016 -0400

----------------------------------------------------------------------
 src/qpid/framing/FieldValue.cpp | 18 ++++++++++++++++--
 src/qpid/framing/FieldValue.h   | 18 +++++++++---------
 2 files changed, 25 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/868caf54/src/qpid/framing/FieldValue.cpp
----------------------------------------------------------------------
diff --git a/src/qpid/framing/FieldValue.cpp b/src/qpid/framing/FieldValue.cpp
index 227c12e..d2bfe89 100644
--- a/src/qpid/framing/FieldValue.cpp
+++ b/src/qpid/framing/FieldValue.cpp
@@ -44,8 +44,6 @@ template<> struct UintType<4> { typedef uint32_t Type; };
 template<> struct UintType<8> { typedef uint64_t Type; };
 
 template<int W> struct FloatType{};
-template<> struct FloatType<1> { typedef int8_t Type; }; // Dummy, never used.
-template<> struct FloatType<2> { typedef int16_t Type; }; // Dummy, never used.
 template<> struct FloatType<4> { typedef float Type; };
 template<> struct FloatType<8> { typedef double Type; };
 
@@ -60,6 +58,22 @@ template<int W> FixedWidthValue<W>* numericFixedWidthValue(uint8_t
kind) {
     }
 }
 
+template<> FixedWidthValue<1>* numericFixedWidthValue<1>(uint8_t kind)
{
+    switch (kind) {
+      case 1: return new FixedWidthIntValue<typename IntType<1>::Type>();
+      case 2: return new FixedWidthIntValue<typename UintType<1>::Type>();
+      default: return new FixedWidthValue<1>();
+    }
+}
+
+template<> FixedWidthValue<2>* numericFixedWidthValue<2>(uint8_t kind)
{
+    switch (kind) {
+      case 1: return new FixedWidthIntValue<typename IntType<2>::Type>();
+      case 2: return new FixedWidthIntValue<typename UintType<2>::Type>();
+      default: return new FixedWidthValue<2>();
+    }
+}
+
 uint8_t FieldValue::getType() const
 {
     return typeOctet;

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/868caf54/src/qpid/framing/FieldValue.h
----------------------------------------------------------------------
diff --git a/src/qpid/framing/FieldValue.h b/src/qpid/framing/FieldValue.h
index e20244e..82ea9b5 100644
--- a/src/qpid/framing/FieldValue.h
+++ b/src/qpid/framing/FieldValue.h
@@ -182,6 +182,15 @@ template <class T> class FixedWidthIntValue : public FixedWidthValue<sizeof(T)>
     double getFloat() const { return getInt(); }
 };
 
+// Explicitly specialise width 1 variants to avoid using the byte swapping code
+template<> inline FixedWidthIntValue<bool>::FixedWidthIntValue(bool v) { this->octets[0]
= v; }
+template<> inline FixedWidthIntValue<int8_t>::FixedWidthIntValue(int8_t v) {
this->octets[0] = v; }
+template<> inline FixedWidthIntValue<uint8_t>::FixedWidthIntValue(uint8_t v)
{ this->octets[0] = v; }
+
+template<> inline int64_t FixedWidthIntValue<bool>::getInt() const { return this->octets[0];
}
+template<> inline int64_t FixedWidthIntValue<int8_t>::getInt() const { return
this->octets[0]; }
+template<> inline int64_t FixedWidthIntValue<uint8_t>::getInt() const { return
this->octets[0]; }
+
 template <class T> class FixedWidthFloatValue : public FixedWidthValue<sizeof(T)>
{
   public:
     FixedWidthFloatValue(T v = 0) { endian::encodeFloat(this->octets, v); }
@@ -189,15 +198,6 @@ template <class T> class FixedWidthFloatValue : public FixedWidthValue<sizeof(T)
     double getFloat() const { return endian::decodeFloat<T>(this->octets); }
 };
 
-// Dummy implementations that are never used but needed to avoid compile errors.
-template <> class FixedWidthFloatValue<uint8_t> : public FixedWidthValue<1>
{
-    FixedWidthFloatValue() { assert(0); }
-};
-template <> class FixedWidthFloatValue<uint16_t> : public FixedWidthValue<2>
{
-    FixedWidthFloatValue() { assert(0); }
-};
-
-
 class UuidData : public FixedWidthValue<16> {
   public:
     UuidData();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message