]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/hashset.h
3cc80a8f5d172d564b2288c13fdf586991ce69cc
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHashSet class
4 // Author: Mattia Barbon
8 // Copyright: (c) Mattia Barbon
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_HASHSET_H_
13 #define _WX_HASHSET_H_
15 #include "wx/hashmap.h"
17 #if wxUSE_STL && defined(HAVE_STL_HASH_MAP)
19 #if defined(HAVE_EXT_HASH_MAP)
20 #include <ext/hash_set>
21 #elif defined(HAVE_HASH_MAP)
25 #define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP )\
26 typedef WX_HASH_MAP_NAMESPACE::hash_set< KEY_T, HASH_T, KEY_EQ_T > CLASSNAME;
28 #else // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
30 // this is a complex way of defining an easily inlineable identity function...
31 #define _WX_DECLARE_HASH_SET_KEY_EX( KEY_T, CLASSNAME, CLASSEXP ) \
34 typedef KEY_T key_type; \
35 typedef const key_type const_key_type; \
36 typedef const_key_type& const_key_reference; \
39 const_key_reference operator()( const_key_reference key ) const \
42 /* the dummy assignment operator is needed to suppress compiler */ \
43 /* warnings from hash table class' operator=(): gcc complains about */ \
44 /* "statement with no effect" without it */ \
45 CLASSNAME& operator=(const CLASSNAME&) { return *this; } \
48 #define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP )\
49 _WX_DECLARE_HASH_SET_KEY_EX( KEY_T, CLASSNAME##_wxImplementation_KeyEx, CLASSEXP ) \
50 _WX_DECLARE_HASHTABLE( KEY_T, KEY_T, HASH_T, CLASSNAME##_wxImplementation_KeyEx, KEY_EQ_T, CLASSNAME##_wxImplementation_HashTable, CLASSEXP, grow_lf70, never_shrink ) \
51 CLASSEXP CLASSNAME:public CLASSNAME##_wxImplementation_HashTable \
54 wxEXPLICIT CLASSNAME( size_type hint = 100, hasher hf = hasher(), \
55 key_equal eq = key_equal() ) \
56 : CLASSNAME##_wxImplementation_HashTable( hint, hf, eq, \
57 CLASSNAME##_wxImplementation_KeyEx() ) {} \
59 void insert( const key_type& key ) \
61 GetOrCreateNode( key ); \
64 const_iterator find( const const_key_type& key ) const \
66 return const_iterator( GetNode( key ), this ); \
69 iterator find( const const_key_type& key ) \
71 return iterator( GetNode( key ), this ); \
74 size_type erase( const key_type& k ) \
75 { return CLASSNAME##_wxImplementation_HashTable::erase( k ); } \
76 void erase( const iterator& it ) { erase( *it ); } \
77 void erase( const const_iterator& it ) { erase( *it ); } \
79 /* count() == 0 | 1 */ \
80 size_type count( const const_key_type& key ) \
81 { return GetNode( key ) ? 1 : 0; } \
84 #endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
86 // these macros are to be used in the user code
87 #define WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME) \
88 _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, class )
90 // and these do exactly the same thing but should be used inside the
92 #define WX_DECLARE_HASH_SET_WITH_DECL( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL) \
93 _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL )
95 #define WX_DECLARE_EXPORTED_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME) \
96 WX_DECLARE_HASH_SET_WITH_DECL( KEY_T, HASH_T, KEY_EQ_T, \
97 CLASSNAME, class WXDLLEXPORT )
99 // delete all hash elements
101 // NB: the class declaration of the hash elements must be visible from the
102 // place where you use this macro, otherwise the proper destructor may not
103 // be called (a decent compiler should give a warning about it, but don't
105 #define WX_CLEAR_HASH_SET(type, hashset) \
106 WX_CLEAR_HASH_MAP(type, hashset)
108 #endif // _WX_HASHSET_H_