diff options
| author | Alan Conway <aconway@apache.org> | 2008-11-20 18:29:20 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2008-11-20 18:29:20 +0000 |
| commit | 24f410931d76bc37dd575436a7b11a87b6aef0c9 (patch) | |
| tree | 49ee770cf521f3a0bba881cee7219082ee89b2c2 /cpp/src/qpid/Address.h | |
| parent | 5b93ee887ca64e26fb2440bab4c9785ea3de2e79 (diff) | |
| download | qpid-python-24f410931d76bc37dd575436a7b11a87b6aef0c9.tar.gz | |
Replaced boost.spirit-based URL parser with simple recursive descent parser.
boost.spirit has some known thread-safety issues and appears to be causing
qpid clients to crash in several scenarios.
The new parser is trivially thread safe and relatively easy to extend.
It's a simple recursive descent parser, sufficient for simple grammars
like those used in URL formats. It's not intended to be a
full-featured parser framework like spirit.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@719317 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/Address.h')
| -rwxr-xr-x | cpp/src/qpid/Address.h | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/cpp/src/qpid/Address.h b/cpp/src/qpid/Address.h index 4913e96e9f..9669985165 100755 --- a/cpp/src/qpid/Address.h +++ b/cpp/src/qpid/Address.h @@ -22,7 +22,7 @@ #include "qpid/sys/IntegerTypes.h" #include <boost/variant.hpp> -#include <ostream> +#include <iosfwd> #include <string> #include <vector> @@ -31,39 +31,54 @@ namespace qpid { /** TCP address of a broker - host:port */ struct TcpAddress { static const uint16_t DEFAULT_PORT=5672; - explicit TcpAddress(const std::string& host_=std::string(), - uint16_t port_=DEFAULT_PORT) - : host(host_), port(port_) {} + explicit TcpAddress(const std::string& host_=std::string(),uint16_t port_=DEFAULT_PORT); std::string host; uint16_t port; }; - -inline bool operator==(const TcpAddress& x, const TcpAddress& y) { - return y.host==x.host && y.port == x.port; -} - +bool operator==(const TcpAddress& x, const TcpAddress& y); std::ostream& operator<<(std::ostream& os, const TcpAddress& a); +/**@internal Not a real address type, this is a placeholder to + * demonstrate and validate multi-protocol Urls for unit tests and + * developer education only. An example address holds just a char. + */ +struct ExampleAddress { + explicit ExampleAddress(char data); + char data; +}; +bool operator==(const ExampleAddress& x, const ExampleAddress& y); +std::ostream& operator<<(std::ostream& os, const ExampleAddress& a); + /** - * Address is a variant of all address types, more coming in future. - * - * Address wraps a boost::variant rather than be defined in terms of - * boost::variant to prevent users from having to deal directly with - * boost. + * Contains the address of an AMQP broker. Can any supported type of + * broker address. Currently only TcpAddress is supported. */ struct Address { public: Address(const Address& a) : value(a.value) {} Address(const TcpAddress& tcp) : value(tcp) {} - template <class T> Address& operator=(const T& t) { value=t; return *this; } - template <class T> T* get() { return boost::get<T>(&value); } - template <class T> const T* get() const { return boost::get<T>(&value); } + Address(const ExampleAddress& eg) : value(eg) {} ///<@internal + + template <class AddressType> Address& operator=(const AddressType& t) { value=t; return *this; } + + /** Get the address of type AddressType. + *@return AddressType* pointing to the contained address or 0 if + *contained address is not of type AddressType. + */ + template <class AddressType> AddressType* get() { return boost::get<AddressType>(&value); } + + /** Get the address of type AddressType. + *@return AddressType* pointing to the contained address or 0 if + *contained address is not of type AddressType. + */ + template <class AddressType> const AddressType* get() const { return boost::get<AddressType>(&value); } private: - boost::variant<TcpAddress> value; + boost::variant<TcpAddress,ExampleAddress> value; + friend std::ostream& operator<<(std::ostream& os, const Address& addr); }; -std::ostream& operator<<(std::ostream& os, const Address& addr); + } // namespace qpid |
