⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 102084 in webkit


Ignore:
Timestamp:
Dec 5, 2011, 6:17:22 PM (15 years ago)
Author:
andersca@apple.com
Message:

Add HashMap::keys() and HashMap::values() for easy iteration of hash map keys and values in C++11.

Reviewed by Darin Adler.

  • wtf/HashMap.h:
Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r102082 r102084  
     12011-12-05  Anders Carlsson  <andersca@apple.com>
     2
     3        Add HashMap::keys() and HashMap::values() for easy iteration of hash map keys and values in C++11.
     4
     5        Reviewed by Darin Adler.
     6
     7        * wtf/HashMap.h:
     8
    192011-12-05  Michael Saboff  <msaboff@apple.com>
    210
  • trunk/Source/JavaScriptCore/wtf/HashMap.h

    r101942 r102084  
    6161            HashFunctions, ValueTraits, KeyTraits> HashTableType;
    6262
     63        class HashMapKeysProxy;
     64        class HashMapValuesProxy;
     65
    6366    public:
    6467        typedef HashTableIteratorAdapter<HashTableType, ValueType> iterator;
    6568        typedef HashTableConstIteratorAdapter<HashTableType, ValueType> const_iterator;
    6669
     70    public:
    6771        void swap(HashMap&);
    6872
     
    7680        const_iterator begin() const;
    7781        const_iterator end() const;
     82
     83        HashMapKeysProxy& keys() { return static_cast<HashMapKeysProxy&>(*this); }
     84        const HashMapKeysProxy& keys() const { return static_cast<const HashMapKeysProxy&>(*this); }
     85
     86        HashMapValuesProxy& values() { return static_cast<HashMapValuesProxy&>(*this); }
     87        const HashMapValuesProxy& values() const { return static_cast<const HashMapValuesProxy&>(*this); }
    7888
    7989        iterator find(const KeyType&);
     
    119129    private:
    120130        pair<iterator, bool> inlineAdd(const KeyType&, MappedPassInReferenceType);
     131
     132        class HashMapKeysProxy : private HashMap {
     133        public:
     134            typedef typename HashMap::iterator::Keys iterator;
     135            typedef typename HashMap::const_iterator::Keys const_iterator;
     136           
     137            iterator begin()
     138            {
     139                return HashMap::begin().keys();
     140            }
     141           
     142            iterator end()
     143            {
     144                return HashMap::end().keys();
     145            }
     146
     147            const_iterator begin() const
     148            {
     149                return HashMap::begin().keys();
     150            }
     151           
     152            const_iterator end() const
     153            {
     154                return HashMap::end().keys();
     155            }
     156
     157        private:
     158            friend class HashMap;
     159
     160            // These are intentionally not implemented.
     161            HashMapKeysProxy();
     162            HashMapKeysProxy(const HashMapKeysProxy&);
     163            HashMapKeysProxy& operator=(const HashMapKeysProxy&);
     164            ~HashMapKeysProxy();
     165        };
     166
     167        class HashMapValuesProxy : private HashMap {
     168        public:
     169            typedef typename HashMap::iterator::Values iterator;
     170            typedef typename HashMap::const_iterator::Values const_iterator;
     171           
     172            iterator begin()
     173            {
     174                return HashMap::begin().values();
     175            }
     176           
     177            iterator end()
     178            {
     179                return HashMap::end().values();
     180            }
     181
     182            const_iterator begin() const
     183            {
     184                return HashMap::begin().values();
     185            }
     186           
     187            const_iterator end() const
     188            {
     189                return HashMap::end().values();
     190            }
     191
     192        private:
     193            friend class HashMap;
     194
     195            // These are intentionally not implemented.
     196            HashMapValuesProxy();
     197            HashMapValuesProxy(const HashMapValuesProxy&);
     198            HashMapValuesProxy& operator=(const HashMapValuesProxy&);
     199            ~HashMapValuesProxy();
     200        };
    121201
    122202        HashTableType m_impl;
Note: See TracChangeset for help on using the changeset viewer.