1

テンプレート化された Vector (std::vector ではなく、数学的なベクトルのように) クラスがあり、2 ~ 4 のサイズでインスタンス化できます。定義は次のようになります。

template <uint32_t Size, typename StorageType>
class Vector
{
public:
  Vector(StorageType x, StorageType y);
  Vector(StorageType x, StorageType y, StorageType z);
  Vector(StorageType x, StorageType y, StorageType z, StorageType w);
  ...
};

SizeSWIG ファイルで、 of3StorageTypeofを持つバージョンをラップしたいint8_tので、

%module Vector
%{
#include "Vector.h"
%}

%include "stdint.i"
%include "Vector.h"

%ignore Vector(int8_t, int8_t);
%ignore Vector(int8_t, int8_t, int8_t, int8_t);
%template(Vector3DInt8) PolyVox::Vector<3,int8_t>;

しかし%ignore、要求されたコンストラクターには失敗します。

マクロ内の SWIG は、%templateテンプレート パラメータから typedef を自動的に「剥ぎ取り」、%template(Vector3DInt8) PolyVox::Vector<3,int8_t>;実際には%template(Vector3DInt8) PolyVox::Vector<3,unsigned char>;. このため、が一致しないため、%ignoreが一致unsigned charしませんint8_t

static_assert()無視したい関数の中に を追加すると、次のようになります。

source/Vector.inl: In constructor ‘Vector<Size, StorageType>::Vector(StorageType, StorageType) [with unsigned int Size = 3u, StorageType = signed char]’:
build/PolyVoxCorePYTHON_wrap.cxx:6446:100:   instantiated from here
source/Vector.inl:56:3: error: static assertion failed: "This constructor should only be used for vectors with two elements."

私も使ってみまし-notemplatereduceたが、効果がないようです。

SWIG に不要なコンストラクタを正しく無視させる方法はありますか?

編集:SWIG 2.0.8でGCC 4.5を使用しています

編集 2: Python タイプマップに必要なため、ファイルに追加stdint.iされました。.iがなくてもstdint.i、 は%ignore正しく機能しますが、実際に Python でバインディングを使用する必要があります。

4

0 に答える 0