1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHashMap class
4 // Author: Mattia Barbon
8 // Copyright: (c) Mattia Barbon
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_HASHMAP_H_
13 #define _WX_HASHMAP_H_
15 #include "wx/string.h"
18 #if (defined(HAVE_EXT_HASH_MAP) || defined(HAVE_HASH_MAP)) \
19 && (defined(HAVE_GNU_CXX_HASH_MAP) || defined(HAVE_STD_HASH_MAP))
20 #define HAVE_STL_HASH_MAP
23 #if wxUSE_STL && defined(HAVE_STL_HASH_MAP)
25 #if defined(HAVE_EXT_HASH_MAP)
26 #include <ext/hash_map>
27 #elif defined(HAVE_HASH_MAP)
31 #if defined(HAVE_GNU_CXX_HASH_MAP)
32 #define WX_HASH_MAP_NAMESPACE __gnu_cxx
33 #elif defined(HAVE_STD_HASH_MAP)
34 #define WX_HASH_MAP_NAMESPACE std
37 #define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \
38 typedef WX_HASH_MAP_NAMESPACE::hash_map< KEY_T, VALUE_T, HASH_T, KEY_EQ_T > CLASSNAME
40 #else // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
44 typedef int ptrdiff_t;
46 #include <stddef.h> // for ptrdiff_t
50 struct WXDLLIMPEXP_BASE _wxHashTable_NodeBase
52 _wxHashTable_NodeBase() : m_nxt(0) {}
54 _wxHashTable_NodeBase
* m_nxt
;
57 // DECLARE_NO_COPY_CLASS(_wxHashTable_NodeBase)
58 // without rewriting the macros, which require a public copy constructor.
62 class WXDLLIMPEXP_BASE _wxHashTableBase2
65 typedef void (*NodeDtor
)(_wxHashTable_NodeBase
*);
66 typedef unsigned long (*BucketFromNode
)(_wxHashTableBase2
*,_wxHashTable_NodeBase
*);
67 typedef _wxHashTable_NodeBase
* (*ProcessNode
)(_wxHashTable_NodeBase
*);
69 static _wxHashTable_NodeBase
* DummyProcessNode(_wxHashTable_NodeBase
* node
);
70 static void DeleteNodes( size_t buckets
, _wxHashTable_NodeBase
** table
,
72 static _wxHashTable_NodeBase
* GetFirstNode( size_t buckets
,
73 _wxHashTable_NodeBase
** table
)
75 for( size_t i
= 0; i
< buckets
; ++i
)
81 // as static const unsigned prime_count = 31 but works with all compilers
82 enum { prime_count
= 31 };
83 static const unsigned long ms_primes
[prime_count
];
85 // returns the first prime in ms_primes greater than n
86 static unsigned long GetNextPrime( unsigned long n
);
88 // returns the first prime in ms_primes smaller than n
89 // ( or ms_primes[0] if n is very small )
90 static unsigned long GetPreviousPrime( unsigned long n
);
92 static void CopyHashTable( _wxHashTable_NodeBase
** srcTable
,
93 size_t srcBuckets
, _wxHashTableBase2
* dst
,
94 _wxHashTable_NodeBase
** dstTable
,
95 BucketFromNode func
, ProcessNode proc
);
97 static void** AllocTable( size_t sz
)
99 return (void **)calloc(sz
, sizeof(void*));
101 static void FreeTable(void *table
)
107 #define _WX_DECLARE_HASHTABLE( VALUE_T, KEY_T, HASH_T, KEY_EX_T, KEY_EQ_T, CLASSNAME, CLASSEXP, SHOULD_GROW, SHOULD_SHRINK ) \
108 CLASSEXP CLASSNAME : protected _wxHashTableBase2 \
111 typedef KEY_T key_type; \
112 typedef VALUE_T value_type; \
113 typedef HASH_T hasher; \
114 typedef KEY_EQ_T key_equal; \
116 typedef size_t size_type; \
117 typedef ptrdiff_t difference_type; \
118 typedef value_type* pointer; \
119 typedef const value_type* const_pointer; \
120 typedef value_type& reference; \
121 typedef const value_type& const_reference; \
122 /* should these be protected? */ \
123 typedef const KEY_T const_key_type; \
124 typedef const VALUE_T const_mapped_type; \
127 typedef KEY_EX_T key_extractor; \
128 typedef CLASSNAME Self; \
131 size_t m_tableBuckets; \
134 key_equal m_equals; \
135 key_extractor m_getKey; \
137 struct Node:public _wxHashTable_NodeBase \
140 Node( const value_type& value ) \
141 : m_value( value ) {} \
142 Node* m_next() { return (Node*)this->m_nxt; } \
144 value_type m_value; \
148 friend CLASSEXP Iterator; \
150 static void DeleteNode( _wxHashTable_NodeBase* node ) \
152 delete (Node*)node; \
156 /* forward iterator */ \
164 Iterator() : m_node(0), m_ht(0) {} \
165 Iterator( Node* node, const Self* ht ) \
166 : m_node(node), m_ht((Self*)ht) {} \
167 bool operator ==( const Iterator& it ) const \
168 { return m_node == it.m_node; } \
169 bool operator !=( const Iterator& it ) const \
170 { return m_node != it.m_node; } \
172 Node* GetNextNode() \
174 size_type bucket = GetBucketForNode(m_ht,m_node); \
175 for( size_type i = bucket + 1; i < m_ht->m_tableBuckets; ++i ) \
177 if( m_ht->m_table[i] ) \
178 return m_ht->m_table[i]; \
185 Node* next = m_node->m_next(); \
186 m_node = next ? next : GetNextNode(); \
191 CLASSEXP iterator : public Iterator \
194 iterator() : Iterator() {} \
195 iterator( Node* node, Self* ht ) : Iterator( node, ht ) {} \
196 iterator& operator++() { PlusPlus(); return *this; } \
197 iterator operator++(int) { iterator it=*this;PlusPlus();return it; } \
198 reference operator *() const { return m_node->m_value; } \
199 pointer operator ->() const { return &(m_node->m_value); } \
202 CLASSEXP const_iterator : public Iterator \
205 const_iterator() : Iterator() {} \
206 const_iterator(iterator i) : Iterator(i) {} \
207 const_iterator( Node* node, const Self* ht ) \
208 : Iterator( node, (Self*)ht ) {} \
209 const_iterator& operator++() { PlusPlus();return *this; } \
210 const_iterator operator++(int) { const_iterator it=*this;PlusPlus();return it; } \
211 const_reference operator *() const { return m_node->m_value; } \
212 const_pointer operator ->() const { return &(m_node->m_value); } \
215 CLASSNAME( size_type sz = 10, const hasher& hfun = hasher(), \
216 const key_equal& k_eq = key_equal(), \
217 const key_extractor& k_ex = key_extractor() ) \
218 : m_tableBuckets( GetNextPrime( (unsigned long) sz ) ), \
224 m_table = (Node**)AllocTable( m_tableBuckets ); \
227 CLASSNAME( const Self& ht ) \
229 m_tableBuckets( 0 ), \
230 m_items( ht.m_items ), \
231 m_hasher( ht.m_hasher ), \
232 m_equals( ht.m_equals ), \
233 m_getKey( ht.m_getKey ) \
238 const Self& operator=( const Self& ht ) \
241 m_hasher = ht.m_hasher; \
242 m_equals = ht.m_equals; \
243 m_getKey = ht.m_getKey; \
244 m_items = ht.m_items; \
253 FreeTable(m_table); \
256 hasher hash_funct() { return m_hasher; } \
257 key_equal key_eq() { return m_equals; } \
259 /* removes all elements from the hash table, but does not */ \
260 /* shrink it ( perhaps it should ) */ \
263 DeleteNodes( m_tableBuckets, (_wxHashTable_NodeBase**)m_table, \
268 size_type size() const { return m_items; } \
269 size_type max_size() const { return size_type(-1); } \
270 bool empty() const { return size() == 0; } \
272 const_iterator end() const { return const_iterator( 0, this ); } \
273 iterator end() { return iterator( 0, this ); } \
274 const_iterator begin() const \
275 { return const_iterator( (Node*)GetFirstNode( m_tableBuckets, (_wxHashTable_NodeBase**)m_table ), this ); } \
277 { return iterator( (Node*)GetFirstNode( m_tableBuckets, (_wxHashTable_NodeBase**)m_table ), this ); } \
279 size_type erase( const const_key_type& key ) \
281 Node** node = GetNodePtr( key ); \
287 Node* temp = (*node)->m_next(); \
290 if( SHOULD_SHRINK( m_tableBuckets, m_items ) ) \
291 ResizeTable( GetPreviousPrime( (unsigned long) m_tableBuckets ) - 1 ); \
296 static size_type GetBucketForNode( Self* ht, Node* node ) \
298 return ht->m_hasher( ht->m_getKey( node->m_value ) ) \
299 % ht->m_tableBuckets; \
301 static Node* CopyNode( Node* node ) { return new Node( *node ); } \
303 Node* GetOrCreateNode( const value_type& value, bool& created ) \
305 const const_key_type& key = m_getKey( value ); \
306 size_t bucket = m_hasher( key ) % m_tableBuckets; \
307 Node* node = m_table[bucket]; \
311 if( m_equals( m_getKey( node->m_value ), key ) ) \
316 node = node->m_next(); \
319 return CreateNode( value, bucket); \
321 Node * CreateNode( const value_type& value, size_t bucket ) \
323 Node* node = new Node( value ); \
324 node->m_nxt = m_table[bucket]; \
325 m_table[bucket] = node; \
327 /* must be after the node is inserted */ \
329 if( SHOULD_GROW( m_tableBuckets, m_items ) ) \
330 ResizeTable( m_tableBuckets ); \
334 void CreateNode( const value_type& value ) \
336 CreateNode(value, m_hasher( m_getKey(value) ) % m_tableBuckets ); \
339 /* returns NULL if not found */ \
340 Node** GetNodePtr( const const_key_type& key ) const \
342 size_t bucket = m_hasher( key ) % m_tableBuckets; \
343 Node** node = &m_table[bucket]; \
347 if( m_equals( m_getKey( (*node)->m_value ), key ) ) \
349 /* Tell the compiler to not do any strict-aliasing assumptions with a void cast? Can we make such a runtime guarantee? */ \
350 node = (Node**)&(*node)->m_nxt; \
356 /* returns NULL if not found */ \
357 /* expressing it in terms of GetNodePtr is 5-8% slower :-( */ \
358 Node* GetNode( const const_key_type& key ) const \
360 size_t bucket = m_hasher( key ) % m_tableBuckets; \
361 Node* node = m_table[bucket]; \
365 if( m_equals( m_getKey( node->m_value ), key ) ) \
367 node = node->m_next(); \
373 void ResizeTable( size_t newSize ) \
375 newSize = GetNextPrime( (unsigned long)newSize ); \
376 Node** srcTable = m_table; \
377 size_t srcBuckets = m_tableBuckets; \
378 m_table = (Node**)AllocTable( newSize ); \
379 m_tableBuckets = newSize; \
381 CopyHashTable( (_wxHashTable_NodeBase**)srcTable, srcBuckets, \
382 this, (_wxHashTable_NodeBase**)m_table, \
383 (BucketFromNode)GetBucketForNode,\
384 (ProcessNode)&DummyProcessNode ); \
385 FreeTable(srcTable); \
388 /* this must be called _after_ m_table has been cleaned */ \
389 void HashCopy( const Self& ht ) \
391 ResizeTable( ht.size() ); \
392 CopyHashTable( (_wxHashTable_NodeBase**)ht.m_table, ht.m_tableBuckets,\
393 (_wxHashTableBase2*)this, \
394 (_wxHashTable_NodeBase**)m_table, \
395 (BucketFromNode)GetBucketForNode, \
396 (ProcessNode)CopyNode ); \
400 // defines an STL-like pair class CLASSNAME storing two fields: first of type
401 // KEY_T and second of type VALUE_T
402 #define _WX_DECLARE_PAIR( KEY_T, VALUE_T, CLASSNAME, CLASSEXP ) \
407 typedef VALUE_T t2; \
408 typedef const KEY_T const_t1; \
409 typedef const VALUE_T const_t2; \
411 CLASSNAME( const const_t1& f, const const_t2& s ):first(t1(f)),second(t2(s)) {} \
417 // defines the class CLASSNAME returning the key part (of type KEY_T) from a
418 // pair of type PAIR_T
419 #define _WX_DECLARE_HASH_MAP_KEY_EX( KEY_T, PAIR_T, CLASSNAME, CLASSEXP ) \
422 typedef KEY_T key_type; \
423 typedef PAIR_T pair_type; \
424 typedef const key_type const_key_type; \
425 typedef const pair_type const_pair_type; \
426 typedef const_key_type& const_key_reference; \
427 typedef const_pair_type& const_pair_reference; \
430 const_key_reference operator()( const_pair_reference pair ) const { return pair.first; }\
432 /* the dummy assignment operator is needed to suppress compiler */ \
433 /* warnings from hash table class' operator=(): gcc complains about */ \
434 /* "statement with no effect" without it */ \
435 CLASSNAME& operator=(const CLASSNAME&) { return *this; } \
438 // grow/shrink predicates
439 inline bool never_grow( size_t, size_t ) { return false; }
440 inline bool never_shrink( size_t, size_t ) { return false; }
441 inline bool grow_lf70( size_t buckets
, size_t items
)
443 return float(items
)/float(buckets
) >= 0.85;
446 #endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
448 // ----------------------------------------------------------------------------
449 // hashing and comparison functors
450 // ----------------------------------------------------------------------------
452 // NB: implementation detail: all of these classes must have dummy assignment
453 // operators to suppress warnings about "statement with no effect" from gcc
454 // in the hash table class assignment operator (where they're assigned)
456 #if wxUSE_STL && defined(HAVE_STL_HASH_MAP)
459 class WXDLLIMPEXP_BASE wxIntegerHash
461 WX_HASH_MAP_NAMESPACE::hash
<long> longHash
;
462 WX_HASH_MAP_NAMESPACE::hash
<unsigned long> ulongHash
;
463 WX_HASH_MAP_NAMESPACE::hash
<int> intHash
;
464 WX_HASH_MAP_NAMESPACE::hash
<unsigned int> uintHash
;
465 WX_HASH_MAP_NAMESPACE::hash
<short> shortHash
;
466 WX_HASH_MAP_NAMESPACE::hash
<unsigned short> ushortHash
;
468 #if defined wxLongLong_t && !defined wxLongLongIsLong
469 // hash<wxLongLong_t> ought to work but doesn't on some compilers
470 #if (!defined SIZEOF_LONG_LONG && SIZEOF_LONG == 4) \
471 || (defined SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_LONG * 2)
472 size_t longlongHash( wxLongLong_t x
) const
474 return longHash( wx_truncate_cast(long, x
) ) ^
475 longHash( wx_truncate_cast(long, x
>> (sizeof(long) * 8)) );
477 #elif defined SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_LONG
478 WX_HASH_MAP_NAMESPACE::hash
<long> longlongHash
;
480 WX_HASH_MAP_NAMESPACE::hash
<wxLongLong_t
> longlongHash
;
486 size_t operator()( long x
) const { return longHash( x
); }
487 size_t operator()( unsigned long x
) const { return ulongHash( x
); }
488 size_t operator()( int x
) const { return intHash( x
); }
489 size_t operator()( unsigned int x
) const { return uintHash( x
); }
490 size_t operator()( short x
) const { return shortHash( x
); }
491 size_t operator()( unsigned short x
) const { return ushortHash( x
); }
492 #if defined wxLongLong_t && !defined wxLongLongIsLong
493 size_t operator()( wxLongLong_t x
) const { return longlongHash(x
); }
494 size_t operator()( wxULongLong_t x
) const { return longlongHash(x
); }
497 wxIntegerHash
& operator=(const wxIntegerHash
&) { return *this; }
500 #else // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
503 class WXDLLIMPEXP_BASE wxIntegerHash
507 unsigned long operator()( long x
) const { return (unsigned long)x
; }
508 unsigned long operator()( unsigned long x
) const { return x
; }
509 unsigned long operator()( int x
) const { return (unsigned long)x
; }
510 unsigned long operator()( unsigned int x
) const { return x
; }
511 unsigned long operator()( short x
) const { return (unsigned long)x
; }
512 unsigned long operator()( unsigned short x
) const { return x
; }
513 #if defined wxLongLong_t && !defined wxLongLongIsLong
514 wxULongLong_t
operator()( wxLongLong_t x
) const { return wx_static_cast(wxULongLong_t
, x
); }
515 wxULongLong_t
operator()( wxULongLong_t x
) const { return x
; }
518 wxIntegerHash
& operator=(const wxIntegerHash
&) { return *this; }
521 #endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
523 class WXDLLIMPEXP_BASE wxIntegerEqual
527 bool operator()( long a
, long b
) const { return a
== b
; }
528 bool operator()( unsigned long a
, unsigned long b
) const { return a
== b
; }
529 bool operator()( int a
, int b
) const { return a
== b
; }
530 bool operator()( unsigned int a
, unsigned int b
) const { return a
== b
; }
531 bool operator()( short a
, short b
) const { return a
== b
; }
532 bool operator()( unsigned short a
, unsigned short b
) const { return a
== b
; }
533 #if defined wxLongLong_t && !defined wxLongLongIsLong
534 bool operator()( wxLongLong_t a
, wxLongLong_t b
) const { return a
== b
; }
535 bool operator()( wxULongLong_t a
, wxULongLong_t b
) const { return a
== b
; }
538 wxIntegerEqual
& operator=(const wxIntegerEqual
&) { return *this; }
542 class WXDLLIMPEXP_BASE wxPointerHash
547 #if wxUSE_STL && defined(HAVE_STL_HASH_MAP)
548 size_t operator()( const void* k
) const { return (size_t)k
; }
550 wxUIntPtr
operator()( const void* k
) const { return wxPtrToUInt(k
); }
553 wxPointerHash
& operator=(const wxPointerHash
&) { return *this; }
556 class WXDLLIMPEXP_BASE wxPointerEqual
560 bool operator()( const void* a
, const void* b
) const { return a
== b
; }
562 wxPointerEqual
& operator=(const wxPointerEqual
&) { return *this; }
565 // wxString, char*, wchar_t*
566 class WXDLLIMPEXP_BASE wxStringHash
570 unsigned long operator()( const wxString
& x
) const
571 { return stringHash( x
.wx_str() ); }
572 unsigned long operator()( const wchar_t* x
) const
573 { return stringHash( x
); }
574 unsigned long operator()( const char* x
) const
575 { return stringHash( x
); }
577 #if WXWIN_COMPATIBILITY_2_8
578 static unsigned long wxCharStringHash( const wxChar
* x
)
579 { return stringHash(x
); }
581 static unsigned long charStringHash( const char* x
)
582 { return stringHash(x
); }
584 #endif // WXWIN_COMPATIBILITY_2_8
586 static unsigned long stringHash( const wchar_t* );
587 static unsigned long stringHash( const char* );
589 wxStringHash
& operator=(const wxStringHash
&) { return *this; }
592 class WXDLLIMPEXP_BASE wxStringEqual
596 bool operator()( const wxString
& a
, const wxString
& b
) const
598 bool operator()( const wxChar
* a
, const wxChar
* b
) const
599 { return wxStrcmp( a
, b
) == 0; }
601 bool operator()( const char* a
, const char* b
) const
602 { return strcmp( a
, b
) == 0; }
603 #endif // wxUSE_UNICODE
605 wxStringEqual
& operator=(const wxStringEqual
&) { return *this; }
608 #if !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
610 #define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \
611 _WX_DECLARE_PAIR( KEY_T, VALUE_T, CLASSNAME##_wxImplementation_Pair, CLASSEXP ) \
612 _WX_DECLARE_HASH_MAP_KEY_EX( KEY_T, CLASSNAME##_wxImplementation_Pair, CLASSNAME##_wxImplementation_KeyEx, CLASSEXP ) \
613 _WX_DECLARE_HASHTABLE( CLASSNAME##_wxImplementation_Pair, KEY_T, HASH_T, CLASSNAME##_wxImplementation_KeyEx, KEY_EQ_T, CLASSNAME##_wxImplementation_HashTable, CLASSEXP, grow_lf70, never_shrink ) \
614 CLASSEXP CLASSNAME:public CLASSNAME##_wxImplementation_HashTable \
617 typedef VALUE_T mapped_type; \
618 _WX_DECLARE_PAIR( iterator, bool, Insert_Result, CLASSEXP ) \
620 wxEXPLICIT CLASSNAME( size_type hint = 100, hasher hf = hasher(), \
621 key_equal eq = key_equal() ) \
622 : CLASSNAME##_wxImplementation_HashTable( hint, hf, eq, \
623 CLASSNAME##_wxImplementation_KeyEx() ) {} \
625 mapped_type& operator[]( const const_key_type& key ) \
628 return GetOrCreateNode( \
629 CLASSNAME##_wxImplementation_Pair( key, mapped_type() ), \
630 created)->m_value.second; \
633 const_iterator find( const const_key_type& key ) const \
635 return const_iterator( GetNode( key ), this ); \
638 iterator find( const const_key_type& key ) \
640 return iterator( GetNode( key ), this ); \
643 Insert_Result insert( const value_type& v ) \
646 Node *node = GetOrCreateNode( \
647 CLASSNAME##_wxImplementation_Pair( v.first, v.second ), \
650 node->m_value.second = v.second; \
651 return Insert_Result(iterator(node, this), created); \
654 size_type erase( const key_type& k ) \
655 { return CLASSNAME##_wxImplementation_HashTable::erase( k ); } \
656 void erase( const iterator& it ) { erase( it->first ); } \
657 void erase( const const_iterator& it ) { erase( it->first ); } \
659 /* count() == 0 | 1 */ \
660 size_type count( const const_key_type& key ) \
662 /* explicit cast needed to suppress CodeWarrior warnings */ \
663 return (size_type)(GetNode( key ) ? 1 : 0); \
667 #endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
669 // these macros are to be used in the user code
670 #define WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME) \
671 _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, class )
673 #define WX_DECLARE_STRING_HASH_MAP( VALUE_T, CLASSNAME ) \
674 _WX_DECLARE_HASH_MAP( wxString, VALUE_T, wxStringHash, wxStringEqual, \
677 #define WX_DECLARE_VOIDPTR_HASH_MAP( VALUE_T, CLASSNAME ) \
678 _WX_DECLARE_HASH_MAP( void*, VALUE_T, wxPointerHash, wxPointerEqual, \
681 // and these do exactly the same thing but should be used inside the
683 #define WX_DECLARE_HASH_MAP_WITH_DECL( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL) \
684 _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL )
686 #define WX_DECLARE_EXPORTED_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME) \
687 WX_DECLARE_HASH_MAP_WITH_DECL( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, \
688 CLASSNAME, class WXDLLEXPORT )
690 #define WX_DECLARE_STRING_HASH_MAP_WITH_DECL( VALUE_T, CLASSNAME, DECL ) \
691 _WX_DECLARE_HASH_MAP( wxString, VALUE_T, wxStringHash, wxStringEqual, \
694 #define WX_DECLARE_EXPORTED_STRING_HASH_MAP( VALUE_T, CLASSNAME ) \
695 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( VALUE_T, CLASSNAME, \
698 #define WX_DECLARE_VOIDPTR_HASH_MAP_WITH_DECL( VALUE_T, CLASSNAME, DECL ) \
699 _WX_DECLARE_HASH_MAP( void*, VALUE_T, wxPointerHash, wxPointerEqual, \
702 #define WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP( VALUE_T, CLASSNAME ) \
703 WX_DECLARE_VOIDPTR_HASH_MAP_WITH_DECL( VALUE_T, CLASSNAME, \
706 // delete all hash elements
708 // NB: the class declaration of the hash elements must be visible from the
709 // place where you use this macro, otherwise the proper destructor may not
710 // be called (a decent compiler should give a warning about it, but don't
712 #define WX_CLEAR_HASH_MAP(type, hashmap) \
714 type::iterator it, en; \
715 for( it = (hashmap).begin(), en = (hashmap).end(); it != en; ++it ) \
720 //---------------------------------------------------------------------------
721 // Declarations of common hashmap classes
723 WX_DECLARE_HASH_MAP_WITH_DECL( long, long, wxIntegerHash
, wxIntegerEqual
,
724 wxLongToLongHashMap
, class WXDLLIMPEXP_BASE
);
727 #endif // _WX_HASHMAP_H_