qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject qpid-proton git commit: PROTON-1287: c++: missing empty() method on message_id, annotation_key
Date Fri, 26 Aug 2016 20:00:54 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master c5f3f3286 -> ba8639fb7


PROTON-1287: c++: missing empty() method on message_id, annotation_key

Added empty() to scalar_base(), since all restricted scalar types can be missing
in a message, so they need to allow the possibility of empty()

Moved internal::scalar_base to proton::scalar_base as it provides part of the
public API.

Moved internal::value_base::empty() and type() to proton::value. There's no need for them
to be on the internal class and they are public API.

Added unit tests to confirm default values on proton::message, esp. empty scalar values.


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

Branch: refs/heads/master
Commit: ba8639fb7325a91d29f356a4e095cb0ae4c7888d
Parents: c5f3f32
Author: Alan Conway <aconway@redhat.com>
Authored: Tue Aug 23 15:28:27 2016 +0100
Committer: Alan Conway <aconway@redhat.com>
Committed: Fri Aug 26 15:57:32 2016 -0400

----------------------------------------------------------------------
 .../cpp/include/proton/annotation_key.hpp       |  10 +-
 .../cpp/include/proton/codec/encoder.hpp        |   4 +-
 .../cpp/include/proton/internal/scalar_base.hpp | 206 ------------------
 .../bindings/cpp/include/proton/message.hpp     |   7 +-
 .../bindings/cpp/include/proton/message_id.hpp  |  10 +-
 proton-c/bindings/cpp/include/proton/scalar.hpp |   7 +-
 .../bindings/cpp/include/proton/scalar_base.hpp | 213 +++++++++++++++++++
 proton-c/bindings/cpp/include/proton/value.hpp  |  18 +-
 proton-c/bindings/cpp/src/encoder.cpp           |   4 +-
 proton-c/bindings/cpp/src/message.cpp           |   2 +
 proton-c/bindings/cpp/src/message_test.cpp      |  29 +++
 proton-c/bindings/cpp/src/scalar_base.cpp       |  17 +-
 proton-c/bindings/cpp/src/value.cpp             |  12 +-
 13 files changed, 290 insertions(+), 249 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/proton-c/bindings/cpp/include/proton/annotation_key.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/annotation_key.hpp b/proton-c/bindings/cpp/include/proton/annotation_key.hpp
index c0c8ca6..23d789b 100644
--- a/proton-c/bindings/cpp/include/proton/annotation_key.hpp
+++ b/proton-c/bindings/cpp/include/proton/annotation_key.hpp
@@ -22,7 +22,7 @@
  *
  */
 
-#include "./internal/scalar_base.hpp"
+#include "./scalar_base.hpp"
 #include "./symbol.hpp"
 
 namespace proton {
@@ -30,12 +30,10 @@ namespace proton {
 /// A key for use with AMQP annotation maps.
 ///
 /// An annotation_key can contain either a uint64_t or a proton::symbol.
-class annotation_key : public internal::scalar_base {
+class annotation_key : public scalar_base {
   public:
-    using internal::scalar_base::type;
-
-    /// An empty annotation key has a uint64_t == 0 value.
-    annotation_key() { put_(uint64_t(0)); }
+    /// An empty annotation key.
+    annotation_key() {}
 
     /// Construct from any type that can be assigned.
     template <class T> annotation_key(const T& x) { *this = x; }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/proton-c/bindings/cpp/include/proton/codec/encoder.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/codec/encoder.hpp b/proton-c/bindings/cpp/include/proton/codec/encoder.hpp
index 847e0a9..b1aff89 100644
--- a/proton-c/bindings/cpp/include/proton/codec/encoder.hpp
+++ b/proton-c/bindings/cpp/include/proton/codec/encoder.hpp
@@ -28,9 +28,9 @@
 #include "./common.hpp"
 
 namespace proton {
+class scalar_base;
 
 namespace internal{
-class scalar_base;
 class value_base;
 }
 
@@ -90,7 +90,7 @@ class encoder : public internal::data {
     PN_CPP_EXTERN encoder& operator<<(const std::string&);
     PN_CPP_EXTERN encoder& operator<<(const symbol&);
     PN_CPP_EXTERN encoder& operator<<(const binary&);
-    PN_CPP_EXTERN encoder& operator<<(const internal::scalar_base&);
+    PN_CPP_EXTERN encoder& operator<<(const scalar_base&);
     PN_CPP_EXTERN encoder& operator<<(const null&);
     /// @}
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/proton-c/bindings/cpp/include/proton/internal/scalar_base.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/internal/scalar_base.hpp b/proton-c/bindings/cpp/include/proton/internal/scalar_base.hpp
deleted file mode 100644
index 2e491d1..0000000
--- a/proton-c/bindings/cpp/include/proton/internal/scalar_base.hpp
+++ /dev/null
@@ -1,206 +0,0 @@
-#ifndef PROTON_INTERNAL_SCALAR_BASE_HPP
-#define PROTON_INTERNAL_SCALAR_BASE_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.
- *
- */
-
-#include "../binary.hpp"
-#include "../decimal.hpp"
-#include "../error.hpp"
-#include "./export.hpp"
-#include "./comparable.hpp"
-#include "./type_traits.hpp"
-#include "../symbol.hpp"
-#include "../timestamp.hpp"
-#include "../type_id.hpp"
-#include "../types_fwd.hpp"
-#include "../uuid.hpp"
-
-#include <iosfwd>
-#include <string>
-#include <typeinfo>
-
-namespace proton {
-class message;
-
-namespace codec {
-class decoder;
-class encoder;
-}
-
-namespace internal {
-
-class scalar_base;
-template<class T> T get(const scalar_base& s);
-
-/// Base class for scalar types.
-class scalar_base : private comparable<scalar_base> {
-  public:
-    /// AMQP type of data stored in the scalar
-    PN_CPP_EXTERN type_id type() const;
-
-    // XXX I don't think many folks ever used this stuff.  Let's
-    // remove it. - Yes, try to remove them.
-    /// @cond INTERNAL
-    /// deprecated
-    template <class T> void get(T& x) const { get_(x); }
-    template <class T> T get() const { T x; get_(x); return x; }
-    /// @endcond
-
-    /// Compare
-  friend PN_CPP_EXTERN bool operator<(const scalar_base& x, const scalar_base&
y);
-    /// Compare
-  friend PN_CPP_EXTERN bool operator==(const scalar_base& x, const scalar_base& y);
-    /// Print the contained value
-  friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream& o, const scalar_base&
x);
-
-  protected:
-    PN_CPP_EXTERN scalar_base(const pn_atom_t& a);
-    PN_CPP_EXTERN scalar_base();
-    PN_CPP_EXTERN scalar_base(const scalar_base&);
-    PN_CPP_EXTERN scalar_base& operator=(const scalar_base&);
-
-    PN_CPP_EXTERN void put_(bool);
-    PN_CPP_EXTERN void put_(uint8_t);
-    PN_CPP_EXTERN void put_(int8_t);
-    PN_CPP_EXTERN void put_(uint16_t);
-    PN_CPP_EXTERN void put_(int16_t);
-    PN_CPP_EXTERN void put_(uint32_t);
-    PN_CPP_EXTERN void put_(int32_t);
-    PN_CPP_EXTERN void put_(uint64_t);
-    PN_CPP_EXTERN void put_(int64_t);
-    PN_CPP_EXTERN void put_(wchar_t);
-    PN_CPP_EXTERN void put_(float);
-    PN_CPP_EXTERN void put_(double);
-    PN_CPP_EXTERN void put_(timestamp);
-    PN_CPP_EXTERN void put_(const decimal32&);
-    PN_CPP_EXTERN void put_(const decimal64&);
-    PN_CPP_EXTERN void put_(const decimal128&);
-    PN_CPP_EXTERN void put_(const uuid&);
-    PN_CPP_EXTERN void put_(const std::string&);
-    PN_CPP_EXTERN void put_(const symbol&);
-    PN_CPP_EXTERN void put_(const binary&);
-    PN_CPP_EXTERN void put_(const char* s); ///< Treated as an AMQP string
-    PN_CPP_EXTERN void put_(const null&);
-
-    template<class T> void put(const T& x) { putter<T>::put(*this, x); }
-
-  private:
-    PN_CPP_EXTERN void get_(bool&) const;
-    PN_CPP_EXTERN void get_(uint8_t&) const;
-    PN_CPP_EXTERN void get_(int8_t&) const;
-    PN_CPP_EXTERN void get_(uint16_t&) const;
-    PN_CPP_EXTERN void get_(int16_t&) const;
-    PN_CPP_EXTERN void get_(uint32_t&) const;
-    PN_CPP_EXTERN void get_(int32_t&) const;
-    PN_CPP_EXTERN void get_(uint64_t&) const;
-    PN_CPP_EXTERN void get_(int64_t&) const;
-    PN_CPP_EXTERN void get_(wchar_t&) const;
-    PN_CPP_EXTERN void get_(float&) const;
-    PN_CPP_EXTERN void get_(double&) const;
-    PN_CPP_EXTERN void get_(timestamp&) const;
-    PN_CPP_EXTERN void get_(decimal32&) const;
-    PN_CPP_EXTERN void get_(decimal64&) const;
-    PN_CPP_EXTERN void get_(decimal128&) const;
-    PN_CPP_EXTERN void get_(uuid&) const;
-    PN_CPP_EXTERN void get_(std::string&) const;
-    PN_CPP_EXTERN void get_(symbol&) const;
-    PN_CPP_EXTERN void get_(binary&) const;
-    PN_CPP_EXTERN void get_(null&) const;
-
-    // use template structs, functions cannot be  partially specialized.
-    template <class T, class Enable=void> struct putter {
-        static void put(scalar_base& s, const T& x) { s.put_(x); }
-    };
-    template <class T> struct putter<T, typename enable_if<is_unknown_integer<T>::value>::type>
{
-        static void put(scalar_base& s, const T& x) { s.put_(static_cast<typename
known_integer<T>::type>(x)); }
-    };
-    template <class T, class Enable=void> struct getter {
-        static T get(const scalar_base& s) { T x; s.get_(x); return x; }
-    };
-    template <class T> struct getter<T, typename enable_if<is_unknown_integer<T>::value>::type>
{
-        static T get(const scalar_base& s) { typename known_integer<T>::type x;
s.get_(x); return x; }
-    };
-
-    void ok(pn_type_t) const;
-    void set(const pn_atom_t&);
-    void set(const binary& x, pn_type_t t);
-
-    pn_atom_t atom_;
-    binary bytes_; // Hold binary data.
-
-    /// @cond INTERNAL
-  friend class proton::message;
-  friend class codec::encoder;
-  friend class codec::decoder;
-  template<class T> friend T get(const scalar_base& s) { return scalar_base::getter<T>::get(s);
}
-    /// @endcond
-};
-
-template <class R, class F> R visit(const scalar_base& s, F f) {
-    switch(s.type()) {
-      case BOOLEAN: return f(s.get<bool>());
-      case UBYTE: return f(s.get<uint8_t>());
-      case BYTE: return f(s.get<int8_t>());
-      case USHORT: return f(s.get<uint16_t>());
-      case SHORT: return f(s.get<int16_t>());
-      case UINT: return f(s.get<uint32_t>());
-      case INT: return f(s.get<int32_t>());
-      case CHAR: return f(s.get<wchar_t>());
-      case ULONG: return f(s.get<uint64_t>());
-      case LONG: return f(s.get<int64_t>());
-      case TIMESTAMP: return f(s.get<timestamp>());
-      case FLOAT: return f(s.get<float>());
-      case DOUBLE: return f(s.get<double>());
-      case DECIMAL32: return f(s.get<decimal32>());
-      case DECIMAL64: return f(s.get<decimal64>());
-      case DECIMAL128: return f(s.get<decimal128>());
-      case UUID: return f(s.get<uuid>());
-      case BINARY: return f(s.get<binary>());
-      case STRING: return f(s.get<std::string>());
-      case SYMBOL: return f(s.get<symbol>());
-      default: throw conversion_error("invalid scalar type "+type_name(s.type()));
-    }
-}
-
-PN_CPP_EXTERN conversion_error make_coercion_error(const char* cpp_type, type_id amqp_type);
-
-template<class T> struct coerce_op {
-    template <class U>
-    typename enable_if<is_convertible<U, T>::value, T>::type operator()(const
U& x) {
-        return static_cast<T>(x);
-    }
-    template <class U>
-    typename enable_if<!is_convertible<U, T>::value, T>::type operator()(const
U&) {
-        throw make_coercion_error(typeid(T).name(), type_id_of<U>::value);
-    }
-};
-
-template <class T> T coerce(const scalar_base& s) { return visit<T>(s, coerce_op<T>());
}
-
-} // internal
-
-/// Return a readable string representation of x for display purposes.
-PN_CPP_EXTERN std::string to_string(const internal::scalar_base& x);
-
-} // proton
-
-#endif // PROTON_INTERNAL_SCALAR_BASE_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/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 3f683f6..e9f1da4 100644
--- a/proton-c/bindings/cpp/include/proton/message.hpp
+++ b/proton-c/bindings/cpp/include/proton/message.hpp
@@ -134,7 +134,7 @@ class message {
 
     /// Get the address for replies.
     PN_CPP_EXTERN std::string reply_to() const;
-    
+
     /// Set the ID for matching related messages.
     PN_CPP_EXTERN void correlation_id(const message_id&);
 
@@ -230,6 +230,8 @@ class message {
     /// The priority of a message impacts ordering guarantees. Within
     /// a given ordered context, higher priority messages may jump
     /// ahead of lower priority messages.
+    ///
+    /// The default value set on newly constructed messages is message::default_priority.
     PN_CPP_EXTERN uint8_t priority() const;
 
     /// Set the priority.
@@ -318,6 +320,9 @@ class message {
 
     /// @}
 
+    /// Default priority assigned to new messages.
+    PN_CPP_EXTERN static const uint8_t default_priority;
+
     /// @cond INTERNAL
   private:
     pn_message_t *pn_msg() const;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/proton-c/bindings/cpp/include/proton/message_id.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/message_id.hpp b/proton-c/bindings/cpp/include/proton/message_id.hpp
index 84f8ab0..5e0de90 100644
--- a/proton-c/bindings/cpp/include/proton/message_id.hpp
+++ b/proton-c/bindings/cpp/include/proton/message_id.hpp
@@ -23,7 +23,7 @@
  */
 
 #include "./binary.hpp"
-#include "./internal/scalar_base.hpp"
+#include "./scalar_base.hpp"
 #include "./uuid.hpp"
 
 #include <string>
@@ -39,10 +39,10 @@ namespace proton {
 ///  - proton::uuid
 ///  - proton::binary
 ///
-class message_id : public internal::scalar_base {
+class message_id : public scalar_base {
   public:
-    /// An empty message_id has a uint64_t value set to 0.
-    message_id() { put_(uint64_t(0)); }
+    /// An empty message_id.
+    message_id() {}
 
     /// Construct from any type that can be assigned.
     template <class T> message_id(const T& x) { *this = x; }
@@ -59,7 +59,7 @@ class message_id : public internal::scalar_base {
     /// @}
 
   private:
-    message_id(const pn_atom_t& a): internal::scalar_base(a) {}
+    message_id(const pn_atom_t& a): scalar_base(a) {}
 
     ///@cond INTERNAL
   friend class message;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/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 ab7cb2a..27de576 100644
--- a/proton-c/bindings/cpp/include/proton/scalar.hpp
+++ b/proton-c/bindings/cpp/include/proton/scalar.hpp
@@ -20,7 +20,7 @@
  * under the License.
  */
 
-#include "./internal/scalar_base.hpp"
+#include "./scalar_base.hpp"
 
 namespace proton {
 
@@ -32,7 +32,7 @@ class encoder;
 /// A holder for an instance of any scalar AMQP type.
 ///
 /// @see @ref types_page
-class scalar : public internal::scalar_base {
+class scalar : public scalar_base {
   public:
     /// Create an empty scalar.
     PN_CPP_EXTERN scalar() {}
@@ -43,9 +43,6 @@ class scalar : public internal::scalar_base {
     /// Assign from any scalar type.
     template <class T> scalar& operator=(const T& x) { put(x); return *this;
}
 
-    /// True if type() == NULL_TYPE.
-    bool empty() const { return type() == NULL_TYPE; }
-
     /// Clear the scalar, making it empty().
     void clear() { *this = null(); }
 };

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/proton-c/bindings/cpp/include/proton/scalar_base.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/scalar_base.hpp b/proton-c/bindings/cpp/include/proton/scalar_base.hpp
new file mode 100644
index 0000000..ba594c3
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/scalar_base.hpp
@@ -0,0 +1,213 @@
+#ifndef PROTON_SCALAR_BASE_HPP
+#define PROTON_SCALAR_BASE_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.
+ *
+ */
+
+#include "./binary.hpp"
+#include "./decimal.hpp"
+#include "./error.hpp"
+#include "./internal/comparable.hpp"
+#include "./internal/export.hpp"
+#include "./internal/type_traits.hpp"
+#include "./symbol.hpp"
+#include "./timestamp.hpp"
+#include "./type_id.hpp"
+#include "./types_fwd.hpp"
+#include "./uuid.hpp"
+
+#include <iosfwd>
+#include <string>
+#include <typeinfo>
+
+namespace proton {
+class message;
+class scalar_base;
+
+namespace codec {
+class decoder;
+class encoder;
+}
+
+namespace internal {
+template<class T> T get(const scalar_base& s);
+}
+
+/// Base class for scalar types.
+class scalar_base : private internal::comparable<scalar_base> {
+  public:
+    /// AMQP type of data stored in the scalar
+    PN_CPP_EXTERN type_id type() const;
+
+    /// True if there is no value, i.e. type() == NULL_TYPE.
+    PN_CPP_EXTERN bool empty() const;
+
+    /// Compare
+  friend PN_CPP_EXTERN bool operator<(const scalar_base& x, const scalar_base&
y);
+    /// Compare
+  friend PN_CPP_EXTERN bool operator==(const scalar_base& x, const scalar_base& y);
+    /// Print the contained value
+  friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream& o, const scalar_base&
x);
+
+  protected:
+    PN_CPP_EXTERN scalar_base(const pn_atom_t& a);
+    PN_CPP_EXTERN scalar_base();
+    PN_CPP_EXTERN scalar_base(const scalar_base&);
+    PN_CPP_EXTERN scalar_base& operator=(const scalar_base&);
+
+    PN_CPP_EXTERN void put_(bool);
+    PN_CPP_EXTERN void put_(uint8_t);
+    PN_CPP_EXTERN void put_(int8_t);
+    PN_CPP_EXTERN void put_(uint16_t);
+    PN_CPP_EXTERN void put_(int16_t);
+    PN_CPP_EXTERN void put_(uint32_t);
+    PN_CPP_EXTERN void put_(int32_t);
+    PN_CPP_EXTERN void put_(uint64_t);
+    PN_CPP_EXTERN void put_(int64_t);
+    PN_CPP_EXTERN void put_(wchar_t);
+    PN_CPP_EXTERN void put_(float);
+    PN_CPP_EXTERN void put_(double);
+    PN_CPP_EXTERN void put_(timestamp);
+    PN_CPP_EXTERN void put_(const decimal32&);
+    PN_CPP_EXTERN void put_(const decimal64&);
+    PN_CPP_EXTERN void put_(const decimal128&);
+    PN_CPP_EXTERN void put_(const uuid&);
+    PN_CPP_EXTERN void put_(const std::string&);
+    PN_CPP_EXTERN void put_(const symbol&);
+    PN_CPP_EXTERN void put_(const binary&);
+    PN_CPP_EXTERN void put_(const char* s); ///< Treated as an AMQP string
+    PN_CPP_EXTERN void put_(const null&);
+
+    template<class T> void put(const T& x) { putter<T>::put(*this, x); }
+
+  private:
+    PN_CPP_EXTERN void get_(bool&) const;
+    PN_CPP_EXTERN void get_(uint8_t&) const;
+    PN_CPP_EXTERN void get_(int8_t&) const;
+    PN_CPP_EXTERN void get_(uint16_t&) const;
+    PN_CPP_EXTERN void get_(int16_t&) const;
+    PN_CPP_EXTERN void get_(uint32_t&) const;
+    PN_CPP_EXTERN void get_(int32_t&) const;
+    PN_CPP_EXTERN void get_(uint64_t&) const;
+    PN_CPP_EXTERN void get_(int64_t&) const;
+    PN_CPP_EXTERN void get_(wchar_t&) const;
+    PN_CPP_EXTERN void get_(float&) const;
+    PN_CPP_EXTERN void get_(double&) const;
+    PN_CPP_EXTERN void get_(timestamp&) const;
+    PN_CPP_EXTERN void get_(decimal32&) const;
+    PN_CPP_EXTERN void get_(decimal64&) const;
+    PN_CPP_EXTERN void get_(decimal128&) const;
+    PN_CPP_EXTERN void get_(uuid&) const;
+    PN_CPP_EXTERN void get_(std::string&) const;
+    PN_CPP_EXTERN void get_(symbol&) const;
+    PN_CPP_EXTERN void get_(binary&) const;
+    PN_CPP_EXTERN void get_(null&) const;
+
+    // use template structs, functions cannot be  partially specialized.
+    template <class T, class Enable=void> struct putter {
+        static void put(scalar_base& s, const T& x) { s.put_(x); }
+    };
+    template <class T>
+    struct putter<T, typename internal::enable_if<internal::is_unknown_integer<T>::value>::type>
{
+        static void put(scalar_base& s, const T& x) {
+            s.put_(static_cast<typename internal::known_integer<T>::type>(x));
+        }
+    };
+    template <class T, class Enable=void>
+    struct getter {
+        static T get(const scalar_base& s) { T x; s.get_(x); return x; }
+    };
+    template <class T>
+    struct getter<T, typename internal::enable_if<internal::is_unknown_integer<T>::value>::type>
{
+        static T get(const scalar_base& s) {
+            typename internal::known_integer<T>::type x; s.get_(x); return x;
+        }
+    };
+
+    void ok(pn_type_t) const;
+    void set(const pn_atom_t&);
+    void set(const binary& x, pn_type_t t);
+
+    pn_atom_t atom_;
+    binary bytes_; // Hold binary data.
+
+    /// @cond INTERNAL
+  friend class proton::message;
+  friend class codec::encoder;
+  friend class codec::decoder;
+  template<class T> friend T internal::get(const scalar_base& s);
+    /// @endcond
+};
+
+namespace internal {
+
+template<class T> T get(const scalar_base& s) {
+      return scalar_base::getter<T>::get(s);
+}
+
+template <class R, class F> R visit(const scalar_base& s, F f) {
+    switch(s.type()) {
+      case BOOLEAN: return f(internal::get<bool>(s));
+      case UBYTE: return f(internal::get<uint8_t>(s));
+      case BYTE: return f(internal::get<int8_t>(s));
+      case USHORT: return f(internal::get<uint16_t>(s));
+      case SHORT: return f(internal::get<int16_t>(s));
+      case UINT: return f(internal::get<uint32_t>(s));
+      case INT: return f(internal::get<int32_t>(s));
+      case CHAR: return f(internal::get<wchar_t>(s));
+      case ULONG: return f(internal::get<uint64_t>(s));
+      case LONG: return f(internal::get<int64_t>(s));
+      case TIMESTAMP: return f(internal::get<timestamp>(s));
+      case FLOAT: return f(internal::get<float>(s));
+      case DOUBLE: return f(internal::get<double>(s));
+      case DECIMAL32: return f(internal::get<decimal32>(s));
+      case DECIMAL64: return f(internal::get<decimal64>(s));
+      case DECIMAL128: return f(internal::get<decimal128>(s));
+      case UUID: return f(internal::get<uuid>(s));
+      case BINARY: return f(internal::get<binary>(s));
+      case STRING: return f(internal::get<std::string>(s));
+      case SYMBOL: return f(internal::get<symbol>(s));
+      default: throw conversion_error("invalid scalar type "+type_name(s.type()));
+    }
+}
+
+PN_CPP_EXTERN conversion_error make_coercion_error(const char* cpp_type, type_id amqp_type);
+
+template<class T> struct coerce_op {
+    template <class U>
+    typename enable_if<is_convertible<U, T>::value, T>::type operator()(const
U& x) {
+        return static_cast<T>(x);
+    }
+    template <class U>
+    typename enable_if<!is_convertible<U, T>::value, T>::type operator()(const
U&) {
+        throw make_coercion_error(typeid(T).name(), type_id_of<U>::value);
+    }
+};
+
+template <class T> T coerce(const scalar_base& s) { return visit<T>(s, coerce_op<T>());
}
+} // namespace internal
+
+/// Return a readable string representation of x for display purposes.
+PN_CPP_EXTERN std::string to_string(const scalar_base& x);
+
+} // proton
+
+#endif // PROTON_SCALAR_BASE_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/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 e7e9f79..242ec68 100644
--- a/proton-c/bindings/cpp/include/proton/value.hpp
+++ b/proton-c/bindings/cpp/include/proton/value.hpp
@@ -34,15 +34,8 @@ namespace proton {
 
 namespace internal {
 
-/// Separate value data from implicit conversion constructors to avoid template recursion.
+// Separate value data from implicit conversion constructors to avoid template recursion.
 class value_base {
-  public:
-    /// Get the type ID for the current value.
-    PN_CPP_EXTERN type_id type() const;
-
-    /// True if the value is null
-    PN_CPP_EXTERN bool empty() const;
-
   protected:
     internal::data& data();
     internal::data data_;
@@ -88,7 +81,14 @@ class value : public internal::value_base, private internal::comparable<value>
{
         return *this;
     }
 
-    /// Reset the value to null
+    /// Get the type ID for the current value.
+    PN_CPP_EXTERN type_id type() const;
+
+    /// True if the value is null
+    PN_CPP_EXTERN bool empty() const;
+
+
+    /// Reset the value to null/empty
     PN_CPP_EXTERN void clear();
 
     /// @cond INTERNAL (deprecated)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/proton-c/bindings/cpp/src/encoder.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/encoder.cpp b/proton-c/bindings/cpp/src/encoder.cpp
index e718c40..89ac8c4 100644
--- a/proton-c/bindings/cpp/src/encoder.cpp
+++ b/proton-c/bindings/cpp/src/encoder.cpp
@@ -27,7 +27,7 @@
 #include "proton/binary.hpp"
 #include "proton/decimal.hpp"
 #include "proton/message_id.hpp"
-#include "proton/internal/scalar_base.hpp"
+#include "proton/scalar_base.hpp"
 #include "proton/symbol.hpp"
 #include "proton/timestamp.hpp"
 #include "proton/value.hpp"
@@ -145,7 +145,7 @@ encoder& encoder::operator<<(const symbol& x) { return insert(x,
pn_data_put_amq
 encoder& encoder::operator<<(const binary& x) { return insert(x, pn_data_put_amqp_binary);
}
 encoder& encoder::operator<<(const null&) { pn_data_put_null(pn_object());
return *this; }
 
-encoder& encoder::operator<<(const internal::scalar_base& x) { return insert(x.atom_,
pn_data_put_atom); }
+encoder& encoder::operator<<(const scalar_base& x) { return insert(x.atom_,
pn_data_put_atom); }
 
 encoder& encoder::operator<<(const internal::value_base& x) {
     data d = x.data_;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/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 ca5f2d5..8524782 100644
--- a/proton-c/bindings/cpp/src/message.cpp
+++ b/proton-c/bindings/cpp/src/message.cpp
@@ -329,4 +329,6 @@ void message::delivery_count(uint32_t d) { pn_message_set_delivery_count(pn_msg(
 int32_t message::group_sequence() const { return pn_message_get_group_sequence(pn_msg());
}
 void message::group_sequence(int32_t d) { pn_message_set_group_sequence(pn_msg(), d); }
 
+const uint8_t message::default_priority = PN_DEFAULT_PRIORITY;
+
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/proton-c/bindings/cpp/src/message_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/message_test.cpp b/proton-c/bindings/cpp/src/message_test.cpp
index 68205c9..4d4e239 100644
--- a/proton-c/bindings/cpp/src/message_test.cpp
+++ b/proton-c/bindings/cpp/src/message_test.cpp
@@ -38,6 +38,30 @@ using namespace proton;
     m.ATTR(#ATTR); \
     ASSERT_EQUAL(scalar(#ATTR), m.ATTR())
 
+void test_message_defaults() {
+    message m;
+    ASSERT(m.body().empty());
+    ASSERT(m.id().empty());
+    ASSERT(m.user().empty());
+    ASSERT(m.to().empty());
+    ASSERT(m.subject().empty());
+    ASSERT(m.reply_to().empty());
+    ASSERT(m.correlation_id().empty());
+    ASSERT(m.content_type().empty());
+    ASSERT(m.content_encoding().empty());
+    ASSERT(m.group_id().empty());
+    ASSERT(m.reply_to_group_id().empty());
+    ASSERT_EQUAL(0, m.expiry_time().milliseconds());
+    ASSERT_EQUAL(0, m.creation_time().milliseconds());
+
+    ASSERT_EQUAL(false, m.inferred());
+    ASSERT_EQUAL(false, m.durable());
+    ASSERT_EQUAL(0, m.ttl().milliseconds());
+    ASSERT_EQUAL(message::default_priority, m.priority());
+    ASSERT_EQUAL(false, m.first_acquirer());
+    ASSERT_EQUAL(0u, m.delivery_count());
+}
+
 void test_message_properties() {
     message m("hello");
     std::string s = get<std::string>(m.body());
@@ -57,6 +81,10 @@ void test_message_properties() {
     ASSERT_EQUAL(m.expiry_time().milliseconds(), 42);
     m.creation_time(timestamp(4242));
     ASSERT_EQUAL(m.creation_time().milliseconds(), 4242);
+    m.ttl(duration(30));
+    ASSERT_EQUAL(m.ttl().milliseconds(), 30);
+    m.priority(3);
+    ASSERT_EQUAL(m.priority(), 3);
 
     message m2(m);
     ASSERT_EQUAL("hello", get<std::string>(m2.body()));
@@ -141,6 +169,7 @@ void test_message_maps() {
 int main(int, char**) {
     int failed = 0;
     RUN_TEST(failed, test_message_properties());
+    RUN_TEST(failed, test_message_defaults());
     RUN_TEST(failed, test_message_body());
     RUN_TEST(failed, test_message_maps());
     return failed;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/proton-c/bindings/cpp/src/scalar_base.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/scalar_base.cpp b/proton-c/bindings/cpp/src/scalar_base.cpp
index c005122..840a6e8 100644
--- a/proton-c/bindings/cpp/src/scalar_base.cpp
+++ b/proton-c/bindings/cpp/src/scalar_base.cpp
@@ -22,8 +22,8 @@
 
 #include "proton/binary.hpp"
 #include "proton/decimal.hpp"
-#include "proton/internal/scalar_base.hpp"
 #include "proton/internal/type_traits.hpp"
+#include "proton/scalar_base.hpp"
 #include "proton/symbol.hpp"
 #include "proton/timestamp.hpp"
 #include "proton/uuid.hpp"
@@ -32,7 +32,6 @@
 #include <sstream>
 
 namespace proton {
-namespace internal {
 
 scalar_base::scalar_base() { atom_.type = PN_NULL; }
 scalar_base::scalar_base(const pn_atom_t& a) { set(a); }
@@ -46,6 +45,8 @@ scalar_base& scalar_base::operator=(const scalar_base& x) {
 
 type_id scalar_base::type() const { return type_id(atom_.type); }
 
+bool scalar_base::empty() const { return type() == NULL_TYPE; }
+
 void scalar_base::set(const binary& x, pn_type_t t) {
     atom_.type = t;
     bytes_ = x;
@@ -115,13 +116,13 @@ namespace {
 struct equal_op {
     const scalar_base& x;
     equal_op(const scalar_base& s) : x(s) {}
-    template<class T> bool operator()(const T& y) { return (get<T>(x) ==
y); }
+    template<class T> bool operator()(const T& y) { return (internal::get<T>(x)
== y); }
 };
 
 struct less_op {
     const scalar_base& x;
     less_op(const scalar_base& s) : x(s) {}
-    template<class T> bool operator()(const T& y) { return (y < get<T>(x));
}
+    template<class T> bool operator()(const T& y) { return (y < internal::get<T>(x));
}
 };
 
 struct ostream_op {
@@ -148,20 +149,22 @@ std::ostream& operator<<(std::ostream& o, const scalar_base&
s) {
     switch (s.type()) {
       case NULL_TYPE: return o; // NULL is empty, doesn't print (like empty string)
         // Print byte types as integer, not char.
-      case BYTE: return o << static_cast<int>(get<int8_t>(s));
-      case UBYTE: return o << static_cast<unsigned int>(get<uint8_t>(s));
+      case BYTE: return o << static_cast<int>(internal::get<int8_t>(s));
+      case UBYTE: return o << static_cast<unsigned int>(internal::get<uint8_t>(s));
         // Other types printed using normal C++ operator <<
       default: return internal::visit<std::ostream&>(s, ostream_op(o));
     }
 }
 
+namespace internal {
+
 conversion_error make_coercion_error(const char* cpp, type_id amqp) {
     return conversion_error(std::string("invalid proton::coerce<") + cpp + ">(" + type_name(amqp)
+ ")");
 }
 
 } // internal
 
-std::string to_string(const internal::scalar_base& x) {
+std::string to_string(const scalar_base& x) {
     std::ostringstream os;
     os << std::boolalpha << x;
     return os.str();

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ba8639fb/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 c223243..ceb3463 100644
--- a/proton-c/bindings/cpp/src/value.cpp
+++ b/proton-c/bindings/cpp/src/value.cpp
@@ -56,12 +56,6 @@ void value::clear() { if (!!data_) data_.clear(); }
 
 namespace internal {
 
-type_id value_base::type() const {
-    return (!data_ || data_.empty()) ? NULL_TYPE : codec::decoder(*this).next_type();
-}
-
-bool value_base::empty() const { return type() == NULL_TYPE; }
-
 // On demand
 internal::data& value_base::data() {
     if (!data_)
@@ -71,6 +65,12 @@ internal::data& value_base::data() {
 
 }
 
+type_id value::type() const {
+    return (!data_ || data_.empty()) ? NULL_TYPE : codec::decoder(*this).next_type();
+}
+
+bool value::empty() const { return type() == NULL_TYPE; }
+
 namespace {
 
 // Compare nodes, return -1 if a<b, 0 if a==b, +1 if a>b


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


Mime
View raw message