12 #ifndef ROC_CORE_LIST_H_
13 #define ROC_CORE_LIST_H_
38 template <
class TT>
class OwnershipPolicy = RefCountedOwnership,
39 class Node = ListNode<> >
45 typedef typename OwnershipPolicy<T>::Pointer
Pointer;
65 return impl_.
size() == 0;
70 const ListData* data = to_node_data_(elem);
79 return from_node_data_(data);
87 return from_node_data_(data);
99 ListData* data = to_node_data_(elem);
101 return from_node_data_(next_data);
113 ListData* data = to_node_data_(elem);
115 return from_node_data_(prev_data);
127 OwnershipPolicy<T>::acquire(elem);
129 ListData* data = to_node_data_(elem);
142 OwnershipPolicy<T>::acquire(elem);
144 ListData* data = to_node_data_(elem);
158 T* elem = from_node_data_(data);
160 OwnershipPolicy<T>::release(*elem);
173 T* elem = from_node_data_(data);
175 OwnershipPolicy<T>::release(*elem);
188 OwnershipPolicy<T>::acquire(elem);
190 ListData* data = to_node_data_(elem);
191 ListData* data_before = to_node_data_(before);
192 impl_.
insert(data, data_before);
205 OwnershipPolicy<T>::acquire(elem);
207 ListData* data = to_node_data_(elem);
208 ListData* data_after = to_node_data_(after);
221 ListData* data = to_node_data_(elem);
224 OwnershipPolicy<T>::release(elem);
228 static ListData* to_node_data_(
const T& elem) {
229 return static_cast<const Node&
>(elem).list_data();
232 static T* from_node_data_(ListData* data) {
233 return static_cast<T*
>(
static_cast<Node*
>(Node::list_node(data)));
ListData * front() const
Get first list node.
ListData * back() const
Get last list node.
ListData * pop_front()
Remove first node and return.
ListData * pop_back()
Remove last node and return.
ListData * prevof(ListData *node) const
Get list node previous to given one.
void remove(ListData *node)
Remove node from list.
void insert(ListData *node, ListData *before)
Insert node into list.
ListData * head()
Get list head (non-node node).
ListData * nextof(ListData *node) const
Get list node next to given one.
bool contains(const ListData *node) const
Check if node belongs to list.
size_t size() const
Get number of nodes in list.
Intrusive doubly-linked list.
List()
Initialize empty list.
Pointer prevof(T &elem) const
Get list element previous to given one.
Pointer nextof(T &elem) const
Get list element next to given one.
void remove(T &elem)
Remove element from list.
Pointer front() const
Get first list element.
~List()
Release ownership of containing objects.
size_t size() const
Get number of elements in list.
Pointer back() const
Get last list element.
OwnershipPolicy< T >::Pointer Pointer
Pointer type.
void pop_back()
Pop last element from list.
void push_front(T &elem)
Prepend element to list.
void insert_after(T &elem, T &after)
Insert element into list.
void insert_before(T &elem, T &before)
Insert element into list.
bool contains(const T &elem)
Check if element belongs to list.
void push_back(T &elem)
Append element to list.
void pop_front()
Pop first element from list.
bool is_empty() const
Check if size is zero.
Base class for non-copyable objects.
Intrusive doubly-linked list implementation.
Commonly used types and functions.
ListData * next
Next list element.