1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHashMap class
4 // Author: Mattia Barbon
7 // Copyright: (c) Mattia Barbon
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HASHMAP_H_
12 #define _WX_HASHMAP_H_
14 #include "wx/string.h"
17 // In wxUSE_STD_CONTAINERS build we prefer to use the standard hash map class
18 // but it can be either in non-standard hash_map header (old g++ and some other
19 // STL implementations) or in C++0x standard unordered_map which can in turn be
20 // available either in std::tr1 or std namespace itself
22 // To summarize: if std::unordered_map is available use it, otherwise use tr1
23 // and finally fall back to non-standard hash_map
25 #if (defined(HAVE_EXT_HASH_MAP) || defined(HAVE_HASH_MAP)) \
26 && (defined(HAVE_GNU_CXX_HASH_MAP) || defined(HAVE_STD_HASH_MAP))
27 #define HAVE_STL_HASH_MAP
30 #if wxUSE_STD_CONTAINERS && \
31 (defined(HAVE_STD_UNORDERED_MAP) || defined(HAVE_TR1_UNORDERED_MAP))
33 #if defined(HAVE_STD_UNORDERED_MAP)
34 #include <unordered_map>
35 #define WX_HASH_MAP_NAMESPACE std
36 #elif defined(HAVE_TR1_UNORDERED_MAP)
37 #include <tr1/unordered_map>
38 #define WX_HASH_MAP_NAMESPACE std::tr1
41 #define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \
42 typedef WX_HASH_MAP_NAMESPACE::unordered_map< KEY_T, VALUE_T, HASH_T, KEY_EQ_T > CLASSNAME
44 #elif wxUSE_STD_CONTAINERS && defined(HAVE_STL_HASH_MAP)
46 #if defined(HAVE_EXT_HASH_MAP)
47 #include <ext/hash_map>
48 #elif defined(HAVE_HASH_MAP)
52 #if defined(HAVE_GNU_CXX_HASH_MAP)
53 #define WX_HASH_MAP_NAMESPACE __gnu_cxx
54 #elif defined(HAVE_STD_HASH_MAP)
55 #define WX_HASH_MAP_NAMESPACE std
58 #define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \
59 typedef WX_HASH_MAP_NAMESPACE::hash_map< KEY_T, VALUE_T, HASH_T, KEY_EQ_T > CLASSNAME
61 #else // !wxUSE_STD_CONTAINERS || no std::{hash,unordered}_map class available
63 #define wxNEEDS_WX_HASH_MAP
66 typedef int ptrdiff_t;
68 #include <stddef.h> // for ptrdiff_t
72 struct WXDLLIMPEXP_BASE _wxHashTable_NodeBase
74 _wxHashTable_NodeBase() : m_next(NULL
) {}
76 _wxHashTable_NodeBase
* m_next
;
79 // wxDECLARE_NO_COPY_CLASS(_wxHashTable_NodeBase);
80 // without rewriting the macros, which require a public copy constructor.
84 class WXDLLIMPEXP_BASE _wxHashTableBase2
87 typedef void (*NodeDtor
)(_wxHashTable_NodeBase
*);
88 typedef unsigned long (*BucketFromNode
)(_wxHashTableBase2
*,_wxHashTable_NodeBase
*);
89 typedef _wxHashTable_NodeBase
* (*ProcessNode
)(_wxHashTable_NodeBase
*);
91 static _wxHashTable_NodeBase
* DummyProcessNode(_wxHashTable_NodeBase
* node
);
92 static void DeleteNodes( size_t buckets
, _wxHashTable_NodeBase
** table
,
94 static _wxHashTable_NodeBase
* GetFirstNode( size_t buckets
,
95 _wxHashTable_NodeBase
** table
)
97 for( size_t i
= 0; i
< buckets
; ++i
)
103 // as static const unsigned prime_count = 31 but works with all compilers
104 enum { prime_count
= 31 };
105 static const unsigned long ms_primes
[prime_count
];
107 // returns the first prime in ms_primes greater than n
108 static unsigned long GetNextPrime( unsigned long n
);
110 // returns the first prime in ms_primes smaller than n
111 // ( or ms_primes[0] if n is very small )
112 static unsigned long GetPreviousPrime( unsigned long n
);
114 static void CopyHashTable( _wxHashTable_NodeBase
** srcTable
,
115 size_t srcBuckets
, _wxHashTableBase2
* dst
,
116 _wxHashTable_NodeBase
** dstTable
,
117 BucketFromNode func
, ProcessNode proc
);
119 static void** AllocTable( size_t sz
)
121 return (void **)calloc(sz
, sizeof(void*));
123 static void FreeTable(void *table
)
129 #define _WX_DECLARE_HASHTABLE( VALUE_T, KEY_T, HASH_T, KEY_EX_T, KEY_EQ_T,\
130 PTROPERATOR, CLASSNAME, CLASSEXP, \
131 SHOULD_GROW, SHOULD_SHRINK ) \
132 CLASSEXP CLASSNAME : protected _wxHashTableBase2 \
135 typedef KEY_T key_type; \
136 typedef VALUE_T value_type; \
137 typedef HASH_T hasher; \
138 typedef KEY_EQ_T key_equal; \
140 typedef size_t size_type; \
141 typedef ptrdiff_t difference_type; \
142 typedef value_type* pointer; \
143 typedef const value_type* const_pointer; \
144 typedef value_type& reference; \
145 typedef const value_type& const_reference; \
146 /* should these be protected? */ \
147 typedef const KEY_T const_key_type; \
148 typedef const VALUE_T const_mapped_type; \
150 typedef KEY_EX_T key_extractor; \
151 typedef CLASSNAME Self; \
153 _wxHashTable_NodeBase** m_table; \
154 size_t m_tableBuckets; \
157 key_equal m_equals; \
158 key_extractor m_getKey; \
160 struct Node:public _wxHashTable_NodeBase \
163 Node( const value_type& value ) \
164 : m_value( value ) {} \
165 Node* next() { return static_cast<Node*>(m_next); } \
167 value_type m_value; \
171 static void DeleteNode( _wxHashTable_NodeBase* node ) \
173 delete static_cast<Node*>(node); \
177 /* forward iterator */ \
185 Iterator() : m_node(NULL), m_ht(NULL) {} \
186 Iterator( Node* node, const Self* ht ) \
187 : m_node(node), m_ht(const_cast<Self*>(ht)) {} \
188 bool operator ==( const Iterator& it ) const \
189 { return m_node == it.m_node; } \
190 bool operator !=( const Iterator& it ) const \
191 { return m_node != it.m_node; } \
193 Node* GetNextNode() \
195 size_type bucket = GetBucketForNode(m_ht,m_node); \
196 for( size_type i = bucket + 1; i < m_ht->m_tableBuckets; ++i ) \
198 if( m_ht->m_table[i] ) \
199 return static_cast<Node*>(m_ht->m_table[i]); \
206 Node* next = m_node->next(); \
207 m_node = next ? next : GetNextNode(); \
210 friend class Iterator; \
213 CLASSEXP iterator : public Iterator \
216 iterator() : Iterator() {} \
217 iterator( Node* node, Self* ht ) : Iterator( node, ht ) {} \
218 iterator& operator++() { PlusPlus(); return *this; } \
219 iterator operator++(int) { iterator it=*this;PlusPlus();return it; } \
220 reference operator *() const { return m_node->m_value; } \
221 PTROPERATOR(pointer) \
224 CLASSEXP const_iterator : public Iterator \
227 const_iterator() : Iterator() {} \
228 const_iterator(iterator i) : Iterator(i) {} \
229 const_iterator( Node* node, const Self* ht ) \
230 : Iterator(node, const_cast<Self*>(ht)) {} \
231 const_iterator& operator++() { PlusPlus();return *this; } \
232 const_iterator operator++(int) { const_iterator it=*this;PlusPlus();return it; } \
233 const_reference operator *() const { return m_node->m_value; } \
234 PTROPERATOR(const_pointer) \
237 CLASSNAME( size_type sz = 10, const hasher& hfun = hasher(), \
238 const key_equal& k_eq = key_equal(), \
239 const key_extractor& k_ex = key_extractor() ) \
240 : m_tableBuckets( GetNextPrime( (unsigned long) sz ) ), \
246 m_table = (_wxHashTable_NodeBase**)AllocTable(m_tableBuckets); \
249 CLASSNAME( const Self& ht ) \
251 m_tableBuckets( 0 ), \
252 m_items( ht.m_items ), \
253 m_hasher( ht.m_hasher ), \
254 m_equals( ht.m_equals ), \
255 m_getKey( ht.m_getKey ) \
260 const Self& operator=( const Self& ht ) \
265 m_hasher = ht.m_hasher; \
266 m_equals = ht.m_equals; \
267 m_getKey = ht.m_getKey; \
268 m_items = ht.m_items; \
278 FreeTable(m_table); \
281 hasher hash_funct() { return m_hasher; } \
282 key_equal key_eq() { return m_equals; } \
284 /* removes all elements from the hash table, but does not */ \
285 /* shrink it ( perhaps it should ) */ \
288 DeleteNodes(m_tableBuckets, m_table, DeleteNode); \
292 size_type size() const { return m_items; } \
293 size_type max_size() const { return size_type(-1); } \
294 bool empty() const { return size() == 0; } \
296 const_iterator end() const { return const_iterator(NULL, this); } \
297 iterator end() { return iterator(NULL, this); } \
298 const_iterator begin() const \
299 { return const_iterator(static_cast<Node*>(GetFirstNode(m_tableBuckets, m_table)), this); } \
301 { return iterator(static_cast<Node*>(GetFirstNode(m_tableBuckets, m_table)), this); } \
303 size_type erase( const const_key_type& key ) \
305 _wxHashTable_NodeBase** node = GetNodePtr(key); \
311 _wxHashTable_NodeBase* temp = (*node)->m_next; \
312 delete static_cast<Node*>(*node); \
314 if( SHOULD_SHRINK( m_tableBuckets, m_items ) ) \
315 ResizeTable( GetPreviousPrime( (unsigned long) m_tableBuckets ) - 1 ); \
320 static size_type GetBucketForNode( Self* ht, Node* node ) \
322 return ht->m_hasher( ht->m_getKey( node->m_value ) ) \
323 % ht->m_tableBuckets; \
325 static Node* CopyNode( Node* node ) { return new Node( *node ); } \
327 Node* GetOrCreateNode( const value_type& value, bool& created ) \
329 const const_key_type& key = m_getKey( value ); \
330 size_t bucket = m_hasher( key ) % m_tableBuckets; \
331 Node* node = static_cast<Node*>(m_table[bucket]); \
335 if( m_equals( m_getKey( node->m_value ), key ) ) \
340 node = node->next(); \
343 return CreateNode( value, bucket); \
345 Node * CreateNode( const value_type& value, size_t bucket ) \
347 Node* node = new Node( value ); \
348 node->m_next = m_table[bucket]; \
349 m_table[bucket] = node; \
351 /* must be after the node is inserted */ \
353 if( SHOULD_GROW( m_tableBuckets, m_items ) ) \
354 ResizeTable( m_tableBuckets ); \
358 void CreateNode( const value_type& value ) \
360 CreateNode(value, m_hasher( m_getKey(value) ) % m_tableBuckets ); \
363 /* returns NULL if not found */ \
364 _wxHashTable_NodeBase** GetNodePtr(const const_key_type& key) const \
366 size_t bucket = m_hasher( key ) % m_tableBuckets; \
367 _wxHashTable_NodeBase** node = &m_table[bucket]; \
371 if (m_equals(m_getKey(static_cast<Node*>(*node)->m_value), key)) \
373 node = &(*node)->m_next; \
379 /* returns NULL if not found */ \
380 /* expressing it in terms of GetNodePtr is 5-8% slower :-( */ \
381 Node* GetNode( const const_key_type& key ) const \
383 size_t bucket = m_hasher( key ) % m_tableBuckets; \
384 Node* node = static_cast<Node*>(m_table[bucket]); \
388 if( m_equals( m_getKey( node->m_value ), key ) ) \
390 node = node->next(); \
396 void ResizeTable( size_t newSize ) \
398 newSize = GetNextPrime( (unsigned long)newSize ); \
399 _wxHashTable_NodeBase** srcTable = m_table; \
400 size_t srcBuckets = m_tableBuckets; \
401 m_table = (_wxHashTable_NodeBase**)AllocTable( newSize ); \
402 m_tableBuckets = newSize; \
404 CopyHashTable( srcTable, srcBuckets, \
406 (BucketFromNode)GetBucketForNode,\
407 (ProcessNode)&DummyProcessNode ); \
408 FreeTable(srcTable); \
411 /* this must be called _after_ m_table has been cleaned */ \
412 void HashCopy( const Self& ht ) \
414 ResizeTable( ht.size() ); \
415 CopyHashTable( ht.m_table, ht.m_tableBuckets, \
416 (_wxHashTableBase2*)this, \
418 (BucketFromNode)GetBucketForNode, \
419 (ProcessNode)CopyNode ); \
423 // defines an STL-like pair class CLASSNAME storing two fields: first of type
424 // KEY_T and second of type VALUE_T
425 #define _WX_DECLARE_PAIR( KEY_T, VALUE_T, CLASSNAME, CLASSEXP ) \
429 typedef KEY_T first_type; \
430 typedef VALUE_T second_type; \
432 typedef VALUE_T t2; \
433 typedef const KEY_T const_t1; \
434 typedef const VALUE_T const_t2; \
436 CLASSNAME(const const_t1& f, const const_t2& s) \
437 : first(const_cast<t1&>(f)), second(const_cast<t2&>(s)) {} \
443 // defines the class CLASSNAME returning the key part (of type KEY_T) from a
444 // pair of type PAIR_T
445 #define _WX_DECLARE_HASH_MAP_KEY_EX( KEY_T, PAIR_T, CLASSNAME, CLASSEXP ) \
448 typedef KEY_T key_type; \
449 typedef PAIR_T pair_type; \
450 typedef const key_type const_key_type; \
451 typedef const pair_type const_pair_type; \
452 typedef const_key_type& const_key_reference; \
453 typedef const_pair_type& const_pair_reference; \
456 const_key_reference operator()( const_pair_reference pair ) const { return pair.first; }\
458 /* the dummy assignment operator is needed to suppress compiler */ \
459 /* warnings from hash table class' operator=(): gcc complains about */ \
460 /* "statement with no effect" without it */ \
461 CLASSNAME& operator=(const CLASSNAME&) { return *this; } \
464 // grow/shrink predicates
465 inline bool never_grow( size_t, size_t ) { return false; }
466 inline bool never_shrink( size_t, size_t ) { return false; }
467 inline bool grow_lf70( size_t buckets
, size_t items
)
469 return float(items
)/float(buckets
) >= 0.85f
;
472 #endif // various hash map implementations
474 // ----------------------------------------------------------------------------
475 // hashing and comparison functors
476 // ----------------------------------------------------------------------------
478 // NB: implementation detail: all of these classes must have dummy assignment
479 // operators to suppress warnings about "statement with no effect" from gcc
480 // in the hash table class assignment operator (where they're assigned)
482 #ifndef wxNEEDS_WX_HASH_MAP
485 struct WXDLLIMPEXP_BASE wxIntegerHash
488 WX_HASH_MAP_NAMESPACE::hash
<long> longHash
;
489 WX_HASH_MAP_NAMESPACE::hash
<unsigned long> ulongHash
;
490 WX_HASH_MAP_NAMESPACE::hash
<int> intHash
;
491 WX_HASH_MAP_NAMESPACE::hash
<unsigned int> uintHash
;
492 WX_HASH_MAP_NAMESPACE::hash
<short> shortHash
;
493 WX_HASH_MAP_NAMESPACE::hash
<unsigned short> ushortHash
;
495 #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
496 // hash<wxLongLong_t> ought to work but doesn't on some compilers
497 #if (!defined SIZEOF_LONG_LONG && SIZEOF_LONG == 4) \
498 || (defined SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_LONG * 2)
499 size_t longlongHash( wxLongLong_t x
) const
501 return longHash( wx_truncate_cast(long, x
) ) ^
502 longHash( wx_truncate_cast(long, x
>> (sizeof(long) * 8)) );
504 #elif defined SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_LONG
505 WX_HASH_MAP_NAMESPACE::hash
<long> longlongHash
;
507 WX_HASH_MAP_NAMESPACE::hash
<wxLongLong_t
> longlongHash
;
509 #endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
513 size_t operator()( long x
) const { return longHash( x
); }
514 size_t operator()( unsigned long x
) const { return ulongHash( x
); }
515 size_t operator()( int x
) const { return intHash( x
); }
516 size_t operator()( unsigned int x
) const { return uintHash( x
); }
517 size_t operator()( short x
) const { return shortHash( x
); }
518 size_t operator()( unsigned short x
) const { return ushortHash( x
); }
519 #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
520 size_t operator()( wxLongLong_t x
) const { return longlongHash(x
); }
521 size_t operator()( wxULongLong_t x
) const { return longlongHash(x
); }
522 #endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
524 wxIntegerHash
& operator=(const wxIntegerHash
&) { return *this; }
527 #else // wxNEEDS_WX_HASH_MAP
530 struct WXDLLIMPEXP_BASE wxIntegerHash
533 unsigned long operator()( long x
) const { return (unsigned long)x
; }
534 unsigned long operator()( unsigned long x
) const { return x
; }
535 unsigned long operator()( int x
) const { return (unsigned long)x
; }
536 unsigned long operator()( unsigned int x
) const { return x
; }
537 unsigned long operator()( short x
) const { return (unsigned long)x
; }
538 unsigned long operator()( unsigned short x
) const { return x
; }
539 #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
540 wxULongLong_t
operator()( wxLongLong_t x
) const { return static_cast<wxULongLong_t
>(x
); }
541 wxULongLong_t
operator()( wxULongLong_t x
) const { return x
; }
542 #endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
544 wxIntegerHash
& operator=(const wxIntegerHash
&) { return *this; }
547 #endif // !wxNEEDS_WX_HASH_MAP/wxNEEDS_WX_HASH_MAP
549 struct WXDLLIMPEXP_BASE wxIntegerEqual
552 bool operator()( long a
, long b
) const { return a
== b
; }
553 bool operator()( unsigned long a
, unsigned long b
) const { return a
== b
; }
554 bool operator()( int a
, int b
) const { return a
== b
; }
555 bool operator()( unsigned int a
, unsigned int b
) const { return a
== b
; }
556 bool operator()( short a
, short b
) const { return a
== b
; }
557 bool operator()( unsigned short a
, unsigned short b
) const { return a
== b
; }
558 #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
559 bool operator()( wxLongLong_t a
, wxLongLong_t b
) const { return a
== b
; }
560 bool operator()( wxULongLong_t a
, wxULongLong_t b
) const { return a
== b
; }
561 #endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
563 wxIntegerEqual
& operator=(const wxIntegerEqual
&) { return *this; }
567 struct WXDLLIMPEXP_BASE wxPointerHash
571 #ifdef wxNEEDS_WX_HASH_MAP
572 wxUIntPtr
operator()( const void* k
) const { return wxPtrToUInt(k
); }
574 size_t operator()( const void* k
) const { return (size_t)k
; }
577 wxPointerHash
& operator=(const wxPointerHash
&) { return *this; }
580 struct WXDLLIMPEXP_BASE wxPointerEqual
583 bool operator()( const void* a
, const void* b
) const { return a
== b
; }
585 wxPointerEqual
& operator=(const wxPointerEqual
&) { return *this; }
588 // wxString, char*, wchar_t*
589 struct WXDLLIMPEXP_BASE wxStringHash
592 unsigned long operator()( const wxString
& x
) const
593 { return stringHash( x
.wx_str() ); }
594 unsigned long operator()( const wchar_t* x
) const
595 { return stringHash( x
); }
596 unsigned long operator()( const char* x
) const
597 { return stringHash( x
); }
599 #if WXWIN_COMPATIBILITY_2_8
600 static unsigned long wxCharStringHash( const wxChar
* x
)
601 { return stringHash(x
); }
603 static unsigned long charStringHash( const char* x
)
604 { return stringHash(x
); }
606 #endif // WXWIN_COMPATIBILITY_2_8
608 static unsigned long stringHash( const wchar_t* );
609 static unsigned long stringHash( const char* );
611 wxStringHash
& operator=(const wxStringHash
&) { return *this; }
614 struct WXDLLIMPEXP_BASE wxStringEqual
617 bool operator()( const wxString
& a
, const wxString
& b
) const
619 bool operator()( const wxChar
* a
, const wxChar
* b
) const
620 { return wxStrcmp( a
, b
) == 0; }
622 bool operator()( const char* a
, const char* b
) const
623 { return strcmp( a
, b
) == 0; }
624 #endif // wxUSE_UNICODE
626 wxStringEqual
& operator=(const wxStringEqual
&) { return *this; }
629 #ifdef wxNEEDS_WX_HASH_MAP
631 #define wxPTROP_NORMAL(pointer) \
632 pointer operator ->() const { return &(m_node->m_value); }
633 #define wxPTROP_NOP(pointer)
635 #define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \
636 _WX_DECLARE_PAIR( KEY_T, VALUE_T, CLASSNAME##_wxImplementation_Pair, CLASSEXP ) \
637 _WX_DECLARE_HASH_MAP_KEY_EX( KEY_T, CLASSNAME##_wxImplementation_Pair, CLASSNAME##_wxImplementation_KeyEx, CLASSEXP ) \
638 _WX_DECLARE_HASHTABLE( CLASSNAME##_wxImplementation_Pair, KEY_T, HASH_T, \
639 CLASSNAME##_wxImplementation_KeyEx, KEY_EQ_T, wxPTROP_NORMAL, \
640 CLASSNAME##_wxImplementation_HashTable, CLASSEXP, grow_lf70, never_shrink ) \
641 CLASSEXP CLASSNAME:public CLASSNAME##_wxImplementation_HashTable \
644 typedef VALUE_T mapped_type; \
645 _WX_DECLARE_PAIR( iterator, bool, Insert_Result, CLASSEXP ) \
647 wxEXPLICIT CLASSNAME( size_type hint = 100, hasher hf = hasher(), \
648 key_equal eq = key_equal() ) \
649 : CLASSNAME##_wxImplementation_HashTable( hint, hf, eq, \
650 CLASSNAME##_wxImplementation_KeyEx() ) {} \
652 mapped_type& operator[]( const const_key_type& key ) \
655 return GetOrCreateNode( \
656 CLASSNAME##_wxImplementation_Pair( key, mapped_type() ), \
657 created)->m_value.second; \
660 const_iterator find( const const_key_type& key ) const \
662 return const_iterator( GetNode( key ), this ); \
665 iterator find( const const_key_type& key ) \
667 return iterator( GetNode( key ), this ); \
670 Insert_Result insert( const value_type& v ) \
673 Node *node = GetOrCreateNode( \
674 CLASSNAME##_wxImplementation_Pair( v.first, v.second ), \
676 return Insert_Result(iterator(node, this), created); \
679 size_type erase( const key_type& k ) \
680 { return CLASSNAME##_wxImplementation_HashTable::erase( k ); } \
681 void erase( const iterator& it ) { erase( (*it).first ); } \
683 /* count() == 0 | 1 */ \
684 size_type count( const const_key_type& key ) \
686 return GetNode( key ) ? 1u : 0u; \
690 #endif // wxNEEDS_WX_HASH_MAP
692 // these macros are to be used in the user code
693 #define WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME) \
694 _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, class )
696 #define WX_DECLARE_STRING_HASH_MAP( VALUE_T, CLASSNAME ) \
697 _WX_DECLARE_HASH_MAP( wxString, VALUE_T, wxStringHash, wxStringEqual, \
700 #define WX_DECLARE_VOIDPTR_HASH_MAP( VALUE_T, CLASSNAME ) \
701 _WX_DECLARE_HASH_MAP( void*, VALUE_T, wxPointerHash, wxPointerEqual, \
704 // and these do exactly the same thing but should be used inside the
706 #define WX_DECLARE_HASH_MAP_WITH_DECL( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL) \
707 _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL )
709 #define WX_DECLARE_EXPORTED_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME) \
710 WX_DECLARE_HASH_MAP_WITH_DECL( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, \
711 CLASSNAME, class WXDLLIMPEXP_CORE )
713 #define WX_DECLARE_STRING_HASH_MAP_WITH_DECL( VALUE_T, CLASSNAME, DECL ) \
714 _WX_DECLARE_HASH_MAP( wxString, VALUE_T, wxStringHash, wxStringEqual, \
717 #define WX_DECLARE_EXPORTED_STRING_HASH_MAP( VALUE_T, CLASSNAME ) \
718 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( VALUE_T, CLASSNAME, \
719 class WXDLLIMPEXP_CORE )
721 #define WX_DECLARE_VOIDPTR_HASH_MAP_WITH_DECL( VALUE_T, CLASSNAME, DECL ) \
722 _WX_DECLARE_HASH_MAP( void*, VALUE_T, wxPointerHash, wxPointerEqual, \
725 #define WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP( VALUE_T, CLASSNAME ) \
726 WX_DECLARE_VOIDPTR_HASH_MAP_WITH_DECL( VALUE_T, CLASSNAME, \
727 class WXDLLIMPEXP_CORE )
729 // delete all hash elements
731 // NB: the class declaration of the hash elements must be visible from the
732 // place where you use this macro, otherwise the proper destructor may not
733 // be called (a decent compiler should give a warning about it, but don't
735 #define WX_CLEAR_HASH_MAP(type, hashmap) \
737 type::iterator it, en; \
738 for( it = (hashmap).begin(), en = (hashmap).end(); it != en; ++it ) \
743 //---------------------------------------------------------------------------
744 // Declarations of common hashmap classes
746 WX_DECLARE_HASH_MAP_WITH_DECL( long, long, wxIntegerHash
, wxIntegerEqual
,
747 wxLongToLongHashMap
, class WXDLLIMPEXP_BASE
);
749 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxString
, wxStringToStringHashMap
,
750 class WXDLLIMPEXP_BASE
);
752 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxUIntPtr
, wxStringToNumHashMap
,
753 class WXDLLIMPEXP_BASE
);
756 #endif // _WX_HASHMAP_H_