Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::core::List< T, OwnershipPolicy, Node > Class Template Reference

Intrusive doubly-linked list. More...

#include <list.h>

Inheritance diagram for roc::core::List< T, OwnershipPolicy, Node >:
Collaboration diagram for roc::core::List< T, OwnershipPolicy, Node >:

Public Types

typedef OwnershipPolicy< T >::Pointer Pointer
 Pointer type. More...
 

Public Member Functions

 List ()
 Initialize empty list. More...
 
 ~List ()
 Release ownership of containing objects. More...
 
size_t size () const
 Get number of elements in list. More...
 
bool is_empty () const
 Check if size is zero. More...
 
bool contains (const T &elem)
 Check if element belongs to list. More...
 
Pointer front () const
 Get first list element. More...
 
Pointer back () const
 Get last list element. More...
 
Pointer nextof (T &elem) const
 Get list element next to given one. More...
 
Pointer prevof (T &elem) const
 Get list element previous to given one. More...
 
void push_front (T &elem)
 Prepend element to list. More...
 
void push_back (T &elem)
 Append element to list. More...
 
void pop_front ()
 Pop first element from list. More...
 
void pop_back ()
 Pop last element from list. More...
 
void insert_before (T &elem, T &before)
 Insert element into list. More...
 
void insert_after (T &elem, T &after)
 Insert element into list. More...
 
void remove (T &elem)
 Remove element from list. More...
 

Detailed Description

template<class T, template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
class roc::core::List< T, OwnershipPolicy, Node >

Intrusive doubly-linked list.

Does not perform allocations. Provides O(1) size check, membership check, insertion, and removal.

Template Parameters
Tdefines object type, it must inherit ListNode.
OwnershipPolicydefines ownership policy which is used to acquire an element ownership when it's added to the list and release ownership when it's removed from the list.
Nodedefines base class of list nodes. It is needed if ListNode is used with non-default tag.

Definition at line 40 of file list.h.

Member Typedef Documentation

◆ Pointer

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
typedef OwnershipPolicy<T>::Pointer roc::core::List< T, OwnershipPolicy, Node >::Pointer

Pointer type.

Remarks
either raw or smart pointer depending on the ownership policy.

Definition at line 45 of file list.h.

Constructor & Destructor Documentation

◆ List()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
roc::core::List< T, OwnershipPolicy, Node >::List ( )
inline

Initialize empty list.

Definition at line 48 of file list.h.

◆ ~List()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
roc::core::List< T, OwnershipPolicy, Node >::~List ( )
inline

Release ownership of containing objects.

Definition at line 52 of file list.h.

Member Function Documentation

◆ back()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
Pointer roc::core::List< T, OwnershipPolicy, Node >::back ( ) const
inline

Get last list element.

Returns
last element or NULL if list is empty.

Definition at line 85 of file list.h.

◆ contains()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
bool roc::core::List< T, OwnershipPolicy, Node >::contains ( const T &  elem)
inline

Check if element belongs to list.

Definition at line 69 of file list.h.

◆ front()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
Pointer roc::core::List< T, OwnershipPolicy, Node >::front ( ) const
inline

Get first list element.

Returns
first element or NULL if list is empty.

Definition at line 77 of file list.h.

◆ insert_after()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
void roc::core::List< T, OwnershipPolicy, Node >::insert_after ( T &  elem,
T &  after 
)
inline

Insert element into list.

Remarks
  • inserts elem after after
  • acquires ownership of elem
Precondition
elem should not be member of any list. after should be member of this list.

Definition at line 204 of file list.h.

◆ insert_before()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
void roc::core::List< T, OwnershipPolicy, Node >::insert_before ( T &  elem,
T &  before 
)
inline

Insert element into list.

Remarks
  • inserts elem before before
  • acquires ownership of elem
Precondition
elem should not be member of any list. before should be member of this list or NULL.

Definition at line 187 of file list.h.

◆ is_empty()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
bool roc::core::List< T, OwnershipPolicy, Node >::is_empty ( ) const
inline

Check if size is zero.

Definition at line 64 of file list.h.

◆ nextof()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
Pointer roc::core::List< T, OwnershipPolicy, Node >::nextof ( T &  elem) const
inline

Get list element next to given one.

Returns
list element following elem if elem is not last, or NULL otherwise.
Precondition
elem should be member of this list.

Definition at line 98 of file list.h.

◆ pop_back()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
void roc::core::List< T, OwnershipPolicy, Node >::pop_back ( )
inline

Pop last element from list.

Remarks
  • removes last element of list
  • releases ownership of removed element
Precondition
the list should not be empty.

Definition at line 171 of file list.h.

◆ pop_front()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
void roc::core::List< T, OwnershipPolicy, Node >::pop_front ( )
inline

Pop first element from list.

Remarks
  • removes first element of list
  • releases ownership of removed element
Precondition
the list should not be empty.

Definition at line 156 of file list.h.

◆ prevof()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
Pointer roc::core::List< T, OwnershipPolicy, Node >::prevof ( T &  elem) const
inline

Get list element previous to given one.

Returns
list element preceding elem if elem is not first, or NULL otherwise.
Precondition
elem should be member of this list.

Definition at line 112 of file list.h.

◆ push_back()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
void roc::core::List< T, OwnershipPolicy, Node >::push_back ( T &  elem)
inline

Append element to list.

Remarks
  • appends elem to list
  • acquires ownership of elem
Precondition
elem should not be member of any list.

Definition at line 141 of file list.h.

◆ push_front()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
void roc::core::List< T, OwnershipPolicy, Node >::push_front ( T &  elem)
inline

Prepend element to list.

Remarks
  • prepends elem to list
  • acquires ownership of elem
Precondition
elem should not be member of any list.

Definition at line 126 of file list.h.

◆ remove()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
void roc::core::List< T, OwnershipPolicy, Node >::remove ( T &  elem)
inline

Remove element from list.

Remarks
  • removes elem from list
  • releases ownership of elem
Precondition
elem should be member of this list.

Definition at line 220 of file list.h.

◆ size()

template<class T , template< class TT > class OwnershipPolicy = RefCountedOwnership, class Node = ListNode<>>
size_t roc::core::List< T, OwnershipPolicy, Node >::size ( ) const
inline

Get number of elements in list.

Definition at line 59 of file list.h.


The documentation for this class was generated from the following file: