]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/hashset.h | |
3 | // Purpose: wxHashSet class | |
4 | // Author: Mattia Barbon | |
5 | // Modified by: | |
6 | // Created: 11/08/2003 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Mattia Barbon | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_HASHSET_H_ | |
13 | #define _WX_HASHSET_H_ | |
14 | ||
15 | #include "wx/hashmap.h" | |
16 | ||
17 | #if wxUSE_STL && defined(HAVE_STL_HASH_MAP) | |
18 | ||
19 | #if defined(HAVE_EXT_HASH_MAP) | |
20 | #include <ext/hash_set> | |
21 | #elif defined(HAVE_HASH_MAP) | |
22 | #include <hash_set> | |
23 | #endif | |
24 | ||
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 | |
27 | ||
28 | #else // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP) | |
29 | ||
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 ) \ | |
32 | CLASSEXP CLASSNAME \ | |
33 | { \ | |
34 | typedef KEY_T key_type; \ | |
35 | typedef const key_type const_key_type; \ | |
36 | typedef const_key_type& const_key_reference; \ | |
37 | public: \ | |
38 | CLASSNAME() { } \ | |
39 | const_key_reference operator()( const_key_reference key ) const \ | |
40 | { return key; } \ | |
41 | \ | |
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; } \ | |
46 | }; | |
47 | ||
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 \ | |
52 | { \ | |
53 | public: \ | |
54 | _WX_DECLARE_PAIR( iterator, bool, Insert_Result, CLASSEXP ) \ | |
55 | \ | |
56 | wxEXPLICIT CLASSNAME( size_type hint = 100, hasher hf = hasher(), \ | |
57 | key_equal eq = key_equal() ) \ | |
58 | : CLASSNAME##_wxImplementation_HashTable( hint, hf, eq, \ | |
59 | CLASSNAME##_wxImplementation_KeyEx() ) {} \ | |
60 | \ | |
61 | Insert_Result insert( const key_type& key ) \ | |
62 | { \ | |
63 | bool created; \ | |
64 | Node *node = GetOrCreateNode( key, created ); \ | |
65 | return Insert_Result( iterator( node, this ), created ); \ | |
66 | } \ | |
67 | \ | |
68 | const_iterator find( const const_key_type& key ) const \ | |
69 | { \ | |
70 | return const_iterator( GetNode( key ), this ); \ | |
71 | } \ | |
72 | \ | |
73 | iterator find( const const_key_type& key ) \ | |
74 | { \ | |
75 | return iterator( GetNode( key ), this ); \ | |
76 | } \ | |
77 | \ | |
78 | size_type erase( const key_type& k ) \ | |
79 | { return CLASSNAME##_wxImplementation_HashTable::erase( k ); } \ | |
80 | void erase( const iterator& it ) { erase( *it ); } \ | |
81 | void erase( const const_iterator& it ) { erase( *it ); } \ | |
82 | \ | |
83 | /* count() == 0 | 1 */ \ | |
84 | size_type count( const const_key_type& key ) \ | |
85 | { return GetNode( key ) ? 1 : 0; } \ | |
86 | } | |
87 | ||
88 | #endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP) | |
89 | ||
90 | // these macros are to be used in the user code | |
91 | #define WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME) \ | |
92 | _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, class ) | |
93 | ||
94 | // and these do exactly the same thing but should be used inside the | |
95 | // library | |
96 | #define WX_DECLARE_HASH_SET_WITH_DECL( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL) \ | |
97 | _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL ) | |
98 | ||
99 | #define WX_DECLARE_EXPORTED_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME) \ | |
100 | WX_DECLARE_HASH_SET_WITH_DECL( KEY_T, HASH_T, KEY_EQ_T, \ | |
101 | CLASSNAME, class WXDLLEXPORT ) | |
102 | ||
103 | // delete all hash elements | |
104 | // | |
105 | // NB: the class declaration of the hash elements must be visible from the | |
106 | // place where you use this macro, otherwise the proper destructor may not | |
107 | // be called (a decent compiler should give a warning about it, but don't | |
108 | // count on it)! | |
109 | #define WX_CLEAR_HASH_SET(type, hashset) \ | |
110 | WX_CLEAR_HASH_MAP(type, hashset) | |
111 | ||
112 | #endif // _WX_HASHSET_H_ |