diff options
-rw-r--r-- | include/anope.h | 5 | ||||
-rw-r--r-- | include/hashcomp.h | 27 | ||||
-rw-r--r-- | src/hashcomp.cpp | 18 |
3 files changed, 47 insertions, 3 deletions
diff --git a/include/anope.h b/include/anope.h index 3749005ed..4cd8fc2b0 100644 --- a/include/anope.h +++ b/include/anope.h @@ -259,6 +259,11 @@ namespace Anope */ struct hash { + /* VS 2008 specific code */ + enum { bucket_size = 4, min_buckets = 8 }; + bool operator()(const string &s1, const string &s2) const; + /* End of 2008 specific code */ + /** Hash an Anope::string for unordered_map * @param s The string * @return A hash value for the string diff --git a/include/hashcomp.h b/include/hashcomp.h index 77e3c0439..9dc992fd0 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -45,9 +45,20 @@ namespace Anope # define unordered_map hash_map # endif #else +# if _MSV_VER >= 1600 /* MSVC 2010+ has tr1. Though MSVC and GCC use different includes! */ -# include <unordered_map> -# define unordered_map_namespace std::tr1 +# include <unordered_map> +# define unordered_map_namespace std::tr1 +# else +# include <hash_map> +# define unordered_map_namespace +template<typename Key, typename Type, typename Compare, typename Unused = void> +class unordered_map : public stdext::hash_map<Key, Type, Compare> +{ + public: + unordered_map() : hash_map() { } +}; +# endif #endif /******************************************************* @@ -161,6 +172,11 @@ namespace irc */ struct hash { + /* VS 2008 specific code */ + enum { bucket_size = 4, min_buckets = 8 }; + bool operator()(const Anope::string &s1, const Anope::string &s2) const; + /* End VS 2008 specific code */ + /** Hash an irc::string for unordered_map * @param s The string * @return A hash value for the string @@ -227,6 +243,11 @@ namespace ci */ struct hash { + /* VS 2008 specific code */ + enum { bucket_size = 4, min_buckets = 8 }; + bool operator()(const Anope::string &s1, const Anope::string &s2) const; + /* End VS 2008 specific code */ + /** Hash a ci::string for unordered_map * @param s The string * @return A hash value for the string @@ -271,7 +292,7 @@ namespace std */ template<> class CoreExport less<ci::string> { - public: + public: /** Compare two Anope::strings as ci::strings and find which one is less * @param s1 The first string * @param s2 The second string diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 129f38e07..5f65738ea 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -25,6 +25,12 @@ * ascii_case_insensitive_map * */ + +/* VS 2008 specific function */ +bool Anope::hash::operator()(const Anope::string &s1, const Anope::string &s2) const +{ + return s1.str().compare(s2.str()) < 0; +} /** Hash an Anope::string for unordered_map * @param s The string @@ -81,6 +87,12 @@ const char *irc::irc_char_traits::find(const char *s1, int n, char c) return n >= 0 ? s1 : NULL; } +/* VS 2008 specific function */ +bool irc::hash::operator()(const Anope::string &s1, const Anope::string &s2) const +{ + return s1.irc_str().compare(s2.irc_str()) < 0; +} + /** Hash an irc::string for unordered_map * @param s The string * @return A hash value for the string @@ -141,6 +153,12 @@ const char *ci::ci_char_traits::find(const char *s1, int n, char c) return n >= 0 ? s1 : NULL; } +/* VS 2008 specific function */ +bool ci::hash::operator()(const Anope::string &s1, const Anope::string &s2) const +{ + return s1.ci_str().compare(s2.ci_str()) < 0; +} + /** Hash a ci::string for unordered_map * @param s The string * @return A hash value for the string |