Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add operator[] to iDynTree Vectors #596

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/releases/v0_12.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ to normalize errors or as initial points of a nonlinear optimization procedure.
* Fixed implementation of Transform::log() method (https://github.com/robotology/idyntree/pull/562)
* Fixed implementation of SpatialMotionVector::exp() method (https://github.com/robotology/idyntree/pull/562)
* Add nameIsValid attribute to iDynTree::SolidShape class.
* Add operator[] method to `iDynTree::VectorDynSize` (https://github.com/robotology/idyntree/pull/596)
* Add operator[] method to `iDynTree::VectorFixSize` (https://github.com/robotology/idyntree/pull/596)

### `Model`
* Implement `getTotalMass()` method for Model class
Expand Down
4 changes: 4 additions & 0 deletions src/core/include/iDynTree/Core/VectorDynSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ namespace iDynTree

double& operator()(const unsigned int index);

double operator[](const unsigned int index) const;

double& operator[](const unsigned int index);

double getVal(const unsigned int index) const;

bool setVal(const unsigned int index, const double new_el);
Expand Down
19 changes: 18 additions & 1 deletion src/core/include/iDynTree/Core/VectorFixSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ namespace iDynTree

double& operator()(const unsigned int index);

double operator[](const unsigned int index) const;

double& operator[](const unsigned int index);

double getVal(const unsigned int index) const;

bool setVal(const unsigned int index, const double new_el);
Expand Down Expand Up @@ -144,7 +148,7 @@ namespace iDynTree
template<unsigned int VecSize>
VectorFixSize<VecSize>::VectorFixSize()
{

}


Expand Down Expand Up @@ -214,6 +218,19 @@ namespace iDynTree
return this->m_data[index];
}

template<unsigned int VecSize>
double VectorFixSize<VecSize>::operator[](const unsigned int index) const
{
assert(index < VecSize);
return this->m_data[index];
}

template<unsigned int VecSize>
double & VectorFixSize<VecSize>::operator[](const unsigned int index)
{
assert(index < VecSize);
return this->m_data[index];
}

template<unsigned int VecSize>
double VectorFixSize<VecSize>::getVal(const unsigned int index) const
Expand Down
12 changes: 12 additions & 0 deletions src/core/src/VectorDynSize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ double VectorDynSize::operator()(unsigned int index) const
return this->m_data[index];
}

double& VectorDynSize::operator[](unsigned int index)
{
assert(index < this->size());
return this->m_data[index];
}

double VectorDynSize::operator[](unsigned int index) const
{
assert(index < this->size());
return this->m_data[index];
}

double VectorDynSize::getVal(const unsigned int index) const
{
if( index >= this->size() )
Expand Down