Skip to content

Commit

Permalink
Merge pull request #646 from GiulioRomualdi/feature/begin_end_methods
Browse files Browse the repository at this point in the history
Add begin/end member functions for iDynTree vectors
  • Loading branch information
traversaro authored Jan 29, 2020
2 parents 41a676f + 559b167 commit 4427d95
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Added `bindings` for `InverseKinematics` (https://github.com/robotology/idyntree/pull/633)
- Implement `cbegin()` / `cend()` and `begin()` / `end()` methods for `VectorDynSize` and `VectorFixSize` (https://github.com/robotology/idyntree/pull/646)

### Fixed
### Fixed
- Remove spurious inclusion of Eigen headers in ExtendedKalmanFilter.h public header, that could create probles when using that header in a downstream project that does not use Eigen (https://github.com/robotology/idyntree/pull/639).
- Added find_dependency(OsqpEigen) and find_dependency(LibXml2) when iDynTree is compiled as a static library, fixing the use of iDynTree on Windows (https://github.com/robotology/idyntree/pull/642).

Expand Down
42 changes: 42 additions & 0 deletions src/core/include/iDynTree/Core/VectorDynSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,48 @@ namespace iDynTree

bool setVal(const unsigned int index, const double new_el);

/**
* Returns a const iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
const double* begin() const noexcept;

/**
* Returns a const iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
const double* end() const noexcept;

/**
* Returns a const iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
const double* cbegin() const noexcept;

/**
* Returns a const iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
const double* cend() const noexcept;

/**
* Returns a iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
double* begin() noexcept;

/**
* Returns a iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
double* end() noexcept;

unsigned int size() const;

///@}
Expand Down
78 changes: 78 additions & 0 deletions src/core/include/iDynTree/Core/VectorFixSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,48 @@ namespace iDynTree

bool setVal(const unsigned int index, const double new_el);

/**
* Returns a const iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
const double* begin() const noexcept;

/**
* Returns a const iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
const double* end() const noexcept;

/**
* Returns a const iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
const double* cbegin() const noexcept;

/**
* Returns a const iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
const double* cend() const noexcept;

/**
* Returns a iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
double* begin() noexcept;

/**
* Returns a iterator to the beginning of the vector
* @note At the moment iterator is implemented as a pointer, it may change in the future.
* For this reason it should not be used as a pointer to the data, use data() instead.
*/
double* end() noexcept;

unsigned int size() const;

///@}
Expand Down Expand Up @@ -189,6 +231,42 @@ namespace iDynTree
return this->m_data;
}

template<unsigned int VecSize>
const double* VectorFixSize<VecSize>::begin() const noexcept
{
return this->m_data;
}

template<unsigned int VecSize>
const double* VectorFixSize<VecSize>::end() const noexcept
{
return this->m_data + VecSize;
}

template<unsigned int VecSize>
const double* VectorFixSize<VecSize>::cbegin() const noexcept
{
return this->m_data;
}

template<unsigned int VecSize>
const double* VectorFixSize<VecSize>::cend() const noexcept
{
return this->m_data + VecSize;
}

template <unsigned int VecSize>
double *VectorFixSize<VecSize>::begin() noexcept
{
return this->m_data;
}

template<unsigned int VecSize>
double* VectorFixSize<VecSize>::end() noexcept
{
return this->m_data + VecSize;
}

template<unsigned int VecSize>
unsigned int VectorFixSize<VecSize>::size() const
{
Expand Down
30 changes: 30 additions & 0 deletions src/core/src/VectorDynSize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,36 @@ bool VectorDynSize::setVal(const unsigned int index, const double new_el)
return true;
}

const double* VectorDynSize::begin() const noexcept
{
return this->m_data;
}

const double* VectorDynSize::end() const noexcept
{
return this->m_data + this->m_size;
}

const double* VectorDynSize::cbegin() const noexcept
{
return this->m_data;
}

const double* VectorDynSize::cend() const noexcept
{
return this->m_data + this->m_size;
}

double* VectorDynSize::begin() noexcept
{
return this->m_data;
}

double* VectorDynSize::end() noexcept
{
return this->m_data + this->m_size;
}

void VectorDynSize::changeCapacityAndCopyData(const unsigned int _newCapacity)
{
//Corner case: zero capacity
Expand Down

0 comments on commit 4427d95

Please sign in to comment.