Question: how do I prevent a %ytpemap(out) for T* to match constructors of T?

Alessio M <[email protected]> Wed, 24 Apr 2024 18:38:08 +0100
Newsgroups gmane.comp.programming.swig
Message-ID <CAL_VXbaX81cFLOx7xZ3253BXmfDUjb+LA7bM-0FznYkqwaM5Gw@mail.gmail.com>
--===============7498791632311694615==
Content-Type: multipart/alternative; boundary="0000000000006e31c20616db247e"

--0000000000006e31c20616db247e
Content-Type: text/plain; charset="UTF-8"

Hi
Hopefully quick question:
I have the following typemap(out) that checks if a result object has_value
and returns Py_None if it does not.
Unfortunately it also matches the constructor of SomeType

Is there a way to prevent that match or override the typemap for all
SomeType constructors

I searched the docs, far and wide, and attempted a few things, but could
not find anything that would give me that level selectivity.

Thank you for any help you can provide!

%typemap(out) SomeType * %{
  if ( $1 && $1->has_value() )
  {
    $result = SWIG_NewPointerObj((void*)$1, $descriptor(SometType *),
SWIG_BUILTIN_INIT | SWIG_POINTER_OWN);
  }
  else
  {
    delete $1;
    $result = Py_None;
    Py_INCREF(Py_None);
  }
%}

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

<div dir=3D"ltr">Hi<div>Hopefully quick question:</div><div>I have the foll=
owing typemap(out) that checks if a result object has_value and returns Py_=
None if it does not.</div><div>Unfortunately it also matches the constructo=
r of SomeType</div><div><br></div><div>Is there a way to prevent that match=
 or override the typemap for all SomeType constructors</div><div><br></div>=
<div>I searched the=C2=A0docs, far and wide, and attempted a few things, bu=
t could not find anything that would give me that level selectivity.</div><=
div><br></div><div>Thank you for any help you can provide!</div><div><br></=
div><div>%typemap(out) SomeType * %{</div><div>=C2=A0 if ( $1 &amp;&amp; $1=
-&gt;has_value() )</div><div>=C2=A0 {</div><div>=C2=A0 =C2=A0 $result =3D S=
WIG_NewPointerObj((void*)$1, $descriptor(SometType *), SWIG_BUILTIN_INIT | =
SWIG_POINTER_OWN);</div><div>=C2=A0 }</div><div>=C2=A0 else</div><div>=C2=
=A0 {</div><div>=C2=A0 =C2=A0 delete $1;</div><div>=C2=A0 =C2=A0 $result =
=3D Py_None;</div><div>=C2=A0 =C2=A0 Py_INCREF(Py_None);</div><div>=C2=A0 }=
</div><div>%}</div></div>

--0000000000006e31c20616db247e--


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


--===============7498791632311694615==
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

--===============7498791632311694615==--