From 24f410931d76bc37dd575436a7b11a87b6aef0c9 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 20 Nov 2008 18:29:20 +0000 Subject: 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 --- cpp/src/qpid/Address.cpp | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'cpp/src/qpid/Address.cpp') diff --git a/cpp/src/qpid/Address.cpp b/cpp/src/qpid/Address.cpp index e278c0295c..ac8c7f30b1 100644 --- a/cpp/src/qpid/Address.cpp +++ b/cpp/src/qpid/Address.cpp @@ -18,17 +18,41 @@ #include "Address.h" +#include + +using namespace std; + namespace qpid { -std::ostream& operator<<(std::ostream& os, const Address& addr) { - const TcpAddress *t = addr.get(); - if (t) - os << *t; - return os; +TcpAddress::TcpAddress(const std::string& h, uint16_t p): host(h), port(p) {} + +struct AddressOstreamVisitor : public boost::static_visitor { + ostream& out; + AddressOstreamVisitor(ostream& o) : out(o) {} + template ostream& operator()(const T& data) { return out << data; } +}; + +ostream& operator<<(ostream& os, const Address& addr) { + AddressOstreamVisitor visitor(os); + return boost::apply_visitor(visitor, addr.value); +} + +bool operator==(const TcpAddress& x, const TcpAddress& y) { + return y.host==x.host && y.port == x.port; } -std::ostream& operator<<(std::ostream& os, const TcpAddress& a) { +ostream& operator<<(ostream& os, const TcpAddress& a) { return os << "tcp:" << a.host << ":" << a.port; } +ExampleAddress::ExampleAddress(const char c) : data(c) {} + +bool operator==(const ExampleAddress& x, const ExampleAddress& y) { + return x.data == y.data; +} + +ostream& operator<<(ostream& os, const ExampleAddress& ex) { + return os << "example:" << ex.data; +} + } // namespace qpid -- cgit v1.2.1