2017-12-13 19 views
0

私はJavaCPPの初心者ですが、今は問題があります。std :: map <std :: string、std :: string> JavaCPPの変換

私TestLibrary.h:

#include <string> 
#include <map> 


    class TestClass { 
     public: 
      TestClass() { 
       property["a"]="b"; 
      } 
      const std::map<std::string,std::string>& getMap(std::string str) { 
       if (str == "a"){ 
        return property; 
       } 
      } 
      std::map<std::string,std::string> property; 
    }; 

TestLibrary.java

import org.bytedeco.javacpp.*; 
import org.bytedeco.javacpp.annotation.*; 

@Platform(include="TestLibrary.h") 
public class TestLibrary { 
    public static class TestClass extends Pointer { 
     static { Loader.load(); } 
     public TestClass() { allocate(); } 
     private native void allocate(); 

     public static native @ByRef KeyValueMap getMap(String str);  
    } 

@Name("std::map<std::string,std::string>") public static class 
KeyValueMap extends Pointer { 
    static { Loader.load(); } 
    public KeyValueMap(Pointer p) { super(p); } 
    public KeyValueMap()  { allocate(); } 
    private native void allocate(); 

    public native long size(); 

    @Index public native @StdString BytePointer get(@StdString 
BytePointer i); 
    public native KeyValueMap put(@StdString BytePointer i, BytePointer 
value); 
} 

    public static void main(String[] args) { 
     TestClass l = new TestClass(); 
     KeyValueMap m = l.getMap("a"); 
     System.out.println(m); 
     //System.out.println(m.get("a")); 
    } 
} 

のjavac -cp javacpp.jar TestLibrary.java
のjava -jar javacpp.jar TestLibrary

jniTestLibrary.cpp:2238:30 :エラー:非静的メンバへの呼び出し オブジェクト引数なしの関数 rptr = & :: TestClass :: getMap(ptr0);
~~~~~~~~~~~~~~~~~~~~~

上記のコードは、NativeLibraryの例から変更されています。しかし、どのようにコンパイルの問題を解決するには? m.get("a")のように使用できますか?

答えて

0

私は変更することで、これを行うために管理...

TestLibrary.h:

#include <string> 
#include <map> 


class TestClass { 
    public: 
     TestClass() { 
      property["a"]="b"; 
     } 
     std::map<std::string,std::string>& getMap(std::string str) { 
      if (str == "a"){ 
       return property; 
      } 
     } 
     std::map<std::string,std::string> property; 
}; 

TestLibrary.java

import org.bytedeco.javacpp.*; 
import org.bytedeco.javacpp.annotation.*; 

@Platform(include="TestLibrary.h") 
public class TestLibrary { 
    public static class TestClass extends Pointer { 
    static { Loader.load(); } 
    public TestClass() { allocate(); } 
    private native void allocate(); 

    public native @ByRef KeyValueMap getMap(String str);  
} 

@Name("std::map<std::string,std::string>") 
public static class KeyValueMap extends Pointer { 
static { Loader.load(); } 
public KeyValueMap(Pointer p) { super(p); } 
public KeyValueMap()  { allocate(); } 
private native void allocate(); 

public native long size(); 

@Index public native @StdString BytePointer get(@StdString BytePointer i); 
public native KeyValueMap put(@StdString BytePointer i, BytePointer value); } 

public static void main(String[] args) { 
    TestClass l = new TestClass(); 
    KeyValueMap m = l.getMap("a"); 
    System.out.println(m.size()); 
    System.out.println(m.get(new BytePointer("a")).getString()); 
}} 
関連する問題