我正在使用SWIG为C#包装一个C类(PointMatcher.h) . 我使用 %template
指令将模板类具体化,如下所示:
%include "../pointmatcher/PointMatcher.h"
%template(PointMatcherFloat) PointMatcher<float>;
但是,事实证明模板 PointMatcher<T>
包含基于 <T>
的typedef和typenames,并且这些不包含在SWIG包装器中 . (具体来说,我需要访问下面的 TransformationParameters
. )
//! The scalar type
typedef T ScalarType;
//! A vector over ScalarType
typedef typename Eigen::Matrix<T, Eigen::Dynamic, 1> Vector;
//! A vector of vector over ScalarType, not a matrix
typedef std::vector<Vector, Eigen::aligned_allocator<Vector> > VectorVector;
//! A quaternion over ScalarType
typedef typename Eigen::Quaternion<T> Quaternion;
//! A vector of quaternions over ScalarType
typedef std::vector<Quaternion, Eigen::aligned_allocator<Quaternion> > QuaternionVector;
//! A dense matrix over ScalarType
typedef typename Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> Matrix;
//! A dense integer matrix
typedef typename Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic> IntMatrix;
//! A matrix holding the parameters a transformation.
/**
The transformation lies in the special Euclidean group of dimension \f$n\f$, \f$SE(n)\f$, implemented as a dense matrix of size \f$n+1 \times n+1\f$ over ScalarType.
*/
typedef Matrix TransformationParameters;
// alias for scope reasons
typedef PointMatcherSupport::Parametrizable Parametrizable; //!< alias
typedef Parametrizable::Parameters Parameters; //!< alias
typedef Parametrizable::ParameterDoc ParameterDoc; //!< alias
typedef Parametrizable::ParametersDoc ParametersDoc; //!< alias
typedef Parametrizable::InvalidParameter InvalidParameter; //!< alias
我尝试使用 T
和 float
将上面的声明复制为 %inline
块 . (如SWIG 3.0 documentation on typedef中所述 . )在这两种情况下,typedef都只包含在.cxx文件中,但不会生成任何关联的类或方法 .
如何确保PointMatcherFloat中提供这些类型?
编辑注释:我以前认为这是关于成员模板(如How to instantiate a template method of a template class with swig?和How to get SWIG to apply templates when wrapping a template class containing vectors?),但它实际上是关于模板中的typedefs / typenames .