0

I am trying to build a typemap(in) for use with C++ boost scoped_arrays. I have C++ functions which take the boost arrays, but I'd like to pass them Lua lists.

I have seen examples for Python, but they seem to contain too much Python-specific code.

Has anyone got help or pointers to an example to get me started?

4

1 に答える 1

1

おそらく次のようなものを使用できます。

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

namespace boost {

template<class T>
class scoped_array {
public:
    scoped_array();
    ~scoped_array();

    void reset();
    void swap(scoped_array& b);

    %extend
    {
        scoped_array(unsigned n)
        {
            return new scoped_array<T>(new T[n]);
        }
        T __getitem__(unsigned int idx)
        {
            return (*self)[idx];
        }
        void __setitem__(unsigned int idx,T val)
        {
            (*self)[idx]=val;
        }
    };
};

}

出発点として。の重要なビットを公開し、SWIG がその標準 typemap ライブラリに持っている実装boost::scoped_arrayに大まかに基づいています。std::vector

特別なメンバー関数と、同時にいくつかのストレージを割り当てる新しいコンストラクターを追加します。ターゲット言語での使用が見られなかったため、SWIG の定義の一部を示していません。

注:これはコンパイルおよびチェックしていません。SWIG はこれに満足しており、生成されたラッパーは正常に見えます。

于 2012-09-17T10:39:55.217 に答える