【发布时间】:2011-10-05 17:48:55
【问题描述】:
我正在尝试使用 SWIG 包装 C++ 类以创建 Java 接口,但是当我在我的文件上运行 SWIG 时,它会生成空文件。
我正在关注此处的示例:http://www.opensource.apple.com/source/swig/swig-4/swig/Examples/java/class/index.html?txt
我有一个这样的头文件:
#include <list>
#include <set>
#include <map>
#include <Heap.h>
#include "Controller.h"
namespace Arbitrator
{
template <class _Tp,class _Val>
class Arbitrator
{
public:
Arbitrator();
bool setBid(Controller<_Tp,_Val>* c, _Tp obj, _Val bid);
bool setBid(Controller<_Tp,_Val>* c, std::set<_Tp> objs, _Val bid);
bool removeBid(Controller<_Tp,_Val>* c, _Tp obj);
bool removeBid(Controller<_Tp,_Val>* c, std::set<_Tp> objs);
bool removeAllBids(Controller<_Tp,_Val>* c);
bool accept(Controller<_Tp,_Val>* c, _Tp obj, _Val bid);
bool accept(Controller<_Tp,_Val>* c, std::set<_Tp> objs, _Val bid);
bool accept(Controller<_Tp,_Val>* c, _Tp obj);
bool accept(Controller<_Tp,_Val>* c, std::set<_Tp> objs);
bool decline(Controller<_Tp,_Val>* c, _Tp obj, _Val bid);
bool decline(Controller<_Tp,_Val>* c, std::set<_Tp> objs, _Val bid);
bool hasBid(_Tp obj) const;
const std::pair<Controller<_Tp,_Val>*, _Val>& getHighestBidder(_Tp obj) const;
const std::list< std::pair<Controller<_Tp,_Val>*, _Val> > getAllBidders(_Tp obj) const;
const std::set<_Tp>& getObjects(Controller<_Tp,_Val>* c) const;
void onRemoveObject(_Tp obj);
_Val getBid(Controller<_Tp,_Val>* c, _Tp obj) const;
void update();
private:
std::map<_Tp,Heap<Controller<_Tp,_Val>*, _Val> > bids;
std::map<_Tp,Controller<_Tp,_Val>* > owner;
std::map<Controller<_Tp,_Val>*, std::set<_Tp> > objects;
std::set<_Tp> updatedObjects;
std::set<_Tp> objectsCanIncreaseBid;
std::set<_Tp> unansweredObjected;
bool inUpdate;
bool inOnOffer;
bool inOnRevoke;
};
template <class _Tp,class _Val>
Arbitrator<_Tp,_Val>::Arbitrator()
{
inUpdate=false;
inOnOffer=false;
inOnRevoke=false;
}
//other code removed to save space
我创建的接口文件如下所示:
/* arb.i */
%module arb
%{
#include "Arbitrator.h"
%}
/* grab header file */
%include "Arbitrator.h"
但是当我运行 SWIG 时:
swig -c++ -java arb.i
SWIG 创建的 Java 文件是空的。
有没有人遇到过这个问题/知道如何解决这个问题?
谢谢
【问题讨论】:
标签: java java-native-interface swig