/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/Url.h

00001 #ifndef QPID_URL_H
00002 #define QPID_URL_H
00003 
00004 /*
00005  *
00006  * Copyright (c) 2006 The Apache Software Foundation
00007  *
00008  * Licensed under the Apache License, Version 2.0 (the "License");
00009  * you may not use this file except in compliance with the License.
00010  * You may obtain a copy of the License at
00011  *
00012  *    http://www.apache.org/licenses/LICENSE-2.0
00013  *
00014  * Unless required by applicable law or agreed to in writing, software
00015  * distributed under the License is distributed on an "AS IS" BASIS,
00016  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017  * See the License for the specific language governing permissions and
00018  * limitations under the License.
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;  // cache string form for efficiency.
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 } // namespace qpid
00108 
00109 #endif  

Generated on Thu Apr 10 11:08:18 2008 for Qpid by  doxygen 1.4.7