epoc32/include/stdapis/stlport/stl/_string_hash.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 /*
     2  * Copyright (c) 1997-1999
     3  * Silicon Graphics Computer Systems, Inc.
     4  *
     5  * Copyright (c) 1999 
     6  * Boris Fomitchev
     7  *
     8  * This material is provided "as is", with absolutely no warranty expressed
     9  * or implied. Any use is at your own risk.
    10  *
    11  * Permission to use or copy this software for any purpose is hereby granted 
    12  * without fee, provided the above notices are retained on all copies.
    13  * Permission to modify the code and to distribute modified code is granted,
    14  * provided the above notices are retained, and a notice that the code was
    15  * modified is included with the above copyright notice.
    16  *
    17  */
    18 
    19 #ifndef _STLP_STRING_HASH_H
    20 # define _STLP_STRING_HASH_H
    21 
    22 #ifndef _STLP_HASH_FUN_H
    23 # include <stl/_hash_fun.h>
    24 #endif
    25 
    26 #ifndef _STLP_STRING_H
    27 # include <stl/_string.h>
    28 #endif
    29 
    30 _STLP_BEGIN_NAMESPACE
    31 
    32 template <class _CharT, class _Traits, class _Alloc>
    33 _STLP_INLINE_LOOP size_t
    34 __stl_string_hash(const basic_string<_CharT,_Traits,_Alloc>& __s) {
    35   unsigned long __h = 0;
    36   typedef typename basic_string<_CharT,_Traits,_Alloc>::const_pointer const_ptr;
    37   size_t __len = __s.size();
    38   const _CharT* __data = __s.data();
    39   for ( size_t __i = 0; __i < __len; ++__i)
    40     __h = 5*__h + __data[__i];
    41   return size_t(__h);
    42 }
    43 
    44 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
    45 
    46 template <class _CharT, class _Traits, class _Alloc>
    47 struct hash<basic_string<_CharT,_Traits,_Alloc> > {
    48   size_t operator()(const basic_string<_CharT,_Traits,_Alloc>& __s) const
    49     { return __stl_string_hash(__s); }
    50 };
    51 
    52 #else
    53 
    54 _STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC hash<string> {
    55   size_t operator()(const string& __s) const
    56     { return __stl_string_hash(__s); }
    57 };
    58 
    59 # if defined (_STLP_HAS_WCHAR_T)
    60 _STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC hash<wstring> {
    61   size_t operator()(const wstring& __s) const
    62     { return __stl_string_hash(__s); }
    63 };
    64 # endif
    65 
    66 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
    67 
    68 _STLP_END_NAMESPACE
    69 
    70 #endif