DeprecatedValueList.h [plain text]
#ifndef DeprecatedValueList_h
#define DeprecatedValueList_h
#include "DeprecatedValueListImpl.h"
namespace WebCore {
template <class T> class DeprecatedValueList;
template <class T> class DeprecatedValueListConstIterator;
template<class T> class DeprecatedValueListNode : private DeprecatedValueListImplNode {
public:
DeprecatedValueListNode(const T &val) : value(val) { }
T value;
friend class DeprecatedValueList<T>;
};
template<class T> class DeprecatedValueListIterator {
public:
DeprecatedValueListIterator() { }
T& operator*() const { return ((DeprecatedValueListNode<T> *)impl.node())->value; }
DeprecatedValueListIterator &operator++() { ++impl; return *this; }
DeprecatedValueListIterator &operator--() { --impl; return *this; }
DeprecatedValueListIterator operator++(int) { return impl++; }
bool operator==(const DeprecatedValueListIterator &other) { return impl == other.impl; }
bool operator!=(const DeprecatedValueListIterator &other) { return impl != other.impl; }
private:
DeprecatedValueListIterator(const DeprecatedValueListImplIterator &pImp) : impl(pImp) { }
DeprecatedValueListImplIterator impl;
friend class DeprecatedValueList<T>;
friend class DeprecatedValueListConstIterator<T>;
};
template<class T> class DeprecatedValueListConstIterator {
public:
DeprecatedValueListConstIterator() { }
DeprecatedValueListConstIterator(const DeprecatedValueListIterator<T> &it) : impl(it.impl) { }
const T& operator*() const { return ((const DeprecatedValueListNode<T> *)impl.node())->value; }
DeprecatedValueListConstIterator &operator++() { ++impl; return *this; }
DeprecatedValueListConstIterator &operator--() { --impl; return *this; }
DeprecatedValueListConstIterator operator++(int) { return impl++; }
bool operator==(const DeprecatedValueListConstIterator &other) { return impl == other.impl; }
bool operator!=(const DeprecatedValueListConstIterator &other) { return impl != other.impl; }
private:
DeprecatedValueListConstIterator(const DeprecatedValueListImplIterator &pImp) : impl(pImp) { }
DeprecatedValueListImplIterator impl;
friend class DeprecatedValueList<T>;
};
template<class T> bool operator==(const DeprecatedValueList<T> &a, const DeprecatedValueList<T> &b);
template <class T> class DeprecatedValueList {
public:
typedef DeprecatedValueListIterator<T> Iterator;
typedef DeprecatedValueListIterator<T> iterator;
typedef DeprecatedValueListConstIterator<T> ConstIterator;
typedef DeprecatedValueListConstIterator<T> const_iterator;
DeprecatedValueList() : impl(deleteNode, copyNode) { }
void clear() { impl.clear(); }
unsigned count() const { return impl.count(); }
bool isEmpty() const { return impl.isEmpty(); }
Iterator append(const T &val) { return impl.appendNode(new DeprecatedValueListNode<T>(val)); }
Iterator prepend(const T &val) { return impl.prependNode(new DeprecatedValueListNode<T>(val)); }
void remove(const T &val) { DeprecatedValueListNode<T> node(val); impl.removeEqualNodes(&node, nodesEqual); }
unsigned contains(const T &val) const { DeprecatedValueListNode<T> node(val); return impl.containsEqualNodes(&node, nodesEqual); }
Iterator find(const T &val) const { DeprecatedValueListNode<T> node(val); return impl.findEqualNode(&node, nodesEqual); }
Iterator insert(Iterator iter, const T& val) { return impl.insert(iter.impl, new DeprecatedValueListNode<T>(val)); }
Iterator remove(Iterator iter) { return impl.removeIterator(iter.impl); }
Iterator fromLast() { return impl.fromLast(); }
T& first() { return static_cast<DeprecatedValueListNode<T> *>(impl.firstNode())->value; }
const T& first() const { return static_cast<DeprecatedValueListNode<T> *>(impl.firstNode())->value; }
T& last() { return static_cast<DeprecatedValueListNode<T> *>(impl.lastNode())->value; }
const T& last() const { return static_cast<DeprecatedValueListNode<T> *>(impl.lastNode())->value; }
Iterator begin() { return impl.begin(); }
Iterator end() { return impl.end(); }
ConstIterator begin() const { return impl.begin(); }
ConstIterator end() const { return impl.end(); }
ConstIterator constBegin() const { return impl.begin(); }
ConstIterator constEnd() const { return impl.end(); }
ConstIterator fromLast() const { return impl.fromLast(); }
T& operator[] (unsigned index) { return ((DeprecatedValueListNode<T> *)impl.nodeAt(index))->value; }
const T& operator[] (unsigned index) const { return ((const DeprecatedValueListNode<T> *)impl.nodeAt(index))->value; }
DeprecatedValueList &operator+=(const T &value) { impl.appendNode(new DeprecatedValueListNode<T>(value)); return *this; }
DeprecatedValueList &operator<<(const T &value) { impl.appendNode(new DeprecatedValueListNode<T>(value)); return *this; }
friend bool operator==<>(const DeprecatedValueList<T> &, const DeprecatedValueList<T> &);
private:
DeprecatedValueListImpl impl;
static void deleteNode(DeprecatedValueListImplNode *node) { delete (DeprecatedValueListNode<T> *)node; }
static bool nodesEqual(const DeprecatedValueListImplNode *a, const DeprecatedValueListImplNode *b)
{ return ((DeprecatedValueListNode<T> *)a)->value == ((DeprecatedValueListNode<T> *)b)->value; }
static DeprecatedValueListImplNode *copyNode(DeprecatedValueListImplNode *node)
{ return new DeprecatedValueListNode<T>(((DeprecatedValueListNode<T> *)node)->value); }
};
template<class T>
inline bool operator==(const DeprecatedValueList<T> &a, const DeprecatedValueList<T> &b)
{
return a.impl.isEqual(b.impl, DeprecatedValueList<T>::nodesEqual);
}
}
#endif