Repository: qpid-proton Updated Branches: refs/heads/master c39a691ed -> 80f6d4b59
PROTON-1153: [C++ binding] Tidied up some C++11 related details - Split apart the various C++11 feature into different flags to test - Added in explicit boolean conversions - Added in move assignment for message Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/80f6d4b5 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/80f6d4b5 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/80f6d4b5 Branch: refs/heads/master Commit: 80f6d4b5913bf1ce4d768a7acebac379f7052c73 Parents: c39a691 Author: Andrew Stitcher <[email protected]> Authored: Thu May 5 19:05:45 2016 -0400 Committer: Andrew Stitcher <[email protected]> Committed: Thu May 5 19:05:45 2016 -0400 ---------------------------------------------------------------------- proton-c/bindings/cpp/include/proton/config.hpp | 24 ++++++++++++++++++++ .../bindings/cpp/include/proton/endpoint.hpp | 2 +- .../cpp/include/proton/error_condition.hpp | 11 +++++---- .../bindings/cpp/include/proton/message.hpp | 11 ++++----- proton-c/bindings/cpp/include/proton/object.hpp | 10 +++++++- .../cpp/include/proton/pn_unique_ptr.hpp | 2 +- proton-c/bindings/cpp/include/proton/sasl.hpp | 6 +++-- .../bindings/cpp/include/proton/types_fwd.hpp | 2 +- proton-c/bindings/cpp/include/proton/value.hpp | 2 +- proton-c/bindings/cpp/src/error_condition.cpp | 6 +++++ proton-c/bindings/cpp/src/message.cpp | 6 ++++- proton-c/bindings/cpp/src/value.cpp | 2 +- 12 files changed, 65 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/proton-c/bindings/cpp/include/proton/config.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/config.hpp b/proton-c/bindings/cpp/include/proton/config.hpp index 59e8874..e6cb8ae 100644 --- a/proton-c/bindings/cpp/include/proton/config.hpp +++ b/proton-c/bindings/cpp/include/proton/config.hpp @@ -47,6 +47,30 @@ #define PN_CPP_HAS_LONG_LONG PN_CPP_HAS_CPP11 #endif +#ifndef PN_CPP_HAS_NULLPTR +#define PN_CPP_HAS_NULLPTR PN_CPP_HAS_CPP11 +#endif + +#ifndef PN_CPP_HAS_RVALUE_REFERENCES +#define PN_CPP_HAS_RVALUE_REFERENCES PN_CPP_HAS_CPP11 +#endif + +#ifndef PN_CPP_HAS_OVERRIDE +#define PN_CPP_HAS_OVERRIDE PN_CPP_HAS_CPP11 +#endif + +#ifndef PN_CPP_HAS_EXPLICIT_CONVERSIONS +#define PN_CPP_HAS_EXPLICIT_CONVERSIONS PN_CPP_HAS_CPP11 +#endif + +#ifndef PN_CPP_HAS_DEFAULTED_FUNCTIONS +#define PN_CPP_HAS_DEFAULTED_FUNCTIONS PN_CPP_HAS_CPP11 +#endif + +#ifndef PN_CPP_HAS_DELETED_FUNCTIONS +#define PN_CPP_HAS_DELETED_FUNCTIONS PN_CPP_HAS_CPP11 +#endif + #endif // CONFIG_HPP /// @endcond http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/proton-c/bindings/cpp/include/proton/endpoint.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/endpoint.hpp b/proton-c/bindings/cpp/include/proton/endpoint.hpp index b4d7034..593ff32 100644 --- a/proton-c/bindings/cpp/include/proton/endpoint.hpp +++ b/proton-c/bindings/cpp/include/proton/endpoint.hpp @@ -49,7 +49,7 @@ PN_CPP_CLASS_EXTERN endpoint { virtual void close() = 0; virtual void close(const error_condition&) = 0; -#if PN_CPP_HAS_CPP11 +#if PN_CPP_HAS_DEFAULTED_FUNCTIONS // Make everything explicit for C++11 compilers endpoint() = default; endpoint& operator=(const endpoint&) = default; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/proton-c/bindings/cpp/include/proton/error_condition.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/error_condition.hpp b/proton-c/bindings/cpp/include/proton/error_condition.hpp index 14b8544..0153f4a 100644 --- a/proton-c/bindings/cpp/include/proton/error_condition.hpp +++ b/proton-c/bindings/cpp/include/proton/error_condition.hpp @@ -46,19 +46,22 @@ class error_condition { PN_CPP_EXTERN error_condition(std::string name, std::string description); PN_CPP_EXTERN error_condition(std::string name, std::string description, proton::value properties); -#if PN_CPP_HAS_CPP11 +#if PN_CPP_HAS_DEFAULTED_FUNCTIONS error_condition(const error_condition&) = default; error_condition(error_condition&&) = default; error_condition& operator=(const error_condition&) = default; error_condition& operator=(error_condition&&) = default; #endif + /// If you are using a C++11 compiler you may use an error_condition + /// in boolean contexts and the expression will be true if the error_condition is set +#if PN_CPP_HAS_EXPLICIT_CONVERSIONS + PN_CPP_EXTERN explicit operator bool() const; +#endif + /// No condition set. PN_CPP_EXTERN bool operator!() const; - /// XXX add C++11 explicit bool conversion with a note about - /// C++11-only usage - /// No condition has been set. PN_CPP_EXTERN bool empty() const; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/proton-c/bindings/cpp/include/proton/message.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/message.hpp b/proton-c/bindings/cpp/include/proton/message.hpp index b0ea95c..c24b4e7 100644 --- a/proton-c/bindings/cpp/include/proton/message.hpp +++ b/proton-c/bindings/cpp/include/proton/message.hpp @@ -59,11 +59,13 @@ class message { /// Copy a message. PN_CPP_EXTERN message(const message&); -#if PN_CPP_HAS_CPP11 + /// Copy a message. + PN_CPP_EXTERN message& operator=(const message&); + +#if PN_CPP_HAS_RVALUE_REFERENCES /// Move a message. PN_CPP_EXTERN message(message&&); - - // XXX move assignment operator? - do this in general for CPP11 + PN_CPP_EXTERN message& operator=(message&&); #endif /// Create a message with its body set from any value that can be @@ -72,9 +74,6 @@ class message { PN_CPP_EXTERN ~message(); - /// Copy a message. - PN_CPP_EXTERN message& operator=(const message&); - /// @name Basic properties and methods /// @{ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/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 7c7495d..db52975 100644 --- a/proton-c/bindings/cpp/include/proton/object.hpp +++ b/proton-c/bindings/cpp/include/proton/object.hpp @@ -42,7 +42,7 @@ template <class T> class pn_ptr : private pn_ptr_base, private comparable<pn_ptr pn_ptr(T* p) : ptr_(p) { incref(ptr_); } pn_ptr(const pn_ptr& o) : ptr_(o.ptr_) { incref(ptr_); } -#if PN_CPP_HAS_CPP11 +#if PN_CPP_HAS_RVALUE_REFERENCES pn_ptr(pn_ptr&& o) : ptr_(0) { std::swap(ptr_, o.ptr_); } #endif @@ -52,8 +52,13 @@ template <class T> class pn_ptr : private pn_ptr_base, private comparable<pn_ptr T* get() const { return ptr_; } T* release() { T *p = ptr_; ptr_ = 0; return p; } + bool operator!() const { return !ptr_; } +#if PN_CPP_HAS_EXPLICIT_CONVERSIONS + explicit operator bool() const { return !!ptr_; } +#endif + static pn_ptr take_ownership(T* p) { return pn_ptr<T>(p, true); } private: @@ -73,6 +78,9 @@ template <class T> pn_ptr<T> take_ownership(T* p) { return pn_ptr<T>::take_owner template <class T> class object : private comparable<object<T> > { public: bool operator!() const { return !object_; } +#if PN_CPP_HAS_EXPLICIT_CONVERSIONS + explicit operator bool() const { return object_; } +#endif protected: object(pn_ptr<T> o) : object_(o) {} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/proton-c/bindings/cpp/include/proton/pn_unique_ptr.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/pn_unique_ptr.hpp b/proton-c/bindings/cpp/include/proton/pn_unique_ptr.hpp index 2056c70..56f8aba 100644 --- a/proton-c/bindings/cpp/include/proton/pn_unique_ptr.hpp +++ b/proton-c/bindings/cpp/include/proton/pn_unique_ptr.hpp @@ -38,7 +38,7 @@ namespace internal { template <class T> class pn_unique_ptr { public: pn_unique_ptr(T* p=0) : ptr_(p) {} -#if PN_CPP_HAS_CPP11 +#if PN_CPP_HAS_RVALUE_REFERENCES pn_unique_ptr(pn_unique_ptr&& x) : ptr_(0) { std::swap(ptr_, x.ptr_); } #else pn_unique_ptr(const pn_unique_ptr& x) : ptr_() { std::swap(ptr_, const_cast<pn_unique_ptr&>(x).ptr_); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/proton-c/bindings/cpp/include/proton/sasl.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/sasl.hpp b/proton-c/bindings/cpp/include/proton/sasl.hpp index eee6b96..db6b77a 100644 --- a/proton-c/bindings/cpp/include/proton/sasl.hpp +++ b/proton-c/bindings/cpp/include/proton/sasl.hpp @@ -38,13 +38,15 @@ class sasl { /// @endcond public: -#if PN_CPP_HAS_CPP11 +#if PN_CPP_HAS_DELETED_FUNCTIONS sasl() = delete; sasl(const sasl&) = delete; - sasl(sasl&&) = default; sasl& operator=(const sasl&) = delete; sasl& operator=(sasl&&) = delete; #endif +#if PN_CPP_HAS_DEFAULTED_FUNCTIONS + sasl(sasl&&) = default; +#endif /// The result of the SASL negotiation. enum outcome { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/proton-c/bindings/cpp/include/proton/types_fwd.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/types_fwd.hpp b/proton-c/bindings/cpp/include/proton/types_fwd.hpp index 77e2bf3..8ece3de 100644 --- a/proton-c/bindings/cpp/include/proton/types_fwd.hpp +++ b/proton-c/bindings/cpp/include/proton/types_fwd.hpp @@ -47,7 +47,7 @@ class value; struct null { null() {} -#if PN_CPP_HAS_CPP11 +#if PN_CPP_HAS_NULLPTR null(std::nullptr_t) {} #endif }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/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 fb3c5a3..8957fdc 100644 --- a/proton-c/bindings/cpp/include/proton/value.hpp +++ b/proton-c/bindings/cpp/include/proton/value.hpp @@ -65,7 +65,7 @@ class value : public value_base, private comparable<value> { ///@{ PN_CPP_EXTERN value(const value&); PN_CPP_EXTERN value& operator=(const value&); -#if PN_CPP_HAS_CPP11 +#if PN_CPP_HAS_RVALUE_REFERENCES PN_CPP_EXTERN value(value&&); PN_CPP_EXTERN value& operator=(value&&); #endif http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/proton-c/bindings/cpp/src/error_condition.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/error_condition.cpp b/proton-c/bindings/cpp/src/error_condition.cpp index b575596..1596d59 100644 --- a/proton-c/bindings/cpp/src/error_condition.cpp +++ b/proton-c/bindings/cpp/src/error_condition.cpp @@ -48,6 +48,12 @@ error_condition::error_condition(std::string name, std::string description, valu properties_(properties) {} +#if PN_CPP_HAS_EXPLICIT_CONVERSIONS +error_condition::operator bool() const { + return !name_.empty(); +} +#endif + bool error_condition::operator!() const { return name_.empty(); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/proton-c/bindings/cpp/src/message.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/message.cpp b/proton-c/bindings/cpp/src/message.cpp index 0ca5d61..98015d8 100644 --- a/proton-c/bindings/cpp/src/message.cpp +++ b/proton-c/bindings/cpp/src/message.cpp @@ -43,8 +43,12 @@ namespace proton { message::message() : pn_msg_(0) {} message::message(const message &m) : pn_msg_(0) { *this = m; } -#if PN_CPP_HAS_CPP11 +#if PN_CPP_HAS_RVALUE_REFERENCES message::message(message &&m) : pn_msg_(0) { swap(*this, m); } +message& message::operator=(message&& m) { + swap(*this, m); + return *this; +} #endif message::message(const value& x) : pn_msg_(0) { body() = x; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/80f6d4b5/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 ba2f540..7019dfd 100644 --- a/proton-c/bindings/cpp/src/value.cpp +++ b/proton-c/bindings/cpp/src/value.cpp @@ -33,7 +33,7 @@ using namespace codec; value::value() {} value::value(const value& x) { *this = x; } value::value(const codec::data& x) { if (!x.empty()) data().copy(x); } -#if PN_CPP_HAS_CPP11 +#if PN_CPP_HAS_RVALUE_REFERENCES value::value(value&& x) { swap(*this, x); } value& value::operator=(value&& x) { swap(*this, x); return *this; } #endif --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
