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