http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/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 01826e7..5d80548 100644 --- a/proton-c/bindings/cpp/include/proton/connection_options.hpp +++ b/proton-c/bindings/cpp/include/proton/connection_options.hpp @@ -1,5 +1,5 @@ -#ifndef PROTON_CPP_CONNECTION_OPTIONS_H -#define PROTON_CPP_CONNECTION_OPTIONS_H +#ifndef PROTON_CONNECTION_OPTIONS_H +#define PROTON_CONNECTION_OPTIONS_H /* * @@ -22,13 +22,12 @@ * */ -#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 "proton/config.hpp" +#include "proton/export.hpp" +#include "proton/duration.hpp" +#include "proton/internal/pn_unique_ptr.hpp" +#include "proton/reconnect_timer.hpp" +#include "proton/types_fwd.hpp" #include <vector> #include <string> @@ -81,7 +80,7 @@ class connection_options { /// Copy options. PN_CPP_EXTERN connection_options& operator=(const connection_options&); - // XXX add C++11 move operations + // XXX add C++11 move operations - Still relevant, and applies to all options /// Set a connection handler. /// @@ -105,11 +104,10 @@ class connection_options { PN_CPP_EXTERN connection_options& virtual_host(const std::string &name); /// @cond INTERNAL - - /// XXX settle questions about reconnect_timer - consider simply - /// reconnect_options and making reconnect_timer internal + // XXX settle questions about reconnect_timer - consider simply + // reconnect_options and making reconnect_timer internal + /// **Experimental** PN_CPP_EXTERN connection_options& reconnect(const reconnect_timer &); - /// @endcond /// Set SSL client options. @@ -129,14 +127,11 @@ class connection_options { /// Specify the allowed mechanisms for use on the connection. PN_CPP_EXTERN connection_options& sasl_allowed_mechs(const std::string &); - /// Set the SASL configuration name. + /// **Experimental** - Set the SASL configuration name. PN_CPP_EXTERN connection_options& sasl_config_name(const std::string &); - /// @cond INTERNAL - /// XXX not clear this should be exposed - /// Set the SASL configuration path. + /// **Experimental** - Set the SASL configuration path. PN_CPP_EXTERN connection_options& sasl_config_path(const std::string &); - /// @endcond /// Update option values from values set in other. PN_CPP_EXTERN connection_options& update(const connection_options& other); @@ -149,12 +144,14 @@ class connection_options { class impl; internal::pn_unique_ptr<impl> impl_; - friend class container_impl; - friend class connector; - friend class io::connection_engine; - friend class connection; + /// @cond INTERNAL + friend class container_impl; + friend class connector; + friend class io::connection_engine; + friend class connection; + /// @endcond }; -} +} // proton -#endif // PROTON_CPP_CONNECTION_OPTIONS_H +#endif // PROTON_CONNECTION_OPTIONS_H
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/container.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/container.hpp b/proton-c/bindings/cpp/include/proton/container.hpp index 6d613e2..f72ea76 100644 --- a/proton-c/bindings/cpp/include/proton/container.hpp +++ b/proton-c/bindings/cpp/include/proton/container.hpp @@ -1,5 +1,5 @@ -#ifndef PROTON_CPP_CONTAINER_H -#define PROTON_CPP_CONTAINER_H +#ifndef PROTON_CONTAINER_HPP +#define PROTON_CONTAINER_HPP /* * @@ -27,7 +27,7 @@ #include <proton/connection_options.hpp> #include <proton/error_condition.hpp> #include <proton/listener.hpp> -#include <proton/pn_unique_ptr.hpp> +#include <proton/internal/pn_unique_ptr.hpp> #include <proton/thread_safe.hpp> #include <string> @@ -47,21 +47,22 @@ class task; class container; -/// A top-level container of connections, sessions, senders and receivers. +/// A top-level container of connections, sessions, senders, and +/// receivers. /// /// A container gives a unique identity to each communicating peer. It /// is often a process-level object. /// -/// It serves as an entry point to the API, allowing connections, senders -/// and receivers to be established. It can be supplied with an event handler -/// in order to intercept important messaging events, such as newly -/// received messages or newly issued credit for sending +/// It serves as an entry point to the API, allowing connections, +/// senders, and receivers to be established. It can be supplied with +/// an event handler in order to intercept important messaging events, +/// such as newly received messages or newly issued credit for sending /// messages. class PN_CPP_CLASS_EXTERN container { - public: + public: PN_CPP_EXTERN virtual ~container(); - /// Connect to url, send an `open` request to the remote peer. + /// Connect to `url` and send an open request to the remote peer. /// /// Options are applied to the connection as follows, values in later /// options override earlier ones: @@ -70,18 +71,18 @@ class PN_CPP_CLASS_EXTERN container { /// 2. options passed to connect() /// /// The handler in the composed options is used to call - /// proton::handler::on_connection_open() when the remote peer's open response - /// is received. - ///@{ + /// proton::handler::on_connection_open() when the remote peer's + /// open response is received. virtual returned<connection> connect(const std::string& url, const connection_options &) = 0; + + /// Connect to `url` and send an open request to the remote peer. PN_CPP_EXTERN returned<connection> connect(const std::string& url); - ///@} - ///@cond INTERNAL + /// @cond INTERNAL /// Stop listening on url, must match the url string given to listen(). /// You can also use the proton::listener object returned by listen() virtual void stop_listening(const std::string& url) = 0; - ///@endcond + /// @endcond // FIXME aconway 2016-05-13: doc options @@ -109,79 +110,96 @@ class PN_CPP_CLASS_EXTERN container { /// With a multithreaded container, call run() in multiple threads to create a thread pool. virtual void run() = 0; - /// If true, the container will stop (i.e. run() will return) when all - /// active connections and listeners are closed. If false the container - /// will keep running till stop() is called. + /// If true, the container will stop (i.e., run() will return) + /// when all active connections and listeners are closed. If false + /// the container will keep running till stop() is called. /// /// auto_stop is set by default when a new container is created. // FIXME aconway 2016-05-06: doc virtual void auto_stop(bool) = 0; - ///@name Stop the container with an optional error_condition err. - /// - abort all open connections and listeners. - /// - process final handler events and injected functions - /// - if !err.empty(), handlers will receive on_transport_error(err) - /// - run() will return in all threads. + /// Stop the container with an optional error_condition err. + /// + /// - Abort all open connections and listeners. + /// - Process final handler events and injected functions + /// - If `!err.empty()`, handlers will receive on_transport_error + /// - run() will return in all threads. virtual void stop(const error_condition& err = error_condition()) = 0; /// Open a connection to `url` and open a sender for `url.path()`. - /// Any supplied sender or connection options will override the - /// container's template options. - /// @{ PN_CPP_EXTERN virtual returned<sender> open_sender(const std::string &url); + + /// Open a connection to `url` and open a sender for `url.path()`. + /// Any supplied sender options will override the container's + /// template options. PN_CPP_EXTERN virtual returned<sender> open_sender(const std::string &url, const proton::sender_options &o); + + /// Open a connection to `url` and open a sender for `url.path()`. + /// Any supplied sender or connection options will override the + /// container's template options. virtual returned<sender> open_sender(const std::string &url, const proton::sender_options &o, const connection_options &c) = 0; - //@} /// Open a connection to `url` and open a receiver for - /// `url.path()`. Any supplied receiver or connection options will - /// override the container's template options. - /// @{ + /// `url.path()`. PN_CPP_EXTERN virtual returned<receiver> open_receiver(const std::string&url); + + + /// Open a connection to `url` and open a receiver for + /// `url.path()`. Any supplied receiver options will override the + /// container's template options. PN_CPP_EXTERN virtual returned<receiver> open_receiver(const std::string&url, const proton::receiver_options &o); + + /// Open a connection to `url` and open a receiver for + /// `url.path()`. Any supplied receiver or connection options will + /// override the container's template options. virtual returned<receiver> open_receiver(const std::string&url, const proton::receiver_options &o, const connection_options &c) = 0; - ///@} /// A unique identifier for the container. virtual std::string id() const = 0; // FIXME aconway 2016-05-04: need timed injection to replace schedule() - /// Connection options that will be to outgoing connections. These are - /// applied first and overriden by options provided in connect() and - /// handler::on_connection_open() - /// @{ + /// Connection options that will be to outgoing connections. These + /// are applied first and overriden by options provided in + /// connect() and handler::on_connection_open(). virtual void client_connection_options(const connection_options &) = 0; + + /// @copydoc client_connection_options virtual connection_options client_connection_options() const = 0; - ///@} - /// Connection options that will be applied to incoming connections. These - /// are applied first and overridden by options provided in listen(), - /// listen_handler::on_accept() and handler::on_connection_open() - /// @{ + /// Connection options that will be applied to incoming + /// connections. These are applied first and overridden by options + /// provided in listen(), listen_handler::on_accept() and + /// handler::on_connection_open(). virtual void server_connection_options(const connection_options &) = 0; + + /// @copydoc server_connection_options virtual connection_options server_connection_options() const = 0; - ///@} - /// Sender options applied to senders created by this container. They are - /// applied before handler::on_sender_open() and can be over-ridden. @{ - /// @{ + /// Sender options applied to senders created by this + /// container. They are applied before handler::on_sender_open() + /// and can be overridden. virtual void sender_options(const sender_options &) = 0; + + /// @copydoc sender_options virtual class sender_options sender_options() const = 0; - ///@} - /// Receiver options applied to receivers created by this container. They - /// are applied before handler::on_receiver_open() and can be over-ridden. - /// @{ + /// Receiver options applied to receivers created by this + /// container. They are applied before handler::on_receiver_open() + /// and can be overridden. virtual void receiver_options(const receiver_options &) = 0; + + /// @copydoc receiver_options virtual class receiver_options receiver_options() const = 0; - /// @} + }; -} -#endif // PROTON_CPP_CONTAINER_H + +} // proton + +#endif // PROTON_CONTAINER_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/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 d305693..968f243 100644 --- a/proton-c/bindings/cpp/include/proton/data.hpp +++ b/proton-c/bindings/cpp/include/proton/data.hpp @@ -1,7 +1,8 @@ -#ifndef PROTON_DATA_HPP -#define PROTON_DATA_HPP +#ifndef PROTON_CODEC_DATA_HPP +#define PROTON_CODEC_DATA_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 @@ -18,34 +19,30 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + * */ -#include <proton/object.hpp> -#include <proton/types_fwd.hpp> -#include <proton/type_id.hpp> - -///@file +#include "proton/internal/object.hpp" +#include "proton/types_fwd.hpp" +#include "proton/type_id.hpp" struct pn_data_t; namespace proton { class value; -///@defgroup codec Internal details of AMQP encoding. -/// -/// You can use these classes on an experimental basis to create your own AMQP -/// encodings for C++ types, but they may change in the future. For examples of use -/// see the built-in encodings, for example in proton/vector.hpp or proton/map.hpp -/// @ingroup codec +// XXX -> internal namespace namespace codec { +/// @cond INTERNAL /// Wrapper for a proton data object. class data : public internal::object<pn_data_t> { /// Wrap an existing proton-C data object. data(pn_data_t* d) : internal::object<pn_data_t>(d) {} public: + /// Create an empty data. data() : internal::object<pn_data_t>(0) {} /// Create a new data object. @@ -81,20 +78,33 @@ class data : public internal::object<pn_data_t> { friend struct state_guard; friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const data&); }; +/// @endcond -// state_guard saves the state and restores it in dtor unless cancel() is called. +/// **Experimental** - Save and restore codec state +/// +/// A state_guard saves the state and restores it in the destructor +/// unless cancel() is called. struct state_guard { + /// @cond INTERNAL data& data_; void* point_; bool cancel_; + /// @endcond + /// @cond INTERNAL state_guard(data& d) : data_(d), point_(data_.point()), cancel_(false) {} + /// @endcond + ~state_guard() { if (!cancel_) data_.restore(point_); } + + /// Discard the saved state. void cancel() { cancel_ = true; } }; -// Start encoding a complex type. +/// **Experimental** - Start encoding a complex type. struct start { + /// @cond INTERNAL + /// XXX Document 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_) {} @@ -103,18 +113,21 @@ struct start { 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) + /// @endcond + /// @cond INTERNAL + /// XXX Document static start array(type_id element, bool described=false) { return start(ARRAY, element, described); } static start list() { return start(LIST); } static start map() { return start(MAP); } static start described() { return start(DESCRIBED, NULL_TYPE, true); } + /// @endcond }; -// Finish inserting or extracting a complex type. +/// **Experimental** - Finish inserting or extracting a complex type. struct finish {}; } // codec - } // proton -#endif /*!PROTON_DATA_HPP*/ +#endif // PROTON_CODEC_DATA_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/decimal.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/decimal.hpp b/proton-c/bindings/cpp/include/proton/decimal.hpp index dada944..8ef5023 100644 --- a/proton-c/bindings/cpp/include/proton/decimal.hpp +++ b/proton-c/bindings/cpp/include/proton/decimal.hpp @@ -1,6 +1,8 @@ -#ifndef DECIMAL_HPP -#define DECIMAL_HPP +#ifndef PROTON_DECIMAL_HPP +#define PROTON_DECIMAL_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 @@ -17,19 +19,20 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + * */ #include "proton/byte_array.hpp" -#include "proton/comparable.hpp" #include "proton/export.hpp" +#include "proton/internal/comparable.hpp" -#include <proton/types.h> +#include "proton/types.h" #include <iosfwd> namespace proton { -///@name AMQP decimal types. +/// @name AMQP decimal types. /// /// AMQP uses the standard IEEE 754-2008 encoding for decimal types. /// @@ -49,16 +52,15 @@ class decimal64 : public byte_array<8> {}; /// 128-bit decimal floating point. class decimal128 : public byte_array<16> {}; -///@} +/// @} /// Print decimal values -///@{ +/// @{ PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const decimal32&); PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const decimal64&); PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const decimal128&); -///@} - +/// @} -} +} // proton -#endif // DECIMAL_HPP +#endif // PROTON_DECIMAL_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/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 deleted file mode 100644 index 32d3adb..0000000 --- a/proton-c/bindings/cpp/include/proton/decoder.hpp +++ /dev/null @@ -1,195 +0,0 @@ -#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 - * 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/data.hpp> -#include <proton/types_fwd.hpp> -#include <proton/type_traits.hpp> - -#include <utility> - -// Proton namespace -namespace proton { - -class annotation_key; -class message_id; -class scalar; -class value; - -namespace internal { -class value_base; -} - -/// @ingroup codec -namespace codec { - -/// Stream-like decoder from AMQP bytes to C++ values. -/// -/// Internal use only, see proton::value, proton::scalar and \ref types -/// for the recommended ways to manage AMQP data. -class decoder : public data { - public: - - /// Wrap Proton-C data object. - /// The exact flag if set means decode only when there is an exact match - /// between the AMQP and C++ type. If not set then perform automatic conversions. - explicit decoder(const data& d, bool exact=false) : data(d), exact_(exact) {} - - /// Attach decoder to a proton::value. The decoder is rewound to the start of the data. - PN_CPP_EXTERN explicit decoder(const internal::value_base&, bool exact=false); - - /// 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 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 value to extract at the current level. - PN_CPP_EXTERN bool more(); - - /// 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 built-in types - /// @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>>(symbol&); - PN_CPP_EXTERN decoder& operator>>(binary&); - 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>>(internal::value_base&); - PN_CPP_EXTERN decoder& operator>>(null&); - ///@} - - /// 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 decoding a container type, and move on to the next value in the stream. - PN_CPP_EXTERN decoder& operator>>(const finish&); - - ///@cond INTERNAL - 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) {} }; - - 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); } - ///@endcond - - /** 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) { - using namespace internal; - 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) { - using namespace internal; - 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: - type_id pre_get(); - template <class T, class U> decoder& extract(T& x, U (*get)(pn_data_t*)); - bool exact_; - - friend class message; -}; - -template<class T> T get(decoder& d) { - assert_type_equal(internal::type_id_of<T>::value, d.next_type()); - T x; - d >> x; - return x; -} - -// operator >> for integer types that are not covered by the standard overrides. -template <class T> typename internal::enable_if<internal::is_unknown_integer<T>::value, decoder&>::type -operator>>(decoder& d, T& i) { - using namespace internal; - 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. - return d; -} - -} // codec -} // proton - -#endif // PROTON_DECODER_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/default_container.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/default_container.hpp b/proton-c/bindings/cpp/include/proton/default_container.hpp index d3a7608..06ed37b 100644 --- a/proton-c/bindings/cpp/include/proton/default_container.hpp +++ b/proton-c/bindings/cpp/include/proton/default_container.hpp @@ -24,13 +24,15 @@ // FIXME aconway 2016-05-04: doc -#include <proton/container.hpp> +#include "proton/container.hpp" namespace proton { // FIXME aconway 2016-05-04: doc + +/// A single-threaded container. class PN_CPP_CLASS_EXTERN default_container : public container { - public: + public: /// Create a default, single-threaded container with a handler. /// The handler will be called for all events on all connections in the container. /// @@ -50,14 +52,17 @@ class PN_CPP_CLASS_EXTERN default_container : public container { /// Wrap an existing container implementation as a default_container. /// Takes ownership of c. - PN_CPP_EXTERN explicit default_container(container* c) : impl_(c) {} + PN_CPP_EXTERN explicit default_container(container* c) : impl_(c) {} // FIXME aconway 2016-05-13: @copydoc all. PN_CPP_EXTERN returned<connection> connect(const std::string& url, const connection_options &) PN_CPP_OVERRIDE; PN_CPP_EXTERN listener listen(const std::string& url, listen_handler& l) PN_CPP_OVERRIDE; + /// @cond INTERNAL + /// XXX Make private PN_CPP_EXTERN void stop_listening(const std::string& url) PN_CPP_OVERRIDE; + /// @endcond PN_CPP_EXTERN void run() PN_CPP_OVERRIDE; PN_CPP_EXTERN void auto_stop(bool set) PN_CPP_OVERRIDE; @@ -79,14 +84,17 @@ class PN_CPP_CLASS_EXTERN default_container : public container { PN_CPP_EXTERN connection_options client_connection_options() const PN_CPP_OVERRIDE; PN_CPP_EXTERN void server_connection_options(const connection_options &o) PN_CPP_OVERRIDE; PN_CPP_EXTERN connection_options server_connection_options() const PN_CPP_OVERRIDE; + /// @copydoc container::sender_options PN_CPP_EXTERN void sender_options(const class sender_options &o) PN_CPP_OVERRIDE; PN_CPP_EXTERN class sender_options sender_options() const PN_CPP_OVERRIDE; + /// @copydoc container::receiver_options PN_CPP_EXTERN void receiver_options(const class receiver_options & o) PN_CPP_OVERRIDE; PN_CPP_EXTERN class receiver_options receiver_options() const PN_CPP_OVERRIDE; - private: + private: internal::pn_unique_ptr<container> impl_; }; -} +} // proton + #endif // PROTON_DEFAULT_CONTAINER_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/delivery.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/delivery.hpp b/proton-c/bindings/cpp/include/proton/delivery.hpp index 3f76166..c587214 100644 --- a/proton-c/bindings/cpp/include/proton/delivery.hpp +++ b/proton-c/bindings/cpp/include/proton/delivery.hpp @@ -1,5 +1,5 @@ -#ifndef PROTON_CPP_DELIVERY_H -#define PROTON_CPP_DELIVERY_H +#ifndef PROTON_DELIVERY_HPP +#define PROTON_DELIVERY_HPP /* * @@ -23,7 +23,7 @@ */ #include "proton/export.hpp" -#include "proton/object.hpp" +#include "proton/internal/object.hpp" #include "proton/transfer.hpp" #include "proton/delivery.h" @@ -33,9 +33,10 @@ namespace proton { class receiver; -/// A message transfer. Every delivery exists within the context of a -/// proton::receiver. A delivery attempt can fail. As a result, a -/// particular message may correspond to multiple deliveries. +/// A received message. +/// +/// A delivery attempt can fail. As a result, a particular message may +/// correspond to multiple deliveries. class delivery : public transfer { /// @cond INTERNAL delivery(pn_delivery_t* d); @@ -44,19 +45,22 @@ class delivery : public transfer { public: delivery() {} - // Return the receiver for this delivery + /// Return the receiver for this delivery. PN_CPP_EXTERN class receiver receiver() const; - /// Settle with ACCEPTED state + // XXX ATM the following don't reflect the differing behaviors we + // get from the different delivery modes. - Deferred + + /// Settle with ACCEPTED state. PN_CPP_EXTERN void accept() { settle(ACCEPTED); } - /// Settle with REJECTED state + /// Settle with REJECTED state. PN_CPP_EXTERN void reject() { settle(REJECTED); } - /// Settle with RELEASED state + /// Settle with RELEASED state. PN_CPP_EXTERN void release() { settle(RELEASED); } - /// Settle with MODIFIED state + /// Settle with MODIFIED state. PN_CPP_EXTERN void modify() { settle(MODIFIED); } /// @cond INTERNAL @@ -64,6 +68,6 @@ class delivery : public transfer { /// @endcond }; -} +} // proton -#endif // PROTON_CPP_DELIVERY_H +#endif // PROTON_DELIVERY_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/delivery_mode.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/delivery_mode.hpp b/proton-c/bindings/cpp/include/proton/delivery_mode.hpp index fe420e6..97b350f 100644 --- a/proton-c/bindings/cpp/include/proton/delivery_mode.hpp +++ b/proton-c/bindings/cpp/include/proton/delivery_mode.hpp @@ -1,5 +1,5 @@ -#ifndef PROTON_CPP_DELIVERY_MODE_H -#define PROTON_CPP_DELIVERY_MODE_H +#ifndef PROTON_DELIVERY_MODE_H +#define PROTON_DELIVERY_MODE_H /* * @@ -28,28 +28,33 @@ namespace proton { /// This structure imitates the newer C++11 "enum class" so that /// The enumeration constants are in the delivery_mode namespace. struct delivery_mode { - enum modes { - // No set policy. The application must settle messages itself - // according to its own policy. - NONE = 0, - // Outgoing messages are settled immediately by the link. - // There are no duplicates. - AT_MOST_ONCE, - // The receiver settles the delivery first with an - // accept/reject/release disposition. The sender waits to - // settle until after the disposition notification is - // received. - AT_LEAST_ONCE - }; - - delivery_mode() : modes_(NONE) {} - delivery_mode(modes m) : modes_(m) {} - operator modes() { return modes_; } - -private: - modes modes_; + /// Delivery modes + enum modes { + /// No set policy. The application must settle messages + /// itself according to its own policy. + NONE = 0, + /// Outgoing messages are settled immediately by the link. + /// There are no duplicates. + AT_MOST_ONCE, + /// The receiver settles the delivery first with an + /// accept/reject/release disposition. The sender waits to + /// settle until after the disposition notification is + /// received. + AT_LEAST_ONCE + }; + + /// @cond INTERNAL + + delivery_mode() : modes_(NONE) {} + delivery_mode(modes m) : modes_(m) {} + operator modes() { return modes_; } + + /// @endcond + + private: + modes modes_; }; -} +} // proton -#endif // PROTON_CPP_DELIVERY_MODE_H +#endif // PROTON_DELIVERY_MODE_H http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/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 deleted file mode 100644 index 7d0b278..0000000 --- a/proton-c/bindings/cpp/include/proton/deque.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#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, internal::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/2dc4afe0/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 1b413a3..7f32e91 100644 --- a/proton-c/bindings/cpp/include/proton/duration.hpp +++ b/proton-c/bindings/cpp/include/proton/duration.hpp @@ -1,5 +1,5 @@ -#ifndef PROTON_CPP_DURATION_H -#define PROTON_CPP_DURATION_H +#ifndef PROTON_DURATION_HPP +#define PROTON_DURATION_HPP /* * @@ -22,9 +22,9 @@ * */ -#include <proton/export.hpp> -#include <proton/comparable.hpp> -#include <proton/types_fwd.hpp> +#include "proton/export.hpp" +#include "proton/internal/comparable.hpp" +#include "proton/types_fwd.hpp" #include <iosfwd> @@ -33,14 +33,19 @@ namespace proton { /// A span of time in milliseconds. class duration : private internal::comparable<duration> { public: - typedef int64_t numeric_type; ///< Numeric type used to store milliseconds + /// Numeric type used to store milliseconds + typedef int64_t numeric_type; - explicit duration(numeric_type ms = 0) : ms_(ms) {} ///< Construct from milliseconds - duration& operator=(numeric_type ms) { ms_ = ms; return *this; } ///< Assign + /// Construct from milliseconds + explicit duration(numeric_type ms = 0) : ms_(ms) {} - numeric_type milliseconds() const { return ms_; } ///< Return milliseconds + /// Assign + duration& operator=(numeric_type ms) { ms_ = ms; return *this; } - PN_CPP_EXTERN static const duration FOREVER; ///< Wait for ever + /// Return milliseconds + numeric_type milliseconds() const { return ms_; } + + PN_CPP_EXTERN static const duration FOREVER; ///< Wait forever PN_CPP_EXTERN static const duration IMMEDIATE; ///< Don't wait at all PN_CPP_EXTERN static const duration SECOND; ///< One second PN_CPP_EXTERN static const duration MINUTE; ///< One minute @@ -52,8 +57,8 @@ class duration : private internal::comparable<duration> { /// Print duration PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, duration); -///@name Comparison and arithmetic operators -///@{ +/// @name Comparison and arithmetic operators +/// @{ inline bool operator<(duration x, duration y) { return x.milliseconds() < y.milliseconds(); } inline bool operator==(duration x, duration y) { return x.milliseconds() == y.milliseconds(); } @@ -61,7 +66,8 @@ inline duration operator+(duration x, duration y) { return duration(x.millisecon inline duration operator-(duration x, duration y) { return duration(x.milliseconds() - y.milliseconds()); } inline duration operator*(duration d, uint64_t n) { return duration(d.milliseconds()*n); } inline duration operator*(uint64_t n, duration d) { return d * n; } -///@} -} +/// @} + +} // proton -#endif // PROTON_CPP_DURATION_H +#endif // PROTON_DURATION_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/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 deleted file mode 100644 index fd15128..0000000 --- a/proton-c/bindings/cpp/include/proton/encoder.hpp +++ /dev/null @@ -1,194 +0,0 @@ -#ifndef PROTON_ENCODER_HPP -#define PROTON_ENCODER_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 <proton/data.hpp> -#include <proton/types_fwd.hpp> -#include <proton/type_traits.hpp> - -namespace proton { - -namespace internal{ -class scalar_base; -class value_base; -} - - -/// @ingroup codec -namespace codec { - -/// Stream-like encoder from AMQP bytes to C++ values. -/// -/// Internal use only, see proton::value, proton::scalar and \ref types -/// for the recommended ways to manage AMQP data. -class encoder : public data { - public: - /// Wrap Proton-C data object. - explicit encoder(const data& d) : data(d) {} - - /// Encoder into v. Clears any current value in v. - PN_CPP_EXTERN explicit encoder(internal::value_base& v); - - /** - * Encode the current values into buffer and update size to reflect the - * number of bytes encoded. - * - * Clears the encoder. - * - *@return if buffer==0 or size is too small then return false and size to the required size. - *Otherwise return true and set size to the number of bytes encoded. - */ - PN_CPP_EXTERN bool encode(char* buffer, size_t& size); - - /** Encode the current values into a std::string, resize the string if necessary. - * - * Clears the encoder. - */ - PN_CPP_EXTERN void encode(std::string&); - - /** Encode the current values into a std::string. Clears the encoder. */ - PN_CPP_EXTERN std::string encode(); - - /// @name Insert built-in types - /// @{ - 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 internal::scalar_base&); - PN_CPP_EXTERN encoder& operator<<(const null&); - ///@} - - /// Insert a proton::value. - /// @internal NOTE insert value_base, not value to avoid recursive implicit conversions. - PN_CPP_EXTERN encoder& operator<<(const internal::value_base&); - - /// Start a complex type - PN_CPP_EXTERN encoder& operator<<(const start&); - /// Finish a complex type - PN_CPP_EXTERN encoder& operator<<(const finish&); - - ///@cond INTERNAL - - // Undefined template to prevent pointers being implicitly converted to bool. - template <class T> void* operator<<(const T*); - - 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); - } - - 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; - } - - 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; - } - - 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; - } - ///@endcond - - 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, const char* s) { return e << std::string(s); } - -/// operator << for integer types that are not covered by the standard overrides. -template <class T> typename internal::enable_if<internal::is_unknown_integer<T>::value, encoder&>::type -operator<<(encoder& e, T i) { - using namespace internal; - return e << static_cast<typename integer_type<sizeof(T), is_signed<T>::value>::type>(i); -} - -///@cond INTERNAL -namespace is_encodable_impl { // Protected the world from wildcard operator<< - -using namespace internal; - -sfinae::no operator<<(sfinae::wildcard, sfinae::wildcard); // Fallback - -template<typename T> struct is_encodable : public sfinae { - static yes test(encoder); - static no test(...); // Failed test, no match. - static encoder &e; - 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 - -using is_encodable_impl::is_encodable; -///@endcond - -} // codec -} // proton - -#endif /*!PROTON_ENCODER_HPP*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/endpoint.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/endpoint.hpp b/proton-c/bindings/cpp/include/proton/endpoint.hpp index 88259ca..c908bac 100644 --- a/proton-c/bindings/cpp/include/proton/endpoint.hpp +++ b/proton-c/bindings/cpp/include/proton/endpoint.hpp @@ -1,5 +1,5 @@ -#ifndef PROTON_CPP_ENDPOINT_H -#define PROTON_CPP_ENDPOINT_H +#ifndef PROTON_ENDPOINT_HPP +#define PROTON_ENDPOINT_HPP /* * @@ -22,10 +22,10 @@ * */ -#include "proton/comparable.hpp" #include "proton/config.hpp" #include "proton/error_condition.hpp" #include "proton/export.hpp" +#include "proton/internal/comparable.hpp" namespace proton { @@ -35,23 +35,35 @@ PN_CPP_CLASS_EXTERN endpoint { public: PN_CPP_EXTERN virtual ~endpoint(); - /// True if the local end is uninitialized + // XXX Add the container accessor here. + + /// True if the local end is uninitialized. virtual bool uninitialized() const = 0; - /// True if the local end is active + + /// True if the local end is active. virtual bool active() const = 0; - /// True if the connection is fully closed, i.e. local and remote - /// ends are closed. + + /// True if the local and remote ends are closed. virtual bool closed() const = 0; /// Get the error condition of the remote endpoint. virtual class error_condition error() const = 0; - /// Close endpoint + // XXX Add virtual open() and open(endpoint_options) + + /// Close the endpoint. + /// + /// @see endpoint_lifecycle virtual void close() = 0; + + /// Close the endpoint with an error condition. + /// + /// @see endpoint_lifecycle virtual void close(const error_condition&) = 0; #if PN_CPP_HAS_DEFAULTED_FUNCTIONS // Make everything explicit for C++11 compilers + endpoint() = default; endpoint& operator=(const endpoint&) = default; endpoint& operator=(endpoint&&) = default; @@ -61,7 +73,6 @@ PN_CPP_CLASS_EXTERN endpoint { #endif }; -///@cond INTERNAL namespace internal { template <class T, class D> class iter_base { @@ -73,7 +84,7 @@ template <class T, class D> class iter_base { D operator++(int) { D x(*this); ++(*this); return x; } bool operator==(const iter_base<T, D>& x) const { return obj_ == x.obj_; } bool operator!=(const iter_base<T, D>& x) const { return obj_ != x.obj_; } - ///@} + protected: explicit iter_base(T p = 0) : obj_(p) {} T obj_; @@ -87,13 +98,12 @@ template<class I> class iter_range { I begin() const { return begin_; } I end() const { return end_; } bool empty() const { return begin_ == end_; } + private: I begin_, end_; }; -} // namespace internal -///@endcond - -} // namespace proton +} // internal +} // proton -#endif // PROTON_CPP_H +#endif // PROTON_ENDPOINT_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/error.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/error.hpp b/proton-c/bindings/cpp/include/proton/error.hpp index 1b77b3f..df4c30e 100644 --- a/proton-c/bindings/cpp/include/proton/error.hpp +++ b/proton-c/bindings/cpp/include/proton/error.hpp @@ -1,5 +1,5 @@ -#ifndef PROTON_CPP_EXCEPTIONS_H -#define PROTON_CPP_EXCEPTIONS_H +#ifndef PROTON_ERROR_HPP +#define PROTON_ERROR_HPP /* * @@ -22,9 +22,9 @@ * */ -#include <proton/config.hpp> -#include <proton/export.hpp> -#include <proton/value.hpp> +#include "proton/config.hpp" +#include "proton/export.hpp" +#include "proton/value.hpp" #include <stdexcept> #include <string> @@ -33,27 +33,30 @@ namespace proton { class value; -/// The base proton error. +/// The base Proton error. /// /// All exceptions thrown from functions in the proton namespace are /// subclasses of proton::error. struct PN_CPP_CLASS_EXTERN error : public std::runtime_error { - PN_CPP_EXTERN explicit error(const std::string&); ///< Construct with message + /// Construct the error with a message. + PN_CPP_EXTERN explicit error(const std::string&); }; -/// Raised if a timeout expires. +/// An operation timed out. struct PN_CPP_CLASS_EXTERN timeout_error : public error { - PN_CPP_EXTERN explicit timeout_error(const std::string&); ///< Construct with message + /// Construct the error with a message. + PN_CPP_EXTERN explicit timeout_error(const std::string&); }; -/// Raised if there is an error converting between AMQP and C++ data. +/// An error converting between AMQP and C++ data. struct PN_CPP_CLASS_EXTERN conversion_error : public error { - PN_CPP_EXTERN explicit conversion_error(const std::string&); ///< Construct with message + /// Construct the error with a message. + PN_CPP_EXTERN explicit conversion_error(const std::string&); }; -} +} // proton -#endif // PROTON_CPP_EXCEPTIONS_H +#endif // PROTON_ERROR_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/error_condition.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/error_condition.hpp b/proton-c/bindings/cpp/include/proton/error_condition.hpp index 232c4fd..10ffeba 100644 --- a/proton-c/bindings/cpp/include/proton/error_condition.hpp +++ b/proton-c/bindings/cpp/include/proton/error_condition.hpp @@ -1,5 +1,5 @@ -#ifndef PROTON_CPP_ERROR_CONDITION_H -#define PROTON_CPP_ERROR_CONDITION_H +#ifndef PROTON_ERROR_CONDITION_H +#define PROTON_ERROR_CONDITION_H /* * @@ -24,7 +24,6 @@ #include "proton/export.hpp" #include "proton/value.hpp" - #include "proton/config.hpp" #include <string> @@ -41,13 +40,18 @@ class error_condition { /// @endcond public: + /// Create an empty error condition. error_condition() {} - /// Construct an error condition with only a description - in this case a default - /// name will be used ("proton:io:error") + + /// Create an error condition with only a description. A default + /// name will be used ("proton:io:error"). PN_CPP_EXTERN error_condition(std::string description); - /// Construct an error_condition with a name and a description + + /// Create an error condition with a name and description. PN_CPP_EXTERN error_condition(std::string name, std::string description); - /// Construct an error_condition with name, description and some informational properties + + /// **Experimental** - Create an error condition with name, + /// description, and informational properties. PN_CPP_EXTERN error_condition(std::string name, std::string description, proton::value properties); #if PN_CPP_HAS_DEFAULTED_FUNCTIONS @@ -57,8 +61,9 @@ class error_condition { error_condition& operator=(error_condition&&) = default; #endif - /// If you are using a C++11 compiler you may use an error_condition - /// in boolean contexts and the expression will be true if the error_condition is set + /// If you are using a C++11 compiler, you may use an + /// error_condition in boolean contexts. The expression will be + /// true if the error_condition is set. #if PN_CPP_HAS_EXPLICIT_CONVERSIONS PN_CPP_EXTERN explicit operator bool() const; #endif @@ -81,20 +86,22 @@ class error_condition { /// Simple printable string for condition. PN_CPP_EXTERN std::string what() const; - /// @cond INTERNAL private: std::string name_; std::string description_; proton::value properties_; - friend class internal::factory<error_condition>; + /// @cond INTERNAL + friend class internal::factory<error_condition>; /// @endcond }; +/// @cond INTERNAL +// XXX Document these PN_CPP_EXTERN bool operator==(const error_condition& x, const error_condition& y); - PN_CPP_EXTERN std::ostream& operator<<(std::ostream& o, const error_condition& err); +/// @endcond -} +} // proton -#endif // PROTON_CPP_ERROR_CONDITION_H +#endif // PROTON_ERROR_CONDITION_H http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/event_loop.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/event_loop.hpp b/proton-c/bindings/cpp/include/proton/event_loop.hpp index ad358c8..9b3d69a 100644 --- a/proton-c/bindings/cpp/include/proton/event_loop.hpp +++ b/proton-c/bindings/cpp/include/proton/event_loop.hpp @@ -1,7 +1,8 @@ -#ifndef PROTON_IO_EVENT_LOOP_HPP -#define PROTON_IO_EVENT_LOOP_HPP +#ifndef PROTON_EVENT_LOOP_HPP +#define PROTON_EVENT_LOOP_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 @@ -18,9 +19,10 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + * */ -#include <proton/config.hpp> +#include "proton/config.hpp" #include <functional> @@ -37,35 +39,46 @@ namespace proton { // FIXME aconway 2016-05-04: doc +/// **Experimental** - A handler for injected code. class inject_handler { public: virtual ~inject_handler() {} + + // XXX I feel like the name of this isn't quite right. The event + // isn't injection, it's execution. + /// The code is executed. virtual void on_inject() = 0; }; +/// **Experimental** - A serial execution context. class PN_CPP_CLASS_EXTERN event_loop { - public: + public: virtual ~event_loop() {} // FIXME aconway 2016-05-05: doc, note bool return not throw because no // atomic way to determine closd status and throw during shutdown is bad. + /// Send code to the event loop for execution. virtual bool inject(inject_handler&) = 0; + #if PN_CPP_HAS_CPP11 + /// Send code to the event loop for execution. virtual bool inject(std::function<void()>) = 0; #endif - protected: + protected: event_loop() {} - private: + private: PN_CPP_EXTERN static event_loop* get(pn_connection_t*); PN_CPP_EXTERN static event_loop* get(pn_session_t*); PN_CPP_EXTERN static event_loop* get(pn_link_t*); + /// @cond INTERNAL friend class connection; - template <class T> friend class thread_safe; + template <class T> friend class thread_safe; + /// @endcond }; -} +} // proton -#endif // PROTON_IO_EVENT_LOOP_HPP +#endif // PROTON_EVENT_LOOP_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/export.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/export.hpp b/proton-c/bindings/cpp/include/proton/export.hpp index 788235f..8dc1204 100644 --- a/proton-c/bindings/cpp/include/proton/export.hpp +++ b/proton-c/bindings/cpp/include/proton/export.hpp @@ -1,5 +1,5 @@ -#ifndef PN_CPP_IMPORTEXPORT_H -#define PN_CPP_IMPORTEXPORT_H +#ifndef PROTON_EXPORT_HPP +#define PROTON_EXPORT_HPP /* * @@ -54,4 +54,4 @@ /// @endcond -#endif // PN_CPP_IMPORTEXPORT_H +#endif // PROTON_EXPORT_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/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 deleted file mode 100644 index 00e3b2c..0000000 --- a/proton-c/bindings/cpp/include/proton/forward_list.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#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, internal::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/2dc4afe0/proton-c/bindings/cpp/include/proton/handler.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/handler.hpp b/proton-c/bindings/cpp/include/proton/handler.hpp index c145fed..d367fd4 100644 --- a/proton-c/bindings/cpp/include/proton/handler.hpp +++ b/proton-c/bindings/cpp/include/proton/handler.hpp @@ -1,5 +1,5 @@ -#ifndef PROTON_CPP_MESSAGING_HANDLER_H -#define PROTON_CPP_MESSAGING_HANDLER_H +#ifndef PROTON_HANDLER_HPP +#define PROTON_HANDLER_HPP /* * @@ -23,8 +23,7 @@ */ #include "proton/export.hpp" - -#include "proton/pn_unique_ptr.hpp" +#include "proton/internal/pn_unique_ptr.hpp" namespace proton { @@ -45,121 +44,134 @@ namespace io { class connection_engine; } -/// Callback functions for handling proton events. +/// A handler for Proton messaging events. +/// +/// Subclass and override the event-handling member functions. +/// +/// #### Close and error handling /// -/// Subclass and override event-handling member functions. +/// There are several objects that have `on_X_close` and `on_X_error` +/// functions. They are called as follows: /// -/// Close and error handling: there are several objects that have on_X_close and on_X_error functions. -/// They are called as follows: +/// - If `X` is closed cleanly, with no error status, then `on_X_close` +/// is called. +/// - If `X` is closed with an error, then `on_X_error` is called, +/// followed by `on_X_close`. The error condition is also available +/// in `on_X_close` from `X::condition()`. /// -/// - If X is closed cleanly, with no error status then on_X_close() is called. -/// - If X is closed with an error then on_X_error() is called followed by on_X_close() -/// Note the error condition is also available in on_X_close from X::condition(). +/// By default, if you do not implement `on_X_error`, it will call +/// `on_error`. If you do not implement `on_error` it will throw a +/// @ref proton::error exception, which may not be what you want but +/// does help to identify forgotten error handling quickly. /// -/// By default, if you do not implement on_X_error, it will call -/// on_unhandled_error(). If you do not implement on_unhandled_error() it will -/// throw a proton::error exception, which may not be what you want but does -/// help to identify forgotten error handling quickly. +/// #### Resource cleanup /// -/// @see proton::event +/// Every `on_X_open` event is paired with an `on_X_close` event which +/// can clean up any resources created by the open handler. In +/// particular this is still true if an error is reported with an +/// `on_X_error` event. The error-handling logic doesn't have to +/// manage resource clean up. It can assume that the close event will +/// be along to handle it. class -PN_CPP_CLASS_EXTERN handler -{ +PN_CPP_CLASS_EXTERN handler { public: PN_CPP_EXTERN handler(); PN_CPP_EXTERN virtual ~handler(); - /// @name Event callbacks - /// - /// Override these member functions to handle events. - /// - /// @{ - /// The container event loop is starting. PN_CPP_EXTERN virtual void on_container_start(container &c); + /// A message is received. PN_CPP_EXTERN virtual void on_message(delivery &d, message &m); + /// A message can be sent. PN_CPP_EXTERN virtual void on_sendable(sender &s); - /// Note that every ..._open event is paired with a ..._close event which can clean - /// up any resources created by the ..._open handler. - /// In particular this is still true if an error is reported with an ..._error event. - /// This makes resource management easier so that the error handling logic doesn't also - /// have to manage the resource clean up, but can just assume that the close event will - /// be along in a minute to handle the clean up. - /// The underlying network transport is open PN_CPP_EXTERN virtual void on_transport_open(transport &t); + /// The underlying network transport has closed. PN_CPP_EXTERN virtual void on_transport_close(transport &t); + /// The underlying network transport has closed with an error /// condition. PN_CPP_EXTERN virtual void on_transport_error(transport &t); /// The remote peer opened the connection. PN_CPP_EXTERN virtual void on_connection_open(connection &c); + /// The remote peer closed the connection. PN_CPP_EXTERN virtual void on_connection_close(connection &c); + /// The remote peer closed the connection with an error condition. PN_CPP_EXTERN virtual void on_connection_error(connection &c); /// The remote peer opened the session. PN_CPP_EXTERN virtual void on_session_open(session &s); + /// The remote peer closed the session. PN_CPP_EXTERN virtual void on_session_close(session &s); + /// The remote peer closed the session with an error condition. PN_CPP_EXTERN virtual void on_session_error(session &s); /// The remote peer opened the link. PN_CPP_EXTERN virtual void on_receiver_open(receiver& l); + /// The remote peer closed the link. PN_CPP_EXTERN virtual void on_receiver_close(receiver& l); + /// The remote peer closed the link with an error condition. PN_CPP_EXTERN virtual void on_receiver_error(receiver& l); /// The remote peer opened the link. PN_CPP_EXTERN virtual void on_sender_open(sender& l); + /// The remote peer closed the link. PN_CPP_EXTERN virtual void on_sender_close(sender& l); + /// The remote peer closed the link with an error condition. PN_CPP_EXTERN virtual void on_sender_error(sender& l); /// The receiving peer accepted a transfer. PN_CPP_EXTERN virtual void on_tracker_accept(tracker &d); + /// The receiving peer rejected a transfer. PN_CPP_EXTERN virtual void on_tracker_reject(tracker &d); + /// The receiving peer released a transfer. PN_CPP_EXTERN virtual void on_tracker_release(tracker &d); + /// The receiving peer settled a transfer. PN_CPP_EXTERN virtual void on_tracker_settle(tracker &d); + /// The sending peer settled a transfer. PN_CPP_EXTERN virtual void on_delivery_settle(delivery &d); /// The receiving peer has requested a drain of remaining credit. PN_CPP_EXTERN virtual void on_sender_drain_start(sender &s); - /// The credit outstanding at the time of the call to receiver::drain has been consumed or returned. + + /// The credit outstanding at the time of the call to + /// receiver::drain has been consumed or returned. PN_CPP_EXTERN virtual void on_receiver_drain_finish(receiver &r); /// Fallback error handling. PN_CPP_EXTERN virtual void on_error(const error_condition &c); - /// @} - - /// @cond INTERNAL private: internal::pn_unique_ptr<messaging_adapter> messaging_adapter_; - friend class container; - friend class container_impl; - friend class io::connection_engine; - friend class connection_options; - friend class receiver_options; - friend class sender_options; - friend class session_options; + /// @cond INTERNAL + friend class container; + friend class container_impl; + friend class io::connection_engine; + friend class connection_options; + friend class receiver_options; + friend class sender_options; + friend class session_options; /// @endcond }; -} +} // proton -#endif // PROTON_CPP_MESSAGING_HANDLER_H +#endif // PROTON_HANDLER_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/internal/comparable.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/internal/comparable.hpp b/proton-c/bindings/cpp/include/proton/internal/comparable.hpp new file mode 100644 index 0000000..b93ec4b --- /dev/null +++ b/proton-c/bindings/cpp/include/proton/internal/comparable.hpp @@ -0,0 +1,40 @@ +#ifndef PROTON_INTERNAL_COMPARABLE_HPP +#define PROTON_INTERNAL_COMPARABLE_HPP + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +namespace proton { +namespace internal { + +/// Base class for comparable types with operator< and +/// operator==. Provides remaining operators. +template <class T> class comparable { + friend bool operator>(const T &a, const T &b) { return b < a; } + friend bool operator<=(const T &a, const T &b) { return !(a > b); } + friend bool operator>=(const T &a, const T &b) { return !(a < b); } + friend bool operator!=(const T &a, const T &b) { return !(a == b); } +}; + +} // internal +} // proton + +#endif // PROTON_INTERNAL_COMPARABLE_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/internal/object.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/internal/object.hpp b/proton-c/bindings/cpp/include/proton/internal/object.hpp new file mode 100644 index 0000000..4ca7e0a --- /dev/null +++ b/proton-c/bindings/cpp/include/proton/internal/object.hpp @@ -0,0 +1,108 @@ +#ifndef PROTON_INTERNAL_OBJECT_HPP +#define PROTON_INTERNAL_OBJECT_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 "proton/config.hpp" +#include "proton/export.hpp" +#include "proton/internal/comparable.hpp" + +#include <memory> + +namespace proton { + +template <class T> class thread_safe; + +namespace internal { + +class pn_ptr_base { + protected: + PN_CPP_EXTERN static void incref(void* p); + PN_CPP_EXTERN static void decref(void* p); +}; + +template <class T> class pn_ptr : private pn_ptr_base, private comparable<pn_ptr<T> > { + public: + pn_ptr() : ptr_(0) {} + pn_ptr(T* p) : ptr_(p) { incref(ptr_); } + pn_ptr(const pn_ptr& o) : ptr_(o.ptr_) { incref(ptr_); } + +#if PN_CPP_HAS_RVALUE_REFERENCES + pn_ptr(pn_ptr&& o) : ptr_(0) { std::swap(ptr_, o.ptr_); } +#endif + + ~pn_ptr() { decref(ptr_); } + + pn_ptr& operator=(pn_ptr o) { std::swap(ptr_, o.ptr_); return *this; } + + T* get() const { return ptr_; } + T* release() { T *p = ptr_; ptr_ = 0; return p; } + + bool operator!() const { return !ptr_; } + +#if PN_CPP_HAS_EXPLICIT_CONVERSIONS + explicit operator bool() const { return !!ptr_; } +#endif + + static pn_ptr take_ownership(T* p) { return pn_ptr<T>(p, true); } + + private: + T *ptr_; + + // Note that it is the presence of the bool in the constructor signature that matters + // to get the "transfer ownership" constructor: The value of the bool isn't checked. + pn_ptr(T* p, bool) : ptr_(p) {} + + friend bool operator==(const pn_ptr& a, const pn_ptr& b) { return a.ptr_ == b.ptr_; } + friend bool operator<(const pn_ptr& a, const pn_ptr& b) { return a.ptr_ < b.ptr_; } +}; + +template <class T> pn_ptr<T> take_ownership(T* p) { return pn_ptr<T>::take_ownership(p); } + +/// Base class for proton object types. +template <class T> class object : private comparable<object<T> > { + public: + bool operator!() const { return !object_; } +#if PN_CPP_HAS_EXPLICIT_CONVERSIONS + explicit operator bool() const { return object_; } +#endif + + protected: + typedef T pn_type; + object(pn_ptr<T> o) : object_(o) {} + T* pn_object() const { return object_.get(); } + + private: + pn_ptr<T> object_; + + friend bool operator==(const object& a, const object& b) { return a.object_ == b.object_; } + friend bool operator<(const object& a, const object& b) { return a.object_ < b.object_; } + template <class U> friend class proton::thread_safe; +}; + +/// Factory class used internally to make wrappers and extract proton objects +template <class T> class factory; + +} // internal +} // proton + +#endif // PROTON_INTERNAL_OBJECT_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/proton-c/bindings/cpp/include/proton/internal/pn_unique_ptr.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/internal/pn_unique_ptr.hpp b/proton-c/bindings/cpp/include/proton/internal/pn_unique_ptr.hpp new file mode 100644 index 0000000..b14b442 --- /dev/null +++ b/proton-c/bindings/cpp/include/proton/internal/pn_unique_ptr.hpp @@ -0,0 +1,68 @@ +#ifndef PROTON_INTERNAL_UNIQUE_PTR_HPP +#define PROTON_INTERNAL_UNIQUE_PTR_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 "proton/config.hpp" + +#include <memory> + +namespace proton { +namespace internal { + +/// A simple unique ownership pointer, used as a return value from +/// functions that transfer ownership to the caller. +/// +/// pn_unique_ptr return values should be converted immediately to +/// std::unique_ptr if that is available or std::auto_ptr (by calling +/// release()) for older C++. You should not use pn_unique_ptr in your +/// own code. It is a limited pointer class designed only to work +/// around differences between C++11 and C++03. +template <class T> class pn_unique_ptr { + public: + pn_unique_ptr(T* p=0) : ptr_(p) {} +#if PN_CPP_HAS_RVALUE_REFERENCES + pn_unique_ptr(pn_unique_ptr&& x) : ptr_(0) { std::swap(ptr_, x.ptr_); } +#else + pn_unique_ptr(const pn_unique_ptr& x) : ptr_() { std::swap(ptr_, const_cast<pn_unique_ptr&>(x).ptr_); } +#endif + ~pn_unique_ptr() { delete(ptr_); } + T& operator*() const { return *ptr_; } + T* operator->() const { return ptr_; } + T* get() const { return ptr_; } + void reset(T* p = 0) { pn_unique_ptr<T> tmp(p); std::swap(ptr_, tmp.ptr_); } + T* release() { T *p = ptr_; ptr_ = 0; return p; } + operator bool() const { return get(); } + bool operator !() const { return get(); } + +#if PN_CPP_HAS_STD_PTR + operator std::unique_ptr<T>() { T *p = ptr_; ptr_ = 0; return std::unique_ptr<T>(p); } +#endif + + private: + T* ptr_; +}; + +} // internal +} // proton + +#endif // PROTON_INTERNAL_UNIQUE_PTR_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2dc4afe0/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 new file mode 100644 index 0000000..b68daf4 --- /dev/null +++ b/proton-c/bindings/cpp/include/proton/internal/scalar_base.hpp @@ -0,0 +1,181 @@ +#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 "proton/binary.hpp" +#include "proton/decimal.hpp" +#include "proton/error.hpp" +#include "proton/export.hpp" +#include "proton/internal/comparable.hpp" +#include "proton/internal/type_traits.hpp" +#include "proton/symbol.hpp" +#include "proton/timestamp.hpp" +#include "proton/type_id.hpp" +#include "proton/types_fwd.hpp" +#include "proton/uuid.hpp" + +#include <iosfwd> +#include <string> + +namespace proton { +class message; + +namespace codec { +class decoder; +class encoder; +} + +namespace internal { + +/// 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&); + + 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; + + private: + 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; + /// @endcond +}; + +template<class T> T get(const scalar_base& s) { T x; s.get(x); return x; } + +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())); + } +} + +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 conversion_error("cannot coerce from " + type_name(type_id_of<U>::value)); + } +}; + +template <class T> T coerce(const scalar_base& s) { return visit<T>(s, coerce_op<T>()); } + +} // internal +} // proton + +#endif // PROTON_INTERNAL_SCALAR_BASE_HPP --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
