3 * (c) 2011 Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
10 * As a special exception, you may use this file as part of a free software
11 * library without restriction. Specifically, if other files instantiate
12 * templates or use macros or inline functions from this file, or you compile
13 * this file and link it with other files to produce an executable, this
14 * file does not by itself cause the resulting executable to be covered by
15 * the GNU General Public License. This exception does not however
16 * invalidate any other reasons why the executable file might be covered by
17 * the GNU General Public License.
24 template< typename T > class D_list;
26 template< typename T >
27 class D_list_item_base
30 friend class D_list<T>;
31 D_list_item_base *_n, *_p;
34 explicit D_list_item_base(D_list_item_base *n = 0, D_list_item_base *p = 0)
37 T *l_next() const { return static_cast<T*>(_n); }
38 T *l_prev() const { return static_cast<T*>(_p); }
48 void l_add_before(D_list_item_base *other)
56 void l_add_after(D_list_item_base *other)
60 if (other->_n) other->_n->_p = this;
64 ~D_list_item_base() { l_remove(); }
68 template< typename T >
69 class D_list_item : private D_list_item_base<T>
72 friend class D_list<T>;
73 friend class D_list_item_base<T>;
74 typedef D_list_item_base<T> B;
80 void l_add_before(T *other) { B::l_add_before(other); }
81 void l_add_after(T *other) { B::l_add_after(other); }
84 template< typename T >
85 class D_list : private D_list_item_base<T>
88 friend class D_list_item_base<T>;
89 typedef D_list_item_base<T> B;
94 D_list() : B(this, this)
97 explicit D_list(T *first) : B(first, first)
106 T *first() const { return B::_n != this ? B::l_next() : 0; }
107 T *last() const { return B::_p != this ? B::l_prev() : 0; }
109 void add(T *e) { e->D_list_item_base<T>::l_add_after(this); }
110 void add_tail(T *e) { e->D_list_item_base<T>::l_add_before(this); }
112 T* next(T const *current) const
113 { return current->_n != this ? current->l_next() : 0; }
115 T* prev(T const *current) const
116 { return current->_p != this ? current->l_prev() : 0; }