• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
DeprecatedPtrList()38     DeprecatedPtrList() : impl(deleteFunc), del_item(false) { }
~DeprecatedPtrList()39     ~DeprecatedPtrList() { impl.clear(del_item); }
40 
DeprecatedPtrList(const DeprecatedPtrList & l)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 
isEmpty()44     bool isEmpty() const { return impl.isEmpty(); }
count()45     unsigned count() const { return impl.count(); }
clear()46     void clear() { impl.clear(del_item); }
47 
at(unsigned n)48     T *at(unsigned n) { return (T *)impl.at(n); }
49 
insert(unsigned n,const T * item)50     bool insert(unsigned n, const T *item) { return impl.insert(n, item); }
remove()51     bool remove() { return impl.remove(del_item); }
remove(unsigned n)52     bool remove(unsigned n) { return impl.remove(n, del_item); }
remove(const T * item)53     bool remove(const T *item) { return impl.removeRef(item, del_item); }
removeFirst()54     bool removeFirst() { return impl.removeFirst(del_item); }
removeLast()55     bool removeLast() { return impl.removeLast(del_item); }
removeRef(const T * item)56     bool removeRef(const T *item) { return impl.removeRef(item, del_item); }
57 
getFirst()58     T *getFirst() const { return (T *)impl.getFirst(); }
getLast()59     T *getLast() const { return (T *)impl.getLast(); }
getNext()60     T *getNext() const { return (T *)impl.getNext(); }
getPrev()61     T *getPrev() const { return (T *)impl.getPrev(); }
current()62     T *current() const { return (T *)impl.current(); }
first()63     T *first() { return (T *)impl.first(); }
last()64     T *last() { return (T *)impl.last(); }
next()65     T *next() { return (T *)impl.next(); }
prev()66     T *prev() { return (T *)impl.prev(); }
take(unsigned n)67     T *take(unsigned n) { return (T *)impl.take(n); }
take()68     T *take() { return (T *)impl.take(); }
69 
append(const T * item)70     void append(const T *item) { impl.append(item); }
prepend(const T * item)71     void prepend(const T *item) { impl.prepend(item); }
72 
containsRef(const T * item)73     unsigned containsRef(const T *item) const { return impl.containsRef(item); }
findRef(const T * item)74     int findRef(const T *item) { return impl.findRef(item); }
75 
76     typedef DeprecatedPtrListIterator<T> Iterator;
77     typedef DeprecatedPtrListIterator<T> ConstIterator;
begin()78     ConstIterator begin() const { return ConstIterator(*this); }
end()79     ConstIterator end() const { ConstIterator itr(*this); itr.toLast(); ++itr; return itr; }
80 
autoDelete()81     bool autoDelete() const { return del_item; }
setAutoDelete(bool autoDelete)82     void setAutoDelete(bool autoDelete) { del_item = autoDelete; }
83 
84  private:
deleteFunc(void * item)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:
DeprecatedPtrListIterator()95     DeprecatedPtrListIterator() { }
DeprecatedPtrListIterator(const DeprecatedPtrList<T> & l)96     DeprecatedPtrListIterator(const DeprecatedPtrList<T> &l) : impl(l.impl) { }
97 
count()98     unsigned count() const { return impl.count(); }
toFirst()99     T *toFirst() { return (T *)impl.toFirst(); }
toLast()100     T *toLast() { return (T *)impl.toLast(); }
current()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