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 { 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()); } 00055 00057 explicit Url(const char* url) { parse(url); } 00058 00059 Url& operator=(const char* s) { parse(s); return *this; } 00060 Url& operator=(const std::string& s) { parse(s); return *this; } 00061 00063 QPID_COMMON_EXTERN void throwIfEmpty() const; 00064 00068 QPID_COMMON_EXTERN void parse(const char* url); 00069 QPID_COMMON_EXTERN void parse(const std::string& url) { parse(url.c_str()); } 00070 00072 QPID_COMMON_EXTERN void parseNoThrow(const char* url); 00073 00077 QPID_COMMON_EXTERN static void addProtocol(const std::string& tag); 00078 00079 QPID_COMMON_EXTERN void setUser(const std::string&); 00080 QPID_COMMON_EXTERN void setPass(const std::string&); 00081 QPID_COMMON_EXTERN std::string getUser() const; 00082 QPID_COMMON_EXTERN std::string getPass() const; 00083 00084 private: 00085 static std::vector<std::string> protocols; 00086 00087 mutable std::string cache; // cache string form for efficiency. 00088 std::string user, pass; 00089 00090 friend class UrlParser; 00091 }; 00092 00093 inline bool operator==(const Url& a, const Url& b) { return a.str()==b.str(); } 00094 inline bool operator!=(const Url& a, const Url& b) { return a.str()!=b.str(); } 00095 00096 QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& os, const Url& url); 00097 QPID_COMMON_EXTERN std::istream& operator>>(std::istream& is, Url& url); 00098 00099 } // namespace qpid 00100 00101 #endif