From 7bae496257cf8a080713011c6cc0db22bbcce094 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Fri, 25 Oct 2013 15:36:24 -0700 Subject: [PATCH] Add hash function to URL --- beast/http/URL.h | 30 ++++++++++++++++++++++++++++++ beast/http/impl/URL.cpp | 10 +++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/beast/http/URL.h b/beast/http/URL.h index 5d80bd809..de192be20 100644 --- a/beast/http/URL.h +++ b/beast/http/URL.h @@ -103,6 +103,36 @@ private: String m_userinfo; }; +/** URL comparisons. */ +/** @{ */ +inline bool operator== (URL const& lhs, URL const& rhs) { return lhs.full() == rhs.full(); } +inline bool operator!= (URL const& lhs, URL const& rhs) { return ! (lhs.full() == rhs.full()); } +inline bool operator< (URL const& lhs, URL const& rhs) { return lhs.full() < rhs.full(); } +inline bool operator> (URL const& lhs, URL const& rhs) { return rhs.full() < lhs.full(); } +inline bool operator<= (URL const& lhs, URL const& rhs) { return ! (rhs.full() < lhs.full()); } +inline bool operator>= (URL const& lhs, URL const& rhs) { return ! (lhs.full() < rhs.full()); } +/** @} */ + +extern std::size_t hash_value (beast::URL const& url); + } +//------------------------------------------------------------------------------ + +namespace std { + +template +struct hash; + +template <> +struct hash +{ + std::size_t operator() (beast::URL const& v) const + { return beast::hash_value (v); } +}; + +} + +//------------------------------------------------------------------------------ + #endif diff --git a/beast/http/impl/URL.cpp b/beast/http/impl/URL.cpp index d0ddfe74a..a6bab6a2d 100644 --- a/beast/http/impl/URL.cpp +++ b/beast/http/impl/URL.cpp @@ -25,7 +25,6 @@ URL::URL () : m_port (0) { } - URL::URL ( String scheme_, String host_, @@ -154,5 +153,14 @@ String URL::full () const return s; } +//------------------------------------------------------------------------------ + +std::size_t hash_value (URL const& v) +{ + return std::size_t (v.full().hash()); } +} + + +// boost::hash support \ No newline at end of file