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 DeprecatedPtrList_h 27 #define DeprecatedPtrList_h 28 29 #include "DeprecatedPtrListImpl.h" 30 #include <wtf/FastAllocBase.h> 31 32 namespace WebCore { 33 34 template <class T> class DeprecatedPtrListIterator; 35 36 template <class T> class DeprecatedPtrList : public FastAllocBase { 37 public: 38 DeprecatedPtrList() : impl(deleteFunc), del_item(false) { } 39 ~DeprecatedPtrList() { impl.clear(del_item); } 40 41 DeprecatedPtrList(const DeprecatedPtrList& l) : impl(l.impl), del_item(false) { } 42 DeprecatedPtrList& operator=(const DeprecatedPtrList &l) { impl.assign(l.impl, del_item); return *this; } 43 44 bool isEmpty() const { return impl.isEmpty(); } 45 unsigned count() const { return impl.count(); } 46 void clear() { impl.clear(del_item); } 47 48 T *at(unsigned n) { return (T *)impl.at(n); } 49 50 bool insert(unsigned n, const T *item) { return impl.insert(n, item); } 51 bool remove() { return impl.remove(del_item); } 52 bool remove(unsigned n) { return impl.remove(n, del_item); } 53 bool remove(const T *item) { return impl.removeRef(item, del_item); } 54 bool removeFirst() { return impl.removeFirst(del_item); } 55 bool removeLast() { return impl.removeLast(del_item); } 56 bool removeRef(const T *item) { return impl.removeRef(item, del_item); } 57 58 T *getFirst() const { return (T *)impl.getFirst(); } 59 T *getLast() const { return (T *)impl.getLast(); } 60 T *getNext() const { return (T *)impl.getNext(); } 61 T *getPrev() const { return (T *)impl.getPrev(); } 62 T *current() const { return (T *)impl.current(); } 63 T *first() { return (T *)impl.first(); } 64 T *last() { return (T *)impl.last(); } 65 T *next() { return (T *)impl.next(); } 66 T *prev() { return (T *)impl.prev(); } 67 T *take(unsigned n) { return (T *)impl.take(n); } 68 T *take() { return (T *)impl.take(); } 69 70 void append(const T *item) { impl.append(item); } 71 void prepend(const T *item) { impl.prepend(item); } 72 73 unsigned containsRef(const T *item) const { return impl.containsRef(item); } 74 int findRef(const T *item) { return impl.findRef(item); } 75 76 typedef DeprecatedPtrListIterator<T> Iterator; 77 typedef DeprecatedPtrListIterator<T> ConstIterator; 78 ConstIterator begin() const { return ConstIterator(*this); } 79 ConstIterator end() const { ConstIterator itr(*this); itr.toLast(); ++itr; return itr; } 80 81 bool autoDelete() const { return del_item; } 82 void setAutoDelete(bool autoDelete) { del_item = autoDelete; } 83 84 private: 85 static void deleteFunc(void *item) { delete (T *)item; } 86 87 friend class DeprecatedPtrListIterator<T>; 88 89 DeprecatedPtrListImpl impl; 90 bool del_item; 91 }; 92 93 template <class T> class DeprecatedPtrListIterator { 94 public: 95 DeprecatedPtrListIterator() { } 96 DeprecatedPtrListIterator(const DeprecatedPtrList<T> &l) : impl(l.impl) { } 97 98 unsigned count() const { return impl.count(); } 99 T *toFirst() { return (T *)impl.toFirst(); } 100 T *toLast() { return (T *)impl.toLast(); } 101 T *current() const { return (T *)impl.current(); } 102 103 operator T *() const { return (T *)impl.current(); } 104 T *operator*() const { return (T *)impl.current(); } 105 T *operator--() { return (T *)--impl; } 106 T *operator++() { return (T *)++impl; } 107 108 private: 109 DeprecatedPtrListImplIterator impl; 110 }; 111 112 } 113 114 #endif 115