%rename with automatically created Setters / Getters

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

%rename with automatically created Setters / Getters

Jimi Damon
Hi,

How could you configure %rename to rename the getters and setters
assigned to a given C structure for a language like Java.

/*-------------- Bar.h --------------------*/
void test_fn_for_later(void );
typedef struct Bar {
  int a;
  int b;
} Bar;
/*------------------------------------*/

I would like to rename the setters or getters to be

set_a / get_a  and set_b / get_b  versus   setA / getA and setB / getB.

I can rename the function test_fn_for_later pretty easily using
something like

%rename("a_new_function") "test_fn_for_later"


but I can't figure out how to create a rule that will match the
generated functions that SWIG gives to the structure Bar ?


I've tried using the

%extend Bar {

     %rename(set_b) SetB;
}

with no success.

Thanks,

-Jimi





--
WARNING - This e-mail or its attachments may contain controlled technical
data or controlled technology within the definition of the International
Traffic in Arms Regulations (ITAR) or Export Administration Regulations
(EAR), and are subject to the export control laws of the U.S. Government.
Transfer of this data or technology by any means to a foreign person,
whether in the United States or abroad, without an export license or other
approval from the U.S. Government, is prohibited. The information contained
in this document is CONFIDENTIAL and property of ACCES I/O Products, Inc.
Any unauthorized review, use, disclosure or distribution is prohibited
without express written consent of ACCES I/O Products, Inc. If you are not
the intended recipient, please contact the sender and destroy all copies of
the original message and enclosed attachments.

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: %rename with automatically created Setters / Getters

William S Fulton
On 16 May 2016 at 22:03, Jimi Damon <[hidden email]> wrote:

> Hi,
>
> How could you configure %rename to rename the getters and setters
> assigned to a given C structure for a language like Java.
>
> /*-------------- Bar.h --------------------*/
> void test_fn_for_later(void );
> typedef struct Bar {
>   int a;
>   int b;
> } Bar;
> /*------------------------------------*/
>
> I would like to rename the setters or getters to be
>
> set_a / get_a  and set_b / get_b  versus   setA / getA and setB / getB.
>
> I can rename the function test_fn_for_later pretty easily using
> something like
>
> %rename("a_new_function") "test_fn_for_later"
>
>
> but I can't figure out how to create a rule that will match the
> generated functions that SWIG gives to the structure Bar ?
>

The naming is not configurable and for Java follows the javabean
pattern. Probably SWIG could be changed to provide some flexibility
here, I'll provide some guidance for anyone who fancies implementing
this. Meanwhile you can take this manual approach:

%ignore Bar::a;
%ignore Bar::b;
%extend Bar {
  int get_b() {
    return $self->b;
  }
  int get_a() {
    return $self->a;
  }
  void set_a(int a) {
    $self->a = a;
  }
  void set_b(int b) {
    $self->b = b;
  }
}

You could improve things somewhat by using a macro to do the repetitive work.

William

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: %rename with automatically created Setters / Getters

Jimi Damon
Hi and Thank you for your response.

My one follow up question is just about the %rename directive and when it can and can't be used.

For instance, I couldn't use it for the automatic java setters and getters.

And , I was unable ( at least I failed in my attempts ) to use %rename in an %extend directive as well ( I was just trying to see if %rename worked there ).

Is there a part of the document that explains when certain directives can be nested inside of others, or when they apply to others ?  For instance, should a rename come before %include but after the #include of a Header interface file.

I'm finding for instance that I had to do a lot of trial and error with %rename, relative to the #include and %include statements , just to get it to rename a global function correctly.

Thanks

-Jimi


On Tue, May 17, 2016 at 11:46 AM, William S Fulton <[hidden email]> wrote:
On 16 May 2016 at 22:03, Jimi Damon <[hidden email]> wrote:
> Hi,
>
> How could you configure %rename to rename the getters and setters
> assigned to a given C structure for a language like Java.
>
> /*-------------- Bar.h --------------------*/
> void test_fn_for_later(void );
> typedef struct Bar {
>   int a;
>   int b;
> } Bar;
> /*------------------------------------*/
>
> I would like to rename the setters or getters to be
>
> set_a / get_a  and set_b / get_b  versus   setA / getA and setB / getB.
>
> I can rename the function test_fn_for_later pretty easily using
> something like
>
> %rename("a_new_function") "test_fn_for_later"
>
>
> but I can't figure out how to create a rule that will match the
> generated functions that SWIG gives to the structure Bar ?
>

The naming is not configurable and for Java follows the javabean
pattern. Probably SWIG could be changed to provide some flexibility
here, I'll provide some guidance for anyone who fancies implementing
this. Meanwhile you can take this manual approach:

%ignore Bar::a;
%ignore Bar::b;
%extend Bar {
  int get_b() {
    return $self->b;
  }
  int get_a() {
    return $self->a;
  }
  void set_a(int a) {
    $self->a = a;
  }
  void set_b(int b) {
    $self->b = b;
  }
}

You could improve things somewhat by using a macro to do the repetitive work.

William





WARNING - This e-mail or its attachments may contain controlled technical data or controlled technology within the definition of the International Traffic in Arms Regulations (ITAR) or Export Administration Regulations (EAR), and are subject to the export control laws of the U.S. Government. Transfer of this data or technology by any means to a foreign person, whether in the United States or abroad, without an export license or other approval from the U.S. Government, is prohibited. The information contained in this document is CONFIDENTIAL and property of ACCES I/O Products, Inc. Any unauthorized review, use, disclosure or distribution is prohibited without express written consent of ACCES I/O Products, Inc. If you are not the intended recipient, please contact the sender and destroy all copies of the original message and enclosed attachments.
------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: %rename with automatically created Setters / Getters

William S Fulton
You need to understand the difference between %include and #include to
figure this out. %rename should come before SWIG parses the definition
you are renaming. This is all covered in the Basics chapter at
http://swig.org/Doc3.0/SWIG.html. I also recommend having a good look
at http://swig.org/Doc3.0/Customization.html.

%rename works if you declare it before the code in %extend, such as:

%rename(shop) ship;
%extend Shape {
  void ship() {
  }
}

William


On 17 May 2016 at 22:32, Jimi Damon <[hidden email]> wrote:

> Hi and Thank you for your response.
>
> My one follow up question is just about the %rename directive and when it
> can and can't be used.
>
> For instance, I couldn't use it for the automatic java setters and getters.
>
> And , I was unable ( at least I failed in my attempts ) to use %rename in an
> %extend directive as well ( I was just trying to see if %rename worked there
> ).
>
> Is there a part of the document that explains when certain directives can be
> nested inside of others, or when they apply to others ?  For instance,
> should a rename come before %include but after the #include of a Header
> interface file.
>
> I'm finding for instance that I had to do a lot of trial and error with
> %rename, relative to the #include and %include statements , just to get it
> to rename a global function correctly.
>
> Thanks
>
> -Jimi
>
>
> On Tue, May 17, 2016 at 11:46 AM, William S Fulton <[hidden email]>
> wrote:
>>
>> On 16 May 2016 at 22:03, Jimi Damon <[hidden email]> wrote:
>> > Hi,
>> >
>> > How could you configure %rename to rename the getters and setters
>> > assigned to a given C structure for a language like Java.
>> >
>> > /*-------------- Bar.h --------------------*/
>> > void test_fn_for_later(void );
>> > typedef struct Bar {
>> >   int a;
>> >   int b;
>> > } Bar;
>> > /*------------------------------------*/
>> >
>> > I would like to rename the setters or getters to be
>> >
>> > set_a / get_a  and set_b / get_b  versus   setA / getA and setB / getB.
>> >
>> > I can rename the function test_fn_for_later pretty easily using
>> > something like
>> >
>> > %rename("a_new_function") "test_fn_for_later"
>> >
>> >
>> > but I can't figure out how to create a rule that will match the
>> > generated functions that SWIG gives to the structure Bar ?
>> >
>>
>> The naming is not configurable and for Java follows the javabean
>> pattern. Probably SWIG could be changed to provide some flexibility
>> here, I'll provide some guidance for anyone who fancies implementing
>> this. Meanwhile you can take this manual approach:
>>
>> %ignore Bar::a;
>> %ignore Bar::b;
>> %extend Bar {
>>   int get_b() {
>>     return $self->b;
>>   }
>>   int get_a() {
>>     return $self->a;
>>   }
>>   void set_a(int a) {
>>     $self->a = a;
>>   }
>>   void set_b(int b) {
>>     $self->b = b;
>>   }
>> }
>>
>> You could improve things somewhat by using a macro to do the repetitive
>> work.
>>
>> William
>
>
>
>
>
>
> WARNING - This e-mail or its attachments may contain controlled technical
> data or controlled technology within the definition of the International
> Traffic in Arms Regulations (ITAR) or Export Administration Regulations
> (EAR), and are subject to the export control laws of the U.S. Government.
> Transfer of this data or technology by any means to a foreign person,
> whether in the United States or abroad, without an export license or other
> approval from the U.S. Government, is prohibited. The information contained
> in this document is CONFIDENTIAL and property of ACCES I/O Products, Inc.
> Any unauthorized review, use, disclosure or distribution is prohibited
> without express written consent of ACCES I/O Products, Inc. If you are not
> the intended recipient, please contact the sender and destroy all copies of
> the original message and enclosed attachments.

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user