bipedal locomotion framework
A suite of libraries for achieving bipedal locomotion on humanoid robots
BipedalLocomotion::GenericContainer::Vector< T > Class Template Reference

Forward declaration of Vector class. More...

#include <GenericContainer/include/BipedalLocomotion/GenericContainer/Vector.h>

Classes

class  Ref
 The class ref is used a substitution to a classical reference to a Vector. More...
 

Public Types

using vector_element_type = typename iDynTree::Span< T >::element_type
 Utility aliases depending on the type T. More...
 
using value_type = typename iDynTree::Span< T >::value_type
 
using index_type = typename iDynTree::Span< T >::index_type
 
using pointer = typename iDynTree::Span< T >::pointer
 
using reference = typename iDynTree::Span< T >::reference
 
using const_reference = const value_type &
 
using size_type = typename iDynTree::Span< T >::size_type
 
using iterator = typename iDynTree::Span< T >::iterator
 Utility aliases to define iterators.
 
using const_iterator = typename iDynTree::Span< T >::const_iterator
 
using reverse_iterator = typename iDynTree::Span< T >::reverse_iterator
 
using const_reverse_iterator = typename iDynTree::Span< T >::const_reverse_iterator
 
using resize_function_type = std::function< iDynTree::Span< T >(index_type)>
 Alias for the type of lambda used to resize the original vector. More...
 
using eigen_map_type = typename Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, 1 > >
 Alias to determine the output type of toEigen()
 
using eigen_map_const_type = typename Eigen::Map< const Eigen::Matrix< T, Eigen::Dynamic, 1 > >
 

Public Member Functions

 Vector (iDynTree::Span< T > span, resize_function_type resizeLambda)
 Constructor. More...
 
 Vector (iDynTree::Span< T > span)
 Constructor. More...
 
 ~Vector ()=default
 Destructor.
 
 Vector (const Vector< T > &other)=delete
 Copy constructor. More...
 
 Vector (Vector< T > &&other)
 Move constructor. More...
 
bool clone (const Vector< T > &other)
 Copies the content of the vector. More...
 
bool clone (iDynTree::Span< T > other)
 Copies the content of the vector. More...
 
Vector< T > & operator= (const Vector< T > &other)
 operator = Copies the content More...
 
Vector< T > & operator= (iDynTree::Span< T > other)
 operator = Copies the content More...
 
Vector< T > & operator= (Vector< T > &&other)
 Move operator = Copies the content. More...
 
bool resizeVector (index_type newSize)
 resizeVector It resize the original vector (if possible) More...
 
void resize (index_type newSize)
 resize It resize the original vector (if possible) More...
 
index_type size () const
 size Get the size of the Vector More...
 
bool empty () const
 empty Checks if the container is empty (zero size) More...
 
const_reference operator[] (index_type idx) const
 operator [] Accessor More...
 
reference operator[] (index_type idx)
 operator [] Accessor More...
 
vector_element_type getVal (index_type idx) const
 getVal Accessor More...
 
bool setVal (index_type idx, vector_element_type val)
 setVal Setter More...
 
const_reference at (index_type idx) const
 at Accessor More...
 
reference at (index_type idx)
 at Accessor More...
 
const_reference operator() (index_type idx) const
 operator () Accessor More...
 
reference operator() (index_type idx)
 operator () Accessor More...
 
pointer data () const
 data Raw pointer to the data More...
 
iterator begin ()
 begin Iterator More...
 
iterator end ()
 end Iterator More...
 
const_iterator begin () const
 begin Iterator More...
 
const_iterator end () const
 end Iterator More...
 
const_iterator cbegin () const
 cbegin Iterator More...
 
const_iterator cend () const
 cend Iterator More...
 
reverse_iterator rbegin ()
 rbegin Iterator to the first element of the reversed vector More...
 
reverse_iterator rend ()
 rend Iterator to the element following the last element of the reversed vector. More...
 
const_reverse_iterator rbegin () const
 rbegin Iterator to the first element of the reversed vector More...
 
const_reverse_iterator rend () const
 rend Iterator to the element following the last element of the reversed vector. More...
 
const_reverse_iterator crbegin () const
 crbegin Iterator to the first element of the reversed vector More...
 
const_reverse_iterator crend () const
 crend Iterator to the element following the last element of the reversed vector. More...
 
eigen_map_type toEigen ()
 Get an Eigen map corresponding to the current generic vector (see https://eigen.tuxfamily.org/dox/classEigen_1_1Map.html).
 
eigen_map_const_type toEigen () const
 Get an Eigen const map corresponding to the current generic vector (see https://eigen.tuxfamily.org/dox/classEigen_1_1Map.html).
 

Protected Member Functions

 Vector ()=default
 The default constructor is private. More...
 

Protected Attributes

iDynTree::Span< T > m_span
 Span of the pointed vector. More...
 
resize_function_type m_resizeLambda
 User specified lambda to resize the existing container.
 

Detailed Description

template<typename T>
class BipedalLocomotion::GenericContainer::Vector< T >

Forward declaration of Vector class.

Vector is a utility class which maps another existing contiguous container.

T is the type of vector (double, float, int, string,...)

It does not contain any data, but only a pointer to an existing contiguous area of memory containing a sequence of objects. It also stores its size, i.e. the number of objects. It does not own this portion of memory, hence it needs to be properly initialized from an existing container, such as an iDynTree::Vector, std::vector, array, yarp::sig::Vector and similar. Even if it does not own the memory, it is possible to resize it. This is done through an user specified lambda, which calls the corresponding "resize" method on the original object from which Vector has been initialized.

Warning
The original object from which Vector has been initialized should not be deallocated before Vector. This would invalidate the pointer inside it.

Member Typedef Documentation

◆ vector_element_type

template<typename T >
using BipedalLocomotion::GenericContainer::Vector< T >::vector_element_type = typename iDynTree::Span<T>::element_type

Utility aliases depending on the type T.

Some notes:

  • vector_element_type has a different name than the corresponding one in iDynTree::Span to avoid some compilation issues.
  • value_type is the same as vector_element_type, but without an eventual const attribute

◆ resize_function_type

template<typename T >
using BipedalLocomotion::GenericContainer::Vector< T >::resize_function_type = std::function<iDynTree::Span<T>(index_type)>

Alias for the type of lambda used to resize the original vector.

In particular, it takes as input the new size (of type index size)

Constructor & Destructor Documentation

◆ Vector() [1/5]

template<typename T >
BipedalLocomotion::GenericContainer::Vector< T >::Vector ( )
protecteddefault

The default constructor is private.

In fact, once the Vector is built, it is assumed to point to an existing container. To be used only if m_span and m_resizeLamba are set manually.

◆ Vector() [2/5]

template<typename T >
BipedalLocomotion::GenericContainer::Vector< T >::Vector ( iDynTree::Span< T >  span,
resize_function_type  resizeLambda 
)
inline

Constructor.

Parameters
spanSpan of the existing container
resizeLambdaUser defined lambda to resize the original container

◆ Vector() [3/5]

template<typename T >
BipedalLocomotion::GenericContainer::Vector< T >::Vector ( iDynTree::Span< T >  span)
inline

Constructor.

Parameters
spanSpan of the existing container

Since no resizeLambda is provided, it is assumed that the original container cannot be resized.

◆ Vector() [4/5]

template<typename T >
BipedalLocomotion::GenericContainer::Vector< T >::Vector ( const Vector< T > &  other)
delete

Copy constructor.

Warning
It has been deleted since it would not be clear if the pointer or the pointed data would be copied.

◆ Vector() [5/5]

template<typename T >
BipedalLocomotion::GenericContainer::Vector< T >::Vector ( Vector< T > &&  other)
inline

Move constructor.

Parameters
otherAnother Vector
Warning
Here the pointers are copied, the content is not duplicated.

Member Function Documentation

◆ clone() [1/2]

template<typename T >
bool BipedalLocomotion::GenericContainer::Vector< T >::clone ( const Vector< T > &  other)
inline

Copies the content of the vector.

Parameters
otherVector from which to copy
Returns
true in case of success. False if the two have different size and this is not resizable.
Warning
It performs memory allocation if this is resizable and the sizes are different.

◆ clone() [2/2]

template<typename T >
bool BipedalLocomotion::GenericContainer::Vector< T >::clone ( iDynTree::Span< T >  other)
inline

Copies the content of the vector.

Parameters
otherSpan from which to copy
Returns
true in case of success. False if the two have different size and this is not resizable.
Warning
It performs memory allocation if this is resizable and the sizes are different.

◆ operator=() [1/3]

template<typename T >
Vector<T>& BipedalLocomotion::GenericContainer::Vector< T >::operator= ( const Vector< T > &  other)
inline

operator = Copies the content

Parameters
otherVector from which to copy
Returns
A reference to the vector.

It calls clone(). There is an assert on its return value.

Warning
It performs memory allocation if this is resizable and the sizes are different.

◆ operator=() [2/3]

template<typename T >
Vector<T>& BipedalLocomotion::GenericContainer::Vector< T >::operator= ( iDynTree::Span< T >  other)
inline

operator = Copies the content

Parameters
otherVector from which to copy
Returns
A reference to the vector.

It calls clone(). There is an assert on its return value.

Warning
It performs memory allocation if this is resizable and the sizes are different.

◆ operator=() [3/3]

template<typename T >
Vector<T>& BipedalLocomotion::GenericContainer::Vector< T >::operator= ( Vector< T > &&  other)
inline

Move operator = Copies the content.

Parameters
otherVector from which to copy
Returns
A reference to the vector.

It calls clone(). There is an assert on its return value.

Warning
It performs memory allocation if this is resizable and the sizes are different.

◆ resizeVector()

template<typename T >
bool BipedalLocomotion::GenericContainer::Vector< T >::resizeVector ( index_type  newSize)
inline

resizeVector It resize the original vector (if possible)

Parameters
newSizeNew size of the vector
Returns
true if the new size matches the desired. False otherwise.
Warning
It may perform memory allocation if the new size is different from the current and the resizeLambda has been specified.

◆ resize()

template<typename T >
void BipedalLocomotion::GenericContainer::Vector< T >::resize ( index_type  newSize)
inline

resize It resize the original vector (if possible)

Parameters
newSizeNew size of the vector It calls resizeVector(). There is an assert on its return value.
Warning
It may perform memory allocation if the new size is different from the current and the resizeLambda has been specified.

◆ size()

template<typename T >
index_type BipedalLocomotion::GenericContainer::Vector< T >::size ( ) const
inline

size Get the size of the Vector

Returns
The size of the Vector

◆ empty()

template<typename T >
bool BipedalLocomotion::GenericContainer::Vector< T >::empty ( ) const
inline

empty Checks if the container is empty (zero size)

Returns
True if empty.

◆ operator[]() [1/2]

template<typename T >
const_reference BipedalLocomotion::GenericContainer::Vector< T >::operator[] ( index_type  idx) const
inline

operator [] Accessor

Parameters
idxThe index to be accessed
Returns
A const reference to the requested element.

◆ operator[]() [2/2]

template<typename T >
reference BipedalLocomotion::GenericContainer::Vector< T >::operator[] ( index_type  idx)
inline

operator [] Accessor

Parameters
idxThe index to be accessed
Returns
A reference to the requested element.

◆ getVal()

template<typename T >
vector_element_type BipedalLocomotion::GenericContainer::Vector< T >::getVal ( index_type  idx) const
inline

getVal Accessor

Parameters
idxThe index to be accessed
Returns
A const reference to the requested element.

◆ setVal()

template<typename T >
bool BipedalLocomotion::GenericContainer::Vector< T >::setVal ( index_type  idx,
vector_element_type  val 
)
inline

setVal Setter

Parameters
idxIndex of the values to be set
valThe new value
Returns
False if idx is not within [0, size()).

◆ at() [1/2]

template<typename T >
const_reference BipedalLocomotion::GenericContainer::Vector< T >::at ( index_type  idx) const
inline

at Accessor

Parameters
idxThe index to be accessed
Returns
A const reference to the requested element.

◆ at() [2/2]

template<typename T >
reference BipedalLocomotion::GenericContainer::Vector< T >::at ( index_type  idx)
inline

at Accessor

Parameters
idxThe index to be accessed
Returns
A reference to the requested element.

◆ operator()() [1/2]

template<typename T >
const_reference BipedalLocomotion::GenericContainer::Vector< T >::operator() ( index_type  idx) const
inline

operator () Accessor

Parameters
idxThe index to be accessed
Returns
A const reference to the requested element.

◆ operator()() [2/2]

template<typename T >
reference BipedalLocomotion::GenericContainer::Vector< T >::operator() ( index_type  idx)
inline

operator () Accessor

Parameters
idxThe index to be accessed
Returns
A reference to the requested element.

◆ data()

template<typename T >
pointer BipedalLocomotion::GenericContainer::Vector< T >::data ( ) const
inline

data Raw pointer to the data

Returns
THe raw pointer to the data

◆ begin() [1/2]

template<typename T >
iterator BipedalLocomotion::GenericContainer::Vector< T >::begin ( )
inline

begin Iterator

Returns
An iterator to the end of the sequence

◆ end() [1/2]

template<typename T >
iterator BipedalLocomotion::GenericContainer::Vector< T >::end ( )
inline

end Iterator

Returns
An iterator to the end of the sequence
Warning
This element acts as a placeholder; attempting to access it results in undefined behavior.

◆ begin() [2/2]

template<typename T >
const_iterator BipedalLocomotion::GenericContainer::Vector< T >::begin ( ) const
inline

begin Iterator

Returns
A const iterator to the end of the sequence

◆ end() [2/2]

template<typename T >
const_iterator BipedalLocomotion::GenericContainer::Vector< T >::end ( ) const
inline

end Iterator

Returns
A const iterator to the end of the sequence
Warning
This element acts as a placeholder; attempting to access it results in undefined behavior.

◆ cbegin()

template<typename T >
const_iterator BipedalLocomotion::GenericContainer::Vector< T >::cbegin ( ) const
inline

cbegin Iterator

Returns
A const iterator to the end of the sequence

◆ cend()

template<typename T >
const_iterator BipedalLocomotion::GenericContainer::Vector< T >::cend ( ) const
inline

cend Iterator

Returns
A const iterator to the end of the sequence
Warning
This element acts as a placeholder; attempting to access it results in undefined behavior.

◆ rbegin() [1/2]

template<typename T >
reverse_iterator BipedalLocomotion::GenericContainer::Vector< T >::rbegin ( )
inline

rbegin Iterator to the first element of the reversed vector

Returns
Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last element of the non-reversed vector

◆ rend() [1/2]

template<typename T >
reverse_iterator BipedalLocomotion::GenericContainer::Vector< T >::rend ( )
inline

rend Iterator to the element following the last element of the reversed vector.

Returns
Returns a reverse iterator to the element following the last element of the reversed vector. It corresponds to the element preceding the first element of the non-reversed vector.
Warning
This element acts as a placeholder; attempting to access it results in undefined behavior.

◆ rbegin() [2/2]

template<typename T >
const_reverse_iterator BipedalLocomotion::GenericContainer::Vector< T >::rbegin ( ) const
inline

rbegin Iterator to the first element of the reversed vector

Returns
Returns a const reverse iterator to the first element of the reversed vector. It corresponds to the last element of the non-reversed vector

◆ rend() [2/2]

template<typename T >
const_reverse_iterator BipedalLocomotion::GenericContainer::Vector< T >::rend ( ) const
inline

rend Iterator to the element following the last element of the reversed vector.

Returns
Returns a reverse iterator to the element following the last element of the reversed vector. It corresponds to the element preceding the first element of the non-reversed vector.
Warning
This element acts as a placeholder; attempting to access it results in undefined behavior.

◆ crbegin()

template<typename T >
const_reverse_iterator BipedalLocomotion::GenericContainer::Vector< T >::crbegin ( ) const
inline

crbegin Iterator to the first element of the reversed vector

Returns
Returns a const reverse iterator to the first element of the reversed vector. It corresponds to the last element of the non-reversed vector

◆ crend()

template<typename T >
const_reverse_iterator BipedalLocomotion::GenericContainer::Vector< T >::crend ( ) const
inline

crend Iterator to the element following the last element of the reversed vector.

Returns
Returns a reverse iterator to the element following the last element of the reversed vector. It corresponds to the element preceding the first element of the non-reversed vector.
Warning
This element acts as a placeholder; attempting to access it results in undefined behavior.

Member Data Documentation

◆ m_span

template<typename T >
iDynTree::Span<T> BipedalLocomotion::GenericContainer::Vector< T >::m_span
protected

Span of the pointed vector.

This allows to point to an existing container without owning it.


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