22 #include <l4/cxx/type_traits> 23 #include <l4/cxx/std_alloc> 24 #include <l4/cxx/std_ops> 51 List_item *operator * ()
const throw() {
return _c; }
52 List_item *operator -> ()
const throw() {
return _c; }
53 Iter &operator ++ ()
throw()
66 Iter operator ++ (
int)
throw()
67 {
Iter o = *
this; operator ++ ();
return o; }
69 Iter &operator -- ()
throw()
82 Iter operator -- (
int)
throw()
83 {
Iter o = *
this; operator -- ();
return o; }
118 template<
typename T,
bool Poly = false>
122 static bool const P = !Conversion<const T*, const List_item *>::exists
125 static List_item *cast_to_li(T *i, Int_to_type<true>)
throw()
128 static List_item *cast_to_li(T *i, Int_to_type<false>)
throw()
131 static T *cast_to_type(
List_item *i, Int_to_type<true>)
throw()
132 {
return dynamic_cast<T*
>(i); }
134 static T *cast_to_type(
List_item *i, Int_to_type<false>)
throw()
135 {
return static_cast<T*
>(i); }
139 template<
typename O >
141 :
Iter(o) {
dynamic_cast<T*
>(*o); }
144 T_iter(T *f = 0)
throw() :
Iter(cast_to_li(f, Int_to_type<P>())) {}
145 T_iter(T *c, T *f)
throw()
146 :
Iter(cast_to_li(c, Int_to_type<P>()),
147 cast_to_li(f, Int_to_type<P>()))
150 inline T *operator * ()
const throw()
151 {
return cast_to_type(Iter::operator * (),Int_to_type<P>()); }
152 inline T *operator -> ()
const throw()
153 {
return operator * (); }
160 { Iter::operator ++ ();
return *
this; }
162 { Iter::operator -- ();
return *
this; }
166 List_item()
throw() : _n(
this), _p(
this) {}
216 template<
typename C,
typename N >
217 static inline C *
push_back(C *head, N *p)
throw();
227 template<
typename C,
typename N >
228 static inline C *
push_front(C *head, N *p)
throw();
238 template<
typename C,
typename N >
239 static inline C *
remove(C *head, N *p)
throw();
247 template<
typename C,
typename N >
254 h->insert_prev_item(p);
258 template<
typename C,
typename N >
264 h->insert_prev_item(p);
268 template<
typename C,
typename N >
280 h =
static_cast<C*
>(p->_n);
287 template<
typename T,
bool Poly >
293 template<
typename T >
302 template<
typename LI >
312 void push_front(LI *e) { _h = LI::push_front(_h, e); }
313 void push_back(LI *e) { _h = LI::push_back(_h, e); }
314 void insert_before(LI *e, LI *p)
316 p->insert_prev_item(e);
320 void insert_after(LI *e, LI *p) { p->insert_next_item(e); }
323 { _h = LI::remove(_h, e); }
325 LI *head()
const {
return _h; }
333 template<
typename D,
template<
typename A>
class Alloc =
New_allocator >
340 E(D
const &d)
throw() : data(d) {}
345 class Node :
private E
348 typedef Alloc<Node> Node_alloc;
360 Iter(E *e)
throw() : _i(e) {}
362 D &operator * ()
const throw() {
return (*_i)->data; }
363 D &operator -> ()
const throw() {
return (*_i)->data; }
365 Iter operator ++ (
int)
throw()
366 {
Iter o = *
this; operator ++ ();
return o; }
367 Iter operator -- (
int)
throw()
368 {
Iter o = *
this; operator -- ();
return o; }
369 Iter &operator ++ ()
throw() { ++_i;
return *
this; }
370 Iter &operator -- ()
throw() { --_i;
return *
this; }
373 operator E* ()
const throw() {
return *_i; }
376 List(Alloc<Node>
const &a = Alloc<Node>())
throw() : _h(0), _l(0), _a(a) {}
381 void *n = _a.alloc();
383 _h = E::push_back(_h,
new (n) E(d));
390 void *n = _a.alloc();
392 _h = E::push_front(_h,
new (n) E(d));
397 void remove(
Iter const &i)
throw()
398 { E *e = i; _h = E::remove(_h, e); --_l; _a.free(e); }
401 unsigned long size()
const throw() {
return _l; }
404 D
const &operator [] (
unsigned long idx)
const throw()
405 {
Iter i = _h;
for (; idx && *i; ++i, --idx) { }
return *i; }
408 D &operator [] (
unsigned long idx)
throw()
409 {
Iter i = _h;
for (; idx && *i; ++i, --idx) { }
return *i; }
void insert_prev_item(List_item *p)
Insert item p before this item.
Iterator for derived classes from ListItem.
Doubly linked list, with internal allocation.
static C * push_front(C *head, N *p)
Prepend item to a list.
static C * push_back(C *head, N *p)
Append item to a list.
void remove_me()
Remove this item from the list.
void insert_next_item(List_item *p)
Insert item p after this item.
void push_front(D const &d)
Add element at the beginning of the list.
Iter items()
Get iterator for the list elements.
unsigned long size() const
Get the length of the list.
static C * remove(C *head, N *p)
Remove item from a list.
Iterator for a list of ListItem-s.
void push_back(D const &d)
Add element at the end of the list.
List_item * get_prev_item() const
Get previous item.
List_item * get_next_item() const
Get next item.
Standard allocator based on operator new () .
List_item * remove_me()
Remove item pointed to by iterator, and return pointer to element.