Skip to content

Commit

Permalink
Added compatibility with SWIG 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-romano committed Sep 6, 2018
1 parent 6fdfc6a commit c4aad59
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/core/include/iDynTree/Core/EigenHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ inline Eigen::Map<const Eigen::VectorXd> toEigen(const VectorDynSize & vec)
return Eigen::Map<const Eigen::VectorXd>(vec.data(),vec.size());
}

#if SWIG_VERSION >= 0x030000
inline Eigen::Map<const Eigen::VectorXd> toEigen(Span<const double> vec)
{
return Eigen::Map<const Eigen::VectorXd>(vec.data(),vec.size());
Expand All @@ -72,6 +73,7 @@ inline Eigen::Map<Eigen::VectorXd> toEigen(iDynTree::Span<double> vec)
{
return Eigen::Map<Eigen::VectorXd>(vec.data(),vec.size());
}
#endif

inline Eigen::Map<const Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> > toEigen(const MatrixDynSize & mat)
{
Expand Down
10 changes: 7 additions & 3 deletions src/core/include/iDynTree/Core/VectorDynSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#ifndef IDYNTREE_DYNAMIC_SIZE_VECTOR_H
#define IDYNTREE_DYNAMIC_SIZE_VECTOR_H


#if SWIG_VERSION >= 0x030000
#include <iDynTree/Core/Span.h>
#endif

#include <string>
#include <iDynTree/Core/Span.h>

namespace iDynTree
{
Expand Down Expand Up @@ -97,6 +98,7 @@ namespace iDynTree
*/
VectorDynSize & operator=(const VectorDynSize& vec);

#if SWIG_VERSION >= 0x030000
/**
* Copy assignment operator.
*
Expand All @@ -107,7 +109,7 @@ namespace iDynTree
* \warning performs dynamic memory allocation operations
*/
VectorDynSize & operator=(const Span<const double>& vec);

#endif
/**
* @name Vector interface methods.
* Methods exposing a vector-like interface to PositionRaw.
Expand Down Expand Up @@ -187,6 +189,7 @@ namespace iDynTree
*/
void fillBuffer(double * buf) const;

#if SWIG_VERSION >= 0x030000
/** Typedefs to enable make_span.
*/
///@{
Expand All @@ -198,6 +201,7 @@ namespace iDynTree

typedef typename std::allocator_traits<std::allocator<double>>::const_pointer const_pointer;
///@}
#endif

/** @name Output helpers.
* Output helpers.
Expand Down
8 changes: 8 additions & 0 deletions src/core/include/iDynTree/Core/VectorFixSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#define IDYNTREE_VECTOR_FIX_SIZE_H

#include <iDynTree/Core/Utils.h>
#if SWIG_VERSION >= 0x030000
#include <iDynTree/Core/Span.h>
#endif
#include <string>
#include <sstream>
#include <cassert>
Expand Down Expand Up @@ -69,13 +71,15 @@ namespace iDynTree

///@}

#if SWIG_VERSION >= 0x030000
/**
* Copy assignment operator for spans.
*
* Checks that dimensions are matching through an assert.
*
*/
VectorFixSize & operator=(const Span<const double>& vec);
#endif

/**
* Raw data accessor
Expand Down Expand Up @@ -120,6 +124,7 @@ namespace iDynTree
std::string reservedToString() const;
///@}

#if SWIG_VERSION >= 0x030000
/** Typedefs to enable make_span.
*/
///@{
Expand All @@ -131,6 +136,7 @@ namespace iDynTree

typedef typename std::allocator_traits<std::allocator<double>>::const_pointer const_pointer;
///@}
#endif

};

Expand Down Expand Up @@ -185,12 +191,14 @@ namespace iDynTree
return VecSize;
}

#if SWIG_VERSION >= 0x030000
template<unsigned int VecSize>
VectorFixSize<VecSize> & VectorFixSize<VecSize>::operator=(const Span<const double>& vec) {
assert(VecSize == vec.size());
std::memcpy(this->m_data, vec.data(), VecSize*sizeof(double));
return *this;
}
#endif

template<unsigned int VecSize>
double VectorFixSize<VecSize>::operator()(const unsigned int index) const
Expand Down
7 changes: 2 additions & 5 deletions src/core/src/VectorDynSize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ VectorDynSize& VectorDynSize::operator=(const VectorDynSize& vec)
return *this;
}

#if SWIG_VERSION >= 0x030000
VectorDynSize &VectorDynSize::operator=(const Span<const double> &vec)
{
// if the size don't match, reallocate the data
Expand All @@ -114,7 +115,7 @@ VectorDynSize &VectorDynSize::operator=(const Span<const double> &vec)

return *this;
}

#endif

void VectorDynSize::zero()
{
Expand Down Expand Up @@ -267,8 +268,4 @@ std::string VectorDynSize::reservedToString() const
return this->toString();
}





}

0 comments on commit c4aad59

Please sign in to comment.