API  4.5.1
For C++ developers
OpenSim::ComponentList< T > Class Template Reference


Collection (linked list) of components to iterate through. More...

Public Member Functions

 ComponentList (const Component &root, const ComponentFilter &f)
 Constructor that takes a Component to iterate over (itself and its descendants) and a ComponentFilter. More...
 
 ComponentList (const Component &root)
 Constructor that takes only a Component to iterate over (itself and its descendants). More...
 
virtual ~ComponentList () noexcept=default
 Destructor of ComponentList. More...
 
iterator begin ()
 Return an iterator pointing to the first component in the tree traversal of components under and including the root component passed to the ComponentList constructor. More...
 
const_iterator begin () const
 Same as cbegin(). More...
 
const_iterator cbegin () const
 Similar to begin(), except it does not permit modifying the elements of the list, even if T is non-const (e.g., ComponentList<Body>). More...
 
iterator end ()
 Use this method to check if you have reached the end of the list. More...
 
const_iterator end () const
 Same as cend(). More...
 
const_iterator cend () const
 Use this method to check if you have reached the end of the list. More...
 
void setFilter (const ComponentFilter &filter)
 Allow users to specify a custom ComponentFilter. More...
 

Public Types

using ConstT = typename std::add_const< T >::type
 
using value_type = T
 
using difference_type = std::ptrdiff_t
 
using reference = T &
 
using const_reference = const T &
 
using pointer = T *
 
using const_pointer = const T *
 
using iterator = ComponentListIterator< T >
 If T is const (e.g., ComponentList<const Body>), then this is the same as const_iterator, and does not allow modifying the elements. More...
 
using const_iterator = ComponentListIterator< ConstT >
 A const forward iterator for iterating through ComponentList<T>. More...
 
using iterator_category = std::forward_iterator_tag
 

Detailed Description

template<typename T>
class OpenSim::ComponentList< T >


Collection (linked list) of components to iterate through.

Typical use is to call getComponentList() on a component (e.g. model) to obtain an instance of this class, then call begin() to get an iterator pointing to the first entry in the list then increment the iterator until end(). The linked list is formed by tree pre-order traversal where each component is visited followed by all its immediate subcomponents (recursively).

The traversal order is wired via Component::initComponentTreeTraversal(), which is called just before getting a ComponentList from a Component, either via Component::getComponentList() or Component::updComponentList().

Member Typedef Documentation

◆ const_iterator

A const forward iterator for iterating through ComponentList<T>.

The const indicates that the iterator provides only const references/pointers, and that components can't be modified through this iterator.

◆ const_pointer

template<typename T>
using OpenSim::ComponentList< T >::const_pointer = const T*

◆ const_reference

template<typename T>
using OpenSim::ComponentList< T >::const_reference = const T&

◆ ConstT

template<typename T>
using OpenSim::ComponentList< T >::ConstT = typename std::add_const<T>::type

◆ difference_type

template<typename T>
using OpenSim::ComponentList< T >::difference_type = std::ptrdiff_t

◆ iterator

template<typename T>
using OpenSim::ComponentList< T >::iterator = ComponentListIterator<T>

If T is const (e.g., ComponentList<const Body>), then this is the same as const_iterator, and does not allow modifying the elements.

If T is not const, then this iterator allows modifying the elements.

◆ iterator_category

template<typename T>
using OpenSim::ComponentList< T >::iterator_category = std::forward_iterator_tag

◆ pointer

template<typename T>
using OpenSim::ComponentList< T >::pointer = T*

◆ reference

template<typename T>
using OpenSim::ComponentList< T >::reference = T&

◆ value_type

template<typename T>
using OpenSim::ComponentList< T >::value_type = T

Constructor & Destructor Documentation

◆ ComponentList() [1/2]

template<typename T>
OpenSim::ComponentList< T >::ComponentList ( const Component root,
const ComponentFilter f 
)
inline

Constructor that takes a Component to iterate over (itself and its descendants) and a ComponentFilter.

You can change the filter later using the setFilter() method. The filter is cloned on construction and can only be changed using setFilter().

◆ ComponentList() [2/2]

template<typename T>
OpenSim::ComponentList< T >::ComponentList ( const Component root)
inline

Constructor that takes only a Component to iterate over (itself and its descendants).

You can change the filter using setFilter() method.

◆ ~ComponentList()

template<typename T>
virtual OpenSim::ComponentList< T >::~ComponentList ( )
virtualdefaultnoexcept

Destructor of ComponentList.

Member Function Documentation

◆ begin() [1/2]

template<typename T>
iterator OpenSim::ComponentList< T >::begin ( )
inline

Return an iterator pointing to the first component in the tree traversal of components under and including the root component passed to the ComponentList constructor.

If T is non-const, then this iterator allows you to modify the elements of this list.

◆ begin() [2/2]

template<typename T>
const_iterator OpenSim::ComponentList< T >::begin ( ) const
inline

Same as cbegin().

◆ cbegin()

template<typename T>
const_iterator OpenSim::ComponentList< T >::cbegin ( ) const
inline

Similar to begin(), except it does not permit modifying the elements of the list, even if T is non-const (e.g., ComponentList<Body>).

◆ cend()

template<typename T>
const_iterator OpenSim::ComponentList< T >::cend ( ) const
inline

Use this method to check if you have reached the end of the list.

This points past the end of the list, not to the last item in the list. Use this if you used cbegin().

Referenced by OpenSim::ComponentList< T >::end().

◆ end() [1/2]

template<typename T>
iterator OpenSim::ComponentList< T >::end ( )
inline

Use this method to check if you have reached the end of the list.

This points past the end of the list, not to the last item in the list.

◆ end() [2/2]

template<typename T>
const_iterator OpenSim::ComponentList< T >::end ( ) const
inline

◆ setFilter()

template<typename T>
void OpenSim::ComponentList< T >::setFilter ( const ComponentFilter filter)
inline

Allow users to specify a custom ComponentFilter.

This object makes a clone of the passed in filter.


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