Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET | Apache Qpid Documentation |
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/Address.h" 00023 #include "qpid/Exception.h" 00024 #include <string> 00025 #include <vector> 00026 #include <new> 00027 #include <ostream> 00028 #include "qpid/CommonImportExport.h" 00029 00030 namespace qpid { 00031 00033 struct Url : public std::vector<Address> { 00034 00036 QPID_COMMON_EXTERN static Url getHostNameUrl(uint16_t port); 00037 00040 QPID_COMMON_EXTERN static Url getIpAddressesUrl(uint16_t port); 00041 00042 struct Invalid : public Exception { QPID_COMMON_EXTERN Invalid(const std::string& s); }; 00043 00045 QPID_COMMON_EXTERN std::string str() const; 00046 00048 Url() {} 00049 00051 explicit Url(const Address& addr) { push_back(addr); } 00052 00054 explicit Url(const std::string& url) { parse(url.c_str()); } 00056 explicit Url(const std::string& url, const std::string& defaultProtocol) { parse(url.c_str(), defaultProtocol); } 00057 00059 explicit Url(const char* url) { parse(url); } 00060 00061 Url& operator=(const char* s) { parse(s); return *this; } 00062 Url& operator=(const std::string& s) { parse(s); return *this; } 00063 00065 QPID_COMMON_EXTERN void throwIfEmpty() const; 00066 00070 QPID_COMMON_EXTERN void parse(const char* url); 00071 QPID_COMMON_EXTERN void parse(const char* url, const std::string& defaultProtocol); 00072 QPID_COMMON_INLINE_EXTERN void parse(const std::string& url) { parse(url.c_str()); } 00073 00075 QPID_COMMON_EXTERN void parseNoThrow(const char* url); 00076 QPID_COMMON_EXTERN void parseNoThrow(const char* url, const std::string& defaultProtocol); 00077 00081 QPID_COMMON_EXTERN static void addProtocol(const std::string& tag); 00082 00083 QPID_COMMON_EXTERN void setUser(const std::string&); 00084 QPID_COMMON_EXTERN void setPass(const std::string&); 00085 QPID_COMMON_EXTERN std::string getUser() const; 00086 QPID_COMMON_EXTERN std::string getPass() const; 00087 00088 private: 00089 mutable std::string cache; // cache string form for efficiency. 00090 std::string user, pass; 00091 00092 friend class UrlParser; 00093 }; 00094 00095 inline bool operator==(const Url& a, const Url& b) { return a.str()==b.str(); } 00096 inline bool operator!=(const Url& a, const Url& b) { return a.str()!=b.str(); } 00097 00098 QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& os, const Url& url); 00099 QPID_COMMON_EXTERN std::istream& operator>>(std::istream& is, Url& url); 00100 00101 } // namespace qpid 00102 00103 #endif