qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [4/4] qpid-proton git commit: PROTON-1085: c++: Replace all operator== and < members with free functions, drop comparable template.
Date Tue, 29 Dec 2015 21:00:55 GMT
PROTON-1085: c++: Replace all operator== and < members with free functions, drop comparable
template.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/117bb7cb
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/117bb7cb
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/117bb7cb

Branch: refs/heads/master
Commit: 117bb7cb0bcb588f91c8a2a6a45b0cb9d211d7d6
Parents: 1622d0e
Author: Alan Conway <aconway@redhat.com>
Authored: Tue Dec 29 13:54:02 2015 -0500
Committer: Alan Conway <aconway@redhat.com>
Committed: Tue Dec 29 15:56:44 2015 -0500

----------------------------------------------------------------------
 .../bindings/cpp/include/proton/comparable.hpp  | 38 --------------------
 .../bindings/cpp/include/proton/duration.hpp    |  8 ++---
 proton-c/bindings/cpp/include/proton/object.hpp |  5 ++-
 proton-c/bindings/cpp/include/proton/scalar.hpp |  6 ++--
 proton-c/bindings/cpp/include/proton/types.hpp  | 15 ++++----
 proton-c/bindings/cpp/include/proton/value.hpp  |  8 ++---
 proton-c/bindings/cpp/src/scalar.cpp            |  1 -
 proton-c/bindings/cpp/src/value.cpp             |  4 +--
 8 files changed, 21 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/117bb7cb/proton-c/bindings/cpp/include/proton/comparable.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/comparable.hpp b/proton-c/bindings/cpp/include/proton/comparable.hpp
deleted file mode 100644
index 2649a8d..0000000
--- a/proton-c/bindings/cpp/include/proton/comparable.hpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef COMPARABLE_HPP
-#define COMPARABLE_HPP
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-namespace proton {
-
-///@cond INTERNAL
-
-/// Internal base class to provide comparison operators. T must provide < and ==.
-template <class T> struct comparable {
-  friend bool operator>(const T &a, const T &b) { return b < a; }
-  friend bool operator<=(const T &a, const T &b) { return !(a > b); }
-  friend bool operator>=(const T &a, const T &b) { return !(a < b); }
-  friend bool operator!=(const T &a, const T &b) { return !(a == b); }
-};
-
-///@endcond
-
-}
-
-#endif // COMPARABLE_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/117bb7cb/proton-c/bindings/cpp/include/proton/duration.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/duration.hpp b/proton-c/bindings/cpp/include/proton/duration.hpp
index e562c47..cea785f 100644
--- a/proton-c/bindings/cpp/include/proton/duration.hpp
+++ b/proton-c/bindings/cpp/include/proton/duration.hpp
@@ -28,21 +28,21 @@
 namespace proton {
 
 /** Duration in milliseconds. */
-class duration : public comparable<duration>
+class duration
 {
   public:
     amqp_ulong milliseconds;
     explicit duration(amqp_ulong ms = 0) : milliseconds(ms) {}
 
-    bool operator<(duration d) { return milliseconds < d.milliseconds; }
-    bool operator==(duration d) { return milliseconds == d.milliseconds; }
-
     PN_CPP_EXTERN static const duration FOREVER; ///< Wait for ever
     PN_CPP_EXTERN static const duration IMMEDIATE; ///< Don't wait at all
     PN_CPP_EXTERN static const duration SECOND; ///< One second
     PN_CPP_EXTERN static const duration MINUTE; ///< One minute
 };
 
+inline bool operator<(duration x, duration y) { return x.milliseconds < y.milliseconds;
}
+inline bool operator==(duration x, duration y) { return x.milliseconds == y.milliseconds;
}
+
 inline duration operator*(duration d, amqp_ulong n) { return duration(d.milliseconds*n);
}
 inline duration operator*(amqp_ulong n, duration d) { return d * n; }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/117bb7cb/proton-c/bindings/cpp/include/proton/object.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/object.hpp b/proton-c/bindings/cpp/include/proton/object.hpp
index e98a956..32bc086 100644
--- a/proton-c/bindings/cpp/include/proton/object.hpp
+++ b/proton-c/bindings/cpp/include/proton/object.hpp
@@ -21,7 +21,6 @@
 
 #include "proton/config.hpp"
 #include "proton/export.hpp"
-#include "proton/comparable.hpp"
 
 #include <memory>
 
@@ -34,7 +33,7 @@ class pn_ptr_base {
     PN_CPP_EXTERN static void decref(void* p);
 };
 
-template <class T> class pn_ptr : public comparable<pn_ptr<T> >, private
pn_ptr_base {
+template <class T> class pn_ptr : private pn_ptr_base {
   public:
     pn_ptr() : ptr_(0) {}
     pn_ptr(T* p) : ptr_(p) { incref(ptr_); }
@@ -71,7 +70,7 @@ template <class T> pn_ptr<T> take_ownership(T* p) { return pn_ptr<T>::take_owner
 /**
  * Base class for proton object types
  */
-template <class T> class object : public comparable<object<T> > {
+template <class T> class object {
   public:
     bool operator!() const { return !object_; }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/117bb7cb/proton-c/bindings/cpp/include/proton/scalar.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/scalar.hpp b/proton-c/bindings/cpp/include/proton/scalar.hpp
index 6fe29fa..d135ab6 100644
--- a/proton-c/bindings/cpp/include/proton/scalar.hpp
+++ b/proton-c/bindings/cpp/include/proton/scalar.hpp
@@ -29,7 +29,7 @@ class encoder;
 class decoder;
 
 /** scalar holds an instance of any scalar AMQP type. */
-class scalar : public comparable<scalar> {
+class scalar {
   public:
     PN_CPP_EXTERN scalar();
     PN_CPP_EXTERN scalar(const scalar&);
@@ -130,9 +130,9 @@ class scalar : public comparable<scalar> {
 };
 
 ///@internal base for restricted scalar types
-class restricted_scalar : public comparable<restricted_scalar> {
+class restricted_scalar {
   public:
-    operator scalar() const { return scalar_; }
+    operator const scalar&() const { return scalar_; }
     type_id type() const { return scalar_.type(); }
 
     ///@name as_ methods do "loose" conversion, they will convert the scalar's

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/117bb7cb/proton-c/bindings/cpp/include/proton/types.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/types.hpp b/proton-c/bindings/cpp/include/proton/types.hpp
index db5989b..062566a 100644
--- a/proton-c/bindings/cpp/include/proton/types.hpp
+++ b/proton-c/bindings/cpp/include/proton/types.hpp
@@ -25,7 +25,6 @@
 
 #include "proton/export.hpp"
 #include "proton/error.hpp"
-#include "proton/comparable.hpp"
 
 #include <proton/codec.h>
 #include <proton/type_compat.h>
@@ -141,7 +140,7 @@ struct amqp_binary : public std::string {
 };
 
 /// Template for opaque proton proton types that can be treated as byte arrays.
-template <class P> struct opaque: public comparable<opaque<P> > {
+template <class P> struct opaque {
     P value;
     opaque(const P& p=P()) : value(p) {}
     operator P() const { return value; }
@@ -153,11 +152,11 @@ template <class P> struct opaque: public comparable<opaque<P>
> {
     const char* end() const { return reinterpret_cast<const char*>(&value)+size();
}
     char& operator[](size_t i) { return *(begin()+i); }
     const char& operator[](size_t i) const { return *(begin()+i); }
-
-    bool operator==(const opaque& x) const { return std::equal(begin(), end(), x.begin());
}
-    bool operator<(const opaque& x) const { return std::lexicographical_compare(begin(),
end(), x.begin(), x.end()); }
 };
 
+template <class T> bool operator==(const opaque<T>& x, const opaque<T>&
y) { return std::equal(x.begin(), x.end(), y.begin()); }
+template <class T> bool operator<(const opaque<T>& x, const opaque<T>&
y) { return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
+
 /// AMQP 16-byte UUID.
 typedef opaque<pn_uuid_t> amqp_uuid;
 PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const amqp_uuid&);
@@ -172,13 +171,13 @@ typedef opaque<pn_decimal128_t> amqp_decimal128;
 PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const amqp_decimal128&);
 
 /// AMQP timestamp, milliseconds since the epoch 00:00:00 (UTC), 1 January 1970.
-struct amqp_timestamp : public comparable<amqp_timestamp> {
+struct amqp_timestamp {
     pn_timestamp_t milliseconds;
     amqp_timestamp(::int64_t ms=0) : milliseconds(ms) {}
     operator pn_timestamp_t() const { return milliseconds; }
-    bool operator==(const amqp_timestamp& x) { return milliseconds == x.milliseconds;
}
-    bool operator<(const amqp_timestamp& x) { return milliseconds < x.milliseconds;
}
 };
+inline bool operator==(amqp_timestamp x, amqp_timestamp y) { return x.milliseconds == y.milliseconds;
}
+inline bool operator<(amqp_timestamp x, amqp_timestamp y) { return x.milliseconds <
y.milliseconds; }
 PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const amqp_timestamp&);
 
 // TODO aconway 2015-06-16: described types.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/117bb7cb/proton-c/bindings/cpp/include/proton/value.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/value.hpp b/proton-c/bindings/cpp/include/proton/value.hpp
index dedcadd..1ecaaa5 100644
--- a/proton-c/bindings/cpp/include/proton/value.hpp
+++ b/proton-c/bindings/cpp/include/proton/value.hpp
@@ -40,7 +40,7 @@ class decoder;
  * Assigning to a proton::value follows the encoder rules, converting from a
  * proton::value (or calling proton::value::get) follows the decoder rules.
  */
-class value : public comparable<value> {
+class value {
   public:
     PN_CPP_EXTERN value();
     PN_CPP_EXTERN value(const value&);
@@ -73,12 +73,10 @@ class value : public comparable<value> {
     /** Get the value. */
     template<class T> T get() const { T t; get(t); return t; }
 
-    // FIXME aconway 2015-12-28: friend ops.
-    PN_CPP_EXTERN bool operator==(const value& x) const;
-    PN_CPP_EXTERN bool operator<(const value& x) const;
-
     PN_CPP_EXTERN void swap(value& v);
 
+  friend PN_CPP_EXTERN bool operator==(const value& x, const value& y);
+  friend PN_CPP_EXTERN bool operator<(const value& x, const value& y);
   friend PN_CPP_EXTERN class encoder operator<<(class encoder e, const value& dv);
   friend PN_CPP_EXTERN class decoder operator>>(class decoder d, value& dv);
   friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream& o, const value&
dv);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/117bb7cb/proton-c/bindings/cpp/src/scalar.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/scalar.cpp b/proton-c/bindings/cpp/src/scalar.cpp
index 9e8d124..d52c8eb 100644
--- a/proton-c/bindings/cpp/src/scalar.cpp
+++ b/proton-c/bindings/cpp/src/scalar.cpp
@@ -137,7 +137,6 @@ std::string scalar::as_string() const {
 }
 
 namespace {
-template<class T> int opaque_cmp(const T& x, const T& y) { return memcmp(&x,
&y, sizeof(T)); }
 
 template <class T, class F> T type_switch(const scalar& a, F f) {
     switch(a.type()) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/117bb7cb/proton-c/bindings/cpp/src/value.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/value.cpp b/proton-c/bindings/cpp/src/value.cpp
index bf652c5..9e8448c 100644
--- a/proton-c/bindings/cpp/src/value.cpp
+++ b/proton-c/bindings/cpp/src/value.cpp
@@ -54,9 +54,9 @@ class decoder value::decoder() const { data_.decoder().rewind(); return
data_.de
 
 type_id value::type() const { return decoder().type(); }
 
-bool value::operator==(const value& x) const { return data_.equal(x.data_); }
+bool operator==(const value& x, const value& y) { return x.data_.equal(y.data_);
}
 
-bool value::operator<(const value& x) const { return data_.less(x.data_); }
+bool operator<(const value& x, const value& y) { return x.data_.less(y.data_);
}
 
 std::ostream& operator<<(std::ostream& o, const value& v) {
     // pn_inspect prints strings with quotes which is not normal in C++.


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


Mime
View raw message