]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/hashmap.h
test whether pointer is non-NULL before using it, not after, in wxAnimation::Load...
[wxWidgets.git] / include / wx / hashmap.h
index cbf9fec2637fc098f851fe7fda8d334d3eb68e91..7f7cc6a97fc08f8eb91c59306e97d842cfde174a 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        hashmap.h
+// Name:        wx/hashmap.h
 // Purpose:     wxHashMap class
 // Author:      Mattia Barbon
 // Modified by:
 // Purpose:     wxHashMap class
 // Author:      Mattia Barbon
 // Modified by:
@@ -202,6 +202,7 @@ public: \
     { \
     public: \
         const_iterator() : Iterator() {} \
     { \
     public: \
         const_iterator() : Iterator() {} \
+        const_iterator(iterator i) : Iterator(i) {} \
         const_iterator( Node* node, const Self* ht ) \
             : Iterator( node, (Self*)ht ) {} \
         const_iterator& operator++() { PlusPlus();return *this; } \
         const_iterator( Node* node, const Self* ht ) \
             : Iterator( node, (Self*)ht ) {} \
         const_iterator& operator++() { PlusPlus();return *this; } \
@@ -464,11 +465,19 @@ class WXDLLIMPEXP_BASE wxIntegerHash
     WX_HASH_MAP_NAMESPACE::hash<unsigned short> ushortHash;
 
 #if defined wxLongLong_t && !defined wxLongLongIsLong
     WX_HASH_MAP_NAMESPACE::hash<unsigned short> ushortHash;
 
 #if defined wxLongLong_t && !defined wxLongLongIsLong
+    // hash<wxLongLong_t> ought to work but doesn't on some compilers
+    #if (!defined SIZEOF_LONG_LONG && SIZEOF_LONG == 4) \
+        || (defined SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_LONG * 2)
     size_t longlongHash( wxLongLong_t x ) const
     {
         return longHash( wx_truncate_cast(long, x) ) ^
                longHash( wx_truncate_cast(long, x >> (sizeof(long) * 8)) );
     }
     size_t longlongHash( wxLongLong_t x ) const
     {
         return longHash( wx_truncate_cast(long, x) ) ^
                longHash( wx_truncate_cast(long, x >> (sizeof(long) * 8)) );
     }
+    #elif defined SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_LONG
+    WX_HASH_MAP_NAMESPACE::hash<long> longlongHash;
+    #else
+    WX_HASH_MAP_NAMESPACE::hash<wxLongLong_t> longlongHash;
+    #endif
 #endif
 
 public:
 #endif
 
 public:
@@ -552,21 +561,29 @@ public:
     wxPointerEqual& operator=(const wxPointerEqual&) { return *this; }
 };
 
     wxPointerEqual& operator=(const wxPointerEqual&) { return *this; }
 };
 
-// wxString, char*, wxChar*
+// wxString, char*, wchar_t*
 class WXDLLIMPEXP_BASE wxStringHash
 {
 public:
     wxStringHash() {}
     unsigned long operator()( const wxString& x ) const
 class WXDLLIMPEXP_BASE wxStringHash
 {
 public:
     wxStringHash() {}
     unsigned long operator()( const wxString& x ) const
-        { return wxCharStringHash( x.c_str() ); }
-    unsigned long operator()( const wxChar* x ) const
-        { return wxCharStringHash( x ); }
-    static unsigned long wxCharStringHash( const wxChar* );
-#if wxUSE_UNICODE
+        { return stringHash( x.wx_str() ); }
+    unsigned long operator()( const wchar_t* x ) const
+        { return stringHash( x ); }
     unsigned long operator()( const char* x ) const
     unsigned long operator()( const char* x ) const
-        { return charStringHash( x ); }
-    static unsigned long charStringHash( const char* );
-#endif // wxUSE_UNICODE
+        { return stringHash( x ); }
+
+#if WXWIN_COMPATIBILITY_2_8
+    static unsigned long wxCharStringHash( const wxChar* x )
+        { return stringHash(x); }
+    #if wxUSE_UNICODE
+    static unsigned long charStringHash( const char* x )
+        { return stringHash(x); }
+    #endif
+#endif // WXWIN_COMPATIBILITY_2_8
+
+    static unsigned long stringHash( const wchar_t* );
+    static unsigned long stringHash( const char* );
 
     wxStringHash& operator=(const wxStringHash&) { return *this; }
 };
 
     wxStringHash& operator=(const wxStringHash&) { return *this; }
 };
@@ -640,7 +657,10 @@ public: \
  \
     /* count() == 0 | 1 */ \
     size_type count( const const_key_type& key ) \
  \
     /* count() == 0 | 1 */ \
     size_type count( const const_key_type& key ) \
-        { return GetNode( key ) ? 1u : 0u; } \
+    { \
+        /* explicit cast needed to suppress CodeWarrior warnings */ \
+        return (size_type)(GetNode( key ) ? 1 : 0); \
+    } \
 }
 
 #endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
 }
 
 #endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
@@ -704,4 +724,3 @@ WX_DECLARE_HASH_MAP_WITH_DECL( long, long, wxIntegerHash, wxIntegerEqual,
 
 
 #endif // _WX_HASHMAP_H_
 
 
 #endif // _WX_HASHMAP_H_
-