#ifndef ALREADY_INCLUDED_2006_LIBD__LIST_NODE_HH
#define ALREADY_INCLUDED_2006_LIBD__LIST_NODE_HH
namespace dmp
{
template<class X>
class List_Node : private Single
{
rtti_same(List_Node);
POOL1;
friend class List<X>;
friend class List_Iterator<X>;
private:
ptr<X> private_data;
LOOP_OK(ptr<List_Node<X> >) private_next;
LOOP_OK(ptr<List_Node<X> >) private_previous;
STAR_OK(List<X>*) private_owner;
bool private_deleteme;
private:
List_Node& operator = (const List_Node&);
List_Node(const List_Node&);
private:
List_Node() : Single(DCODE_LIST_NODE)
{
private_owner = null;
private_deleteme = false;
}
private:
static ptr<List_Node> ctor()
{
return new List_Node<X>();
}
private:
template <class T> friend class ptr;
~List_Node()
{
private_owner = null;
}
private:
void delete_node()
{
ASSERT(this != null);
{
if (this->private_previous != null)
{
if (this->private_previous->private_next == this)
{
this->private_previous->private_next = this->private_next;
}
}
if (this->private_next != null)
{
if (this->private_next->private_previous == this)
{
this->private_next->private_previous = this->private_previous;
}
}
if (this->private_owner != null)
{
this->private_owner->private_length--;
}
}
if (this->private_owner != null)
{
if (this->private_owner->private_first == this)
{
this->private_owner->private_first = this->private_next;
}
if (this->private_owner->private_last == this)
{
this->private_owner->private_last = this->private_previous;
}
this->private_owner = null;
}
this->private_previous = null;
this->private_next = null;
}
private:
void add_after(const ptr<X>& x)
{
ASSERT(this != null);
ASSERT(&x != null);
ASSERT(x != null);
ptr<List_Node<X> > n = List_Node<X>::ctor();
n->private_data = x;
n->private_next = this->private_next;
n->private_previous = this;
n->private_owner = private_owner;
if (n->private_next != null)
{
n->private_next->private_previous = n;
}
if (n->private_previous != null)
{
n->private_previous->private_next = n;
}
if (n->private_owner != null)
{
if (n->private_owner->private_last == this)
{
n->private_owner->private_last = n;
}
n->private_owner->private_length++;
}
}
private:
void add_before(const ptr<X>& x)
{
ASSERT(this != null);
ASSERT(&x != null);
ASSERT(x != null);
ptr<List_Node<X> > n = List_Node<X>::ctor();
n->private_data = x;
n->private_next = this;
n->private_previous = this->private_previous;
n->private_owner = this->private_owner;
if (n->private_next != null)
{
n->private_next->private_previous = n;
}
if (n->private_previous != null)
{
n->private_previous->private_next = n;
}
if (n->private_owner != null)
{
if (n->private_owner->private_first == this)
{
n->private_owner->private_first = n;
}
n->private_owner->private_length++;
}
}
#ifdef DAVINS_IO_ONLINE
friend dmp::Writer& operator << (dmp::Writer& w, const List_Node<X>& node)
{
ASSERT(&w != null);
if (&node == null) {
w << "null";
}
else
{
w << node.private_data;
}
return w;
}
#endif
};
}
#endif