API  4.2
For MATLAB, Python, Java, and C++ users
OpenSim::ComponentListIterator< T > Class Template Reference

Class used to iterate over subcomponents of a specific type (by default, any Component). More...

+ Inheritance diagram for OpenSim::ComponentListIterator< T >:

Public Member Functions

template<typename OtherT >
bool operator== (const ComponentListIterator< OtherT > &other) const
 Check that the component under the current iterator is the same (has same address) as the right-hand iterator. More...
 
template<typename OtherT >
bool operator!= (const ComponentListIterator< OtherT > &other) const
 Check for inequality using same convention as operator==. More...
 
T & operator* () const
 Dereference the iterator to get a reference to Component of proper type (matching Filter if specified). More...
 
T & deref () const
 
T * operator-> () const
 Another dereferencing operator that returns a pointer. More...
 
ComponentListIteratoroperator++ ()
 Prefix increment operator to get the next item in the ComponentList. More...
 
ComponentListIterator operator++ (int)
 Postfix increment operator to get the next item in the ComponentList. More...
 
ComponentListIteratornext ()
 Method equivalent to pre-increment operator for operator-deficient languages. More...
 
template<typename FromT >
 ComponentListIterator (const ComponentListIterator< FromT > &source, typename std::enable_if< std::is_convertible< FromT *, T * >::value >::type *=0)
 Allow converting from non-const iterator to const_iterator. More...
 
bool equals (const ComponentListIterator &other) const
 @ Comparison operators for scripting These variants accept only an iterator with the same template parameter. More...
 
bool operator== (const ComponentListIterator &other) const
 
bool operator!= (const ComponentListIterator &other) const
 

Detailed Description

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

Class used to iterate over subcomponents of a specific type (by default, any Component).

This iterator is can either be a const_iterator or non-const iterator, depending on how you got it. If this is a const_iterator, it returns only a const reference to a component. If this is a non-const iterator, then it returns a non-const reference to a component, and thus you can modify the component.

If you got this iterator from something like a ComponentList<const Body>, then it is necessarily a const_iterator. If you got this iterator from something like ComponentList<Body>, then this may be either a const_iterator (e.g., from ComponentList<Body>::cbegin()) or non-const iterator (e.g., from ComponentList<Body>::begin()).

If you have a non-const iterator, you should not add (sub)components to any components.

This iterator works only in the forward direction (not bidirectional).

Here is an example of using this iterator with a range for loop (const_iterator):

ComponentList<const GeometryPath> geomPathList = model.getComponentList<GeometryPath>();
for (const GeometryPath& gpath : geomPathList) {
// do something with gpath
}

Here is a similar example, but where you can modify the components:

ComponentList<GeometryPath> geomPathList = model.updComponentList<GeometryPath>();
for (GeometryPath& gpath : geomPathList) {
// do something with gpath
}

Constructor & Destructor Documentation

◆ ComponentListIterator()

template<typename T >
template<typename FromT >
OpenSim::ComponentListIterator< T >::ComponentListIterator ( const ComponentListIterator< FromT > &  source,
typename std::enable_if< std::is_convertible< FromT *, T * >::value >::type *  = 0 
)
inline

Allow converting from non-const iterator to const_iterator.

This helps with iterating through the list in a const way, even if you have a non-const list. This allows the following code:

ComponentList<Body> bodies = model.getComponentList<Body>();
ComponentListIterator< ConstT > const_iterator
A const forward iterator for iterating through ComponentList<T>.
Definition: ComponentList.h:127

This constructor does not allow converting from a const_iterator to a non-const iterator (through the enable_if).

Member Function Documentation

◆ deref()

template<typename T >
T& OpenSim::ComponentListIterator< T >::deref ( ) const
inline

◆ equals()

template<typename T >
bool OpenSim::ComponentListIterator< T >::equals ( const ComponentListIterator< T > &  other) const
inline

@ Comparison operators for scripting These variants accept only an iterator with the same template parameter.

Check for (non)equality using a normal method rather than an operator.

◆ next()

template<typename T >
ComponentListIterator& OpenSim::ComponentListIterator< T >::next ( )
inline

Method equivalent to pre-increment operator for operator-deficient languages.

Referenced by OpenSim::ComponentListIterator< T >::operator++().

◆ operator!=() [1/2]

template<typename T >
bool OpenSim::ComponentListIterator< T >::operator!= ( const ComponentListIterator< T > &  other) const
inline

◆ operator!=() [2/2]

template<typename T >
template<typename OtherT >
bool OpenSim::ComponentListIterator< T >::operator!= ( const ComponentListIterator< OtherT > &  other) const
inline

Check for inequality using same convention as operator==.

◆ operator*()

template<typename T >
T& OpenSim::ComponentListIterator< T >::operator* ( ) const
inline

Dereference the iterator to get a reference to Component of proper type (matching Filter if specified).

If you have a const iterator, then this returns a const reference; otherwise, this returns a non-const reference.

References OpenSim::ComponentListIterator< T >::operator->().

◆ operator++() [1/2]

template<typename T >
ComponentListIterator< T > & OpenSim::ComponentListIterator< T >::operator++

Prefix increment operator to get the next item in the ComponentList.

ComponentListIterator<T> pre-increment operator, advances the iterator to the next valid entry.

Prefer to use ++iter and not iter++.

◆ operator++() [2/2]

template<typename T >
ComponentListIterator OpenSim::ComponentListIterator< T >::operator++ ( int  )
inline

Postfix increment operator to get the next item in the ComponentList.

To enable usage as iter++, although ++iter is more efficient.

References OpenSim::ComponentListIterator< T >::next().

◆ operator->()

template<typename T >
T* OpenSim::ComponentListIterator< T >::operator-> ( ) const
inline

Another dereferencing operator that returns a pointer.

Referenced by OpenSim::ComponentListIterator< T >::deref(), and OpenSim::ComponentListIterator< T >::operator*().

◆ operator==() [1/2]

template<typename T >
bool OpenSim::ComponentListIterator< T >::operator== ( const ComponentListIterator< T > &  other) const
inline

◆ operator==() [2/2]

template<typename T >
template<typename OtherT >
bool OpenSim::ComponentListIterator< T >::operator== ( const ComponentListIterator< OtherT > &  other) const
inline

Check that the component under the current iterator is the same (has same address) as the right-hand iterator.


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