]> git.saurik.com Git - wxWidgets.git/blob - include/wx/hashset.h
added wxFileConfig::Save(stream); documented it in new, separate from wxConfig, wxFil...
[wxWidgets.git] / include / wx / hashset.h
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 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() ) {} \
58 \
59 void insert( const key_type& key ) \
60 { \
61 GetOrCreateNode( key ); \
62 } \
63 \
64 const_iterator find( const const_key_type& key ) const \
65 { \
66 return const_iterator( GetNode( key ), this ); \
67 } \
68 \
69 iterator find( const const_key_type& key ) \
70 { \
71 return iterator( GetNode( key ), this ); \
72 } \
73 \
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 ); } \
78 \
79 /* count() == 0 | 1 */ \
80 size_type count( const const_key_type& key ) \
81 { return GetNode( key ) ? 1 : 0; } \
82 }
83
84 #endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
85
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 )
89
90 // and these do exactly the same thing but should be used inside the
91 // library
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 )
94
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 )
98
99 // delete all hash elements
100 //
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
104 // count on it)!
105 #define WX_CLEAR_HASH_SET(type, hashset) \
106 WX_CLEAR_HASH_MAP(type, hashset)
107
108 #endif // _WX_HASHSET_H_