00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef DeprecatedValueList_h
00027 #define DeprecatedValueList_h
00028
00029 #include "DeprecatedValueListImpl.h"
00030
00031 namespace WebCore {
00032
00033 template <class T> class DeprecatedValueList;
00034 template <class T> class DeprecatedValueListConstIterator;
00035
00036 template<class T> class DeprecatedValueListNode : private DeprecatedValueListImplNode {
00037 public:
00038 DeprecatedValueListNode(const T &val) : value(val) { }
00039 T value;
00040 friend class DeprecatedValueList<T>;
00041 };
00042
00043 template<class T> class DeprecatedValueListIterator {
00044 public:
00045 DeprecatedValueListIterator() { }
00046
00047 T& operator*() const { return ((DeprecatedValueListNode<T> *)impl.node())->value; }
00048
00049 DeprecatedValueListIterator &operator++() { ++impl; return *this; }
00050 DeprecatedValueListIterator &operator--() { --impl; return *this; }
00051 DeprecatedValueListIterator operator++(int) { return impl++; }
00052
00053 bool operator==(const DeprecatedValueListIterator &other) { return impl == other.impl; }
00054 bool operator!=(const DeprecatedValueListIterator &other) { return impl != other.impl; }
00055
00056 private:
00057 DeprecatedValueListIterator(const DeprecatedValueListImplIterator &pImp) : impl(pImp) { }
00058
00059 DeprecatedValueListImplIterator impl;
00060
00061 friend class DeprecatedValueList<T>;
00062 friend class DeprecatedValueListConstIterator<T>;
00063 };
00064
00065 template<class T> class DeprecatedValueListConstIterator {
00066 public:
00067 DeprecatedValueListConstIterator() { }
00068 DeprecatedValueListConstIterator(const DeprecatedValueListIterator<T> &it) : impl(it.impl) { }
00069
00070 const T& operator*() const { return ((const DeprecatedValueListNode<T> *)impl.node())->value; }
00071
00072 DeprecatedValueListConstIterator &operator++() { ++impl; return *this; }
00073 DeprecatedValueListConstIterator &operator--() { --impl; return *this; }
00074 DeprecatedValueListConstIterator operator++(int) { return impl++; }
00075
00076 bool operator==(const DeprecatedValueListConstIterator &other) { return impl == other.impl; }
00077 bool operator!=(const DeprecatedValueListConstIterator &other) { return impl != other.impl; }
00078
00079 private:
00080 DeprecatedValueListConstIterator(const DeprecatedValueListImplIterator &pImp) : impl(pImp) { }
00081
00082 DeprecatedValueListImplIterator impl;
00083
00084 friend class DeprecatedValueList<T>;
00085 };
00086
00087 template<class T> bool operator==(const DeprecatedValueList<T> &a, const DeprecatedValueList<T> &b);
00088
00089 template <class T> class DeprecatedValueList {
00090 public:
00091 typedef DeprecatedValueListIterator<T> Iterator;
00092 typedef DeprecatedValueListIterator<T> iterator;
00093 typedef DeprecatedValueListConstIterator<T> ConstIterator;
00094 typedef DeprecatedValueListConstIterator<T> const_iterator;
00095
00096 DeprecatedValueList() : impl(deleteNode, copyNode) { }
00097
00098 void clear() { impl.clear(); }
00099 unsigned count() const { return impl.count(); }
00100 bool isEmpty() const { return impl.isEmpty(); }
00101
00102 Iterator append(const T &val) { return impl.appendNode(new DeprecatedValueListNode<T>(val)); }
00103 Iterator prepend(const T &val) { return impl.prependNode(new DeprecatedValueListNode<T>(val)); }
00104 void remove(const T &val) { DeprecatedValueListNode<T> node(val); impl.removeEqualNodes(&node, nodesEqual); }
00105 unsigned contains(const T &val) const { DeprecatedValueListNode<T> node(val); return impl.containsEqualNodes(&node, nodesEqual); }
00106 Iterator find(const T &val) const { DeprecatedValueListNode<T> node(val); return impl.findEqualNode(&node, nodesEqual); }
00107
00108 Iterator insert(Iterator iter, const T& val) { return impl.insert(iter.impl, new DeprecatedValueListNode<T>(val)); }
00109 Iterator remove(Iterator iter) { return impl.removeIterator(iter.impl); }
00110 Iterator fromLast() { return impl.fromLast(); }
00111
00112 T& first() { return static_cast<DeprecatedValueListNode<T> *>(impl.firstNode())->value; }
00113 const T& first() const { return static_cast<DeprecatedValueListNode<T> *>(impl.firstNode())->value; }
00114 T& last() { return static_cast<DeprecatedValueListNode<T> *>(impl.lastNode())->value; }
00115 const T& last() const { return static_cast<DeprecatedValueListNode<T> *>(impl.lastNode())->value; }
00116
00117 Iterator begin() { return impl.begin(); }
00118 Iterator end() { return impl.end(); }
00119
00120 ConstIterator begin() const { return impl.begin(); }
00121 ConstIterator end() const { return impl.end(); }
00122 ConstIterator constBegin() const { return impl.begin(); }
00123 ConstIterator constEnd() const { return impl.end(); }
00124 ConstIterator fromLast() const { return impl.fromLast(); }
00125
00126 T& operator[] (unsigned index) { return ((DeprecatedValueListNode<T> *)impl.nodeAt(index))->value; }
00127 const T& operator[] (unsigned index) const { return ((const DeprecatedValueListNode<T> *)impl.nodeAt(index))->value; }
00128 DeprecatedValueList &operator+=(const T &value) { impl.appendNode(new DeprecatedValueListNode<T>(value)); return *this; }
00129 DeprecatedValueList &operator<<(const T &value) { impl.appendNode(new DeprecatedValueListNode<T>(value)); return *this; }
00130
00131 friend bool operator==<>(const DeprecatedValueList<T> &, const DeprecatedValueList<T> &);
00132
00133 private:
00134 DeprecatedValueListImpl impl;
00135
00136 static void deleteNode(DeprecatedValueListImplNode *node) { delete (DeprecatedValueListNode<T> *)node; }
00137 static bool nodesEqual(const DeprecatedValueListImplNode *a, const DeprecatedValueListImplNode *b)
00138 { return ((DeprecatedValueListNode<T> *)a)->value == ((DeprecatedValueListNode<T> *)b)->value; }
00139 static DeprecatedValueListImplNode *copyNode(DeprecatedValueListImplNode *node)
00140 { return new DeprecatedValueListNode<T>(((DeprecatedValueListNode<T> *)node)->value); }
00141 };
00142
00143 template<class T>
00144 inline bool operator==(const DeprecatedValueList<T> &a, const DeprecatedValueList<T> &b)
00145 {
00146 return a.impl.isEqual(b.impl, DeprecatedValueList<T>::nodesEqual);
00147 }
00148
00149 }
00150
00151 #endif