X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/68c30476e796c7604eaf0679862d0a1104089644..b057f88ab8d0d448e094204802c9033fad271ccc:/include/wx/hashmap.h diff --git a/include/wx/hashmap.h b/include/wx/hashmap.h index 95314ada5a..89601b6ec3 100644 --- a/include/wx/hashmap.h +++ b/include/wx/hashmap.h @@ -143,8 +143,8 @@ public: \ value_type m_value; \ }; \ \ - struct Iterator; \ - friend struct Iterator; \ + CLASSEXP Iterator; \ + friend CLASSEXP Iterator; \ protected: \ static void DeleteNode( _wxHashTable_NodeBase* node ) \ { \ @@ -154,8 +154,9 @@ public: \ /* */ \ /* forward iterator */ \ /* */ \ - struct Iterator \ + CLASSEXP Iterator \ { \ + public: \ Node* m_node; \ Self* m_ht; \ \ @@ -186,8 +187,9 @@ public: \ }; \ \ public: \ - struct iterator:public Iterator \ + CLASSEXP iterator : public Iterator \ { \ + public: \ iterator() : Iterator() {} \ iterator( Node* node, Self* ht ) : Iterator( node, ht ) {} \ iterator& operator++() { PlusPlus(); return *this; } \ @@ -196,8 +198,9 @@ public: \ pointer operator ->() const { return &(m_node->m_value); } \ }; \ \ - struct const_iterator:public Iterator \ + CLASSEXP const_iterator : public Iterator \ { \ + public: \ const_iterator() : Iterator() {} \ const_iterator( Node* node, const Self* ht ) \ : Iterator( node, (Self*)ht ) {} \ @@ -295,7 +298,7 @@ protected: \ } \ static Node* CopyNode( Node* node ) { return new Node( *node ); } \ \ - Node* GetOrCreateNode( const value_type& value ) \ + Node* GetOrCreateNode( const value_type& value, bool& created ) \ { \ const const_key_type& key = m_getKey( value ); \ size_t bucket = m_hasher( key ) % m_tableBuckets; \ @@ -304,10 +307,14 @@ protected: \ while( node ) \ { \ if( m_equals( m_getKey( node->m_value ), key ) ) \ + { \ + created = false; \ return node; \ + } \ node = node->m_next(); \ } \ - return CreateNode( value , bucket); \ + created = true; \ + return CreateNode( value, bucket); \ }\ Node * CreateNode( const value_type& value, size_t bucket ) \ {\ @@ -426,8 +433,8 @@ public: \ }; // grow/shrink predicates -inline bool never_grow( size_t, size_t ) { return FALSE; } -inline bool never_shrink( size_t, size_t ) { return FALSE; } +inline bool never_grow( size_t, size_t ) { return false; } +inline bool never_shrink( size_t, size_t ) { return false; } inline bool grow_lf70( size_t buckets, size_t items ) { return float(items)/float(buckets) >= 0.85; @@ -570,6 +577,7 @@ CLASSEXP CLASSNAME:public CLASSNAME##_wxImplementation_HashTable \ { \ public: \ typedef VALUE_T mapped_type; \ + _WX_DECLARE_PAIR( iterator, bool, Insert_Result, CLASSEXP ) \ \ wxEXPLICIT CLASSNAME( size_type hint = 100, hasher hf = hasher(), \ key_equal eq = key_equal() ) \ @@ -578,7 +586,10 @@ public: \ \ mapped_type& operator[]( const const_key_type& key ) \ { \ - return GetOrCreateNode( CLASSNAME##_wxImplementation_Pair( key, mapped_type() ) )->m_value.second; \ + bool created; \ + return GetOrCreateNode( \ + CLASSNAME##_wxImplementation_Pair( key, mapped_type() ), \ + created)->m_value.second; \ } \ \ const_iterator find( const const_key_type& key ) const \ @@ -591,7 +602,16 @@ public: \ return iterator( GetNode( key ), this ); \ } \ \ - void insert( const value_type& v ) { (*this)[v.first] = v.second; } \ + Insert_Result insert( const value_type& v ) \ + { \ + bool created; \ + Node *node = GetOrCreateNode( \ + CLASSNAME##_wxImplementation_Pair( v.first, v.second ), \ + created); \ + if ( !created ) \ + node->m_value.second = v.second; \ + return Insert_Result(iterator(node, this), created); \ + } \ \ size_type erase( const key_type& k ) \ { return CLASSNAME##_wxImplementation_HashTable::erase( k ); } \