]> git.saurik.com Git - wxWidgets.git/blame - include/wx/hashset.h
capitalize the application name in GetAppDisplayName() by default; this results in...
[wxWidgets.git] / include / wx / hashset.h
CommitLineData
8142d704
MB
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
65571936 9// Licence: wxWindows licence
8142d704
MB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_HASHSET_H_
13#define _WX_HASHSET_H_
14
15#include "wx/hashmap.h"
16
f380544a
VZ
17// see comment in wx/hashmap.h which also applies to different standard hash
18// set classes
19
20#if wxUSE_STL && \
21 (defined(HAVE_STD_UNORDERED_SET) || defined(HAVE_TR1_UNORDERED_SET))
22
23#if defined(HAVE_STD_UNORDERED_SET)
24 #include <unordered_set>
25 #define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP )\
26 typedef std::unordered_set< KEY_T, HASH_T, KEY_EQ_T > CLASSNAME
27#elif defined(HAVE_TR1_UNORDERED_SET)
28 #include <tr1/unordered_set>
29 #define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP )\
30 typedef std::tr1::unordered_set< KEY_T, HASH_T, KEY_EQ_T > CLASSNAME
31#else
32#error Update this code: unordered_set is available, but I do not know where.
33#endif
34
35#elif wxUSE_STL && defined(HAVE_STL_HASH_MAP)
bdcade0a
MB
36
37#if defined(HAVE_EXT_HASH_MAP)
38 #include <ext/hash_set>
39#elif defined(HAVE_HASH_MAP)
40 #include <hash_set>
41#endif
42
43#define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP )\
e786a78b 44 typedef WX_HASH_MAP_NAMESPACE::hash_set< KEY_T, HASH_T, KEY_EQ_T > CLASSNAME
bdcade0a
MB
45
46#else // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
47
8142d704
MB
48// this is a complex way of defining an easily inlineable identity function...
49#define _WX_DECLARE_HASH_SET_KEY_EX( KEY_T, CLASSNAME, CLASSEXP ) \
50CLASSEXP CLASSNAME \
51{ \
52 typedef KEY_T key_type; \
53 typedef const key_type const_key_type; \
54 typedef const_key_type& const_key_reference; \
55public: \
56 CLASSNAME() { } \
57 const_key_reference operator()( const_key_reference key ) const \
58 { return key; } \
59 \
60 /* the dummy assignment operator is needed to suppress compiler */ \
61 /* warnings from hash table class' operator=(): gcc complains about */ \
62 /* "statement with no effect" without it */ \
63 CLASSNAME& operator=(const CLASSNAME&) { return *this; } \
64};
65
66#define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP )\
67_WX_DECLARE_HASH_SET_KEY_EX( KEY_T, CLASSNAME##_wxImplementation_KeyEx, CLASSEXP ) \
68_WX_DECLARE_HASHTABLE( KEY_T, KEY_T, HASH_T, CLASSNAME##_wxImplementation_KeyEx, KEY_EQ_T, CLASSNAME##_wxImplementation_HashTable, CLASSEXP, grow_lf70, never_shrink ) \
69CLASSEXP CLASSNAME:public CLASSNAME##_wxImplementation_HashTable \
70{ \
71public: \
d7ab66a1
MB
72 _WX_DECLARE_PAIR( iterator, bool, Insert_Result, CLASSEXP ) \
73 \
d8771ac7
MB
74 wxEXPLICIT CLASSNAME( size_type hint = 100, hasher hf = hasher(), \
75 key_equal eq = key_equal() ) \
8142d704
MB
76 : CLASSNAME##_wxImplementation_HashTable( hint, hf, eq, \
77 CLASSNAME##_wxImplementation_KeyEx() ) {} \
78 \
d7ab66a1 79 Insert_Result insert( const key_type& key ) \
8142d704 80 { \
d7ab66a1
MB
81 bool created; \
82 Node *node = GetOrCreateNode( key, created ); \
83 return Insert_Result( iterator( node, this ), created ); \
8142d704
MB
84 } \
85 \
86 const_iterator find( const const_key_type& key ) const \
87 { \
88 return const_iterator( GetNode( key ), this ); \
89 } \
90 \
91 iterator find( const const_key_type& key ) \
92 { \
93 return iterator( GetNode( key ), this ); \
94 } \
95 \
96 size_type erase( const key_type& k ) \
97 { return CLASSNAME##_wxImplementation_HashTable::erase( k ); } \
98 void erase( const iterator& it ) { erase( *it ); } \
99 void erase( const const_iterator& it ) { erase( *it ); } \
100 \
101 /* count() == 0 | 1 */ \
102 size_type count( const const_key_type& key ) \
103 { return GetNode( key ) ? 1 : 0; } \
3f5c62f9 104}
8142d704 105
bdcade0a
MB
106#endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
107
8142d704
MB
108// these macros are to be used in the user code
109#define WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME) \
110 _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, class )
111
112// and these do exactly the same thing but should be used inside the
113// library
114#define WX_DECLARE_HASH_SET_WITH_DECL( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL) \
115 _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME, DECL )
116
117#define WX_DECLARE_EXPORTED_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, CLASSNAME) \
118 WX_DECLARE_HASH_SET_WITH_DECL( KEY_T, HASH_T, KEY_EQ_T, \
53a2db12 119 CLASSNAME, class WXDLLIMPEXP_CORE )
8142d704
MB
120
121// delete all hash elements
122//
123// NB: the class declaration of the hash elements must be visible from the
124// place where you use this macro, otherwise the proper destructor may not
125// be called (a decent compiler should give a warning about it, but don't
126// count on it)!
127#define WX_CLEAR_HASH_SET(type, hashset) \
3115bfa8
VS
128 { \
129 type::iterator it, en; \
130 for( it = (hashset).begin(), en = (hashset).end(); it != en; ++it ) \
131 delete *it; \
132 (hashset).clear(); \
133 }
8142d704
MB
134
135#endif // _WX_HASHSET_H_