1 /* 2 * Copyright (C) 2003 Apple Computer, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef DeprecatedPtrListImpl_h 27 #define DeprecatedPtrListImpl_h 28 29 namespace WebCore { 30 31 class DeprecatedListNode; 32 class DeprecatedPtrListImplIterator; 33 34 class DeprecatedPtrListImpl 35 { 36 public: 37 38 DeprecatedPtrListImpl(void (*deleteFunc)(void *)); 39 DeprecatedPtrListImpl(const DeprecatedPtrListImpl &impl); 40 ~DeprecatedPtrListImpl(); 41 isEmpty()42 bool isEmpty() const { return nodeCount == 0; } count()43 unsigned count() const { return nodeCount; } 44 void clear(bool deleteItems); 45 46 void *at(unsigned n); 47 48 bool insert(unsigned n, const void *item); 49 bool remove(bool deleteItem); 50 bool remove(unsigned n, bool deleteItem); 51 bool removeFirst(bool deleteItem); 52 bool removeLast(bool deleteItem); 53 bool removeRef(const void *item, bool deleteItem); 54 55 void *getFirst() const; 56 void *getLast() const; 57 void *getNext() const; 58 void *getPrev() const; 59 void *current() const; 60 void *first(); 61 void *last(); 62 void *next(); 63 void *prev(); 64 void *take(unsigned n); 65 void *take(); 66 67 void append(const void *item); 68 void prepend(const void *item); 69 70 unsigned containsRef(const void *item) const; 71 int findRef(const void *item); 72 73 DeprecatedPtrListImpl &assign(const DeprecatedPtrListImpl &impl, bool deleteItems); 74 75 private: 76 DeprecatedPtrListImpl &operator =(const DeprecatedPtrListImpl &impl); 77 78 void swap(DeprecatedPtrListImpl &impl); 79 80 void addIterator(DeprecatedPtrListImplIterator *iter) const; 81 void removeIterator(DeprecatedPtrListImplIterator *iter) const; 82 83 DeprecatedListNode *head; 84 DeprecatedListNode *tail; 85 DeprecatedListNode *cur; 86 unsigned nodeCount; 87 void (*deleteItem)(void *); 88 mutable DeprecatedPtrListImplIterator *iterators; 89 90 friend class DeprecatedPtrListImplIterator; 91 }; 92 93 94 class DeprecatedPtrListImplIterator { 95 public: 96 DeprecatedPtrListImplIterator(); 97 DeprecatedPtrListImplIterator(const DeprecatedPtrListImpl &impl); 98 ~DeprecatedPtrListImplIterator(); 99 100 DeprecatedPtrListImplIterator(const DeprecatedPtrListImplIterator &impl); 101 DeprecatedPtrListImplIterator &operator=(const DeprecatedPtrListImplIterator &impl); 102 103 unsigned count() const; 104 void *toFirst(); 105 void *toLast(); 106 void *current() const; 107 108 void *operator--(); 109 void *operator++(); 110 111 private: 112 const DeprecatedPtrListImpl *list; 113 DeprecatedListNode *node; 114 DeprecatedPtrListImplIterator *next; 115 DeprecatedPtrListImplIterator *prev; 116 117 friend class DeprecatedPtrListImpl; 118 }; 119 120 } 121 122 #endif 123