summaryrefslogtreecommitdiff
path: root/cpp/src/qpid
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-01-18 21:44:55 +0000
committerAlan Conway <aconway@apache.org>2008-01-18 21:44:55 +0000
commit1ee12a31fc2a0e8f25860852f71ed3e1a9d38074 (patch)
treebc084704bace0e3dfc006895049fa320acb139ab /cpp/src/qpid
parentb43036056e0dc7ad8fb919bd1f5b065ff01502c5 (diff)
downloadqpid-python-1ee12a31fc2a0e8f25860852f71ed3e1a9d38074.tar.gz
qpid/IList.h: Added public T* getNext(), T* getPrev() to IListNode so node subclasses
can follow their own links. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@613290 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid')
-rw-r--r--cpp/src/qpid/IList.h30
1 files changed, 21 insertions, 9 deletions
diff --git a/cpp/src/qpid/IList.h b/cpp/src/qpid/IList.h
index 5467a708d1..c0c8b503f0 100644
--- a/cpp/src/qpid/IList.h
+++ b/cpp/src/qpid/IList.h
@@ -43,15 +43,25 @@ template <class T, int N> class IList;
* IList<Foo, 0> - uses the 0 links
* IList<Foo, 1> - uses the 1 links
*@endcode
+ *
+ *@param T The derived class.
+ *@param N ID for multiple inheritance.
*/
-template<int N=0> class IListNode : public virtual RefCounted {
+template<class T, int N=0> class IListNode : public virtual RefCounted {
intrusive_ptr<IListNode> prev;
intrusive_ptr<IListNode> next;
void insert(IListNode*);
void erase();
- template <class T, int NN> friend class IList;
+ virtual T* self() const { // Virutal so anchor can hide.
+ return boost::polymorphic_downcast<T*>(const_cast<IListNode*>(this));
+ }
+ friend class IList<T,N>;
public:
IListNode(IListNode* p=0) : prev(p), next(p) {}
+ T* getNext() { return next ? next->self() : 0; }
+ T* getPrev() { return prev ? prev->self() : 0; }
+ const T* getNext() const { return next ? next->self() : 0; }
+ const T* getPrev() const { return prev ? prev->self() : 0; }
};
/**
@@ -62,7 +72,7 @@ template<int N=0> class IListNode : public virtual RefCounted {
*/
template <class T, int N=0> class IList {
private:
- typedef IListNode<N> Node;
+ typedef IListNode<T,N> Node;
template <class R>
class Iterator :
@@ -109,7 +119,7 @@ template <class T, int N=0> class IList {
const_iterator last() const { return const_iterator(anchor.prev.get()); }
/// Note: takes a non-const reference, unlike standard containers.
- void insert(iterator pos, reference x) { x.IListNode<N>::insert(pos.ptr); }
+ void insert(iterator pos, reference x) { x.Node::insert(pos.ptr); }
void erase(iterator pos) { pos.ptr->erase(); }
void swap(IList &x) { anchor.swap(x.anchor); }
@@ -147,11 +157,13 @@ template <class T, int N=0> class IList {
Anchor() : Node(this) {}
// Suppress refcounting for the anchor node.
void release() const {}
+ // Hide anchor from public get functions.
+ T* self() const { return 0; }
} anchor;
};
-template <int N>
-void IListNode<N>::insert(IListNode* node) {
+template <class T, int N>
+void IListNode<T,N>::insert(IListNode* node) {
assert(!next && !prev); // Not already in a list.
assert(node);
assert(node->next && node->prev);
@@ -161,10 +173,10 @@ void IListNode<N>::insert(IListNode* node) {
next->prev = this;
}
-template <int N>
-void IListNode<N>::erase() {
+template <class T, int N>
+void IListNode<T,N>::erase() {
assert(prev && next);
- intrusive_ptr<IListNode> self(this); // Protect till exit.
+ intrusive_ptr<IListNode> save(this); // Protect till exit.
prev->next = next;
next->prev = prev;
prev = next = 0;