From f52ad32e62cfa750e386c257abddf33eaca7ec8b Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Mon, 10 Dec 2012 15:15:21 -0500 Subject: SERVER-7886 - StringMap is now based on StringData - UnorderedFastKeyTable more methods to match std::map --- src/mongo/util/string_map.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/mongo/util/string_map.h') diff --git a/src/mongo/util/string_map.h b/src/mongo/util/string_map.h index e2fd7e01bc7..1aa6c678e60 100644 --- a/src/mongo/util/string_map.h +++ b/src/mongo/util/string_map.h @@ -17,34 +17,41 @@ #pragma once -#include +#include "mongo/base/string_data.h" #include "mongo/util/unordered_fast_key_table.h" namespace mongo { struct StringMapDefaultHash { - size_t operator()( const char* k ) const; + size_t operator()( const StringData& k ) const; }; struct StringMapDefaultEqual { - bool operator()( const char* a, const char* b ) const { - return strcmp( a,b ) == 0; + bool operator()( const StringData& a, const StringData& b ) const { + return a == b; } }; struct StringMapDefaultConvertor { - const char* operator()( const std::string& s ) const { - return s.c_str(); + StringData operator()( const std::string& s ) const { + return StringData( s ); + } + }; + + struct StringMapDefaultConvertorOther { + string operator()( const StringData& s ) const { + return s.toString(); } }; template< typename V > - class StringMap : public UnorderedFastKeyTable< const char*, // K_L - std::string, // K_S - V, // V - StringMapDefaultHash, - StringMapDefaultEqual, - StringMapDefaultConvertor > { + class StringMap : public UnorderedFastKeyTable< StringData, // K_L + std::string, // K_S + V, // V + StringMapDefaultHash, + StringMapDefaultEqual, + StringMapDefaultConvertor, + StringMapDefaultConvertorOther > { }; } -- cgit v1.2.1