Java, wrapping struct vs typedef struct

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Java, wrapping struct vs typedef struct

Marty Kube
Hi,

I'm following the java manual section of wrapping 'struct pointer to
pointer'.  The effect I hope to achieve is to override the java
constructor for a struct's typewrapper class.

The wrapping is much different depending on how I declare a struct (see
the following example).  

For the typedef'd struct the %typemap(javabody) is applied.  However,
the %typemap(javabody) is not applied for the plain struct.

Is this the intended behavior?  Or is it my old, rusty C getting in the
way?

I'll need to deal with a plain struct, so suggestions on how to get the
javabody typemap to apply would be great.

Thanks

SWIG Version 1.3.27

**** Input File: Tmp.i ******

%module Tmp;
%typemap (javabody) bar %{
        /* hello */
%}
%typemap (javabody) foo %{
        /* hello */
%}
%inline {
        struct bar {
                int j;
        };
        typedef struct {
                int i;
        } foo;
};

**** Generated File: bar.java *****
public class bar {
  private long swigCPtr;
  protected boolean swigCMemOwn;

  protected bar(long cPtr, boolean cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = cPtr;
  }

  protected static long getCPtr(bar obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public void delete() {
...

**** Generated File: foo.java *****
public class foo {
        /* hello */

  protected void finalize() {
    delete();
  }

  public void delete() {
...



               
__________________________________________
Yahoo! DSL ? Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: Java, wrapping struct vs typedef struct

William S Fulton
Marty Kube wrote:

> Hi,
>
> I'm following the java manual section of wrapping 'struct pointer to
> pointer'.  The effect I hope to achieve is to override the java
> constructor for a struct's typewrapper class.
>
> The wrapping is much different depending on how I declare a struct (see
> the following example).  
>
> For the typedef'd struct the %typemap(javabody) is applied.  However,
> the %typemap(javabody) is not applied for the plain struct.
>
> Is this the intended behavior?  Or is it my old, rusty C getting in the
> way?
>
> I'll need to deal with a plain struct, so suggestions on how to get the
> javabody typemap to apply would be great.
>
> Thanks
>
> SWIG Version 1.3.27
>
> **** Input File: Tmp.i ******
>
> %module Tmp;
> %typemap (javabody) bar %{
> /* hello */
> %}
> %typemap (javabody) foo %{
> /* hello */
> %}
> %inline {
> struct bar {
> int j;
> };
> typedef struct {
> int i;
> } foo;
> };
>

Bit of a late response, I know, but you must use C types for typemaps.
There is no 'bar' type, but there is a 'struct bar' type, so use:

%typemap(javabody) struct bar %{ ... %}

William


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user