Java SWIG问题,正在生成空文件
我试图用SWIG来封装C++类来创建java接口,但是当我在文件上运行Sigg时,它会生成空文件。 我遵循这里的示例: 我有这样一个头文件:Java SWIG问题,正在生成空文件,java,java-native-interface,swig,Java,Java Native Interface,Swig,我试图用SWIG来封装C++类来创建java接口,但是当我在文件上运行Sigg时,它会生成空文件。 我遵循这里的示例: 我有这样一个头文件: #include <list> #include <set> #include <map> #include <Heap.h> #include "Controller.h" namespace Arbitrator { template <class _Tp,class _Val> cl
#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文件是空的
是否有人遇到过此问题/知道如何解决此问题
谢谢您必须明确指示SWIG使用%template指令为模板生成代码 从: SWIG提供了处理模板的支持,但在默认情况下,它 不会为生成任何成员变量或函数包装 模板类。为了创建这些包装,您需要 显式地告诉SWIG实例化它们。这是通过 %模板指令 以下是一些简单的例子:
/*实例化几个不同版本的模板*/
%模板(intList)列表;
%模板(双重列表)列表;
/* Instantiate a few different versions of the template */
%template(intList) List<int>;
%template(doubleList) List<double>;