OpenWalnut  1.5.0dev
Public Types | Public Member Functions | List of all members
WSharedSequenceContainer< S > Class Template Reference

This class provides a common interface for thread-safe access to sequence containers (list, vector, dequeue ). More...

#include <WSharedSequenceContainer.h>

+ Inheritance diagram for WSharedSequenceContainer< S >:
+ Collaboration diagram for WSharedSequenceContainer< S >:

Public Types

typedef S::const_iterator ConstIterator
 A typedef for the correct const iterator useful to traverse this sequence container. More...
 
typedef S::iterator Iterator
 A typedef for the correct iterator to traverse this sequence container. More...
 
typedef S::value_type value_type
 The type of the elements. More...
 
- Public Types inherited from WSharedObject< S >
typedef S ValueT
 The type protected by this shared object class. More...
 
typedef std::shared_ptr< WSharedObjectTicketRead< S > > ReadTicket
 Type for read tickets. More...
 
typedef std::shared_ptr< WSharedObjectTicketWrite< S > > WriteTicket
 Type for write tickets. More...
 
typedef std::shared_ptr< WSharedObject< S > > SPtr
 Shared pointer abbreviation. More...
 
typedef std::shared_ptr< WSharedObject< S > > ConstSPtr
 Const shared ptr abbreviation. More...
 

Public Member Functions

 WSharedSequenceContainer ()
 Default constructor. More...
 
virtual ~WSharedSequenceContainer ()
 Destructor. More...
 
void push_back (const typename S::value_type &x)
 Adds a new element at the end of the container. More...
 
void push_front (const typename S::value_type &x)
 Adds a new element at the beginning of the container. More...
 
void pop_back ()
 Removes an element from the end. More...
 
void unique_push_back (const typename S::value_type &x)
 Add the element only if it is not inside the container until now. More...
 
void unique_push_front (const typename S::value_type &x)
 Add the element only if it is not inside the container until now. More...
 
void clear ()
 Clears the container. More...
 
size_t size () const
 The size of the container. More...
 
S::value_type & operator[] (size_t n)
 Get item at position n. More...
 
const S::value_type & operator[] (size_t n) const
 Get item at position n. More...
 
S::value_type & at (size_t n)
 Get item at position n. More...
 
const S::value_type & at (size_t n) const
 Get item at position n. More...
 
void remove (const typename S::value_type &element)
 Searches and removes the specified element. More...
 
WSharedSequenceContainer< S >::Iterator erase (typename WSharedSequenceContainer< S >::Iterator position)
 Erase the element at the specified position. More...
 
WSharedSequenceContainer< S >::Iterator erase (typename WSharedSequenceContainer< S >::Iterator first, typename WSharedSequenceContainer< S >::Iterator last)
 Erase the specified range of elements. More...
 
void replace (const typename S::value_type &oldValue, const typename S::value_type &newValue)
 Replaces the specified old value by a new one. More...
 
size_t count (const value_type &value)
 Counts the number of occurrences of the specified value inside the container. More...
 
template<typename Comparator >
void sort (Comparator comp)
 Resorts the container using the specified comparator from its begin to its end. More...
 
template<typename Comparator >
void sort (typename WSharedSequenceContainer< S >::Iterator first, typename WSharedSequenceContainer< S >::Iterator last, Comparator comp)
 Resorts the container using the specified comparator between [first,last) in ascending order. More...
 
template<typename Comparator >
void stableSort (Comparator comp)
 Resorts the container using the specified comparator from its begin to its end. More...
 
template<typename Comparator >
void stableSort (typename WSharedSequenceContainer< S >::Iterator first, typename WSharedSequenceContainer< S >::Iterator last, Comparator comp)
 Resorts the container using the specified comparator between [first,last) in ascending order. More...
 
WSharedSequenceContainer< S >::Iterator find (typename WSharedSequenceContainer< S >::Iterator first, typename WSharedSequenceContainer< S >::Iterator last, const typename S::value_type &value)
 Searches the specified value in the range [first,last). More...
 
WSharedSequenceContainer< S >::ConstIterator find (const typename S::value_type &value)
 Searches the specified value in the range [begin,end). More...
 
- Public Member Functions inherited from WSharedObject< S >
 WSharedObject ()
 Default constructor. More...
 
virtual ~WSharedObject ()
 Destructor. More...
 
ReadTicket getReadTicket () const
 Returns a ticket to get read access to the contained data. More...
 
WriteTicket getWriteTicket (bool suppressNotify=false) const
 Returns a ticket to get write access to the contained data. More...
 
std::shared_ptr< WConditiongetChangeCondition () const
 This condition fires whenever the encapsulated object changed. More...
 

Additional Inherited Members

- Protected Attributes inherited from WSharedObject< S >
m_object
 The object wrapped by this class. More...
 
std::shared_ptr< std::shared_mutex > m_lock
 The lock to ensure thread safe access. More...
 
std::shared_ptr< WConditionm_changeCondition
 This condition set fires whenever the contained object changes. More...
 

Detailed Description

template<typename S>
class WSharedSequenceContainer< S >

This class provides a common interface for thread-safe access to sequence containers (list, vector, dequeue ).

Parameters
Sthe sequence container to use. Everything is allowed here which provides push_back and pop_back as well as size functionality.

Definition at line 39 of file WSharedSequenceContainer.h.

Member Typedef Documentation

◆ ConstIterator

template<typename S >
typedef S::const_iterator WSharedSequenceContainer< S >::ConstIterator

A typedef for the correct const iterator useful to traverse this sequence container.

Definition at line 47 of file WSharedSequenceContainer.h.

◆ Iterator

template<typename S >
typedef S::iterator WSharedSequenceContainer< S >::Iterator

A typedef for the correct iterator to traverse this sequence container.

Definition at line 52 of file WSharedSequenceContainer.h.

◆ value_type

template<typename S >
typedef S::value_type WSharedSequenceContainer< S >::value_type

The type of the elements.

Definition at line 57 of file WSharedSequenceContainer.h.

Constructor & Destructor Documentation

◆ WSharedSequenceContainer()

Default constructor.

Definition at line 277 of file WSharedSequenceContainer.h.

◆ ~WSharedSequenceContainer()

template<typename S >
WSharedSequenceContainer< S >::~WSharedSequenceContainer
virtual

Destructor.

Definition at line 284 of file WSharedSequenceContainer.h.

Member Function Documentation

◆ at() [1/2]

template<typename S >
S::value_type & WSharedSequenceContainer< S >::at ( size_t  n)

Get item at position n.

Uses the at-method of the underlying container. Please do not use this for iteration as it locks every access. Use iterators and read/write tickets for fast iteration.

Parameters
nthe item index
Returns
reference to element at the specified position

Definition at line 370 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getReadTicket().

+ Here is the call graph for this function:

◆ at() [2/2]

template<typename S >
const S::value_type & WSharedSequenceContainer< S >::at ( size_t  n) const

Get item at position n.

Uses the at-method of the underlying container. Please do not use this for iteration as it locks every access. Use iterators and read/write tickets for fast iteration.

Parameters
nthe item index
Returns
reference to element at the specified position

Definition at line 378 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getReadTicket().

+ Here is the call graph for this function:

◆ clear()

template<typename S >
void WSharedSequenceContainer< S >::clear

Clears the container.

Definition at line 338 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

Referenced by WUIWidgetBase::close().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ count()

template<typename S >
size_t WSharedSequenceContainer< S >::count ( const value_type value)

Counts the number of occurrences of the specified value inside the container.

This is a comfortable forwarder for std::count.

Parameters
valuethe value to count
Returns
the number of items found.

Definition at line 418 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getReadTicket().

Referenced by WGEColormapping::deregisterTextureInst(), WGEColormapping::registerTextureInst(), and WGEColormapping::replaceTextureInst().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ erase() [1/2]

template<typename S >
WSharedSequenceContainer< S >::Iterator WSharedSequenceContainer< S >::erase ( typename WSharedSequenceContainer< S >::Iterator  first,
typename WSharedSequenceContainer< S >::Iterator  last 
)

Erase the specified range of elements.

Read your STL reference for more details.

Parameters
firstIterators specifying a range within the vector to be removed: [first,last).
lastIterators specifying a range within the vector to be removed: [first,last).
Returns
A random access iterator pointing to the new location of the element that followed the last element erased by the function call.

Definition at line 401 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

+ Here is the call graph for this function:

◆ erase() [2/2]

template<typename S >
WSharedSequenceContainer< S >::Iterator WSharedSequenceContainer< S >::erase ( typename WSharedSequenceContainer< S >::Iterator  position)

Erase the element at the specified position.

Read your STL reference for more details.

Parameters
positionwhere to erase
Returns
A random access iterator pointing to the new location of the element that followed the last element erased by the function call.

Definition at line 393 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

+ Here is the call graph for this function:

◆ find() [1/2]

template<typename S >
WSharedSequenceContainer< S >::ConstIterator WSharedSequenceContainer< S >::find ( const typename S::value_type &  value)

Searches the specified value in the range [begin,end).

Parameters
valuethe value to search.
Returns
the iterator pointing to the found element.

Definition at line 468 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getReadTicket().

+ Here is the call graph for this function:

◆ find() [2/2]

template<typename S >
WSharedSequenceContainer< S >::Iterator WSharedSequenceContainer< S >::find ( typename WSharedSequenceContainer< S >::Iterator  first,
typename WSharedSequenceContainer< S >::Iterator  last,
const typename S::value_type &  value 
)

Searches the specified value in the range [first,last).

Parameters
firstthe first element
lastthe last element
valuethe value to search.
Returns
the iterator pointing to the found element.

Definition at line 459 of file WSharedSequenceContainer.h.

◆ operator[]() [1/2]

template<typename S >
S::value_type & WSharedSequenceContainer< S >::operator[] ( size_t  n)

Get item at position n.

Uses the [] operator of the underlying container. Please do not use this for iteration as it locks every access. Use iterators and read/write tickets for fast iteration.

Parameters
nthe item index
Returns
reference to element at the specified position

Definition at line 355 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getReadTicket().

+ Here is the call graph for this function:

◆ operator[]() [2/2]

template<typename S >
const S::value_type & WSharedSequenceContainer< S >::operator[] ( size_t  n) const

Get item at position n.

Uses the [] operator of the underlying container. Please do not use this for iteration as it locks every access. Use iterators and read/write tickets for fast iteration.

Parameters
nthe item index
Returns
reference to element at the specified position

Definition at line 363 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getReadTicket().

+ Here is the call graph for this function:

◆ pop_back()

template<typename S >
void WSharedSequenceContainer< S >::pop_back

Removes an element from the end.

Definition at line 330 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

+ Here is the call graph for this function:

◆ push_back()

template<typename S >
void WSharedSequenceContainer< S >::push_back ( const typename S::value_type &  x)

Adds a new element at the end of the container.

Parameters
xthe new element.

Definition at line 290 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

Referenced by WSubject::addDataSet(), WLogger::addStream(), WDataHandler::addSubject(), WBatchLoader::threadMain(), and WLogger::WLogger().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ push_front()

template<typename S >
void WSharedSequenceContainer< S >::push_front ( const typename S::value_type &  x)

Adds a new element at the beginning of the container.

Parameters
xthe new element.

Definition at line 298 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

Referenced by WGEColormapping::registerTextureInst().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remove()

template<typename S >
void WSharedSequenceContainer< S >::remove ( const typename S::value_type &  element)

Searches and removes the specified element.

If it is not found, nothing happens. It mainly is a comfortable forwarder for std::remove and S::erase.

Parameters
elementthe element to remove

Definition at line 385 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

Referenced by WMainWindow::deregisterCustomWidget(), WProjectFile::deregisterParser(), WGEColormapping::deregisterTextureInst(), and WLogger::removeStream().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replace()

template<typename S >
void WSharedSequenceContainer< S >::replace ( const typename S::value_type &  oldValue,
const typename S::value_type &  newValue 
)

Replaces the specified old value by a new one.

If the old one does not exist, nothing happens. This is a comfortable forwarder for std::replace.

Parameters
oldValuethe old value to replace
newValuethe new value

Definition at line 411 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

Referenced by WGEColormapping::replaceTextureInst().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

template<typename S >
size_t WSharedSequenceContainer< S >::size

The size of the container.

Returns
the size.
Note
: be aware that the size can change at every moment after getting the size, since the read lock got freed. Better use access objects to lock the container and use size() on the container directly.

Definition at line 346 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getReadTicket().

Referenced by WGEColormapping::size(), WSubjectTest::testAddGetDataSet(), and WSubjectTest::testGetNumberOfDataSet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sort() [1/2]

template<typename S >
template<typename Comparator >
void WSharedSequenceContainer< S >::sort ( Comparator  comp)

Resorts the container using the specified comparator from its begin to its end.

Template Parameters
Comparatorthe comparator type. Usually a boost::function or class providing the operator().
Parameters
compthe comparator

Definition at line 426 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

Referenced by WGEColormapping::sort().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sort() [2/2]

template<typename S >
template<typename Comparator >
void WSharedSequenceContainer< S >::sort ( typename WSharedSequenceContainer< S >::Iterator  first,
typename WSharedSequenceContainer< S >::Iterator  last,
Comparator  comp 
)

Resorts the container using the specified comparator between [first,last) in ascending order.

Parameters
firstthe first element
lastthe last element
compthe comparator

Definition at line 434 of file WSharedSequenceContainer.h.

◆ stableSort() [1/2]

template<typename S >
template<typename Comparator >
void WSharedSequenceContainer< S >::stableSort ( Comparator  comp)

Resorts the container using the specified comparator from its begin to its end.

Uses stable sort algorithm.

Template Parameters
Comparatorthe comparator type. Usually a boost::function or class providing the operator().
Parameters
compthe comparator

Definition at line 443 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

Referenced by WGEColormapping::stableSort().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stableSort() [2/2]

template<typename S >
template<typename Comparator >
void WSharedSequenceContainer< S >::stableSort ( typename WSharedSequenceContainer< S >::Iterator  first,
typename WSharedSequenceContainer< S >::Iterator  last,
Comparator  comp 
)

Resorts the container using the specified comparator between [first,last) in ascending order.

Uses stable sort algorithm.

Parameters
firstthe first element
lastthe last element
compthe comparator

Definition at line 451 of file WSharedSequenceContainer.h.

◆ unique_push_back()

template<typename S >
void WSharedSequenceContainer< S >::unique_push_back ( const typename S::value_type &  x)

Add the element only if it is not inside the container until now.

This is a shortcut to a combined used of find and push_back.

Parameters
xthe element to push back.

Definition at line 306 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

Referenced by WUIWidgetBase::registerChild(), and WMainWindow::registerCustomWidget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unique_push_front()

template<typename S >
void WSharedSequenceContainer< S >::unique_push_front ( const typename S::value_type &  x)

Add the element only if it is not inside the container until now.

This is a shortcut to a combined used of find and push_front.

Parameters
xthe element to push front.

Definition at line 318 of file WSharedSequenceContainer.h.

References WSharedObject< T >::getWriteTicket().

+ Here is the call graph for this function:

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