简体   繁体   中英

Swig java c ++ passing a vector of vectors containing a c++ structure

I have been looking around at the relevant questions and i cannot get rid of the swig pointer.

Basically i have a simple structure

typedef struct mbuf{
 int date
 int time
}

and within my class i define a vector of vectors

class Profile {

private:

    std::vector<std::vector<mbuf> > mbufArray;

    std::vector<std::vector<mbuf> > getMbufArray() const {
        return mbufArray;
    }

    void setMbufArray(std::vector<std::vector<mbuf> > mbufArray) {
        this->mbufArray = mbufArray;
    }

}

the get and set function have been auto generated for me. I have generated out the swig java class using the information from other questions

%{
  define SWIG_JAVA_EXTRA_NATIVE_CONTAINERS 
%}

%include "std_vector.i"
%{ 
 include <vector> 
%} 


%template(ProfileVector) std::vector<std::vector<mbuf> >;

%typemap(out) std::vector<std::vector<mbuf> >::value_type { 
$result = SWIG_NewPointerObj(SWIG_as_voidptr(&$1), $descriptor(std::vector<mbuf>), 0 |  0 ); 
} 


%typemap(out) std::vector<std::vector<mbuf> >::value_type & { 
    $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), $descriptor(std::vector<mbuf>), 0 |  0 ); 
}

My problem is i still receive a SWIGTYPE_p_std__vectorT_mbuf_t for my set and get types, i could create function that give me the elements but what i really need is more natural access to the vector elements in java.

Any help would be much appreciated.

Ok i figured it out i was missing a typedef for the actual vector.

I now have acces to the mbuf type by adding the line to my .i file

%template(ProfileVector) std::vector<mbuf>;
%template(VectorProfileVector) std::vector<std::vector<mbuf> >;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM