簡體   English   中英

SWIG C ++ List to Java

[英]SWIG C++ List to Java

我正在嘗試使用SWIG來包裝C ++,它定義了像這樣的對象的LIST

    typedef std::list<Country> CountryList;

我在接口文件中究竟需要具備什么才能適應這種情況?

謝謝,

插口

只需將以下內容添加到swig界面文件中:

%include "std_list.i"
%include "Country.h" /* or declaration of Country */
%template(Country_List) std::list<Country>;

編輯:我不知道swig沒有為Java提供std_list.i來包裝std::list 看一下為std::vector提供的那個,這可以適應std::list 請注意,大多數功能都不可用,因為您確實希望使用迭代器來訪問列表元素。 無論如何,這里是:

std_list.i

%include <std_common.i>

%{
#include <list>
#include <stdexcept>
%}

namespace std {
    template<class T> class list {
      public:
        typedef size_t size_type;
        typedef T value_type;
        typedef const value_type& const_reference;
        list();
        list(size_type n);
        size_type size() const;
        %rename(isEmpty) empty;
        bool empty() const;
        void clear();
        const_reference back();
        %rename(add) push_back;
        void push_back(const value_type& x);
        void pop_back();
    };
}

您可能希望將其轉換為Java中的相應列表,而不是包裝std::list<Country> 但是,為此,您需要編寫適當的類型映射

std_list尚未在“最新版本”(痛飲-3.0.12)可以從下載 ,但已經在GitHub上的主分支 您可以下載並使用( %include )它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM