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 // In wxUSE_STL build we prefer to use the standard hash map class but it can
19 // be either in non-standard hash_map header (old g++ and some other STL
20 // implementations) or in C++0x standard unordered_map which can in turn be
21 // available either in std::tr1 or std namespace itself
23 // To summarize: if std::unordered_map is available use it, otherwise use tr1
24 // and finally fall back to non-standard hash_map
26 #if (defined(HAVE_EXT_HASH_MAP) || defined(HAVE_HASH_MAP)) \
27 && (defined(HAVE_GNU_CXX_HASH_MAP) || defined(HAVE_STD_HASH_MAP))
28 #define HAVE_STL_HASH_MAP
32 (defined(HAVE_STD_UNORDERED_MAP) || defined(HAVE_TR1_UNORDERED_MAP))
34 #if defined(HAVE_STD_UNORDERED_MAP)
35 #include <unordered_map>
36 #define WX_HASH_MAP_NAMESPACE std
37 #elif defined(HAVE_TR1_UNORDERED_MAP)
38 #include <tr1/unordered_map>
39 #define WX_HASH_MAP_NAMESPACE std::tr1
42 #define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \
43 typedef WX_HASH_MAP_NAMESPACE::unordered_map< KEY_T, VALUE_T, HASH_T, KEY_EQ_T > CLASSNAME
45 #elif wxUSE_STL && defined(HAVE_STL_HASH_MAP)
47 #if defined(HAVE_EXT_HASH_MAP)
48 #include <ext/hash_map>
49 #elif defined(HAVE_HASH_MAP)
53 #if defined(HAVE_GNU_CXX_HASH_MAP)
54 #define WX_HASH_MAP_NAMESPACE __gnu_cxx
55 #elif defined(HAVE_STD_HASH_MAP)
56 #define WX_HASH_MAP_NAMESPACE std
59 #define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \
60 typedef WX_HASH_MAP_NAMESPACE::hash_map< KEY_T, VALUE_T, HASH_T, KEY_EQ_T > CLASSNAME
62 #else // !wxUSE_STL || no std::{hash,unordered}_map class available
64 #define wxNEEDS_WX_HASH_MAP
67 typedef int ptrdiff_t;
69 #include <stddef.h> // for ptrdiff_t
73 struct WXDLLIMPEXP_BASE _wxHashTable_NodeBase
75 _wxHashTable_NodeBase() : m_next(NULL
) {}
77 _wxHashTable_NodeBase
* m_next
;
80 // DECLARE_NO_COPY_CLASS(_wxHashTable_NodeBase)
81 // without rewriting the macros, which require a public copy constructor.
85 class WXDLLIMPEXP_BASE _wxHashTableBase2
88 typedef void (*NodeDtor
)(_wxHashTable_NodeBase
*);
89 typedef unsigned long (*BucketFromNode
)(_wxHashTableBase2
*,_wxHashTable_NodeBase
*);
90 typedef _wxHashTable_NodeBase
* (*ProcessNode
)(_wxHashTable_NodeBase
*);
92 static _wxHashTable_NodeBase
* DummyProcessNode(_wxHashTable_NodeBase
* node
);
93 static void DeleteNodes( size_t buckets
, _wxHashTable_NodeBase
** table
,
95 static _wxHashTable_NodeBase
* GetFirstNode( size_t buckets
,
96 _wxHashTable_NodeBase
** table
)
98 for( size_t i
= 0; i
< buckets
; ++i
)
104 // as static const unsigned prime_count = 31 but works with all compilers
105 enum { prime_count
= 31 };
106 static const unsigned long ms_primes
[prime_count
];
108 // returns the first prime in ms_primes greater than n
109 static unsigned long GetNextPrime( unsigned long n
);
111 // returns the first prime in ms_primes smaller than n
112 // ( or ms_primes[0] if n is very small )
113 static unsigned long GetPreviousPrime( unsigned long n
);
115 static void CopyHashTable( _wxHashTable_NodeBase
** srcTable
,
116 size_t srcBuckets
, _wxHashTableBase2
* dst
,
117 _wxHashTable_NodeBase
** dstTable
,
118 BucketFromNode func
, ProcessNode proc
);
120 static void** AllocTable( size_t sz
)
122 return (void **)calloc(sz
, sizeof(void*));
124 static void FreeTable(void *table
)
130 #define _WX_DECLARE_HASHTABLE( VALUE_T, KEY_T, HASH_T, KEY_EX_T, KEY_EQ_T, CLASSNAME, CLASSEXP, SHOULD_GROW, SHOULD_SHRINK ) \
131 CLASSEXP CLASSNAME : protected _wxHashTableBase2 \
134 typedef KEY_T key_type; \
135 typedef VALUE_T value_type; \
136 typedef HASH_T hasher; \
137 typedef KEY_EQ_T key_equal; \
139 typedef size_t size_type; \
140 typedef ptrdiff_t difference_type; \
141 typedef value_type* pointer; \
142 typedef const value_type* const_pointer; \
143 typedef value_type& reference; \
144 typedef const value_type& const_reference; \
145 /* should these be protected? */ \
146 typedef const KEY_T const_key_type; \
147 typedef const VALUE_T const_mapped_type; \
149 typedef KEY_EX_T key_extractor; \
150 typedef CLASSNAME Self; \
152 _wxHashTable_NodeBase** m_table; \
153 size_t m_tableBuckets; \
156 key_equal m_equals; \
157 key_extractor m_getKey; \
159 struct Node:public _wxHashTable_NodeBase \
162 Node( const value_type& value ) \
163 : m_value( value ) {} \
164 Node* next() { return wx_static_cast(Node*, m_next); } \
166 value_type m_value; \
170 static void DeleteNode( _wxHashTable_NodeBase* node ) \
172 delete wx_static_cast(Node*, node); \
176 /* forward iterator */ \
184 Iterator() : m_node(NULL), m_ht(NULL) {} \
185 Iterator( Node* node, const Self* ht ) \
186 : m_node(node), m_ht(wx_const_cast(Self*, ht)) {} \
187 bool operator ==( const Iterator& it ) const \
188 { return m_node == it.m_node; } \
189 bool operator !=( const Iterator& it ) const \
190 { return m_node != it.m_node; } \
192 Node* GetNextNode() \
194 size_type bucket = GetBucketForNode(m_ht,m_node); \
195 for( size_type i = bucket + 1; i < m_ht->m_tableBuckets; ++i ) \
197 if( m_ht->m_table[i] ) \
198 return wx_static_cast(Node*, m_ht->m_table[i]); \
205 Node* next = m_node->next(); \
206 m_node = next ? next : GetNextNode(); \
209 friend class Iterator; \
212 CLASSEXP iterator : public Iterator \
215 iterator() : Iterator() {} \
216 iterator( Node* node, Self* ht ) : Iterator( node, ht ) {} \
217 iterator& operator++() { PlusPlus(); return *this; } \
218 iterator operator++(int) { iterator it=*this;PlusPlus();return it; } \
219 reference operator *() const { return m_node->m_value; } \
220 pointer operator ->() const { return &(m_node->m_value); } \
223 CLASSEXP const_iterator : public Iterator \
226 const_iterator() : Iterator() {} \
227 const_iterator(iterator i) : Iterator(i) {} \
228 const_iterator( Node* node, const Self* ht ) \
229 : Iterator(node, wx_const_cast(Self*, ht)) {} \
230 const_iterator& operator++() { PlusPlus();return *this; } \
231 const_iterator operator++(int) { const_iterator it=*this;PlusPlus();return it; } \
232 const_reference operator *() const { return m_node->m_value; } \
233 const_pointer operator ->() const { return &(m_node->m_value); } \
236 CLASSNAME( size_type sz = 10, const hasher& hfun = hasher(), \
237 const key_equal& k_eq = key_equal(), \
238 const key_extractor& k_ex = key_extractor() ) \
239 : m_tableBuckets( GetNextPrime( (unsigned long) sz ) ), \
245 m_table = (_wxHashTable_NodeBase**)AllocTable(m_tableBuckets); \
248 CLASSNAME( const Self& ht ) \
250 m_tableBuckets( 0 ), \
251 m_items( ht.m_items ), \
252 m_hasher( ht.m_hasher ), \
253 m_equals( ht.m_equals ), \
254 m_getKey( ht.m_getKey ) \
259 const Self& operator=( const Self& ht ) \
264 m_hasher = ht.m_hasher; \
265 m_equals = ht.m_equals; \
266 m_getKey = ht.m_getKey; \
267 m_items = ht.m_items; \
277 FreeTable(m_table); \
280 hasher hash_funct() { return m_hasher; } \
281 key_equal key_eq() { return m_equals; } \
283 /* removes all elements from the hash table, but does not */ \
284 /* shrink it ( perhaps it should ) */ \
287 DeleteNodes(m_tableBuckets, m_table, DeleteNode); \
291 size_type size() const { return m_items; } \
292 size_type max_size() const { return size_type(-1); } \
293 bool empty() const { return size() == 0; } \
295 const_iterator end() const { return const_iterator(NULL, this); } \
296 iterator end() { return iterator(NULL, this); } \
297 const_iterator begin() const \
298 { return const_iterator(wx_static_cast(Node*, GetFirstNode(m_tableBuckets, m_table)), this); } \
300 { return iterator(wx_static_cast(Node*, GetFirstNode(m_tableBuckets, m_table)), this); } \
302 size_type erase( const const_key_type& key ) \
304 _wxHashTable_NodeBase** node = GetNodePtr(key); \
310 _wxHashTable_NodeBase* temp = (*node)->m_next; \
311 delete wx_static_cast(Node*, *node); \
313 if( SHOULD_SHRINK( m_tableBuckets, m_items ) ) \
314 ResizeTable( GetPreviousPrime( (unsigned long) m_tableBuckets ) - 1 ); \
319 static size_type GetBucketForNode( Self* ht, Node* node ) \
321 return ht->m_hasher( ht->m_getKey( node->m_value ) ) \
322 % ht->m_tableBuckets; \
324 static Node* CopyNode( Node* node ) { return new Node( *node ); } \
326 Node* GetOrCreateNode( const value_type& value, bool& created ) \
328 const const_key_type& key = m_getKey( value ); \
329 size_t bucket = m_hasher( key ) % m_tableBuckets; \
330 Node* node = wx_static_cast(Node*, m_table[bucket]); \
334 if( m_equals( m_getKey( node->m_value ), key ) ) \
339 node = node->next(); \
342 return CreateNode( value, bucket); \
344 Node * CreateNode( const value_type& value, size_t bucket ) \
346 Node* node = new Node( value ); \
347 node->m_next = m_table[bucket]; \
348 m_table[bucket] = node; \
350 /* must be after the node is inserted */ \
352 if( SHOULD_GROW( m_tableBuckets, m_items ) ) \
353 ResizeTable( m_tableBuckets ); \
357 void CreateNode( const value_type& value ) \
359 CreateNode(value, m_hasher( m_getKey(value) ) % m_tableBuckets ); \
362 /* returns NULL if not found */ \
363 _wxHashTable_NodeBase** GetNodePtr(const const_key_type& key) const \
365 size_t bucket = m_hasher( key ) % m_tableBuckets; \
366 _wxHashTable_NodeBase** node = &m_table[bucket]; \
370 if (m_equals(m_getKey(wx_static_cast(Node*, *node)->m_value), key)) \
372 node = &(*node)->m_next; \
378 /* returns NULL if not found */ \
379 /* expressing it in terms of GetNodePtr is 5-8% slower :-( */ \
380 Node* GetNode( const const_key_type& key ) const \
382 size_t bucket = m_hasher( key ) % m_tableBuckets; \
383 Node* node = wx_static_cast(Node*, m_table[bucket]); \
387 if( m_equals( m_getKey( node->m_value ), key ) ) \
389 node = node->next(); \
395 void ResizeTable( size_t newSize ) \
397 newSize = GetNextPrime( (unsigned long)newSize ); \
398 _wxHashTable_NodeBase** srcTable = m_table; \
399 size_t srcBuckets = m_tableBuckets; \
400 m_table = (_wxHashTable_NodeBase**)AllocTable( newSize ); \
401 m_tableBuckets = newSize; \
403 CopyHashTable( srcTable, srcBuckets, \
405 (BucketFromNode)GetBucketForNode,\
406 (ProcessNode)&DummyProcessNode ); \
407 FreeTable(srcTable); \
410 /* this must be called _after_ m_table has been cleaned */ \
411 void HashCopy( const Self& ht ) \
413 ResizeTable( ht.size() ); \
414 CopyHashTable( ht.m_table, ht.m_tableBuckets, \
415 (_wxHashTableBase2*)this, \
417 (BucketFromNode)GetBucketForNode, \
418 (ProcessNode)CopyNode ); \
422 // defines an STL-like pair class CLASSNAME storing two fields: first of type
423 // KEY_T and second of type VALUE_T
424 #define _WX_DECLARE_PAIR( KEY_T, VALUE_T, CLASSNAME, CLASSEXP ) \
429 typedef VALUE_T t2; \
430 typedef const KEY_T const_t1; \
431 typedef const VALUE_T const_t2; \
433 CLASSNAME(const const_t1& f, const const_t2& s) \
434 : first(wx_const_cast(t1&, f)), second(wx_const_cast(t2&, s)) {} \
440 // defines the class CLASSNAME returning the key part (of type KEY_T) from a
441 // pair of type PAIR_T
442 #define _WX_DECLARE_HASH_MAP_KEY_EX( KEY_T, PAIR_T, CLASSNAME, CLASSEXP ) \
445 typedef KEY_T key_type; \
446 typedef PAIR_T pair_type; \
447 typedef const key_type const_key_type; \
448 typedef const pair_type const_pair_type; \
449 typedef const_key_type& const_key_reference; \
450 typedef const_pair_type& const_pair_reference; \
453 const_key_reference operator()( const_pair_reference pair ) const { return pair.first; }\
455 /* the dummy assignment operator is needed to suppress compiler */ \
456 /* warnings from hash table class' operator=(): gcc complains about */ \
457 /* "statement with no effect" without it */ \
458 CLASSNAME& operator=(const CLASSNAME&) { return *this; } \
461 // grow/shrink predicates
462 inline bool never_grow( size_t, size_t ) { return false; }
463 inline bool never_shrink( size_t, size_t ) { return false; }
464 inline bool grow_lf70( size_t buckets
, size_t items
)
466 return float(items
)/float(buckets
) >= 0.85;
469 #endif // various hash map implementations
471 // ----------------------------------------------------------------------------
472 // hashing and comparison functors
473 // ----------------------------------------------------------------------------
475 // NB: implementation detail: all of these classes must have dummy assignment
476 // operators to suppress warnings about "statement with no effect" from gcc
477 // in the hash table class assignment operator (where they're assigned)
479 #ifndef wxNEEDS_WX_HASH_MAP
482 class WXDLLIMPEXP_BASE wxIntegerHash
484 WX_HASH_MAP_NAMESPACE::hash
<long> longHash
;
485 WX_HASH_MAP_NAMESPACE::hash
<unsigned long> ulongHash
;
486 WX_HASH_MAP_NAMESPACE::hash
<int> intHash
;
487 WX_HASH_MAP_NAMESPACE::hash
<unsigned int> uintHash
;
488 WX_HASH_MAP_NAMESPACE::hash
<short> shortHash
;
489 WX_HASH_MAP_NAMESPACE::hash
<unsigned short> ushortHash
;
491 #if defined wxLongLong_t && !defined wxLongLongIsLong
492 // hash<wxLongLong_t> ought to work but doesn't on some compilers
493 #if (!defined SIZEOF_LONG_LONG && SIZEOF_LONG == 4) \
494 || (defined SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_LONG * 2)
495 size_t longlongHash( wxLongLong_t x
) const
497 return longHash( wx_truncate_cast(long, x
) ) ^
498 longHash( wx_truncate_cast(long, x
>> (sizeof(long) * 8)) );
500 #elif defined SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_LONG
501 WX_HASH_MAP_NAMESPACE::hash
<long> longlongHash
;
503 WX_HASH_MAP_NAMESPACE::hash
<wxLongLong_t
> longlongHash
;
509 size_t operator()( long x
) const { return longHash( x
); }
510 size_t operator()( unsigned long x
) const { return ulongHash( x
); }
511 size_t operator()( int x
) const { return intHash( x
); }
512 size_t operator()( unsigned int x
) const { return uintHash( x
); }
513 size_t operator()( short x
) const { return shortHash( x
); }
514 size_t operator()( unsigned short x
) const { return ushortHash( x
); }
515 #if defined wxLongLong_t && !defined wxLongLongIsLong
516 size_t operator()( wxLongLong_t x
) const { return longlongHash(x
); }
517 size_t operator()( wxULongLong_t x
) const { return longlongHash(x
); }
520 wxIntegerHash
& operator=(const wxIntegerHash
&) { return *this; }
523 #else // wxNEEDS_WX_HASH_MAP
526 class WXDLLIMPEXP_BASE wxIntegerHash
530 unsigned long operator()( long x
) const { return (unsigned long)x
; }
531 unsigned long operator()( unsigned long x
) const { return x
; }
532 unsigned long operator()( int x
) const { return (unsigned long)x
; }
533 unsigned long operator()( unsigned int x
) const { return x
; }
534 unsigned long operator()( short x
) const { return (unsigned long)x
; }
535 unsigned long operator()( unsigned short x
) const { return x
; }
536 #if defined wxLongLong_t && !defined wxLongLongIsLong
537 wxULongLong_t
operator()( wxLongLong_t x
) const { return wx_static_cast(wxULongLong_t
, x
); }
538 wxULongLong_t
operator()( wxULongLong_t x
) const { return x
; }
541 wxIntegerHash
& operator=(const wxIntegerHash
&) { return *this; }
544 #endif // !wxNEEDS_WX_HASH_MAP/wxNEEDS_WX_HASH_MAP
546 class WXDLLIMPEXP_BASE wxIntegerEqual
550 bool operator()( long a
, long b
) const { return a
== b
; }
551 bool operator()( unsigned long a
, unsigned long b
) const { return a
== b
; }
552 bool operator()( int a
, int b
) const { return a
== b
; }
553 bool operator()( unsigned int a
, unsigned int b
) const { return a
== b
; }
554 bool operator()( short a
, short b
) const { return a
== b
; }
555 bool operator()( unsigned short a
, unsigned short b
) const { return a
== b
; }
556 #if defined wxLongLong_t && !defined wxLongLongIsLong
557 bool operator()( wxLongLong_t a
, wxLongLong_t b
) const { return a
== b
; }
558 bool operator()( wxULongLong_t a
, wxULongLong_t b
) const { return a
== b
; }
561 wxIntegerEqual
& operator=(const wxIntegerEqual
&) { return *this; }
565 class WXDLLIMPEXP_BASE wxPointerHash
570 #ifdef wxNEEDS_WX_HASH_MAP
571 wxUIntPtr
operator()( const void* k
) const { return wxPtrToUInt(k
); }
573 size_t operator()( const void* k
) const { return (size_t)k
; }
576 wxPointerHash
& operator=(const wxPointerHash
&) { return *this; }
579 class 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 class WXDLLIMPEXP_BASE wxStringHash
593 unsigned long operator()( const wxString
& x
) const
594 { return stringHash( x
.wx_str() ); }
595 unsigned long operator()( const wchar_t* x
) const
596 { return stringHash( x
); }
597 unsigned long operator()( const char* x
) const
598 { return stringHash( x
); }
600 #if WXWIN_COMPATIBILITY_2_8
601 static unsigned long wxCharStringHash( const wxChar
* x
)
602 { return stringHash(x
); }
604 static unsigned long charStringHash( const char* x
)
605 { return stringHash(x
); }
607 #endif // WXWIN_COMPATIBILITY_2_8
609 static unsigned long stringHash( const wchar_t* );
610 static unsigned long stringHash( const char* );
612 wxStringHash
& operator=(const wxStringHash
&) { return *this; }
615 class WXDLLIMPEXP_BASE wxStringEqual
619 bool operator()( const wxString
& a
, const wxString
& b
) const
621 bool operator()( const wxChar
* a
, const wxChar
* b
) const
622 { return wxStrcmp( a
, b
) == 0; }
624 bool operator()( const char* a
, const char* b
) const
625 { return strcmp( a
, b
) == 0; }
626 #endif // wxUSE_UNICODE
628 wxStringEqual
& operator=(const wxStringEqual
&) { return *this; }
631 #ifdef wxNEEDS_WX_HASH_MAP
633 #define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \
634 _WX_DECLARE_PAIR( KEY_T, VALUE_T, CLASSNAME##_wxImplementation_Pair, CLASSEXP ) \
635 _WX_DECLARE_HASH_MAP_KEY_EX( KEY_T, CLASSNAME##_wxImplementation_Pair, CLASSNAME##_wxImplementation_KeyEx, CLASSEXP ) \
636 _WX_DECLARE_HASHTABLE( CLASSNAME##_wxImplementation_Pair, KEY_T, HASH_T, CLASSNAME##_wxImplementation_KeyEx, KEY_EQ_T, CLASSNAME##_wxImplementation_HashTable, CLASSEXP, grow_lf70, never_shrink ) \
637 CLASSEXP CLASSNAME:public CLASSNAME##_wxImplementation_HashTable \
640 typedef VALUE_T mapped_type; \
641 _WX_DECLARE_PAIR( iterator, bool, Insert_Result, CLASSEXP ) \
643 wxEXPLICIT CLASSNAME( size_type hint = 100, hasher hf = hasher(), \
644 key_equal eq = key_equal() ) \
645 : CLASSNAME##_wxImplementation_HashTable( hint, hf, eq, \
646 CLASSNAME##_wxImplementation_KeyEx() ) {} \
648 mapped_type& operator[]( const const_key_type& key ) \
651 return GetOrCreateNode( \
652 CLASSNAME##_wxImplementation_Pair( key, mapped_type() ), \
653 created)->m_value.second; \
656 const_iterator find( const const_key_type& key ) const \
658 return const_iterator( GetNode( key ), this ); \
661 iterator find( const const_key_type& key ) \
663 return iterator( GetNode( key ), this ); \
666 Insert_Result insert( const value_type& v ) \
669 Node *node = GetOrCreateNode( \
670 CLASSNAME##_wxImplementation_Pair( v.first, v.second ), \
673 node->m_value.second = v.second; \
674 return Insert_Result(iterator(node, this), created); \
677 size_type erase( const key_type& k ) \
678 { return CLASSNAME##_wxImplementation_HashTable::erase( k ); } \
679 void erase( const iterator& it ) { erase( it->first ); } \
680 void erase( const const_iterator& it ) { erase( it->first ); } \
682 /* count() == 0 | 1 */ \
683 size_type count( const const_key_type& key ) \
685 /* explicit cast needed to suppress CodeWarrior warnings */ \
686 return (size_type)(GetNode( key ) ? 1 : 0); \
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
);
750 #endif // _WX_HASHMAP_H_