sptk2 logo
SPTK Home Page
Public Types | Public Member Functions | List of all members
sptk::SynchronizedList< T > Class Template Reference

#include <SynchronizedList.h>

Public Types

using CallbackFunction = std::function< bool(T &item)>
 

Public Member Functions

 SynchronizedList ()=default
 
 SynchronizedList (const SynchronizedList &)=delete
 
 SynchronizedList (SynchronizedList &&) noexcept=default
 
SynchronizedListoperator= (const SynchronizedList &)=delete
 
SynchronizedListoperator= (SynchronizedList &&) noexcept=default
 
virtual ~SynchronizedList ()=default
 
virtual void push_front (const T &data)
 
virtual bool pop_front (T &item, std::chrono::milliseconds timeout)
 
virtual void push_back (const T &data)
 
virtual bool pop_back (T &item, std::chrono::milliseconds timeout)
 
virtual void remove (T &item)
 
virtual void wakeup ()
 
bool empty () const
 
size_t size () const
 
void clear ()
 
bool each (const CallbackFunction &callbackFunction)
 

Detailed Description

template<class T>
class sptk::SynchronizedList< T >

Synchronized template list

Simple thread-safe list

Member Typedef Documentation

◆ CallbackFunction

template<class T >
using sptk::SynchronizedList< T >::CallbackFunction = std::function<bool(T& item)>

List callback function used in each() method.

Iterates through list until false is returned.

Parameters
itemT&, List item
datavoid*, Optional function-specific data

Constructor & Destructor Documentation

◆ SynchronizedList()

template<class T >
sptk::SynchronizedList< T >::SynchronizedList ( )
default

Default constructor

◆ ~SynchronizedList()

template<class T >
virtual sptk::SynchronizedList< T >::~SynchronizedList ( )
virtualdefault

Destructor

Member Function Documentation

◆ clear()

template<class T >
void sptk::SynchronizedList< T >::clear ( )
inline

Removes all items from the list

◆ each()

template<class T >
bool sptk::SynchronizedList< T >::each ( const CallbackFunction callbackFunction)
inline

Calls for every list until false is returned

Parameters
callbackFunctionCallback function that is executed for list items
dataFunction-specific data
Returns
true if every list item was processed

◆ empty()

template<class T >
bool sptk::SynchronizedList< T >::empty ( ) const
inline

Returns true if the list is empty

◆ pop_back()

template<class T >
virtual bool sptk::SynchronizedList< T >::pop_back ( T &  item,
std::chrono::milliseconds  timeout 
)
inlinevirtual

Pops a data item from the list back

If list is empty then waits until timeout occurs. Returns false if timeout occurs.

Parameters
itemT&, A list item (output)
timeoutstd::chrono::milliseconds, Operation timeout

References sptk::Semaphore::sleep_for().

◆ pop_front()

template<class T >
virtual bool sptk::SynchronizedList< T >::pop_front ( T &  item,
std::chrono::milliseconds  timeout 
)
inlinevirtual

Pops a data item from the list front

If list is empty then waits until timeout milliseconds occurs. Returns false if timeout occurs.

Parameters
itemT&, A list item (output)
timeoutstd::chrono::milliseconds, Operation timeout

References sptk::Semaphore::sleep_for().

◆ push_back()

template<class T >
virtual void sptk::SynchronizedList< T >::push_back ( const T &  data)
inlinevirtual

Pushes a data item to the list back

Automatically posts internal semaphore to indicate list item availability.

Parameters
dataconst T&, A data item

References sptk::Semaphore::post().

◆ push_front()

template<class T >
virtual void sptk::SynchronizedList< T >::push_front ( const T &  data)
inlinevirtual

Pushes a data item to the list front

Automatically posts internal semaphore to indicate list item availability.

Parameters
dataconst T&, A data item

References sptk::Semaphore::post().

◆ remove()

template<class T >
virtual void sptk::SynchronizedList< T >::remove ( T &  item)
inlinevirtual

Removes all elements with the specific value from the list

◆ size()

template<class T >
size_t sptk::SynchronizedList< T >::size ( ) const
inline

Returns number of items in the list

◆ wakeup()

template<class T >
virtual void sptk::SynchronizedList< T >::wakeup ( )
inlinevirtual

Wakes up list semaphore to interrupt waiting

Any waiting pop() operation immediately returns false.

References sptk::Semaphore::post().


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

Fri Oct 14 2022 09:58:45: SPTK 5.4.1