2012-03-12 2 views
0

私はboost::tupleのリストを持っています。私はこのタプルリストをSWIGを通してJavaバインディングに公開したいと思っています。私はSWIGによって生成されたMT wrap.cxxを、コンパイルしようとする。しかし、私は次のエラーを取得:boost :: tuples :: tupleをJavaバインディングに公開するにはどうすればいいですか?

d:\xyz\...\vector.h(115) : error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const boost::tuples::tuple<T0,T1>' (or there is no acceptable conversion) 
     with 
     [ 
      T0=std::string, 
      T1=std::string 
     ] 
     c:\program files\microsoft visual studio 8\vc\platformsdk\include\guiddef.h(192): or 'int operator ==(const GUID &,const GUID &)' 
     while trying to match the argument list '(const boost::tuples::tuple<T0,T1>, const MyTuple)' 
     with 
     [ 
      T0=std::string, 
      T1=std::string 
     ] 
     d:\xyz\...\vector.h(111) : while compiling class template member function 'int Vector<T>::index(const T &) const' 
     with 
     [ 
      T=MyTuple 
     ] 
     d:\xyz\...\MyTuple_wrap.cxx(17731) : see reference to class template instantiation 'Vector<T>' being compiled 
     with 
     [ 
      T=MyTuple 
     ] 

誰もが、私はこの問題を解決するために何をすべきかを教えてもらえますか?

+0

あなたのインターフェイスファイルにはどのようなものが見えますか? – Flexo

+0

jniと直接インタフェースするのではなく、swigを使用する理由はありますか? – ylabidi

+0

私のオリジナルの質問にコメントできますか?それは私からの答えを得るという点で賞金よりも効果的です:) – Flexo

答えて

3

あなたが表示されたエラーにどう到着したかは不明です。 boost::tupleはデフォルトでラップするのが難しく、SWIGに標準インターフェイスが含まれていないようです。私のテストでは、インターフェイスファイルを手作業で書くことなく、あなたが見ていたエラーに近づくことができませんでした。

しかし私は、次のインターフェイスファイルを使用して、ブーストのタプルをラップすることに成功しました:

%{ 
#include <boost/tuple/tuple.hpp> 
%} 

namespace boost { 
    template <typename T1=void, typename T2=void, typename T3=void> 
    struct tuple; 

    template <> 
    struct tuple<void,void,void> { 
    }; 

    template <typename T1> 
    struct tuple<T1, void, void> { 
    tuple(T1); 
    %extend { 
     T1 first() const { 
     return boost::get<0>(*$self); 
     } 
    } 
    }; 

    template <typename T1, typename T2> 
    struct tuple <T1, T2, void> { 
    tuple(T1,T2); 
    %extend { 
     T1 first() const { 
     return boost::get<0>(*$self); 
     } 
     T2 second() const { 
     return boost::get<1>(*$self); 
     } 
    } 
    }; 

    template <typename T1, typename T2, typename T3> 
    struct tuple <T1,T2,T3> { 
    tuple(T1,T2,T3); 
    %extend { 
     T1 first() const { 
     return boost::get<0>(*$self); 
     } 
     T2 second() const { 
     return boost::get<1>(*$self); 
     } 
     T3 third() const { 
     return boost::get<2>(*$self); 
     } 
    } 
    }; 
} 

基本的にはそれがないすべてはあなたが気に可能性があるタプルの専門のそれぞれにアクセス用関数を追加しています。 Javaやその他の言語では最小限にするだけで十分です。あなたは明らかにこれを拡大してより大きなタプルをカバーしたいと思うでしょう。あなたのタプルが不変でないように意図されていなければ、メンバ関数を取得/設定したいと思うかもしれません。

私はSWIGモジュールでこれをテストすることができました:

次のJavaで期待通りに働いていた
%module test 

%include "boost_tuple.i" 

%template(TestTuple) boost::tuple<int, double, char>; 

%template(SingleTuple) boost::tuple<char>; 

%inline %{ 
boost::tuple<int, double, char> func1() { 
    return boost::make_tuple(3, 2.0, '1'); 
} 

void test1(boost::tuple<int, double, char>) { 
} 

%} 

public class run { 
    public static void main(String[] argv) { 
    System.loadLibrary("test"); 
    TestTuple t = test.func1(); 
    System.out.println("1: " + t.first() + " 2: " + t.second() + " 3: " + t.third()); 
    test.test1(test.func1()); 
    test.test1(new TestTuple(0, 0.0, '0')); 
    } 
} 
関連する問題