Ignore:
Timestamp:
Jan 17, 2006, 8:33:55 PM (19 years ago)
Author:
darin
Message:

Reviewed by Anders.

  • kxmlcore/HashTable.h: (KXMLCore::addIterator): Added. Helper function that adds an iterator to the list maintained by the specified hash table. (KXMLCore::removeIterator): Added. Helper function that removes an iterator from the list maintained by the hash table it's in. (KXMLCore::HashTableConstIterator::HashTableConstIterator): Added a HashTable parameter, ignored when not debugging. Call addIterator. (KXMLCore::HashTableConstIterator::~HashTableConstIterator): (KXMLCore::HashTableConstIterator::operator=): Call removeIterator. (KXMLCore::HashTableConstIterator::operator*): Call checkValidity. (KXMLCore::HashTableConstIterator::operator->): Ditto. (KXMLCore::HashTableConstIterator::operator++): Ditto. (KXMLCore::HashTableConstIterator::operator==): Ditto. (KXMLCore::HashTableConstIterator::operator!=): Ditto. (KXMLCore::HashTableConstIterator::checkValidity): Checks that the hash table pointer is not 0 and if there are two iterators that both point at the same table. (KXMLCore::HashTableIterator::HashTableIterator): Changed to use the const iterator as an implementation detail, to avoid having two separate iterator implementations. (KXMLCore::HashTableIterator::operator*): Ditto. (KXMLCore::HashTableIterator::operator->): Ditto. (KXMLCore::HashTableIterator::operator++): Ditto. (KXMLCore::HashTableIterator::operator==): Ditto. (KXMLCore::HashTableIterator::operator!=): Ditto. (KXMLCore::HashTable::HashTable): Initialize pointer to head of iterators list. (KXMLCore::HashTable::~HashTable): Added call to invalidateIterators. (KXMLCore::HashTable::makeIterator): Pass this pointer. (KXMLCore::HashTable::makeConstIterator): Ditto. (KXMLCore::HashTable::insert): Call invalidateIterators, since this is a public entry point that modifies the hash table. (KXMLCore::HashTable::remove): Ditto. (KXMLCore::HashTable::clear): Ditto. (KXMLCore::HashTable::swap): Ditto. (KXMLCore::HashTable::invalidateIterators): Added. Walks the iterators list and clears out the table, next, and previous pointers in all of them, and then clears the head so we have an empty list. (KXMLCore::addIterator): Added. Adds the iterator the the linked list in the passed-in table, and points the iterator at the table. (KXMLCore::removeIterator): Added. Removes the iterator from the linked list in the passed-in table.
  • kxmlcore/HashTraits.h: A bit of tweaking and formatting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kxmlcore/HashTraits.h

    r11962 r12162  
    22/*
    33 * This file is part of the KDE libraries
    4  * Copyright (C) 2005 Apple Computer, Inc.
     4 * Copyright (C) 2005, 2006 Apple Computer, Inc.
    55 *
    66 * This library is free software; you can redistribute it and/or
     
    3030
    3131    using std::pair;
    32    
     32
    3333    template <typename T> struct IsInteger           { static const bool value = false; };
    3434    template <> struct IsInteger<bool>               { static const bool value = true; };
     
    4444    template <> struct IsInteger<long long>          { static const bool value = true; };
    4545    template <> struct IsInteger<unsigned long long> { static const bool value = true; };
    46        
    47     template<typename T>
    48     struct GenericHashTraits {
     46
     47    template<typename T> struct GenericHashTraits {
    4948        typedef T TraitType;
    5049        static const bool emptyValueIsZero = IsInteger<T>::value;
     
    5352    };
    5453
    55     template<typename T>
    56     struct HashTraits : GenericHashTraits<T> {
    57     };
     54    template<typename T> struct HashTraits : GenericHashTraits<T> { };
    5855
    59     // may not be appropriate for all uses since it would disallow 0 and -1 as keys
    60     template<>
    61     struct HashTraits<int> : GenericHashTraits<int> {
     56    // may not be appropriate for all uses since it disallows 0 and -1 as keys
     57    template<> struct HashTraits<int> : GenericHashTraits<int> {
    6258        static TraitType deletedValue() { return -1; }
    6359    };
    6460
    65     template<typename P>
    66     struct HashTraits<P *> : GenericHashTraits<P *> {
    67         typedef P *TraitType;
     61    template<typename P> struct HashTraits<P*> : GenericHashTraits<P*> {
     62        typedef P* TraitType;
    6863        static const bool emptyValueIsZero = true;
    6964        static const bool needsDestruction = false;
    70         static TraitType emptyValue() { return reinterpret_cast<P *>(0); }
    71         static TraitType deletedValue() { return reinterpret_cast<P *>(-1); }
     65        static TraitType emptyValue() { return 0; }
     66        static TraitType deletedValue() { return reinterpret_cast<P*>(-1); }
    7267    };
    7368
    74     template<typename P>
    75     struct HashTraits<RefPtr<P> > : GenericHashTraits<RefPtr<P> > {
     69    template<typename P> struct HashTraits<RefPtr<P> > : GenericHashTraits<RefPtr<P> > {
    7670        static const bool emptyValueIsZero = true;
    7771    };
    7872
    79     template<typename T, typename Traits>
    80     class DeletedValueAssigner;
     73    template<typename T, typename Traits> class DeletedValueAssigner;
    8174
    82     template<typename T, typename Traits>
    83     inline void assignDeleted(T& location)
     75    template<typename T, typename Traits> inline void assignDeleted(T& location)
    8476    {
    8577        DeletedValueAssigner<T, Traits>::assignDeletedValue(location);
     
    9688        static const bool emptyValueIsZero = FirstTraits::emptyValueIsZero && SecondTraits::emptyValueIsZero;
    9789        static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
    98        
    99         static TraitType emptyValue() 
     90
     91        static TraitType emptyValue()
    10092        {
    10193            return TraitType(FirstTraits::emptyValue(), SecondTraits::emptyValue());
    10294        }
    10395
    104         static TraitType deletedValue() 
     96        static TraitType deletedValue()
    10597        {
    10698            return TraitType(FirstTraits::deletedValue(), SecondTraits::emptyValue());
     
    115107
    116108    template<typename First, typename Second>
    117     struct HashTraits<pair<First, Second> > : public PairHashTraits<HashTraits<First>, HashTraits<Second> > {
    118     };
     109    struct HashTraits<pair<First, Second> > : public PairHashTraits<HashTraits<First>, HashTraits<Second> > { };
    119110
    120     template<typename T, typename Traits>
    121     struct DeletedValueAssigner
    122     {
    123         static void assignDeletedValue(T& location)
    124         {
    125             location = Traits::deletedValue();
    126         }
     111    template<typename T, typename Traits> struct DeletedValueAssigner {
     112        static void assignDeletedValue(T& location) { location = Traits::deletedValue(); }
    127113    };
    128114
     
    130116    struct DeletedValueAssigner<pair<typename FirstTraits::TraitType, typename SecondTraits::TraitType>, PairHashTraits<FirstTraits, SecondTraits> >
    131117    {
    132         static void assignDeletedValue(pair<typename FirstTraits::TraitType, typename SecondTraits::TraitType>& location) 
    133         { 
     118        static void assignDeletedValue(pair<typename FirstTraits::TraitType, typename SecondTraits::TraitType>& location)
     119        {
    134120            PairHashTraits<FirstTraits, SecondTraits>::assignDeletedValue(location);
    135121        }
     
    139125    struct DeletedValueAssigner<pair<First, Second>, HashTraits<pair<First, Second> > >
    140126    {
    141         static void assignDeletedValue(pair<First, Second>& location) 
    142         { 
     127        static void assignDeletedValue(pair<First, Second>& location)
     128        {
    143129            HashTraits<pair<First, Second> >::assignDeletedValue(location);
    144130        }
Note: See TracChangeset for help on using the changeset viewer.