Re: Fwd: Re: how to map 'new' to 'CUSTOM_NEW_T'

William S Fulton <[email protected]> Wed, 22 Jan 2025 07:39:45 +0000
Newsgroups gmane.comp.programming.swig
Message-ID <CANGqftBLuZ1PXpg-QGyNdNPrra6LOp+koJtq5Urf0Rkne09tiA@mail.gmail.com>
--===============6715173374111725065==
Content-Type: multipart/alternative; boundary="00000000000062cf3a062c469ba2"

--00000000000062cf3a062c469ba2
Content-Type: text/plain; charset="UTF-8"

On Mon, 20 Jan 2025 at 08:57, William S Fulton <[email protected]>
wrote:

> The goal here is to customise this line:
>
>   result = (Bar *)new Bar();
>
> to something else:
>
>   result=CUSTOM_NEW_T(Bar);
>
> This is the "action" part of the code in SWIG and can be achieved via the
> low level "action" feature as follows:
>
>   %feature("action") Bar::Bar "result=CUSTOM_NEW_T(Bar);"
>

Just a quick follow up note that using Bar::Bar for the match will match
all constructors but CUSTOM_NEW_T(Bar) will only call the default
constructor which is not correct. Better to use an explicit match for each
constructor such as for the default constructor shown just below.


>
> Note that as this is a feature, the method (contructors in this case)
> being wrapped are specified for matching, that is Bar::Bar. Instead of
> matching all constructors, you can of course match, say just the default
> constructor, with:
>
>   %feature("action") Bar::Bar() "result=CUSTOM_NEW_T(Bar);"
>

William

--00000000000062cf3a062c469ba2
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote g=
mail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, 20 Jan =
2025 at 08:57, William S Fulton &lt;<a href=3D"mailto:[email protected].=
uk">[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,=
204,204);padding-left:1ex"><div dir=3D"ltr"><div>The goal here is to custom=
ise this line:</div><div><br></div><div>=C2=A0 result =3D (Bar *)new Bar();=
</div><div><br></div><div>to something else:</div><div><br></div><div>=C2=
=A0 result=3DCUSTOM_NEW_T(Bar);</div><div><br></div><div>This is the &quot;=
action&quot; part of the code in SWIG and can be achieved via the low level=
 &quot;action&quot; feature as follows:</div><div><br></div><div>=C2=A0 %fe=
ature(&quot;action&quot;) Bar::Bar &quot;result=3DCUSTOM_NEW_T(Bar);&quot; =
<br></div></div></blockquote><div><br></div><div>Just a quick follow up not=
e that using Bar::Bar for the match will match all constructors but CUSTOM_=
NEW_T(Bar) will only call the default constructor which is not correct. Bet=
ter to use an explicit match for each constructor such as for the default c=
onstructor shown just below.<br></div><div>=C2=A0<br></div><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid r=
gb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div></div><div><br></di=
v><div>Note that as this is a feature, the method (contructors in this case=
) being wrapped are specified for matching, that is Bar::Bar. Instead of ma=
tching all constructors, you can of course match, say just the default cons=
tructor, with:</div><div><br></div><div><div>=C2=A0 %feature(&quot;action&q=
uot;) Bar::Bar() &quot;result=3DCUSTOM_NEW_T(Bar);&quot; <br></div><div></d=
iv></div></div></blockquote><div><br></div>William<br></div></div>

--00000000000062cf3a062c469ba2--


--===============6715173374111725065==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============6715173374111725065==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user

--===============6715173374111725065==--