X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/083f7497d34a1df453b92ab411aace3fc4ace927..5b72b3440180cf270f4518ff0e28ff56582438fb:/include/wx/hashmap.h diff --git a/include/wx/hashmap.h b/include/wx/hashmap.h index e774c0a193..14d8684f54 100644 --- a/include/wx/hashmap.h +++ b/include/wx/hashmap.h @@ -18,8 +18,14 @@ #include "wx/string.h" +#include // for ptrdiff_t + +#ifdef __WXWINCE__ +typedef int ptrdiff_t; +#endif + // private -struct WXDLLEXPORT _wxHashTable_NodeBase +struct WXDLLIMPEXP_BASE _wxHashTable_NodeBase { _wxHashTable_NodeBase() : m_nxt(0) {} @@ -31,7 +37,7 @@ struct WXDLLEXPORT _wxHashTable_NodeBase }; // private -class WXDLLEXPORT _wxHashTableBase2 +class WXDLLIMPEXP_BASE _wxHashTableBase2 { public: typedef void (*NodeDtor)(_wxHashTable_NodeBase*); @@ -68,7 +74,11 @@ protected: static void** AllocTable( size_t sz ) { +#ifdef __WXWINCE__ + return (void **)malloc(sz * sizeof(void*)); +#else return (void **)calloc(sz, sizeof(void*)); +#endif } }; @@ -276,8 +286,11 @@ protected: \ return node; \ node = node->m_next(); \ } \ - \ - node = new Node( value ); \ + return CreateNode( value , bucket); \ + }\ + Node * CreateNode( const value_type& value, size_t bucket ) \ + {\ + Node* node = new Node( value ); \ node->m_nxt = m_table[bucket]; \ m_table[bucket] = node; \ \ @@ -288,6 +301,10 @@ protected: \ \ return node; \ } \ + void CreateNode( const value_type& value ) \ + {\ + CreateNode(value, m_hasher( m_getKey(value) ) % m_tableBuckets ); \ + }\ \ /* returns NULL if not found */ \ Node** GetNodePtr( const const_key_type& key ) const \ @@ -405,7 +422,7 @@ inline bool grow_lf70( size_t buckets, size_t items ) // in the hash table class assignment operator (where they're assigned) // integer types -class WXDLLEXPORT wxIntegerHash +class WXDLLIMPEXP_BASE wxIntegerHash { public: wxIntegerHash() { } @@ -419,7 +436,7 @@ public: wxIntegerHash& operator=(const wxIntegerHash&) { return *this; } }; -class WXDLLEXPORT wxIntegerEqual +class WXDLLIMPEXP_BASE wxIntegerEqual { public: wxIntegerEqual() { } @@ -434,7 +451,7 @@ public: }; // pointers -class WXDLLEXPORT wxPointerHash +class WXDLLIMPEXP_BASE wxPointerHash { public: wxPointerHash() { } @@ -446,7 +463,7 @@ public: wxPointerHash& operator=(const wxPointerHash&) { return *this; } }; -class WXDLLEXPORT wxPointerEqual +class WXDLLIMPEXP_BASE wxPointerEqual { public: wxPointerEqual() { } @@ -456,7 +473,7 @@ public: }; // wxString, char*, wxChar* -class WXDLLEXPORT wxStringHash +class WXDLLIMPEXP_BASE wxStringHash { public: wxStringHash() {} @@ -474,7 +491,7 @@ public: wxStringHash& operator=(const wxStringHash&) { return *this; } }; -class WXDLLEXPORT wxStringEqual +class WXDLLIMPEXP_BASE wxStringEqual { public: wxStringEqual() {} @@ -554,5 +571,19 @@ public: \ _WX_DECLARE_HASH_MAP( void*, VALUE_T, wxPointerHash, wxPointerEqual, \ CLASSNAME, class WXDLLEXPORT ) +// delete all hash elements +// +// NB: the class declaration of the hash elements must be visible from the +// place where you use this macro, otherwise the proper destructor may not +// be called (a decent compiler should give a warning about it, but don't +// count on it)! +#define WX_CLEAR_HASH_MAP(type, hashmap) \ + { \ + type::iterator it, en; \ + for( it = (hashmap).begin(), en = (hashmap).end(); it != en; ++it ) \ + delete it->second; \ + (hashmap).clear(); \ + } + #endif // _WX_HASHMAP_H_