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