24 #include <servus/types.h>
65 typedef std::map<std::string, std::string> KVMap;
66 typedef KVMap::const_iterator ConstKVIter;
76 SERVUS_API
explicit URI(
const std::string& uri);
79 SERVUS_API
explicit URI(
const char* uri);
82 SERVUS_API
URI(
const URI& from);
87 SERVUS_API URI&
operator=(
const URI& rhs);
90 SERVUS_API
bool operator==(
const URI& rhs)
const;
93 SERVUS_API
bool operator!=(
const URI& rhs)
const;
97 SERVUS_API
const std::string& getScheme()
const;
98 SERVUS_API
const std::string& getUserinfo()
const;
99 SERVUS_API uint16_t getPort()
const;
100 SERVUS_API
const std::string& getHost()
const;
106 SERVUS_API
const std::string& getPath()
const;
107 SERVUS_API
const std::string& getQuery()
const;
108 SERVUS_API
const std::string& getFragment()
const;
113 SERVUS_API
void setScheme(
const std::string& scheme);
114 SERVUS_API
void setUserInfo(
const std::string& userinfo);
115 SERVUS_API
void setHost(
const std::string& host);
116 SERVUS_API
void setPort(uint16_t port);
117 SERVUS_API
void setPath(
const std::string& path);
118 SERVUS_API
void setQuery(
const std::string& query);
119 SERVUS_API
void setFragment(
const std::string& fragment);
132 SERVUS_API ConstKVIter
queryEnd()
const;
137 SERVUS_API ConstKVIter
findQuery(
const std::string& key)
const;
140 SERVUS_API
void addQuery(
const std::string& key,
const std::string& value);
144 detail::URI*
const _impl;
147 inline std::ostream& operator<<(std::ostream& os,
const URI& uri)
149 if (!uri.getScheme().empty())
150 os << uri.getScheme() <<
"://";
153 if (!uri.getHost().empty())
155 if (!uri.getUserinfo().empty())
156 os << uri.getUserinfo() <<
"@";
159 os <<
':' << uri.getPort();
162 if (!uri.getQuery().empty())
163 os <<
'?' << uri.getQuery();
164 if (!uri.getFragment().empty())
165 os <<
'#' << uri.getFragment();
172 inline std::string to_string(
const servus::URI& uri)
179 #endif // SERVUS_URI_H
void addQuery(const std::string &key, const std::string &value)
Add a key-value pair to the query.
The URI class parses the given uri using the generic syntax from RFC3986 and RFC6570.
Defines export visibility macros for library Servus.
URI & operator=(const URI &rhs)
Assign the data from another URI.
bool operator==(const URI &rhs) const
Equals operator.
ConstKVIter queryEnd() const
ConstKVIter queryBegin() const
ConstKVIter findQuery(const std::string &key) const
URI()
Construct an empty URI.
bool operator!=(const URI &rhs) const
Not equals operator.
std::string getAuthority() const
Return the compound authority part of the URI.