Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
Url.h
Go to the documentation of this file.
1 #ifndef QPID_URL_H
2 #define QPID_URL_H
3 
4 /*
5  *
6  * Copyright (c) 2006 The Apache Software Foundation
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #include "qpid/Address.h"
23 #include "qpid/Exception.h"
24 #include <string>
25 #include <vector>
26 #include <new>
27 #include <ostream>
29 
30 namespace qpid {
31 
33 struct Url : public std::vector<Address> {
34 
35  struct Invalid : public Exception { QPID_COMMON_EXTERN Invalid(const std::string& s); };
36 
38  QPID_COMMON_EXTERN std::string str() const;
39 
41  Url() {}
42 
44  explicit Url(const Address& addr) { push_back(addr); }
45 
47  explicit Url(const std::string& url) { parse(url.c_str()); }
49  explicit Url(const std::string& url, const std::string& defaultProtocol) { parse(url.c_str(), defaultProtocol); }
50 
52  explicit Url(const char* url) { parse(url); }
53 
54  Url& operator=(const char* s) { parse(s); return *this; }
55  Url& operator=(const std::string& s) { parse(s); return *this; }
56 
58  QPID_COMMON_EXTERN void throwIfEmpty() const;
59 
63  QPID_COMMON_EXTERN void parse(const char* url);
64  QPID_COMMON_EXTERN void parse(const char* url, const std::string& defaultProtocol);
65  QPID_COMMON_INLINE_EXTERN void parse(const std::string& url) { parse(url.c_str()); }
66 
68  QPID_COMMON_EXTERN void parseNoThrow(const char* url);
69  QPID_COMMON_EXTERN void parseNoThrow(const char* url, const std::string& defaultProtocol);
70 
74  QPID_COMMON_EXTERN static void addProtocol(const std::string& tag);
75 
76  QPID_COMMON_EXTERN void setUser(const std::string&);
77  QPID_COMMON_EXTERN void setPass(const std::string&);
78  QPID_COMMON_EXTERN std::string getUser() const;
79  QPID_COMMON_EXTERN std::string getPass() const;
80 
81  private:
82  mutable std::string cache; // cache string form for efficiency.
83  std::string user, pass;
84 
85  friend class UrlParser;
86 };
87 
88 inline bool operator==(const Url& a, const Url& b) { return a.str()==b.str(); }
89 inline bool operator!=(const Url& a, const Url& b) { return a.str()!=b.str(); }
90 
91 QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& os, const Url& url);
92 QPID_COMMON_EXTERN std::istream& operator>>(std::istream& is, Url& url);
93 
94 } // namespace qpid
95 
96 #endif
#define QPID_COMMON_EXTERN
Url & operator=(const std::string &s)
Definition: Url.h:55
void parse(const char *url)
Replace contents with parsed url if the url is invalid.
Url(const Address &addr)
URL containing a single address.
Definition: Url.h:44
Contains the protocol address of an AMQP broker.
Definition: Address.h:34
bool operator!=(const Address &x, const Address &y)
bool operator==(const Address &x, const Address &y)
void setPass(const std::string &)
Url(const std::string &url)
Parse url, throw Invalid if invalid.
Definition: Url.h:47
An AMQP URL contains a list of addresses.
Definition: Url.h:33
Base class for Qpid runtime exceptions.
Definition: Exception.h:39
Url(const char *url)
Parse url, throw Invalid if invalid.
Definition: Url.h:52
QPID_COMMON_INLINE_EXTERN void parse(const std::string &url)
Definition: Url.h:65
Invalid(const std::string &s)
Url & operator=(const char *s)
Definition: Url.h:54
void setUser(const std::string &)
std::string getPass() const
static void addProtocol(const std::string &tag)
Add a protocol tag to be recognzed in URLs.
friend class UrlParser
Definition: Url.h:85
std::istream & operator>>(std::istream &is, Url &url)
std::string getUser() const
std::ostream & operator<<(std::ostream &os, const Address &addr)
Url(const std::string &url, const std::string &defaultProtocol)
Parse url, throw Invalid if invalid.
Definition: Url.h:49
#define QPID_COMMON_INLINE_EXTERN
void parseNoThrow(const char *url)
Replace contesnts with parsed URL.
void throwIfEmpty() const
Throw Invalid if the URL does not contain any addresses.
Url()
Empty URL.
Definition: Url.h:41
std::string str() const
Convert to string form.

Qpid C++ API Reference
Generated on Tue Aug 19 2014 for Qpid C++ Client API by doxygen 1.8.7