編輯:解決,我的錯誤;在我的答案中解釋。在SWIG for Python中包裝std :: boost :: shared_ptr的向量
我有這樣的:
std::vector < boost::shared_ptr <Entity> > entities;
我嘗試通過痛飲這樣的揭露它:
%include "boost_shared_ptr.i"
%include "std_vector.i"
%shared_ptr(Entity)
%include <Entity.h>
namespace std {
%template(EntityVector) vector<boost::shared_ptr<Entity> >;
};
%include <TheFileWithEntities.h>
然而,在Python實體結束是一個元組:
import MyModule
print type(MyModule.cvar.entities)
# Output: (type 'tuple')
我已經谷歌搜索這個,但找不到任何具體的例子如何包裝這個。一頁給出了一個用於包裝C#的小例子,但對我來說並沒有幫助。
任何幫助,非常感謝。
感謝您的迴應,但正如您在我的問題中所看到的,我已經知道如何包裝std :: vector。問題是包裝一個boost :: shared_ptr的std :: vector。 SWIG似乎將它暴露爲一個元組,因爲它無法找出它的shared_ptr部分。 – morrog 2011-04-04 21:32:34
您是否看到過這樣的內容:http://www.swig.org/Doc1.3/SWIGPlus.html#SWIGPlus_nn34 – sehe 2011-04-04 21:35:14
是的,謝謝,我已閱讀過,但沒有看到任何相關內容。再次,我可以包裝boost :: shared_ptr,我可以包裝std :: vector,並按預期工作。這個問題具體是std :: vector>,它在Python中顯示爲一個元組。 Python可以訪問元組,查看其中的內容,操縱元組內的單個實體,但不能追加或修改它,因爲它是一個元組。 –
morrog
2011-04-05 01:22:47