You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2016/03/11 22:45:53 UTC
[3/4] qpid-proton git commit: PROTON-1138: c++: Encode/decode of
complex types
PROTON-1138: c++: Encode/decode of complex types
- encode/decode std:: vector, map, list, deque, unordered_map, forward_list
- cleanup of encoder/decoder, remove dead code.
- simplify value enable-if logic.
- fix compile issues on old windows comilers.
- prevent accidental encoding of pointers as bool.
- pass encoder/decoder by reference for op << and >>
- rename `namespace internal` to `codec` for codec-related classes.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/4fa5fa41
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/4fa5fa41
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/4fa5fa41
Branch: refs/heads/master
Commit: 4fa5fa41bf465d6098f60f2a487efcdfa839f006
Parents: a2eb5f0
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Mar 8 18:50:00 2016 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Mar 11 16:45:22 2016 -0500
----------------------------------------------------------------------
cpp.cmake | 34 --
examples/cpp/README.hpp | 1 -
examples/cpp/encode_decode.cpp | 71 ++--
examples/cpp/engine/broker.cpp | 1 -
examples/cpp/example_test.py | 1 +
proton-c/bindings/cpp/CMakeLists.txt | 2 +-
.../bindings/cpp/include/proton/acceptor.hpp | 6 +-
proton-c/bindings/cpp/include/proton/amqp.hpp | 10 +-
.../cpp/include/proton/annotation_key.hpp | 22 +-
.../bindings/cpp/include/proton/byte_array.hpp | 20 +-
.../cpp/include/proton/connection_options.hpp | 15 +-
proton-c/bindings/cpp/include/proton/data.hpp | 109 +++---
.../bindings/cpp/include/proton/decoder.hpp | 302 ++++++---------
proton-c/bindings/cpp/include/proton/deque.hpp | 58 +++
.../bindings/cpp/include/proton/duration.hpp | 6 +-
.../bindings/cpp/include/proton/encoder.hpp | 241 +++++-------
proton-c/bindings/cpp/include/proton/event.hpp | 8 +-
.../cpp/include/proton/forward_list.hpp | 58 +++
proton-c/bindings/cpp/include/proton/link.hpp | 20 +-
proton-c/bindings/cpp/include/proton/list.hpp | 58 +++
proton-c/bindings/cpp/include/proton/map.hpp | 40 ++
.../bindings/cpp/include/proton/message.hpp | 22 +-
.../bindings/cpp/include/proton/message_id.hpp | 22 +-
proton-c/bindings/cpp/include/proton/scalar.hpp | 52 ++-
proton-c/bindings/cpp/include/proton/symbol.hpp | 4 +-
.../bindings/cpp/include/proton/type_id.hpp | 69 ++++
.../bindings/cpp/include/proton/type_traits.hpp | 107 ++----
proton-c/bindings/cpp/include/proton/types.hpp | 145 ++-----
.../bindings/cpp/include/proton/types_fwd.hpp | 47 +++
.../cpp/include/proton/unordered_map.hpp | 40 ++
proton-c/bindings/cpp/include/proton/url.hpp | 4 +-
proton-c/bindings/cpp/include/proton/uuid.hpp | 4 +-
proton-c/bindings/cpp/include/proton/value.hpp | 76 ++--
proton-c/bindings/cpp/include/proton/vector.hpp | 55 +++
proton-c/bindings/cpp/src/codec_test.cpp | 33 +-
proton-c/bindings/cpp/src/data.cpp | 145 ++-----
proton-c/bindings/cpp/src/decimal.cpp | 4 +-
proton-c/bindings/cpp/src/decoder.cpp | 381 ++++++++-----------
proton-c/bindings/cpp/src/duration.cpp | 8 +-
proton-c/bindings/cpp/src/encoder.cpp | 141 +++----
proton-c/bindings/cpp/src/engine_test.cpp | 2 +-
proton-c/bindings/cpp/src/id_generator.hpp | 2 +-
proton-c/bindings/cpp/src/interop_test.cpp | 26 +-
proton-c/bindings/cpp/src/link_options.cpp | 14 +-
proton-c/bindings/cpp/src/message.cpp | 37 +-
proton-c/bindings/cpp/src/msg.hpp | 2 +-
proton-c/bindings/cpp/src/posix/io.cpp | 2 +
proton-c/bindings/cpp/src/reactor.hpp | 1 +
proton-c/bindings/cpp/src/scalar.cpp | 25 +-
proton-c/bindings/cpp/src/scalar_test.cpp | 30 +-
proton-c/bindings/cpp/src/test_bits.hpp | 32 +-
proton-c/bindings/cpp/src/timestamp.cpp | 5 +
proton-c/bindings/cpp/src/transport.cpp | 7 +-
proton-c/bindings/cpp/src/type_id.cpp | 65 ++++
proton-c/bindings/cpp/src/types.cpp | 81 ----
proton-c/bindings/cpp/src/types_internal.hpp | 12 +-
proton-c/bindings/cpp/src/uuid.cpp | 10 +-
proton-c/bindings/cpp/src/value.cpp | 132 ++++++-
proton-c/bindings/cpp/src/value_test.cpp | 195 +++++++---
tests/tools/apps/cpp/reactor_send.cpp | 2 +-
60 files changed, 1674 insertions(+), 1450 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/cpp.cmake
----------------------------------------------------------------------
diff --git a/cpp.cmake b/cpp.cmake
deleted file mode 100644
index 0998546..0000000
--- a/cpp.cmake
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# 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.
-#
-
-# Check C++ capabilities.
-
-include(CheckCXXSourceCompiles)
-
-if (CMAKE_CXX_COMPILER)
- set(CMAKE_REQUIRED_FLAGS "${CXX_WARNING_FLAGS}")
- check_cxx_source_compiles("long long ll; int main(int, char**) { return 0; }" HAS_LONG_LONG)
- if (HAS_LONG_LONG)
- add_definitions(-DPN_HAS_LONG_LONG=1)
- endif()
- check_cxx_source_compiles("#include <memory>\nstd::shared_ptr<int> i; std::unique_ptr<int> u; int main(int, char**) { return 0; }" HAS_STD_PTR)
- if (HAS_STD_PTR)
- add_definitions(-DPN_HAS_STD_PTR=1)
- endif()
-endif()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/examples/cpp/README.hpp
----------------------------------------------------------------------
diff --git a/examples/cpp/README.hpp b/examples/cpp/README.hpp
index ccfb7e9..1e78774 100644
--- a/examples/cpp/README.hpp
+++ b/examples/cpp/README.hpp
@@ -60,7 +60,6 @@ Make sure to stop the broker first or use a different port for `direct_recv`.
*/
/// @cond INTERNAL
-/// XXX change namespaces
/** @example encode_decode.cpp
Shows how C++ data types can be converted to and from AMQP types.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/examples/cpp/encode_decode.cpp
----------------------------------------------------------------------
diff --git a/examples/cpp/encode_decode.cpp b/examples/cpp/encode_decode.cpp
index 8944f6d..12fc1ed 100644
--- a/examples/cpp/encode_decode.cpp
+++ b/examples/cpp/encode_decode.cpp
@@ -17,16 +17,14 @@
* under the License.
*/
-#include <proton/value.hpp>
-#include <proton/symbol.hpp>
+#include <proton/types.hpp>
+#include <proton/encoder.hpp>
+#include <proton/decoder.hpp>
+
#include <algorithm>
#include <iostream>
#include <iterator>
-#include <map>
#include <sstream>
-#include <vector>
-#include <list>
-
// Examples of how to use the encoder and decoder to create and examine AMQP values.
//
@@ -77,7 +75,7 @@ void uniform_containers() {
std::cout << a1 << std::endl;
// You can specify that a container should be encoded as an AMQP list instead.
- v = proton::internal::as<proton::LIST>(a1);
+ v = proton::codec::encoder::list(a1);
print(v);
std::cout << v.get<std::vector<int> >() << std::endl;
@@ -89,17 +87,27 @@ void uniform_containers() {
print(v);
std::cout << v.get<std::map<std::string, int> >() << std::endl;
- // You can convert a sequence of pairs to an AMQP map if you need to control the
- // encoded ordering.
+ // A sequence of pairs encodes as an AMQP MAP, which lets you control the encoded order.
std::vector<std::pair<std::string, int> > pairs;
pairs.push_back(std::make_pair("z", 3));
pairs.push_back(std::make_pair("a", 4));
- v = proton::internal::as<proton::MAP>(pairs);
+ v = pairs;
print(v);
- // You can also decode an AMQP map as a sequence of pairs using decoder() and proton::to_pairs
+
+ // You can also decode an AMQP map as a sequence of pairs to preserve encode order.
std::vector<std::pair<std::string, int> > pairs2;
- v.decode() >> proton::internal::to_pairs(pairs2);
+ proton::codec::decoder d(v);
+ d >> pairs2;
std::cout << pairs2 << std::endl;
+
+ // A vector of proton::value is normally encoded as a mixed-type AMQP LIST,
+ // but you can encoded it as an array provided all the values match the array type.
+ std::vector<proton::value> vv;
+ vv.push_back(proton::value("a"));
+ vv.push_back(proton::value("b"));
+ vv.push_back(proton::value("c"));
+ v = vv;
+ print(v);
}
// Containers with mixed types use value to represent arbitrary AMQP types.
@@ -132,22 +140,25 @@ void insert_stream_operators() {
proton::value v;
// Create an array of INT with values [1, 2, 3]
- v.encode() << proton::internal::start::array(proton::INT)
- << int32_t(1) << int32_t(2) << int32_t(3)
- << proton::internal::finish();
+ proton::codec::encoder e(v);
+ e << proton::codec::start::array(proton::INT)
+ << int32_t(1) << int32_t(2) << int32_t(3)
+ << proton::codec::finish();
print(v);
// Create a mixed-type list of the values [42, false, "x"].
- v.encode() << proton::internal::start::list()
- << int32_t(42) << false << proton::symbol("x")
- << proton::internal::finish();
+ proton::codec::encoder e2(v);
+ e2 << proton::codec::start::list()
+ << int32_t(42) << false << proton::symbol("x")
+ << proton::codec::finish();
print(v);
// Create a map { "k1":42, "k2": false }
- v.encode() << proton::internal::start::map()
- << "k1" << int32_t(42)
- << proton::symbol("k2") << false
- << proton::internal::finish();
+ proton::codec::encoder e3(v);
+ e3 << proton::codec::start::map()
+ << "k1" << int32_t(42)
+ << proton::symbol("k2") << false
+ << proton::codec::finish();
print(v);
}
@@ -168,9 +179,9 @@ int main(int, char**) {
// NOTE this is for example puroses only: There is a built in ostream operator<< for values.
//
//
-void print_next(proton::internal::decoder& d) {
- proton::type_id type = d.type();
- proton::internal::start s;
+void print_next(proton::codec::decoder& d) {
+ proton::type_id type = d.next_type();
+ proton::codec::start s;
switch (type) {
case proton::ARRAY: {
d >> s;
@@ -185,7 +196,7 @@ void print_next(proton::internal::decoder& d) {
print_next(d);
}
std::cout << "]";
- d >> proton::internal::finish();
+ d >> proton::codec::finish();
break;
}
case proton::LIST: {
@@ -196,7 +207,7 @@ void print_next(proton::internal::decoder& d) {
print_next(d);
}
std::cout << "]";
- d >> proton::internal::finish();
+ d >> proton::codec::finish();
break;
}
case proton::MAP: {
@@ -209,7 +220,7 @@ void print_next(proton::internal::decoder& d) {
print_next(d);
}
std::cout << "}";
- d >> proton::internal::finish();
+ d >> proton::codec::finish();
break;
}
case proton::DESCRIBED: {
@@ -217,7 +228,7 @@ void print_next(proton::internal::decoder& d) {
std::cout << "described(";
print_next(d); // Descriptor
print_next(d); // value
- d >> proton::internal::finish();
+ d >> proton::codec::finish();
break;
}
default:
@@ -231,7 +242,7 @@ void print_next(proton::internal::decoder& d) {
// Print a value, for example purposes. Normal code can use operator<<
void print(proton::value& v) {
- proton::internal::decoder d = v.decode();
+ proton::codec::decoder d(v);
d.rewind();
while (d.more()) {
print_next(d);
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/examples/cpp/engine/broker.cpp
----------------------------------------------------------------------
diff --git a/examples/cpp/engine/broker.cpp b/examples/cpp/engine/broker.cpp
index 09345de..f5e9205 100644
--- a/examples/cpp/engine/broker.cpp
+++ b/examples/cpp/engine/broker.cpp
@@ -24,7 +24,6 @@
#include <iostream>
-// FIXME aconway 2016-01-23: port broker to windows, need io::poller.
#ifdef WIN32
#include "proton/acceptor.hpp"
#include "proton/container.hpp"
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/examples/cpp/example_test.py
----------------------------------------------------------------------
diff --git a/examples/cpp/example_test.py b/examples/cpp/example_test.py
index f85d4be..6cfc632 100644
--- a/examples/cpp/example_test.py
+++ b/examples/cpp/example_test.py
@@ -288,6 +288,7 @@ map{string(one):int(1), string(two):int(2)}
{ one:1 two:2 }
map{string(z):int(3), string(a):int(4)}
[ z:3 a:4 ]
+list[string(a), string(b), string(c)]
== List and map of mixed type values.
list[int(42), string(foo)]
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/CMakeLists.txt b/proton-c/bindings/cpp/CMakeLists.txt
index 74a2356..7c667bf 100644
--- a/proton-c/bindings/cpp/CMakeLists.txt
+++ b/proton-c/bindings/cpp/CMakeLists.txt
@@ -66,7 +66,7 @@ set(qpid-proton-cpp-source
src/terminus.cpp
src/timestamp.cpp
src/transport.cpp
- src/types.cpp
+ src/type_id.cpp
src/url.cpp
src/uuid.cpp
src/value.cpp
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/acceptor.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/acceptor.hpp b/proton-c/bindings/cpp/include/proton/acceptor.hpp
index 64bd2e4..1b0ea12 100644
--- a/proton-c/bindings/cpp/include/proton/acceptor.hpp
+++ b/proton-c/bindings/cpp/include/proton/acceptor.hpp
@@ -22,9 +22,9 @@
*
*/
-#include "proton/reactor.h"
-#include "proton/export.hpp"
-#include "proton/object.hpp"
+#include <proton/reactor.h>
+#include <proton/export.hpp>
+#include <proton/object.hpp>
struct pn_connection_t;
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/amqp.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/amqp.hpp b/proton-c/bindings/cpp/include/proton/amqp.hpp
index 43662ce..2ca122f 100644
--- a/proton-c/bindings/cpp/include/proton/amqp.hpp
+++ b/proton-c/bindings/cpp/include/proton/amqp.hpp
@@ -19,20 +19,12 @@
* under the License.
*/
-#include "proton/types.hpp"
+#include <proton/types_fwd.hpp>
#include <string>
namespace proton {
-class uuid;
-class binary;
-class symbol;
-class timestamp;
-class uuid;
-class decimal32;
-class decimal64;
-class decimal128;
/// This namespace contains typedefs to associate AMQP scalar type names with
/// the corresponding C++ types. These are provided as a convenience for those
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/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 cfb883d..61b6434 100644
--- a/proton-c/bindings/cpp/include/proton/annotation_key.hpp
+++ b/proton-c/bindings/cpp/include/proton/annotation_key.hpp
@@ -22,7 +22,6 @@
#include <proton/scalar.hpp>
#include <proton/symbol.hpp>
-#include <proton/types.hpp>
namespace proton {
@@ -31,15 +30,22 @@ namespace proton {
/// An annotation_key can contain either a uint64_t or a proton::symbol.
class annotation_key : public restricted_scalar {
public:
- annotation_key(uint64_t x = 0) { *this = x; }
- annotation_key(const symbol& x) { *this = x; }
- /// `char*` is encoded as proton::amqp::symbol.
- annotation_key(const char *x) { *this = x; }
+ /// An empty annotation key has a uint64_t == 0 value.
+ annotation_key() { scalar_ = uint64_t(0); }
+ annotation_key(const annotation_key& x) { scalar_ = x; }
+ annotation_key& operator=(const annotation_key& x) { scalar_ = x; return *this; }
+
+ annotation_key(uint64_t x) { scalar_ = x; }
+ annotation_key(const symbol& x) { scalar_ = x; }
+
+ ///@name Extra conversions for strings, treated as amqp::SYMBOL.
+ ///@{
+ annotation_key(const std::string& x) { scalar_ = symbol(x); }
+ annotation_key(const char *x) {scalar_ = symbol(x); }
+ ///@}
annotation_key& operator=(uint64_t x) { scalar_ = x; return *this; }
annotation_key& operator=(const symbol& x) { scalar_ = x; return *this; }
- /// `char*` is encoded as proton::amqp::symbol.
- annotation_key& operator=(const char *x) { scalar_ = symbol(x); return *this; }
/// @name Get methods
///
@@ -52,7 +58,7 @@ class annotation_key : public restricted_scalar {
template<class T> T get() const { T x; get(x); return x; }
friend class message;
- friend class internal::decoder;
+ friend class codec::decoder;
};
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/byte_array.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/byte_array.hpp b/proton-c/bindings/cpp/include/proton/byte_array.hpp
index 88b05aa..29ad2ee 100644
--- a/proton-c/bindings/cpp/include/proton/byte_array.hpp
+++ b/proton-c/bindings/cpp/include/proton/byte_array.hpp
@@ -19,7 +19,7 @@
* under the License.
*/
-#include <proton/config.hpp>
+#include <proton/types_fwd.hpp>
#include <proton/comparable.hpp>
#include <algorithm>
@@ -30,19 +30,21 @@ namespace proton {
/// as an array of bytes.
template <size_t N> class byte_array : private comparable<byte_array<N> > {
public:
+ typedef uint8_t value_type;
+
/// Initially all 0.
- byte_array() : bytes_() {}
+ byte_array() { std::fill(bytes_, bytes_+N, '\0'); }
/// Returns N
static size_t size() { return N; }
- char* begin() { return bytes_; }
- char* end() { return bytes_+N; }
- char& operator[](size_t i) { return bytes_[i]; }
+ uint8_t* begin() { return bytes_; }
+ uint8_t* end() { return bytes_+N; }
+ uint8_t& operator[](size_t i) { return bytes_[i]; }
- const char* begin() const { return bytes_; }
- const char* end() const { return bytes_+N; }
- const char& operator[](size_t i) const { return bytes_[i]; }
+ const uint8_t* begin() const { return bytes_; }
+ const uint8_t* end() const { return bytes_+N; }
+ const uint8_t& operator[](size_t i) const { return bytes_[i]; }
friend bool operator==(const byte_array& x, const byte_array& y) {
return std::equal(x.begin(), x.end(), y.begin());
@@ -53,7 +55,7 @@ template <size_t N> class byte_array : private comparable<byte_array<N> > {
}
private:
- char bytes_[N];
+ uint8_t bytes_[N];
};
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/connection_options.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/connection_options.hpp b/proton-c/bindings/cpp/include/proton/connection_options.hpp
index 6af4784..71e12f1 100644
--- a/proton-c/bindings/cpp/include/proton/connection_options.hpp
+++ b/proton-c/bindings/cpp/include/proton/connection_options.hpp
@@ -22,16 +22,19 @@
*
*/
-#include "proton/config.hpp"
-#include "proton/export.hpp"
-#include "proton/duration.hpp"
-#include "proton/pn_unique_ptr.hpp"
-#include "proton/reconnect_timer.hpp"
-#include "proton/types.hpp"
+#include <proton/config.hpp>
+#include <proton/export.hpp>
+#include <proton/duration.hpp>
+#include <proton/pn_unique_ptr.hpp>
+#include <proton/reconnect_timer.hpp>
+#include <proton/types_fwd.hpp>
+
#include <vector>
#include <string>
+struct pn_connection_t;
+
namespace proton {
class proton_handler;
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/data.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/data.hpp b/proton-c/bindings/cpp/include/proton/data.hpp
index 31baf0f..3d39154 100644
--- a/proton-c/bindings/cpp/include/proton/data.hpp
+++ b/proton-c/bindings/cpp/include/proton/data.hpp
@@ -1,5 +1,5 @@
-#ifndef DATA_H
-#define DATA_H
+#ifndef PROTON_DATA_HPP
+#define PROTON_DATA_HPP
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -20,56 +20,42 @@
* under the License.
*/
-/// @cond INTERNAL
-/// XXX remove
-
-#include "proton/decoder.hpp"
-#include "proton/encoder.hpp"
-#include "proton/export.hpp"
-#include "proton/object.hpp"
-
-#include <iosfwd>
+#include <proton/object.hpp>
+#include <proton/types_fwd.hpp>
+#include <proton/type_id.hpp>
struct pn_data_t;
namespace proton {
-namespace internal {
-class data;
+class value;
-/// Holds a sequence of AMQP values, allows inserting and extracting
-/// via encoder() and decoder(). Cannot be directly instantiated, use
-/// `value`.
-class data : public object<pn_data_t> {
+namespace codec {
+
+/// Wrapper for a proton data object.
+class data : public internal::object<pn_data_t> {
public:
- data(pn_data_t* d=0) : object<pn_data_t>(d) {}
+ data(pn_data_t* d=0) : internal::object<pn_data_t>(d) {}
PN_CPP_EXTERN static data create();
- // Copy the contents of another data object t this one.
- PN_CPP_EXTERN data& copy(const data&);
-
- template<class T> typename enable_amqp_type<T, data>::type& copy(T &t) {
- clear(); encoder() << t; return *this;
- }
+ // Copy the contents of another data object.
+ PN_CPP_EXTERN void copy(const data&);
/** Clear the data. */
PN_CPP_EXTERN void clear();
+ /** Rewind current position to the start */
+ PN_CPP_EXTERN void rewind();
+
/** True if there are no values. */
PN_CPP_EXTERN bool empty() const;
- /** Encoder to encode into this value */
- PN_CPP_EXTERN class encoder encoder();
-
- /** Decoder to decode from this value */
- PN_CPP_EXTERN class decoder decoder();
-
/** Return the data cursor position */
- PN_CPP_EXTERN uintptr_t point() const;
+ PN_CPP_EXTERN void* point() const;
/** Restore the cursor position to a previously saved position */
- PN_CPP_EXTERN void restore(uintptr_t h);
+ PN_CPP_EXTERN void restore(void* h);
PN_CPP_EXTERN void narrow();
@@ -79,29 +65,52 @@ class data : public object<pn_data_t> {
PN_CPP_EXTERN int appendn(data src, int limit);
- PN_CPP_EXTERN bool next() const;
+ PN_CPP_EXTERN bool next();
- /** Rewind and return the type of the first value*/
- PN_CPP_EXTERN type_id type() const;
+ PN_CPP_EXTERN bool prev();
- /** Rewind and decode the first value */
- template<class T> void get(T &t) const { decoder().rewind(); decoder() >> t; }
+ friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const data&);
+};
- template<class T> T get() const { T t; get(t); return t; }
+/// state_guard saves the state and restores it in dtor unless cancel() is called.
+struct state_guard {
+ data& data_;
+ void* point_;
+ bool cancel_;
- PN_CPP_EXTERN bool equal(const data& x) const;
- PN_CPP_EXTERN bool less(const data& x) const;
+ state_guard(data& d) : data_(d), point_(data_.point()), cancel_(false) {}
+ ~state_guard() { if (!cancel_) data_.restore(point_); }
+ void cancel() { cancel_ = true; }
+};
- /** Human readable representation of data. */
- friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const data&);
- friend class value;
- private:
- data(pn_ptr<pn_data_t> d) : object<pn_data_t>(d) {}
- class decoder decoder() const { return const_cast<data*>(this)->decoder(); }
+/// Narrow the data object, widen it in dtor.
+struct narrow_guard {
+ data& data_;
+ narrow_guard(data& d) : data_(d) { data_.narrow(); }
+ ~narrow_guard() { data_.widen(); }
};
-}
-}
-/// @endcond
+// Start encoding a complex type.
+struct start {
+ start(type_id type_=NULL_TYPE, type_id element_=NULL_TYPE,
+ bool described_=false, size_t size_=0) :
+ type(type_), element(element_), is_described(described_), size(size_) {}
+
+ type_id type; ///< The container type: ARRAY, LIST, MAP or DESCRIBED.
+ type_id element; ///< the element type for array only.
+ bool is_described; ///< true if first value is a descriptor.
+ size_t size; ///< the element count excluding the descriptor (if any)
+
+ PN_CPP_EXTERN static start array(type_id element, bool described=false) { return start(ARRAY, element, described); }
+ PN_CPP_EXTERN static start list() { return start(LIST); }
+ PN_CPP_EXTERN static start map() { return start(MAP); }
+ PN_CPP_EXTERN static start described() { return start(DESCRIBED, NULL_TYPE, true); }
+};
+
+/// Finish inserting or extracting a complex type.
+struct finish {};
+
+} // codec
+} // proton
-#endif // DATA_H
+#endif // PROTON_DATA_HPP
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/decoder.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/decoder.hpp b/proton-c/bindings/cpp/include/proton/decoder.hpp
index 9f5d65c..efa87e4 100644
--- a/proton-c/bindings/cpp/include/proton/decoder.hpp
+++ b/proton-c/bindings/cpp/include/proton/decoder.hpp
@@ -1,5 +1,5 @@
-#ifndef DECODER_H
-#define DECODER_H
+#ifndef PROTON_DECODER_HPP
+#define PROTON_DECODER_HPP
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -19,152 +19,148 @@
* under the License.
*/
-/// @cond INTERNAL
-/// XXX change namespace, review better
+#include <proton/data.hpp>
+#include <proton/type_traits.hpp>
-#include "proton/error.hpp"
-#include "proton/type_traits.hpp"
-#include "proton/types.hpp"
-#include "proton/object.hpp"
-#include "proton/timestamp.hpp"
-#include "proton/uuid.hpp"
-#include <iosfwd>
-
-#include <vector>
-#include <deque>
-#include <list>
-#include <map>
-
-#if PN_CPP_HAS_CPP11
-#include <array>
-#include <forward_list>
-#include <unordered_map>
-#endif // PN_CPP_HAS_CPP11
-
-struct pn_data_t;
+#include <utility>
namespace proton {
-class scalar;
-class message_id;
class annotation_key;
+class message_id;
+class scalar;
class value;
-namespace internal {
-class data;
-
-/** Skips a value with `dec >> skip()`. */
-struct skip{};
-
-/** Assert the next type of value in the decoder: `dec >> assert_type(t)`
- * throws if decoder.type() != t
- */
-struct assert_type {
- type_id type;
- assert_type(type_id t) : type(t) {}
-};
-
-/** Rewind the decoder with `dec >> rewind()`. */
-struct rewind{};
+namespace codec {
/// Stream-like decoder from AMQP bytes to C++ values.
///
/// Internal use only, see proton::value, proton::scalar and proton::amqp
/// for the recommended ways to manage AMQP data.
-class decoder : public object<pn_data_t> {
+class decoder : public data {
public:
- decoder(pn_data_t* d) : object<pn_data_t>(d) {}
-
- /** Copy AMQP data from a byte buffer into the decoder. */
- PN_CPP_EXTERN decoder(const char* buffer, size_t size);
+ ///@internal
+ explicit decoder(const data& d) : data(d) {}
- /** Copy AMQP data from a std::string into the decoder. */
- PN_CPP_EXTERN decoder(const std::string&);
+ /// Attach decoder to a proton::value. The decoder is rewound to the start of the data.
+ PN_CPP_EXTERN explicit decoder(codec::exact_cref<value>);
- /** Decode AMQP data from a byte buffer onto the end of the value stream. */
+ /// Decode AMQP data from a buffer and add it to the end of the decoders stream. */
PN_CPP_EXTERN void decode(const char* buffer, size_t size);
- /** Decode AMQP data from bytes in std::string onto the end of the value stream. */
+ /// Decode AMQP data from a std::string and add it to the end of the decoders stream. */
PN_CPP_EXTERN void decode(const std::string&);
- /** Return true if there are more values to read at the current level. */
- PN_CPP_EXTERN bool more() const;
+ /// Return true if there are more value to extract at the current level.
+ PN_CPP_EXTERN bool more();
- /** Type of the next value that will be read by operator>>
- *@throw error if empty().
- */
- PN_CPP_EXTERN type_id type() const;
-
- /** Rewind to the start of the data. */
- PN_CPP_EXTERN void rewind();
-
- /** Skip one value */
- PN_CPP_EXTERN void skip();
-
- /** Back up by one value */
- PN_CPP_EXTERN void backup();
+ /// Get the type of the next value that will be read by operator>>.
+ /// @throw conversion_error if no more values. @see decoder::more().
+ PN_CPP_EXTERN type_id next_type();
/** @name Extract simple types
* Overloads to extract simple types.
- * @throw error if the decoder is empty or the current value has an incompatible type.
+ * @throw conversion_error if the decoder is empty or has an incompatible type.
* @{
*/
- PN_CPP_EXTERN decoder operator>>(bool&);
- PN_CPP_EXTERN decoder operator>>(uint8_t&);
- PN_CPP_EXTERN decoder operator>>(int8_t&);
- PN_CPP_EXTERN decoder operator>>(uint16_t&);
- PN_CPP_EXTERN decoder operator>>(int16_t&);
- PN_CPP_EXTERN decoder operator>>(uint32_t&);
- PN_CPP_EXTERN decoder operator>>(int32_t&);
- PN_CPP_EXTERN decoder operator>>(wchar_t&);
- PN_CPP_EXTERN decoder operator>>(uint64_t&);
- PN_CPP_EXTERN decoder operator>>(int64_t&);
- PN_CPP_EXTERN decoder operator>>(timestamp&);
- PN_CPP_EXTERN decoder operator>>(float&);
- PN_CPP_EXTERN decoder operator>>(double&);
- PN_CPP_EXTERN decoder operator>>(decimal32&);
- PN_CPP_EXTERN decoder operator>>(decimal64&);
- PN_CPP_EXTERN decoder operator>>(decimal128&);
- PN_CPP_EXTERN decoder operator>>(uuid&);
- PN_CPP_EXTERN decoder operator>>(std::string&);
- PN_CPP_EXTERN decoder operator>>(message_id&);
- PN_CPP_EXTERN decoder operator>>(annotation_key&);
- PN_CPP_EXTERN decoder operator>>(scalar&);
- PN_CPP_EXTERN decoder operator>>(value&);
- PN_CPP_EXTERN decoder operator>>(null&);
+ PN_CPP_EXTERN decoder& operator>>(bool&);
+ PN_CPP_EXTERN decoder& operator>>(uint8_t&);
+ PN_CPP_EXTERN decoder& operator>>(int8_t&);
+ PN_CPP_EXTERN decoder& operator>>(uint16_t&);
+ PN_CPP_EXTERN decoder& operator>>(int16_t&);
+ PN_CPP_EXTERN decoder& operator>>(uint32_t&);
+ PN_CPP_EXTERN decoder& operator>>(int32_t&);
+ PN_CPP_EXTERN decoder& operator>>(wchar_t&);
+ PN_CPP_EXTERN decoder& operator>>(uint64_t&);
+ PN_CPP_EXTERN decoder& operator>>(int64_t&);
+ PN_CPP_EXTERN decoder& operator>>(timestamp&);
+ PN_CPP_EXTERN decoder& operator>>(float&);
+ PN_CPP_EXTERN decoder& operator>>(double&);
+ PN_CPP_EXTERN decoder& operator>>(decimal32&);
+ PN_CPP_EXTERN decoder& operator>>(decimal64&);
+ PN_CPP_EXTERN decoder& operator>>(decimal128&);
+ PN_CPP_EXTERN decoder& operator>>(uuid&);
+ PN_CPP_EXTERN decoder& operator>>(std::string&);
+ PN_CPP_EXTERN decoder& operator>>(message_id&);
+ PN_CPP_EXTERN decoder& operator>>(annotation_key&);
+ PN_CPP_EXTERN decoder& operator>>(scalar&);
+ PN_CPP_EXTERN decoder& operator>>(value&);
+ PN_CPP_EXTERN decoder& operator>>(null&);
///@}
- // start extracting complex type.
- PN_CPP_EXTERN decoder operator>>(start&);
+ /// Start decoding a container type, such as an ARRAY, LIST or MAP.
+ /// This "enters" the container, more() will return false at the end of the container.
+ /// Call finish() to "exit" the container and move on to the next value.
+ PN_CPP_EXTERN decoder& operator>>(start&);
- /// Finish extracting a container value. */
- PN_CPP_EXTERN decoder operator>>(finish);
+ // Finish decoding a container type, and move on to the next value in the stream.
+ PN_CPP_EXTERN decoder& operator>>(const finish&);
- /** Skip a value */
- PN_CPP_EXTERN decoder operator>>(struct skip);
+ // XXX doc
+ template <class T> struct sequence_ref { T& ref; sequence_ref(T& r) : ref(r) {} };
+ template <class T> struct associative_ref { T& ref; associative_ref(T& r) : ref(r) {} };
+ template <class T> struct pair_sequence_ref { T& ref; pair_sequence_ref(T& r) : ref(r) {} };
- /** Throw an exception if decoder.type() != assert_type.type */
- PN_CPP_EXTERN decoder operator>>(assert_type);
+ template <class T> static sequence_ref<T> sequence(T& x) { return sequence_ref<T>(x); }
+ template <class T> static associative_ref<T> associative(T& x) { return associative_ref<T>(x); }
+ template <class T> static pair_sequence_ref<T> pair_sequence(T& x) { return pair_sequence_ref<T>(x); }
- /** Rewind to the beginning */
- PN_CPP_EXTERN decoder operator>>(struct rewind);
+ /** Extract any AMQP sequence (ARRAY, LIST or MAP) to a C++ sequence
+ * container of T if the elements types are convertible to T. A MAP is
+ * extracted as [key1, value1, key2, value2...]
+ */
+ template <class T> decoder& operator>>(sequence_ref<T> r) {
+ start s;
+ *this >> s;
+ if (s.is_described) next();
+ r.ref.resize(s.size);
+ for (typename T::iterator i = r.ref.begin(); i != r.ref.end(); ++i)
+ *this >> *i;
+ return *this;
+ }
+
+ /** Extract an AMQP MAP to a C++ associative container */
+ template <class T> decoder& operator>>(associative_ref<T> r) {
+ start s;
+ *this >> s;
+ assert_type_equal(MAP, s.type);
+ r.ref.clear();
+ for (size_t i = 0; i < s.size/2; ++i) {
+ typename remove_const<typename T::key_type>::type k;
+ typename remove_const<typename T::mapped_type>::type v;
+ *this >> k >> v;
+ r.ref[k] = v;
+ }
+ return *this;
+ }
+
+ /// Extract an AMQP MAP to a C++ push_back sequence of pairs
+ /// preserving encoded order.
+ template <class T> decoder& operator>>(pair_sequence_ref<T> r) {
+ start s;
+ *this >> s;
+ assert_type_equal(MAP, s.type);
+ r.ref.clear();
+ for (size_t i = 0; i < s.size/2; ++i) {
+ typedef typename T::value_type value_type;
+ typename remove_const<typename value_type::first_type>::type k;
+ typename remove_const<typename value_type::second_type>::type v;
+ *this >> k >> v;
+ r.ref.push_back(value_type(k, v));
+ }
+ return *this;
+ }
private:
- PN_CPP_EXTERN void check_type(type_id);
-};
+ type_id pre_get();
+ template <class T, class U> void extract(T& x, U (*get)(pn_data_t*));
-/** Call decoder::start() in constructor, decoder::finish in destructor().
- *
- */
-struct scope : public start {
- decoder decoder_;
- scope(decoder d) : decoder_(d) { decoder_ >> *this; }
- ~scope() { decoder_ >> finish(); }
+ friend class message;
};
// operator >> for integer types that are not covered by the standard overrides.
-template <class T> typename enable_integer<T, decoder>::type
-operator>>(decoder d, T& i) {
+template <class T> typename codec::enable_unknown_integer<T, decoder&>::type
+operator>>(decoder& d, T& i) {
typename integer_type<sizeof(T), is_signed<T>::value>::type v;
d >> v; // Extract as a known integer type
i = v; // C++ conversion to the target type.
@@ -172,88 +168,10 @@ operator>>(decoder d, T& i) {
}
///@cond INTERNAL
-template <class T> struct ref {
- ref(T& v) : value(v) {}
- T& value;
-};
-template <class T> struct sequence_ref : public ref<T> { sequence_ref(T& v) : ref<T>(v) {} };
-template <class T> struct map_ref : public ref<T> { map_ref(T& v) : ref<T>(v) {} };
-template <class T> struct pairs_ref : public ref<T> { pairs_ref(T& v) : ref<T>(v) {} };
-
-// FIXME aconway 2016-03-03: rename
-
-template <class T> sequence_ref<T> to_sequence(T& v) { return sequence_ref<T>(v); }
-
-template <class T> map_ref<T> to_map(T& v) { return map_ref<T>(v); }
-template <class T> pairs_ref<T> to_pairs(T& v) { return pairs_ref<T>(v); }
-
-/** Extract any AMQP sequence (ARRAY, LIST or MAP) to a C++ container of T if
- * the elements types are convertible to T. A MAP is extracted as [key1, value1,
- * key2, value2...]
- */
-template <class T> decoder operator>>(decoder d, sequence_ref<T> ref) {
- scope s(d);
- if (s.is_described) d >> skip();
- T& v = ref.value;
- v.clear();
- v.resize(s.size);
- for (typename T::iterator i = v.begin(); i != v.end(); ++i)
- d >> *i;
- return d;
-}
-
-PN_CPP_EXTERN void assert_map_scope(const scope& s);
-
-/** Extract an AMQP MAP to a C++ map */
-template <class T> decoder operator>>(decoder d, map_ref<T> ref) {
- scope s(d);
- assert_map_scope(s);
- T& m = ref.value;
- m.clear();
- for (size_t i = 0; i < s.size/2; ++i) {
- typename remove_const<typename T::key_type>::type k;
- typename remove_const<typename T::mapped_type>::type v;
- d >> k >> v;
- m[k] = v;
- }
- return d;
-}
-
-/** Extract an AMQP MAP to a C++ container of std::pair, preserving order. */
-template <class T> decoder operator>>(decoder d, pairs_ref<T> ref) {
- scope s(d);
- assert_map_scope(s);
- T& m = ref.value;
- m.clear();
- m.resize(s.size/2);
- for (typename T::iterator i = m.begin(); i != m.end(); ++i) {
- d >> i->first >> i->second;
- }
- return d;
-}
-
-// Decode to sequence.
-template <class T, class A> decoder operator>>(decoder d, std::vector<T, A>& v) { return d >> to_sequence(v); }
-template <class T, class A> decoder operator>>(decoder d, std::deque<T, A>& v) { return d >> to_sequence(v); }
-template <class T, class A> decoder operator>>(decoder d, std::list<T, A>& v) { return d >> to_sequence(v); }
-
-// Decode to map.
-template <class K, class T, class C, class A> decoder operator>>(decoder d, std::map<K, T, C, A>& v) { return d >> to_map(v); }
-
-#if PN_CPP_HAS_CPP11
-
-// Decode to sequence.
-template <class T, class A> decoder operator>>(decoder d, std::forward_list<T, A>& v) { return d >> to_sequence(v); }
-template <class T, std::size_t N> decoder operator>>(decoder d, std::array<T, N>& v) { return d >> to_sequence(v); }
-
-// Decode to map.
-template <class K, class T, class C, class A> decoder operator>>(decoder d, std::unordered_map<K, T, C, A>& v) { return d >> to_map(v); }
-
-#endif // PN_CPP_HAS_CPP11
-}
-}
+} // internal
+} // proton
/// @endcond
-#endif // DECODER_H
+#endif // PROTON_DECODER_HPP
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/deque.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/deque.hpp b/proton-c/bindings/cpp/include/proton/deque.hpp
new file mode 100644
index 0000000..18d142d
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/deque.hpp
@@ -0,0 +1,58 @@
+#ifndef PROTON_DEQUE_HPP
+#define PROTON_DEQUE_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 <deque>
+#include <utility>
+
+#include <proton/encoder.hpp>
+#include <proton/decoder.hpp>
+
+namespace proton {
+namespace codec {
+
+/// std::deque<T> for most T is encoded as an amqp::ARRAY (same type elements)
+template <class T, class A>
+encoder& operator<<(encoder& e, const std::deque<T, A>& x) {
+ return e << encoder::array(x, type_id_of<T>::value);
+}
+
+/// std::deque<value> encodes as amqp::LIST (mixed type elements)
+template <class A>
+encoder& operator<<(encoder& e, const std::deque<value, A>& x) { return e << encoder::list(x); }
+
+/// std::deque<scalar> encodes as amqp::LIST (mixed type elements)
+template <class A>
+encoder& operator<<(encoder& e, const std::deque<scalar, A>& x) { return e << encoder::list(x); }
+
+/// std::deque<std::pair<k,t> > encodes as amqp::MAP.
+/// Map entries are encoded in order they appear in the list.
+template <class A, class K, class T>
+encoder& operator<<(encoder& e, const std::deque<std::pair<K,T>, A>& x) { return e << encoder::map(x); }
+
+/// Decode to std::deque<T> from an amqp::LIST or amqp::ARRAY.
+template <class T, class A> decoder& operator>>(decoder& d, std::deque<T, A>& x) { return d >> decoder::sequence(x); }
+
+/// Decode to std::deque<std::pair<K, T> from an amqp::MAP.
+template <class A, class K, class T> decoder& operator>>(decoder& d, std::deque<std::pair<K, T> , A>& x) { return d >> decoder::pair_sequence(x); }
+
+}
+}
+#endif // PROTON_DEQUE_HPP
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/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 2596df9..51f7a46 100644
--- a/proton-c/bindings/cpp/include/proton/duration.hpp
+++ b/proton-c/bindings/cpp/include/proton/duration.hpp
@@ -22,9 +22,9 @@
*
*/
-#include "proton/export.hpp"
-#include "proton/comparable.hpp"
-#include "proton/types.hpp"
+#include <proton/export.hpp>
+#include <proton/comparable.hpp>
+#include <proton/types_fwd.hpp>
#include <iosfwd>
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/encoder.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/encoder.hpp b/proton-c/bindings/cpp/include/proton/encoder.hpp
index 3efa349..6ca2ce7 100644
--- a/proton-c/bindings/cpp/include/proton/encoder.hpp
+++ b/proton-c/bindings/cpp/include/proton/encoder.hpp
@@ -20,62 +20,27 @@
* under the License.
*/
-/// @cond INTERNAL
-/// XXX change namespace, review better
-
-#include "proton/error.hpp"
-#include "proton/types.hpp"
-#include "proton/type_traits.hpp"
-#include "proton/object.hpp"
-#include <iosfwd>
-
-#include <vector>
-#include <deque>
-#include <list>
-#include <map>
-
-#if PN_CPP_HAS_CPP11
-#include <array>
-#include <forward_list>
-#include <unordered_map>
-#endif // PN_CPP_HAS_CPP11
-
-/// @file
-/// @internal
-
-struct pn_data_t;
+#include <proton/data.hpp>
+#include <proton/type_traits.hpp>
namespace proton {
class scalar;
class value;
-namespace internal {
-
-class data;
-
-template<class T, type_id A> struct cref {
- typedef T cpp_type;
- static const type_id type;
-
- cref(const T& v) : value(v) {}
- const T& value;
-};
-
-template <class T, type_id A> const type_id cref<T, A>::type = A;
-
-/**
- * Indicate the desired AMQP type to use when encoding T.
- */
-template <type_id A, class T> cref<T, A> as(const T& value) { return cref<T, A>(value); }
+namespace codec {
/// Stream-like encoder from AMQP bytes to C++ values.
///
/// Internal use only, see proton::value, proton::scalar and proton::amqp
/// for the recommended ways to manage AMQP data.
-class encoder : public object<pn_data_t> {
+class encoder : public data {
public:
- encoder(pn_data_t* e) : object<pn_data_t>(e) {}
+ ///@internal
+ explicit encoder(const data& d) : data(d) {}
+
+ /// Encoder into v. Clears any current value in v.
+ PN_CPP_EXTERN explicit encoder(value& v);
/**
* Encode the current values into buffer and update size to reflect the
@@ -97,126 +62,98 @@ class encoder : public object<pn_data_t> {
/** Encode the current values into a std::string. Clears the encoder. */
PN_CPP_EXTERN std::string encode();
- PN_CPP_EXTERN encoder operator<<(bool);
- PN_CPP_EXTERN encoder operator<<(uint8_t);
- PN_CPP_EXTERN encoder operator<<(int8_t);
- PN_CPP_EXTERN encoder operator<<(uint16_t);
- PN_CPP_EXTERN encoder operator<<(int16_t);
- PN_CPP_EXTERN encoder operator<<(uint32_t);
- PN_CPP_EXTERN encoder operator<<(int32_t);
- PN_CPP_EXTERN encoder operator<<(wchar_t);
- PN_CPP_EXTERN encoder operator<<(uint64_t);
- PN_CPP_EXTERN encoder operator<<(int64_t);
- PN_CPP_EXTERN encoder operator<<(timestamp);
- PN_CPP_EXTERN encoder operator<<(float);
- PN_CPP_EXTERN encoder operator<<(double);
- PN_CPP_EXTERN encoder operator<<(decimal32);
- PN_CPP_EXTERN encoder operator<<(decimal64);
- PN_CPP_EXTERN encoder operator<<(decimal128);
- PN_CPP_EXTERN encoder operator<<(const uuid&);
- 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 scalar&);
- PN_CPP_EXTERN encoder operator<<(const null&);
-
- /// Start encoding a complex type.
- PN_CPP_EXTERN encoder operator<<(const start&);
+ PN_CPP_EXTERN encoder& operator<<(bool);
+ PN_CPP_EXTERN encoder& operator<<(uint8_t);
+ PN_CPP_EXTERN encoder& operator<<(int8_t);
+ PN_CPP_EXTERN encoder& operator<<(uint16_t);
+ PN_CPP_EXTERN encoder& operator<<(int16_t);
+ PN_CPP_EXTERN encoder& operator<<(uint32_t);
+ PN_CPP_EXTERN encoder& operator<<(int32_t);
+ PN_CPP_EXTERN encoder& operator<<(wchar_t);
+ PN_CPP_EXTERN encoder& operator<<(uint64_t);
+ PN_CPP_EXTERN encoder& operator<<(int64_t);
+ PN_CPP_EXTERN encoder& operator<<(timestamp);
+ PN_CPP_EXTERN encoder& operator<<(float);
+ PN_CPP_EXTERN encoder& operator<<(double);
+ PN_CPP_EXTERN encoder& operator<<(decimal32);
+ PN_CPP_EXTERN encoder& operator<<(decimal64);
+ PN_CPP_EXTERN encoder& operator<<(decimal128);
+ PN_CPP_EXTERN encoder& operator<<(const uuid&);
+ 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 scalar&);
+ PN_CPP_EXTERN encoder& operator<<(const null&);
+
+ /// Inserts proton::value.
+ PN_CPP_EXTERN encoder& operator<<(exact_cref<value>);
+
+ PN_CPP_EXTERN encoder& operator<<(const start&);
/// Finish a complex type
- PN_CPP_EXTERN encoder operator<<(const finish&);
+ PN_CPP_EXTERN encoder& operator<<(const finish&);
+
+ // XXX doc
+ template <class T> struct list_cref { T& ref; list_cref(T& r) : ref(r) {} };
+ template <class T> struct map_cref { T& ref; map_cref(T& r) : ref(r) {} };
+
+ template <class T> struct array_cref {
+ start array_start;
+ T& ref;
+ array_cref(T& r, type_id el, bool described) : array_start(ARRAY, el, described), ref(r) {}
+ };
+
+ template <class T> static list_cref<T> list(T& x) { return list_cref<T>(x); }
+ template <class T> static map_cref<T> map(T& x) { return map_cref<T>(x); }
+ template <class T> static array_cref<T> array(T& x, type_id element, bool described=false) {
+ return array_cref<T>(x, element, described);
+ }
- // FIXME aconway 2016-03-03: hide
- PN_CPP_EXTERN void insert(const value& v);
+ template <class T> encoder& operator<<(const map_cref<T>& x) {
+ state_guard sg(*this);
+ *this << start::map();
+ for (typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
+ *this << i->first << i->second;
+ *this << finish();
+ return *this;
+ }
- private:
+ template <class T> encoder& operator<<(const list_cref<T>& x) {
+ state_guard sg(*this);
+ *this << start::list();
+ for (typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
+ *this << *i;
+ *this << finish();
+ return *this;
+ }
- friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const encoder&);
+ template <class T> encoder& operator<<(const array_cref<T>& x) {
+ state_guard sg(*this);
+ *this << x.array_start;
+ for (typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
+ *this << *i;
+ *this << finish();
+ return *this;
+ }
- /**@name Insert values returned by the as<type_id> helper.
- *@{
- */
- template <class T, type_id A> friend PN_CPP_EXTERN encoder operator<<(encoder, cref<T, A>);
- template <class T> friend encoder operator<<(encoder, cref<T, ARRAY>);
- template <class T> friend encoder operator<<(encoder, cref<T, LIST>);
- template <class T> friend encoder operator<<(encoder, cref<T, MAP>);
- // TODO aconway 2015-06-16: described values.
- ///@}
+ private:
+ template<class T, class U> encoder& insert(const T& x, int (*put)(pn_data_t*, U));
+ void check(long result);
};
-// Treat char* as string
-inline encoder operator<<(encoder e, char* s) { return e << std::string(s); }
-inline encoder operator<<(encoder e, const char* s) { return e << std::string(s); }
+///@internal
+/// Invalid template to prevent pointers being implicitly converted to bool.
+template <class T> void* operator<<(encoder&, const T*);
-
-// FIXME aconway 2016-03-08: explain
-template <class T> typename enable_if<is_same<T, value>::value, encoder>::type
-operator<<(encoder e, const T& x) { e.insert(x); return e; }
- ///@}
+// Treat char* as string
+inline encoder& operator<<(encoder& e, const char* s) { return e << std::string(s); }
// operator << for integer types that are not covered by the standard overrides.
-template <class T> typename enable_integer<T, encoder>::type
-operator<<(encoder e, T i) {
+template <class T> typename codec::enable_unknown_integer<T, encoder&>::type
+operator<<(encoder& e, T i) {
return e << static_cast<typename integer_type<sizeof(T), is_signed<T>::value>::type>(i);
}
-// TODO aconway 2015-06-16: described array insertion.
-
-template <class T> encoder operator<<(encoder e, cref<T, ARRAY> a) {
- e << start::array(type_id_of<typename T::value_type>::value);
- for (typename T::const_iterator i = a.value.begin(); i != a.value.end(); ++i)
- e << *i;
- e << finish();
- return e;
-}
-
-template <class T> encoder operator<<(encoder e, cref<T, LIST> l) {
- e << start::list();
- for (typename T::const_iterator i = l.value.begin(); i != l.value.end(); ++i)
- e << *i;
- e << finish();
- return e;
-}
-
-template <class T> encoder operator<<(encoder e, cref<T, MAP> m){
- e << start::map();
- for (typename T::const_iterator i = m.value.begin(); i != m.value.end(); ++i) {
- e << i->first;
- e << i->second;
- }
- e << finish();
- return e;
-}
-
-// Encode as ARRAY
-template <class T, class A> encoder operator<<(encoder e, const std::vector<T, A>& v) { return e << as<ARRAY>(v); }
-template <class T, class A> encoder operator<<(encoder e, const std::deque<T, A>& v) { return e << as<ARRAY>(v); }
-template <class T, class A> encoder operator<<(encoder e, const std::list<T, A>& v) { return e << as<ARRAY>(v); }
-
-// Encode as LIST
-template <class A> encoder operator<<(encoder e, const std::vector<value, A>& v) { return e << as<LIST>(v); }
-template <class A> encoder operator<<(encoder e, const std::deque<value, A>& v) { return e << as<LIST>(v); }
-template <class A> encoder operator<<(encoder e, const std::list<value, A>& v) { return e << as<LIST>(v); }
-
-// Encode as MAP
-template <class K, class T, class C, class A> encoder operator<<(encoder e, const std::map<K, T, C, A>& v) { return e << as<MAP>(v); }
-
-#if PN_CPP_HAS_CPP11
-
-// Encode as ARRAY.
-template <class T, class A> encoder operator<<(encoder e, const std::forward_list<T, A>& v) { return e << as<ARRAY>(v); }
-template <class T, std::size_t N> encoder operator<<(encoder e, const std::array<T, N>& v) { return e << as<ARRAY>(v); }
-
-// Encode as LIST.
-template <class A> encoder operator<<(encoder e, const std::forward_list<value, A>& v) { return e << as<LIST>(v); }
-template <std::size_t N> encoder operator<<(encoder e, const std::array<value, N>& v) { return e << as<LIST>(v); }
-
-// Encode as map.
-template <class K, class T, class C, class A> encoder operator<<(encoder e, const std::unordered_map<K, T, C, A>& v) { return e << as<MAP>(v); }
-
-#endif // PN_CPP_HAS_CPP11
-}
-}
-
-/// @endcond
+} // internal
+} // proton
#endif // ENCODER_H
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/event.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/event.hpp b/proton-c/bindings/cpp/include/proton/event.hpp
index 14dd727..fc29f11 100644
--- a/proton-c/bindings/cpp/include/proton/event.hpp
+++ b/proton-c/bindings/cpp/include/proton/event.hpp
@@ -22,10 +22,10 @@
*
*/
-#include "proton/export.hpp"
-#include "proton/link.hpp"
-#include "proton/connection.hpp"
-#include "proton/message.hpp"
+#include <proton/export.hpp>
+#include <proton/link.hpp>
+#include <proton/connection.hpp>
+#include <proton/message.hpp>
#include <vector>
#include <string>
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/forward_list.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/forward_list.hpp b/proton-c/bindings/cpp/include/proton/forward_list.hpp
new file mode 100644
index 0000000..9358da9
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/forward_list.hpp
@@ -0,0 +1,58 @@
+#ifndef PROTON_FORWARD_LIST_HPP
+#define PROTON_FORWARD_LIST_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 <forward_list>
+#include <utility>
+
+#include <proton/encoder.hpp>
+#include <proton/decoder.hpp>
+
+namespace proton {
+namespace codec {
+/// std::forward_list<T> for most T is encoded as an AMQP array.
+template <class T, class A>
+encoder& operator<<(encoder& e, const std::forward_list<T, A>& x) {
+ return e << encoder::array(x, type_id_of<T>::value);
+}
+
+/// Specialize for std::forward_list<value>, encode as AMQP forward_list (variable type)
+template <class A>
+encoder& operator<<(encoder& e, const std::forward_list<value, A>& x) { return e << encoder::list(x); }
+
+/// Specialize for std::forward_list<scalar>, encode as AMQP list (variable type)
+template <class A>
+encoder& operator<<(encoder& e, const std::forward_list<scalar, A>& x) { return e << encoder::list(x); }
+
+/// Specialize for std::forward_list<std::pair<k,t> >, encode as AMQP map.
+/// Allows control over the order of encoding map entries.
+template <class A, class K, class T>
+encoder& operator<<(encoder& e, const std::forward_list<std::pair<K,T>, A>& x) { return e << encoder::map(x); }
+
+/// Decode to std::forward_list<T> from an amqp::LIST or amqp::ARRAY.
+template <class T, class A> decoder& operator>>(decoder& d, std::forward_list<T, A>& x) { return d >> decoder::sequence(x); }
+
+/// Decode to std::forward_list<std::pair<K, T> from an amqp::MAP.
+template <class A, class K, class T> decoder& operator>>(decoder& d, std::forward_list<std::pair<K, T> , A>& x) { return d >> decoder::pair_sequence(x); }
+
+}
+}
+
+#endif // PROTON_FORWARD_LIST_HPP
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/link.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/link.hpp b/proton-c/bindings/cpp/include/proton/link.hpp
index cde39ee..e626398 100644
--- a/proton-c/bindings/cpp/include/proton/link.hpp
+++ b/proton-c/bindings/cpp/include/proton/link.hpp
@@ -22,13 +22,15 @@
*
*/
-#include "proton/endpoint.hpp"
-#include "proton/export.hpp"
-#include "proton/message.hpp"
-#include "proton/terminus.hpp"
-#include "proton/types.h"
-#include "proton/object.hpp"
-#include "proton/link_options.hpp"
+#include <proton/endpoint.hpp>
+#include <proton/export.hpp>
+#include <proton/message.hpp>
+#include <proton/terminus.hpp>
+
+#include <proton/object.hpp>
+#include <proton/link_options.hpp>
+
+#include <proton/types.h>
#include <string>
@@ -165,7 +167,7 @@ typedef internal::iter_range<link_iterator> link_range;
}
-#include "proton/sender.hpp"
-#include "proton/receiver.hpp"
+#include <proton/sender.hpp>
+#include <proton/receiver.hpp>
#endif // PROTON_CPP_LINK_H
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/list.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/list.hpp b/proton-c/bindings/cpp/include/proton/list.hpp
new file mode 100644
index 0000000..0172b24
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/list.hpp
@@ -0,0 +1,58 @@
+#ifndef PROTON_LIST_HPP
+#define PROTON_LIST_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 <list>
+#include <utility>
+
+#include <proton/encoder.hpp>
+#include <proton/decoder.hpp>
+
+namespace proton {
+namespace codec {
+/// std::list<T> for most T is encoded as an AMQP array.
+template <class T, class A>
+encoder& operator<<(encoder& e, const std::list<T, A>& x) {
+ return e << encoder::array(x, type_id_of<T>::value);
+}
+
+/// Specialize for std::list<value>, encode as AMQP list (variable type)
+template <class A>
+encoder& operator<<(encoder& e, const std::list<value, A>& x) { return e << encoder::list(x); }
+
+/// Specialize for std::list<scalar>, encode as AMQP list (variable type)
+template <class A>
+encoder& operator<<(encoder& e, const std::list<scalar, A>& x) { return e << encoder::list(x); }
+
+/// Specialize for std::list<std::pair<k,t> >, encode as AMQP map.
+/// Allows control over the order of encoding map entries.
+template <class A, class K, class T>
+encoder& operator<<(encoder& e, const std::list<std::pair<K,T>, A>& x) { return e << encoder::map(x); }
+
+/// Decode to std::list<T> from an amqp::LIST or amqp::ARRAY.
+template <class T, class A> decoder& operator>>(decoder& d, std::list<T, A>& x) { return d >> decoder::sequence(x); }
+
+/// Decode to std::list<std::pair<K, T> from an amqp::MAP.
+template <class A, class K, class T> decoder& operator>>(decoder& d, std::list<std::pair<K, T> , A>& x) { return d >> decoder::pair_sequence(x); }
+
+}
+}
+
+#endif // PROTON_LIST_HPP
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/map.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/map.hpp b/proton-c/bindings/cpp/include/proton/map.hpp
new file mode 100644
index 0000000..e640bab
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/map.hpp
@@ -0,0 +1,40 @@
+#ifndef PROTON_MAP_HPP
+#define PROTON_MAP_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 <map>
+#include <proton/encoder.hpp>
+#include <proton/decoder.hpp>
+
+namespace proton {
+namespace codec {
+
+/// Encode std::map<K, T> as amqp::MAP.
+template <class K, class T, class C, class A>
+encoder& operator<<(encoder& e, const std::map<K, T, C, A>& m) { return e << encoder::map(m); }
+
+/// Decode to std::map<K, T> from amqp::MAP.
+template <class K, class T, class C, class A>
+decoder& operator>>(decoder& d, std::map<K, T, C, A>& m) { return d >> decoder::associative(m); }
+
+} // internal
+} // proton
+
+#endif // PROTON_MAP_HPP
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/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 88bac15..0fc4cc1 100644
--- a/proton-c/bindings/cpp/include/proton/message.hpp
+++ b/proton-c/bindings/cpp/include/proton/message.hpp
@@ -22,12 +22,13 @@
*
*/
-#include "proton/export.hpp"
-#include "proton/message_id.hpp"
-#include "proton/annotation_key.hpp"
-#include "proton/pn_unique_ptr.hpp"
-#include "proton/value.hpp"
-#include "proton/duration.hpp"
+#include <proton/map.hpp>
+#include <proton/annotation_key.hpp>
+#include <proton/duration.hpp>
+#include <proton/export.hpp>
+#include <proton/message_id.hpp>
+#include <proton/pn_unique_ptr.hpp>
+#include <proton/value.hpp>
#include <string>
#include <vector>
@@ -67,9 +68,8 @@ class message {
#endif
/// Create a message with its body set from any value that can be
- /// assigned to a proton::value. proton::amqp for encoding
- template <class T> message(const T& x, typename enable_amqp_type<T>::type * = 0) :
- pn_msg_(0) { body() = x; }
+ /// converted to a proton::value.
+ PN_CPP_EXTERN message(const value& x);
PN_CPP_EXTERN ~message();
@@ -122,8 +122,8 @@ class message {
/// @name Content
/// @{
- /// Set the body, equivalent to body() = v
- template<class T> typename enable_amqp_type<T>::type body(const T& v) { body() = v; }
+ /// Set the body, equivalent to body() = x
+ PN_CPP_EXTERN void body(const value& x);
/// Get the body.
PN_CPP_EXTERN const value& body() const;
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/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 dbc62c3..0def327 100644
--- a/proton-c/bindings/cpp/include/proton/message_id.hpp
+++ b/proton-c/bindings/cpp/include/proton/message_id.hpp
@@ -20,8 +20,11 @@
* under the License.
*/
-#include "proton/types.hpp"
-#include "proton/scalar.hpp"
+#include <proton/binary.hpp>
+#include <proton/scalar.hpp>
+#include <proton/uuid.hpp>
+
+#include <string>
namespace proton {
@@ -36,11 +39,18 @@ namespace proton {
///
class message_id : public restricted_scalar {
public:
- message_id(uint64_t x = 0) { scalar_ = x; }
+ /// An empty message_id has a uint64_t == 0 value.
+ message_id() { scalar_ = uint64_t(0); }
+ message_id(const message_id& x) { scalar_ = x; }
+ message_id& operator=(const message_id& x) { scalar_ = x; return *this; }
+
+ message_id(uint64_t x) { scalar_ = x; }
message_id(const uuid& x) { scalar_ = x; }
message_id(const binary& x) { scalar_ = x; }
message_id(const std::string& x) { scalar_ = x; }
- message_id(const char *x) { scalar_ = std::string(x); }
+
+ /// Extra conversion - treat char* as amqp::STRING
+ message_id(const char* x) { scalar_ = x; }
/// @name Assignment operators
///
@@ -51,8 +61,6 @@ class message_id : public restricted_scalar {
message_id& operator=(const uuid& x) { scalar_ = x; return *this; }
message_id& operator=(const binary& x) { scalar_ = x; return *this; }
message_id& operator=(const std::string& x) { scalar_ = x; return *this; }
- /// char* is encoded as std::string
- message_id& operator=(const char *x) { scalar_ = std::string(x); return *this; }
/// @}
/// @name Get methods
@@ -74,7 +82,7 @@ class message_id : public restricted_scalar {
message_id(const pn_atom_t& a): restricted_scalar(a) {}
friend class message;
- friend class internal::decoder;
+ friend class codec::decoder;
};
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/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 234d547..9b7e7af 100644
--- a/proton-c/bindings/cpp/include/proton/scalar.hpp
+++ b/proton-c/bindings/cpp/include/proton/scalar.hpp
@@ -20,23 +20,17 @@
* under the License.
*/
-#include "proton/comparable.hpp"
-#include "proton/types.hpp"
+#include <proton/export.hpp>
+#include <proton/comparable.hpp>
+#include <proton/types_fwd.hpp>
+#include <proton/type_id.hpp>
#include <iosfwd>
#include <string>
namespace proton {
-class binary;
-class decimal128;
-class decimal32;
-class decimal64;
-class symbol;
-class timestamp;
-class uuid;
-
-namespace internal {
+namespace codec {
class decoder;
class encoder;
}
@@ -61,6 +55,34 @@ class scalar : private comparable<scalar> {
/// True if the scalar is empty.
PN_CPP_EXTERN bool empty() const;
+ /// @name Construct from a C++ value.
+ /// See proton::amqp for the list of type correspondences.
+ ///
+ /// @{
+ PN_CPP_EXTERN scalar(bool x);
+ PN_CPP_EXTERN scalar(uint8_t x);
+ PN_CPP_EXTERN scalar(int8_t x);
+ PN_CPP_EXTERN scalar(uint16_t x);
+ PN_CPP_EXTERN scalar(int16_t x);
+ PN_CPP_EXTERN scalar(uint32_t x);
+ PN_CPP_EXTERN scalar(int32_t x);
+ PN_CPP_EXTERN scalar(uint64_t x);
+ PN_CPP_EXTERN scalar(int64_t x);
+ PN_CPP_EXTERN scalar(wchar_t x);
+ PN_CPP_EXTERN scalar(float x);
+ PN_CPP_EXTERN scalar(double x);
+ PN_CPP_EXTERN scalar(timestamp x);
+ PN_CPP_EXTERN scalar(const decimal32& x);
+ PN_CPP_EXTERN scalar(const decimal64& x);
+ PN_CPP_EXTERN scalar(const decimal128& x);
+ PN_CPP_EXTERN scalar(const uuid& x);
+ PN_CPP_EXTERN scalar(const std::string& x);
+ PN_CPP_EXTERN scalar(const symbol& x);
+ PN_CPP_EXTERN scalar(const binary& x);
+ PN_CPP_EXTERN scalar(const char* s); ///< Treated as an AMQP string
+ /// @}
+
+
/// @name Assignment operators
///
/// Assign a C++ value as the corresponding AMQP type.
@@ -90,8 +112,6 @@ class scalar : private comparable<scalar> {
PN_CPP_EXTERN scalar& operator=(const char* s); ///< Treated as an AMQP string
/// @}
- /// Create a scalar from any type that we can assign from.
- template <class T> explicit scalar(T x) { *this = x; }
/// @name Get methods
///
@@ -160,9 +180,8 @@ class scalar : private comparable<scalar> {
friend class message;
friend class restricted_scalar;
- friend class internal::encoder;
- friend class internal::decoder;
-
+ friend class codec::encoder;
+ friend class codec::decoder;
};
/// @cond INTERNAL
@@ -188,6 +207,7 @@ class restricted_scalar : private comparable<restricted_scalar> {
protected:
restricted_scalar() {}
restricted_scalar(const pn_atom_t& a) : scalar_(a) {}
+ restricted_scalar(const restricted_scalar& x) : scalar_(x.scalar_) {}
scalar scalar_;
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/symbol.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/symbol.hpp b/proton-c/bindings/cpp/include/proton/symbol.hpp
index 4e6db7a..24a5213 100644
--- a/proton-c/bindings/cpp/include/proton/symbol.hpp
+++ b/proton-c/bindings/cpp/include/proton/symbol.hpp
@@ -26,8 +26,8 @@ namespace proton {
///
class symbol : public std::string {
public:
- explicit symbol(const std::string& s=std::string()) : std::string(s) {}
- explicit symbol(const char* s) : std::string(s) {}
+ symbol(const std::string& s=std::string()) : std::string(s) {}
+ symbol(const char* s) : std::string(s) {}
};
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/type_id.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/type_id.hpp b/proton-c/bindings/cpp/include/proton/type_id.hpp
new file mode 100644
index 0000000..2d399a5
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/type_id.hpp
@@ -0,0 +1,69 @@
+#ifndef TYPES_H
+#define TYPES_H
+
+/*
+ * 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 <proton/export.hpp>
+#include <proton/codec.h>
+#include <string>
+
+namespace proton {
+
+/// An identifier for AMQP types.
+enum type_id {
+ NULL_TYPE = PN_NULL, ///< The null type, contains no data.
+ BOOLEAN = PN_BOOL, ///< Boolean true or false.
+ UBYTE = PN_UBYTE, ///< Unsigned 8 bit integer.
+ BYTE = PN_BYTE, ///< Signed 8 bit integer.
+ USHORT = PN_USHORT, ///< Unsigned 16 bit integer.
+ SHORT = PN_SHORT, ///< Signed 16 bit integer.
+ UINT = PN_UINT, ///< Unsigned 32 bit integer.
+ INT = PN_INT, ///< Signed 32 bit integer.
+ CHAR = PN_CHAR, ///< 32 bit unicode character.
+ ULONG = PN_ULONG, ///< Unsigned 64 bit integer.
+ LONG = PN_LONG, ///< Signed 64 bit integer.
+ TIMESTAMP = PN_TIMESTAMP, ///< Signed 64 bit milliseconds since the epoch.
+ FLOAT = PN_FLOAT, ///< 32 bit binary floating point.
+ DOUBLE = PN_DOUBLE, ///< 64 bit binary floating point.
+ DECIMAL32 = PN_DECIMAL32, ///< 32 bit decimal floating point.
+ DECIMAL64 = PN_DECIMAL64, ///< 64 bit decimal floating point.
+ DECIMAL128 = PN_DECIMAL128, ///< 128 bit decimal floating point.
+ UUID = PN_UUID, ///< 16 byte UUID.
+ BINARY = PN_BINARY, ///< Variable length sequence of bytes.
+ STRING = PN_STRING, ///< Variable length utf8-encoded string.
+ SYMBOL = PN_SYMBOL, ///< Variable length encoded string.
+ DESCRIBED = PN_DESCRIBED, ///< A descriptor and a value.
+ ARRAY = PN_ARRAY, ///< A sequence of values of the same type.
+ LIST = PN_LIST, ///< A sequence of values, may be of mixed types.
+ MAP = PN_MAP ///< A sequence of key:value pairs, may be of mixed types.
+};
+
+/// Get the name of the AMQP type.
+PN_CPP_EXTERN std::string type_name(type_id);
+
+/// Print the type name.
+PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, type_id);
+
+/// Throw a conversion_error if want != got with a message including the names of the types.
+PN_CPP_EXTERN void assert_type_equal(type_id want, type_id got);
+
+} // proton
+
+#endif // TYPES_H
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/proton-c/bindings/cpp/include/proton/type_traits.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/type_traits.hpp b/proton-c/bindings/cpp/include/proton/type_traits.hpp
index 7c1f6b0..9f67715 100644
--- a/proton-c/bindings/cpp/include/proton/type_traits.hpp
+++ b/proton-c/bindings/cpp/include/proton/type_traits.hpp
@@ -1,5 +1,5 @@
-#ifndef TYPE_TRAITS_HPP
-#define TYPE_TRAITS_HPP
+#ifndef PROTON_TYPE_TRAITS_HPP
+#define PROTON_TYPE_TRAITS_HPP
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -29,22 +29,12 @@
/// Also provides workarounds for missing type_traits classes on older
/// C++ compilers.
-#include "proton/config.hpp"
-#include "proton/types.hpp"
+#include <proton/config.hpp>
+#include <proton/types_fwd.hpp>
+#include <proton/type_id.hpp>
namespace proton {
-
-class binary;
-class decimal128;
-class decimal32;
-class decimal64;
-class scalar;
-class symbol;
-class timestamp;
-class uuid;
-class value;
-
-namespace internal {
+namespace codec {
class decoder;
class encoder;
@@ -139,27 +129,12 @@ template <class T> struct is_unknown_integer {
static const bool value = !has_type_id<T>::value && is_integral<T>::value;
};
-// Types for SFINAE tests.
+namespace is_encodable_impl { // Protected the world from wildcard operator<<
+
typedef char yes;
typedef double no;
struct wildcard { wildcard(...); };
-namespace is_decodable_impl { // Protected the world from wildcard operator<<
-
-no operator>>(wildcard, wildcard); // Fallback
-
-template<typename T> struct is_decodable {
- static char test(decoder);
- static double test(...); // Failed test, no match.
- static decoder& d;
- static T &t;
- static bool const value = (sizeof(test(d >> t)) == sizeof(yes));
-};
-} // namespace is_decodable_impl
-
-
-namespace is_encodable_impl { // Protected the world from wildcard operator<<
-
no operator<<(wildcard, wildcard); // Fallback
template<typename T> struct is_encodable {
@@ -169,51 +144,39 @@ template<typename T> struct is_encodable {
static const T& t;
static bool const value = sizeof(test(e << t)) == sizeof(yes);
};
+// Avoid recursion
+template <> struct is_encodable<value> : public true_type {};
} // namespace is_encodable_impl
/// is_encodable<T>::value is true if there is an operator<< for encoder and T.
using is_encodable_impl::is_encodable;
-/// Metafunction: is_decodable<T>::value is true if `T t; decoder >> t` is valid.
-using is_decodable_impl::is_decodable;
-
-
-// Start encoding a complex type.
-struct start {
- PN_CPP_EXTERN start(type_id type=NULL_TYPE, type_id element=NULL_TYPE, bool described=false, size_t size=0);
- type_id type; ///< The container type: ARRAY, LIST, MAP or DESCRIBED.
- type_id element; ///< the element type for array only.
- bool is_described; ///< true if first value is a descriptor.
- size_t size; ///< the element count excluding the descriptor (if any)
-
- /// Return a start for an array.
- PN_CPP_EXTERN static start array(type_id element, bool described=false);
-
- /// Return a start for a list.
- PN_CPP_EXTERN static start list();
-
- /// Return a start for a map.
- PN_CPP_EXTERN static start map();
-
- /// Return a start for a described type.
- PN_CPP_EXTERN static start described();
-};
-
-/// Finish inserting or extracting a container value.
-struct finish {};
-
-} // namespace internal
-
-/// An enabler template for C++ values that can be converted to AMQP.
+/// An enabler template for C++ values that can be converted to AMQP values.
template<class T, class U=void> struct enable_amqp_type :
- public internal::enable_if<internal::is_encodable<T>::value, U> {};
-
-/// An enabler for integer types.
-template <class T, class U=void> struct enable_integer :
- public internal::enable_if<internal::is_unknown_integer<T>::value, U> {};
-} // namespace proton
+ public enable_if<is_encodable<T>::value, U> {};
+
+/// Enabler for encodable types excluding proton::value.
+template<class T, class U=void> struct assignable : enable_amqp_type<T, U> {};
+template<class U> struct assignable<value, U> : public false_type {};
+/// An enabler for integer types that are not directly AMQP types.
+template <class T, class U=void> struct enable_unknown_integer :
+ public enable_if<is_unknown_integer<T>::value, U> {};
+
+/// Using `exact_cref<const T>` as an argument type instead of `const &T`
+/// ensures that the function will only accept references to an existing T, and
+/// not to a temporary T created by implicit conversion.
+template <class T> struct exact_cref;
+
+template <class T> struct exact_cref {
+ template <class U> exact_cref(
+ const U& r,
+ typename enable_if<is_same<T,U>::value>::type* = 0) : ref(r) {}
+ operator const T&() const { return ref; }
+ const T& ref;
+};
-/// @endcond
+} // internal
+} // proton
-#endif // TYPE_TRAITS_HPP
+#endif // PROTON_TYPE_TRAITS_HPP
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/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 61fbbdc..bb2017b 100644
--- a/proton-c/bindings/cpp/include/proton/types.hpp
+++ b/proton-c/bindings/cpp/include/proton/types.hpp
@@ -1,6 +1,5 @@
-#ifndef TYPES_H
-#define TYPES_H
-
+#ifndef PROTON_TYPES_HPP
+#define PROTON_TYPES_HPP
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,115 +19,33 @@
* under the License.
*/
-/// @file
-///
-/// Defines C++ types representing AMQP types.
-
-#include "proton/export.hpp"
-#include "proton/error.hpp"
-
-#include <proton/codec.h> // XXX everywhere else folks are using "codec.h"
-#include <proton/type_compat.h>
-#include <algorithm>
-#include <bitset>
-#include <string>
-#include <memory.h>
-
-namespace proton {
-
-/// An identifier for AMQP types.
-enum type_id {
- NULL_TYPE = PN_NULL, ///< The null type, contains no data.
- BOOLEAN = PN_BOOL, ///< Boolean true or false.
- UBYTE = PN_UBYTE, ///< Unsigned 8 bit integer.
- BYTE = PN_BYTE, ///< Signed 8 bit integer.
- USHORT = PN_USHORT, ///< Unsigned 16 bit integer.
- SHORT = PN_SHORT, ///< Signed 16 bit integer.
- UINT = PN_UINT, ///< Unsigned 32 bit integer.
- INT = PN_INT, ///< Signed 32 bit integer.
- CHAR = PN_CHAR, ///< 32 bit unicode character.
- ULONG = PN_ULONG, ///< Unsigned 64 bit integer.
- LONG = PN_LONG, ///< Signed 64 bit integer.
- TIMESTAMP = PN_TIMESTAMP, ///< Signed 64 bit milliseconds since the epoch.
- FLOAT = PN_FLOAT, ///< 32 bit binary floating point.
- DOUBLE = PN_DOUBLE, ///< 64 bit binary floating point.
- DECIMAL32 = PN_DECIMAL32, ///< 32 bit decimal floating point.
- DECIMAL64 = PN_DECIMAL64, ///< 64 bit decimal floating point.
- DECIMAL128 = PN_DECIMAL128, ///< 128 bit decimal floating point.
- UUID = PN_UUID, ///< 16 byte UUID.
- BINARY = PN_BINARY, ///< Variable length sequence of bytes.
- STRING = PN_STRING, ///< Variable length utf8-encoded string.
- SYMBOL = PN_SYMBOL, ///< Variable length encoded string.
- DESCRIBED = PN_DESCRIBED, ///< A descriptor and a value.
- ARRAY = PN_ARRAY, ///< A sequence of values of the same type.
- LIST = PN_LIST, ///< A sequence of values, may be of mixed types.
- MAP = PN_MAP ///< A sequence of key:value pairs, may be of mixed types.
-};
-
-/// Get the name of the AMQP type.
-PN_CPP_EXTERN std::string type_name(type_id);
-
-/// Print the type name.
-PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, type_id);
-
-/// AMQP UTF-8 encoded string.
-struct amqp_string : public std::string {
- explicit amqp_string(const std::string& s=std::string()) : std::string(s) {}
- explicit amqp_string(const char* s) : std::string(s) {}
- explicit amqp_string(const pn_bytes_t& b) : std::string(b.start, b.size) {}
-};
-
-/// AMQP ASCII encoded symbolic name.
-struct amqp_symbol : public std::string {
- explicit amqp_symbol(const std::string& s=std::string()) : std::string(s) {}
- explicit amqp_symbol(const char* s) : std::string(s) {}
- explicit amqp_symbol(const pn_bytes_t& b) : std::string(b.start, b.size) {}
-};
-
-/// AMQP variable-length binary data.
-struct amqp_binary : public std::string {
- explicit amqp_binary(const std::string& s=std::string()) : std::string(s) {}
- explicit amqp_binary(const char* s) : std::string(s) {}
- explicit amqp_binary(const pn_bytes_t& b) : std::string(b.start, b.size) {}
-};
-
-// TODO aconway 2015-06-16: described types.
-
-/// @name Type test functions
+///@file
///
-/// Attributes of a type_id value, returns same result as the
-/// corresponding std::type_traits tests for the corresponding C++
-/// types.
-///
-/// @{
-
-/// Any scalar type
-PN_CPP_EXTERN bool type_id_is_scalar(type_id);
-/// One of the signed integer types: BYTE, SHORT, INT or LONG
-PN_CPP_EXTERN bool type_id_is_signed_int(type_id);
-/// One of the unsigned integer types: UBYTE, USHORT, UINT or ULONG
-PN_CPP_EXTERN bool type_id_is_unsigned_int(type_id);
-/// Any of the signed or unsigned integers, BOOL, CHAR or TIMESTAMP.
-PN_CPP_EXTERN bool type_id_is_integral(type_id);
-/// A floating point type, float or double
-PN_CPP_EXTERN bool type_id_is_floating_point(type_id);
-/// Any signed integer, float or double. BOOL, CHAR and TIMESTAMP are not signed.
-PN_CPP_EXTERN bool type_id_is_signed(type_id);
-/// Any DECIMAL type.
-PN_CPP_EXTERN bool type_id_is_decimal(type_id);
-/// STRING, SYMBOL or BINARY
-PN_CPP_EXTERN bool type_id_is_string_like(type_id);
-/// Container types: MAP, LIST, ARRAY or DESCRIBED.
-PN_CPP_EXTERN bool type_id_is_container(type_id);
-
-/// @}
-
-/// Print the name of a type.
-PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, type_id);
-/// @endcond
-
-struct null {};
-
-}
-
-#endif // TYPES_H
+/// Include the definitions of all proton types used to represent AMQP types.
+/// Provided for convenience, you can include types individually instead.
+
+#include <proton/binary.hpp>
+#include <proton/config.hpp>
+#include <proton/decimal.hpp>
+#include <proton/deque.hpp>
+#include <proton/duration.hpp>
+#include <proton/list.hpp>
+#include <proton/map.hpp>
+#include <proton/scalar.hpp>
+#include <proton/symbol.hpp>
+#include <proton/timestamp.hpp>
+#include <proton/types_fwd.hpp>
+#include <proton/uuid.hpp>
+#include <proton/value.hpp>
+#include <proton/vector.hpp>
+
+#include <proton/annotation_key.hpp>
+#include <proton/message_id.hpp>
+
+#include <proton/config.hpp>
+#if PN_CPP_HAS_CPP11
+#include <proton/forward_list.hpp>
+#include <proton/unordered_map.hpp>
+#endif
+
+#endif // PROTON_TYPES_HPP
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4fa5fa41/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
new file mode 100644
index 0000000..0eca2ed
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/types_fwd.hpp
@@ -0,0 +1,47 @@
+#ifndef PROTON_TYPES_FWD_HPP
+#define PROTON_TYPES_FWD_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.
+ */
+
+
+///@file
+///
+/// Forward declarations for all the C++ types used by proton to represent AMQP types.
+
+#include <proton/type_compat.h>
+#include <string>
+
+namespace proton {
+
+class binary;
+class decimal128;
+class decimal32;
+class decimal64;
+class scalar;
+class symbol;
+class timestamp;
+class duration;
+class uuid;
+class uuid;
+class value;
+struct null {};
+
+}
+
+#endif // PROTON_TYPES_FWD_HPP
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org