OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
WItemSelector Class Reference

This class represents a subset of a WItemSelection. More...

#include <WItemSelector.h>

+ Collaboration diagram for WItemSelector:

Public Types

typedef std::vector< size_t > IndexList
 The type used for storing index lists. More...
 

Public Member Functions

 WItemSelector (const WItemSelector &other)
 Copy constructor. More...
 
WItemSelectoroperator= (const WItemSelector &other)
 Copy assignment. More...
 
virtual ~WItemSelector ()
 Destructor. More...
 
WItemSelector newSelector (IndexList selected) const
 Creates a new valid instance with the specified items selected. More...
 
WItemSelector newSelector (size_t selected) const
 Creates a new valid instance with the specified items selected. More...
 
WItemSelector newSelector (const std::string asString) const
 Creates a new valid instance with the specified items selected. More...
 
WItemSelector newSelector () const
 Creates a new selector, but basing on this instance as old one. More...
 
bool operator== (const WItemSelector &other) const
 Compares two selector. More...
 
std::ostream & operator<< (std::ostream &out) const
 Write a selection in string representation to the given output stream. More...
 
virtual size_t sizeAll () const
 Gives the count of elements in the set of selectable items. More...
 
virtual size_t size () const
 The number of selected items. More...
 
virtual bool empty () const
 True if the selection is empty. More...
 
virtual const std::shared_ptr< WItemSelectionItematAll (size_t index) const
 Gets the item with the given index from the WItemSelection. More...
 
virtual const std::shared_ptr< WItemSelectionItemat (size_t index) const
 Gets the selected item with the given index. More...
 
virtual size_t getItemIndexOfSelected (size_t index) const
 Helps to get the index of an selected item in the WItemSelection. More...
 
virtual bool isValid () const
 Checks whether the selection is valid anymore. More...
 
void lock ()
 Read locks the underlying selection. More...
 
void unlock ()
 Unlocks the selection again. More...
 
 operator unsigned int () const
 Allow cast from selector to unsigned int. More...
 
IndexList getIndexList () const
 Casts the selector to a list of indices currently selected. More...
 

Protected Member Functions

 WItemSelector (std::shared_ptr< WItemSelection > selection, IndexList selected)
 Constructor creates an selector for the specified selection of items. More...
 

Protected Attributes

std::shared_ptr< WItemSelectionm_selection
 The selection handled by this selector. More...
 
IndexList m_selected
 The list of items currently selected. More...
 
boost::signals2::connection m_invalidateSignalConnection
 Stores the connection made using WItemSelection::subscribeInvalidateSignal. More...
 

Private Member Functions

WItemSelector createSelector (const IndexList &selected) const
 Creates a new selector instance using the specified index list. More...
 
void invalidate ()
 Handles the case of invalidation. More...
 

Private Attributes

bool m_valid
 If true the selector is valid. More...
 
WItemSelection::ReadTicket m_lock
 This locks prevents the selection to be modified during selector iteration. More...
 

Friends

class WItemSelection
 Only class allowed to instanciate this class. More...
 

Detailed Description

This class represents a subset of a WItemSelection.

It is a class for managing selections. The class is kept very restrictive. The selection can't be edited after the instantiation of the class to keep the interface clean, easily usable and consistent among multiple threads. So please DO NOT extend it to provide methods for changing it!

This class can be seen as some kind of special "iterator" providing access to the underlying set without allowing it to be modified. The class provides methods to access the whole set and the subset represented by itself. The restrictive interface ensures thread-safety and enforces that each new selection is done by a new instance of this class, which is needed by the WPropertyVariable to work properly.

Note
the protected constructor avoids instance creation of classes not the WItemSelection. This is restrictive but needed. Nobody can create instances of it, changing the underlying WItemSelection and using it as selector for another ItemSelection instance.

Definition at line 52 of file WItemSelector.h.

Member Typedef Documentation

◆ IndexList

typedef std::vector< size_t > WItemSelector::IndexList

The type used for storing index lists.

It is a list of integer correlating with the elements in the managed WItemSelection class.

Definition at line 59 of file WItemSelector.h.

Constructor & Destructor Documentation

◆ WItemSelector() [1/2]

WItemSelector::WItemSelector ( const WItemSelector other)

Copy constructor.

Creates a new copy of the selector and ensure proper signal subscriptions to the underlying selection.

Parameters
otherthe selector to copy

Definition at line 43 of file WItemSelector.cpp.

References invalidate(), m_invalidateSignalConnection, and m_selection.

Referenced by createSelector().

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

◆ ~WItemSelector()

WItemSelector::~WItemSelector ( )
virtual

Destructor.

Definition at line 66 of file WItemSelector.cpp.

References m_invalidateSignalConnection.

◆ WItemSelector() [2/2]

WItemSelector::WItemSelector ( std::shared_ptr< WItemSelection selection,
IndexList  selected 
)
protected

Constructor creates an selector for the specified selection of items.

Noting is selected after construction.

Parameters
selectionthe selection handled by this instance
selectedthe set of selected items

Definition at line 33 of file WItemSelector.cpp.

References invalidate(), m_invalidateSignalConnection, and m_selection.

+ Here is the call graph for this function:

Member Function Documentation

◆ at()

const std::shared_ptr< WItemSelectionItem > WItemSelector::at ( size_t  index) const
virtual

Gets the selected item with the given index.

This is not the same index as the element has in the corresponding WItemSelection! This method is especially useful to iterate the through the selected items.

Parameters
indexthe index
Returns
the item

Definition at line 151 of file WItemSelector.cpp.

References getItemIndexOfSelected(), and m_selection.

Referenced by WMPickingDVREvaluation::interactionMapping(), WFilterPropertyHandler::isPDGTypeSelected(), WMPickingDVREvaluation::moduleMain(), WMTemplate::moduleMain(), WMCoordinateSystem::propertyChanged(), WColumnPropertyHandler::propertyNotifier(), WFilterPropertyHandler::selectPdgAndSaveEvent(), and WFilterPropertyHandler::setDefaultForRenameField().

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

◆ atAll()

const std::shared_ptr< WItemSelectionItem > WItemSelector::atAll ( size_t  index) const
virtual

Gets the item with the given index from the WItemSelection.

This index does not equal the index of the same item for at. This method is useful to go through the list of ALL items (not only the selected).

Parameters
indexthe index
Returns
the item

Definition at line 146 of file WItemSelector.cpp.

References m_selection.

Referenced by WPropertySelectionWidget::update().

+ Here is the caller graph for this function:

◆ createSelector()

WItemSelector WItemSelector::createSelector ( const IndexList selected) const
private

Creates a new selector instance using the specified index list.

Handles all needed signal subscription stuff.

Parameters
selectedthe index list of selected items
Returns
new selector

Definition at line 176 of file WItemSelector.cpp.

References m_selection, and WItemSelector().

Referenced by newSelector().

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

◆ empty()

bool WItemSelector::empty ( ) const
virtual

True if the selection is empty.

Returns
true if nothing is selected.

Definition at line 161 of file WItemSelector.cpp.

References size().

Referenced by WFilterPropertyHandler::setDefaultForRenameField().

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

◆ getIndexList()

WItemSelector::IndexList WItemSelector::getIndexList ( ) const

Casts the selector to a list of indices currently selected.

It contains the list of index in the corresponding WItemSelection. This is especially useful if the whole index list is needed without nasty iterations.

Returns
the list of index.

Definition at line 199 of file WItemSelector.cpp.

References m_selected.

Referenced by WGEShaderPropertyDefineOptionsIndexAdapter< WPropSelection >::operator()().

+ Here is the caller graph for this function:

◆ getItemIndexOfSelected()

size_t WItemSelector::getItemIndexOfSelected ( size_t  index) const
virtual

Helps to get the index of an selected item in the WItemSelection.

This is somehow similar to at, but does not return the item but the index to it.

Parameters
indexthe index in the selection (not the item index in WItemSelection)
Returns
the index in WItemSelection.

Definition at line 156 of file WItemSelector.cpp.

References m_selected.

Referenced by at(), WMCoordinateSystem::findBoundingBox(), WMScalarSegmentation::moduleMain(), WMTriangleMeshRenderer::moduleMain(), WMCoordinateSystem::propertyChanged(), WMSurfaceIllustrator::renderMesh(), WMTriangleMeshRenderer::renderMesh(), WPropertySelectionWidget::update(), and WMGridRenderer::updateNode().

+ Here is the caller graph for this function:

◆ invalidate()

void WItemSelector::invalidate ( )
private

Handles the case of invalidation.

Definition at line 166 of file WItemSelector.cpp.

References m_valid.

Referenced by operator=(), and WItemSelector().

+ Here is the caller graph for this function:

◆ isValid()

bool WItemSelector::isValid ( ) const
virtual

Checks whether the selection is valid anymore.

If a selector is not valid anymore, you should ask the one providing the selectors (most probably a WPropSelection) for a new one.

Returns
true if valid.

Definition at line 171 of file WItemSelector.cpp.

References m_valid.

◆ lock()

void WItemSelector::lock ( )

Read locks the underlying selection.

This ensure, that the selection stays fixed as long as this selector is locked. This also ensures that no invalidation can be issued as long as this selector has the lock. BUT it is possible that an invalidation occurs while this selector waits. So please always check for validity of the selector ater locking.

Definition at line 182 of file WItemSelector.cpp.

References m_lock, and m_selection.

Referenced by WPropertySelectionWidget::update().

+ Here is the caller graph for this function:

◆ newSelector() [1/4]

WItemSelector WItemSelector::newSelector ( ) const

Creates a new selector, but basing on this instance as old one.

The new selector tries to keep the old selection but makes the internal selection list valid with the current underlying selection.

Note
Please be aware that, in the moment this method returns, another thread can make all selectors invalid again causing the returned one to be invalid too. To avoid this, use the newSelector method only if the old has locked the selection using lock and unlock.
Returns
the new (valid) selector.

Definition at line 98 of file WItemSelector.cpp.

References m_selected, m_selection, and m_valid.

◆ newSelector() [2/4]

WItemSelector WItemSelector::newSelector ( const std::string  asString) const

Creates a new valid instance with the specified items selected.

This is especially useful to simply create a new selection if only the string representing it is known. This somehow correlates to the << operator.

Note
Please be aware that, in the moment this method returns, another thread can make all selectors invalid again causing the returned one to be invalid too. To avoid this, use the newSelector method only if the old has locked the selection using lock and unlock.
Parameters
asStringthe selected items
Returns
the new selector instance

Definition at line 84 of file WItemSelector.cpp.

References createSelector(), and string_utils::tokenize().

+ Here is the call graph for this function:

◆ newSelector() [3/4]

WItemSelector WItemSelector::newSelector ( IndexList  selected) const

Creates a new valid instance with the specified items selected.

This is especially useful to simply create a new selection if only the old selection is known.

Note
Please be aware that, in the moment this method returns, another thread can make all selectors invalid again causing the returned one to be invalid too. To avoid this, use the newSelector method only if the old has locked the selection using lock and unlock.
Parameters
selectedthe selected items (their index in WItemSelection).
Returns
the new selector instance

Definition at line 72 of file WItemSelector.cpp.

References createSelector().

Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_SELECTION >::create(), and WMGridRenderer::properties().

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

◆ newSelector() [4/4]

WItemSelector WItemSelector::newSelector ( size_t  selected) const

Creates a new valid instance with the specified items selected.

This can be useful to add a certain index. The new selector has the selection from this AND the specified one. If you want to create a selector containing only one selected item, use the method that uses the IndexList.

Note
Please be aware that, in the moment this method returns, another thread can make all selectors invalid again causing the returned one to be invalid too. To avoid this, use the newSelector method only if the old has locked the selection using lock and unlock.
Parameters
selectedthe selected item (the index in WItemSelection).
Returns
the new selector instance

Definition at line 77 of file WItemSelector.cpp.

References createSelector(), and m_selected.

+ Here is the call graph for this function:

◆ operator unsigned int()

WItemSelector::operator unsigned int ( ) const

Allow cast from selector to unsigned int.

Returns
the index of the first selected item in the selection.

Definition at line 194 of file WItemSelector.cpp.

◆ operator<<()

std::ostream & WItemSelector::operator<< ( std::ostream &  out) const

Write a selection in string representation to the given output stream.

Parameters
outthe output stream where to put the information
Returns
the output stream extended by the information of this selector

Definition at line 113 of file WItemSelector.cpp.

References m_selected.

◆ operator=()

WItemSelector & WItemSelector::operator= ( const WItemSelector other)

Copy assignment.

Creates a new copy of the selector and ensure proper signal subscriptions to the underlying selection.

Parameters
otherthe selector to copy
Returns
this.

Definition at line 51 of file WItemSelector.cpp.

References invalidate(), m_invalidateSignalConnection, m_selected, m_selection, and m_valid.

+ Here is the call graph for this function:

◆ operator==()

bool WItemSelector::operator== ( const WItemSelector other) const

Compares two selector.

They are assumed to be equal if the selected items are equal and if the underlying WItemSelection is the same.

Parameters
otherthe selector
Returns
true if equal

Definition at line 131 of file WItemSelector.cpp.

References m_selected, m_selection, and m_valid.

◆ size()

size_t WItemSelector::size ( ) const
virtual

The number of selected items.

Returns
the number of selected items.

Definition at line 141 of file WItemSelector.cpp.

References m_selected.

Referenced by empty(), WFilterPropertyHandler::isPDGTypeSelected(), WMTemplate::moduleMain(), WPropertySelectionWidget::update(), and WMGridRenderer::updateNode().

+ Here is the caller graph for this function:

◆ sizeAll()

size_t WItemSelector::sizeAll ( ) const
virtual

Gives the count of elements in the set of selectable items.

This is size + number of unselected items.

Returns
the number of all items in the item set.

Definition at line 136 of file WItemSelector.cpp.

References m_selection.

Referenced by WPropertySelectionWidget::update().

+ Here is the caller graph for this function:

◆ unlock()

void WItemSelector::unlock ( )

Unlocks the selection again.

Always call this after a lock.

Definition at line 189 of file WItemSelector.cpp.

References m_lock.

Friends And Related Function Documentation

◆ WItemSelection

friend class WItemSelection
friend

Only class allowed to instanciate this class.

Definition at line 54 of file WItemSelector.h.

Member Data Documentation

◆ m_invalidateSignalConnection

boost::signals2::connection WItemSelector::m_invalidateSignalConnection
protected

Stores the connection made using WItemSelection::subscribeInvalidateSignal.

Definition at line 259 of file WItemSelector.h.

Referenced by operator=(), WItemSelector(), and ~WItemSelector().

◆ m_lock

WItemSelection::ReadTicket WItemSelector::m_lock
private

This locks prevents the selection to be modified during selector iteration.

Definition at line 284 of file WItemSelector.h.

Referenced by lock(), and unlock().

◆ m_selected

IndexList WItemSelector::m_selected
protected

The list of items currently selected.

Definition at line 254 of file WItemSelector.h.

Referenced by getIndexList(), getItemIndexOfSelected(), newSelector(), operator<<(), operator=(), operator==(), and size().

◆ m_selection

std::shared_ptr< WItemSelection > WItemSelector::m_selection
protected

The selection handled by this selector.

Definition at line 249 of file WItemSelector.h.

Referenced by at(), atAll(), createSelector(), lock(), newSelector(), operator=(), operator==(), sizeAll(), and WItemSelector().

◆ m_valid

bool WItemSelector::m_valid
private

If true the selector is valid.

Definition at line 279 of file WItemSelector.h.

Referenced by invalidate(), isValid(), newSelector(), operator=(), and operator==().


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