Orocos Real-Time Toolkit  2.9.0
Public Types | Public Member Functions | List of all members
RTT::internal::ListLocked< T > Class Template Reference

A simple lock-based list implementation to append or erase data of type T. More...

#include <rtt/internal/ListLocked.hpp>

Public Types

typedef T value_t
 

Public Member Functions

 ListLocked (unsigned int lsize, unsigned int unused=0)
 Create a lock-based list wich can store lsize elements. More...
 
 ~ListLocked ()
 
size_t capacity () const
 
size_t size () const
 
bool empty () const
 
void grow (size_t items=1)
 Grow the capacity to contain at least n additional items. More...
 
void shrink (size_t items=1)
 Shrink the capacity with at most n items. More...
 
void reserve (size_t lsize)
 Reserve a capacity for this list. More...
 
void clear ()
 
bool append (value_t item)
 Append a single value to the list. More...
 
value_t front () const
 Returns the first element of the list. More...
 
value_t back () const
 Returns the last element of the list. More...
 
size_t append (const std::vector< T > &items)
 Append a sequence of values to the list. More...
 
bool erase (value_t item)
 Erase a value from the list. More...
 
template<typename Pred >
bool delete_if (Pred pred)
 Erase a value from the list. More...
 
template<class Function >
void apply (Function func)
 Apply a function to the elements of the whole list. More...
 
template<class Function >
value_t find_if (Function func, value_t blank=value_t())
 Find an item in the list such that func( item ) == true. More...
 

Detailed Description

template<class T>
class RTT::internal::ListLocked< T >

A simple lock-based list implementation to append or erase data of type T.

Note
The mutex used by this implementation is recursive in order to allow apply() to call apply() recursively. Erasing self (using clear() or erase()) from within apply() is not supported and may lead to abnormal program termination.
Parameters
TThe value type to be stored in the list. Example : ListLocked is a list which holds values of type A.

Definition at line 72 of file ListLocked.hpp.

Member Typedef Documentation

template<class T>
typedef T RTT::internal::ListLocked< T >::value_t

Definition at line 76 of file ListLocked.hpp.

Constructor & Destructor Documentation

template<class T>
RTT::internal::ListLocked< T >::ListLocked ( unsigned int  lsize,
unsigned int  unused = 0 
)
inline

Create a lock-based list wich can store lsize elements.

Parameters
lsizethe initial capacity of the list.

Definition at line 96 of file ListLocked.hpp.

template<class T>
RTT::internal::ListLocked< T >::~ListLocked ( )
inline

Definition at line 103 of file ListLocked.hpp.

References RTT::internal::ListLocked< T >::clear().

Member Function Documentation

template<class T>
bool RTT::internal::ListLocked< T >::append ( value_t  item)
inline

Append a single value to the list.

Parameters
dthe value to write
Returns
false if the list is full.

Definition at line 182 of file ListLocked.hpp.

template<class T>
size_t RTT::internal::ListLocked< T >::append ( const std::vector< T > &  items)
inline

Append a sequence of values to the list.

Parameters
itemsthe values to append.
Returns
the number of values written (may be less than items.size())

Definition at line 214 of file ListLocked.hpp.

template<class T>
template<class Function >
void RTT::internal::ListLocked< T >::apply ( Function  func)
inline

Apply a function to the elements of the whole list.

Parameters
funcThe function to apply.
Note
func may not call clear() or erase() on the current element of this list.

Definition at line 274 of file ListLocked.hpp.

template<class T>
value_t RTT::internal::ListLocked< T >::back ( ) const
inline

Returns the last element of the list.

Definition at line 203 of file ListLocked.hpp.

template<class T>
size_t RTT::internal::ListLocked< T >::capacity ( ) const
inline

Definition at line 111 of file ListLocked.hpp.

template<class T>
void RTT::internal::ListLocked< T >::clear ( )
inline

Definition at line 171 of file ListLocked.hpp.

Referenced by RTT::internal::ListLocked< T >::~ListLocked().

template<class T>
template<typename Pred >
bool RTT::internal::ListLocked< T >::delete_if ( Pred  pred)
inline

Erase a value from the list.

Parameters
functioneach elements for which pred returns true are removed
Returns
true if at least one element has been removed
Note
This function is only real-time if the destructor and copy-constructor of of T is real-time.

Definition at line 245 of file ListLocked.hpp.

template<class T>
bool RTT::internal::ListLocked< T >::empty ( ) const
inline

Definition at line 123 of file ListLocked.hpp.

template<class T>
bool RTT::internal::ListLocked< T >::erase ( value_t  item)
inline

Erase a value from the list.

Parameters
itemis to be erased from the list.
Returns
true if found and erased.

Definition at line 230 of file ListLocked.hpp.

template<class T>
template<class Function >
value_t RTT::internal::ListLocked< T >::find_if ( Function  func,
value_t  blank = value_t() 
)
inline

Find an item in the list such that func( item ) == true.

Parameters
blankThe value to return if not found.
Returns
The item that matches func(item) or blank if none matches.

Definition at line 288 of file ListLocked.hpp.

template<class T>
value_t RTT::internal::ListLocked< T >::front ( ) const
inline

Returns the first element of the list.

Definition at line 194 of file ListLocked.hpp.

template<class T>
void RTT::internal::ListLocked< T >::grow ( size_t  items = 1)
inline

Grow the capacity to contain at least n additional items.

This method tries to avoid too much re-allocations, by growing a bit more than required every N invocations and growing nothing in between.

Parameters
itemsThe number of items to at least additionally reserve.

Definition at line 136 of file ListLocked.hpp.

template<class T>
void RTT::internal::ListLocked< T >::reserve ( size_t  lsize)
inline

Reserve a capacity for this list.

Parameters
lsizethe minimal number of items this list will be able to hold. Will not drop below the current capacity() and this method will do nothing if lsize < this->capacity().

Definition at line 163 of file ListLocked.hpp.

template<class T>
void RTT::internal::ListLocked< T >::shrink ( size_t  items = 1)
inline

Shrink the capacity with at most n items.

This method does not actually free memory, it just prevents a (number of) subsequent grow() invocations to allocate more memory.

Parameters
itemsThe number of items to at most remove from the capacity.

Definition at line 152 of file ListLocked.hpp.

template<class T>
size_t RTT::internal::ListLocked< T >::size ( ) const
inline

Definition at line 117 of file ListLocked.hpp.


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