00001 #ifndef QPID_URL_H
00002 #define QPID_URL_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "qpid/Exception.h"
00023 #include <boost/variant.hpp>
00024 #include <string>
00025 #include <vector>
00026 #include <new>
00027 #include <ostream>
00028
00029 namespace qpid {
00030
00032 struct TcpAddress {
00033 static const uint16_t DEFAULT_PORT=5672;
00034 explicit TcpAddress(const std::string& host_=std::string(),
00035 uint16_t port_=DEFAULT_PORT)
00036 : host(host_), port(port_) {}
00037 std::string host;
00038 uint16_t port;
00039 };
00040
00041 inline bool operator==(const TcpAddress& x, const TcpAddress& y) {
00042 return y.host==x.host && y.port == x.port;
00043 }
00044
00045 std::ostream& operator<<(std::ostream& os, const TcpAddress& a);
00046
00048 typedef boost::variant<TcpAddress> Address;
00049
00051 struct Url : public std::vector<Address> {
00052
00054 static Url getHostNameUrl(uint16_t port);
00055
00058 static Url getIpAddressesUrl(uint16_t port);
00059
00060 struct InvalidUrl : public Exception {
00061 InvalidUrl(const std::string& s) : Exception(s) {}
00062 };
00063
00065 std::string str() const;
00066
00068 Url() {}
00069
00071 explicit Url(const Address& addr) { push_back(addr); }
00072
00074 explicit Url(const std::string& url) { parse(url.c_str()); }
00075
00077 explicit Url(const char* url) { parse(url); }
00078
00079 template<class T> Url& operator=(T s) { parse(s); return *this; }
00080
00082 void throwIfEmpty() const;
00083
00088 void parse(const char* url);
00089 void parse(const std::string& url) { parse(url.c_str()); }
00090
00095 void parseNoThrow(const char* url);
00096
00097 private:
00098 mutable std::string cache;
00099 };
00100
00101 inline bool operator==(const Url& a, const Url& b) { return a.str()==b.str(); }
00102 inline bool operator!=(const Url& a, const Url& b) { return a.str()!=b.str(); }
00103
00104 std::ostream& operator<<(std::ostream& os, const Url& url);
00105 std::istream& operator>>(std::istream& is, Url& url);
00106
00107 }
00108
00109 #endif