[Ns-developers] Python bindings do not include template class methods
tomh at tomh.org
Sat Feb 6 16:17:25 PST 2021
On 2/5/21 1:59 AM, Gustavo Carneiro wrote:
> Here's an idea. Instead of going through it via gccxml and header
> scanning, why not manually register these methods. See attached patch.
> Seems to work, for 1 the case of 1 and 2 params (more may be added). And
> the Python code remains the same:
> wifiMac.SetType("ns3::StaWifiMac", "Ssid", ns.wifi.SsidValue(ssid))
Thanks Gustavo, this has been helpful.
The problem is more general than this class. ObjectFactory's API was
recently converted to variadic templates, and those methods are now
missing from the core module bindings also. We presently now have two
types of object factory declarations in our helper; the non-variadic
version (e.g. SpectrumChannelHelper, and there are many others), and
these newer variadic template declarations such as the new WifiMacHelper.
The non-variadic API does scan successfully, but leads to a more verbose
header. If we want to keep migrating our helpers to variadic templates,
we probably have to manually add the bindings that Gustavo suggested.
Or we could revert to avoiding the use of variadic templates for these
object factory configurations.
Longer-term, as newer C++ language features are proposed for ns-3, we
will have to consider whether we keep going with pybindgen, adding
support to that toolchain (or writing manual bindings when we can't), or
else switching to another framework. pybind11 is another popular
compile-time bindings generator, but appears to also have limitations
with variadic templates. cppyy is a run-time generator that might solve
variadic template issues and other issues such as lack of compile-time
traced callback type information.
Any thoughts on how we should proceed? I would be inclined to add
custom bindings as needed for the time being, and find a volunteer to
explore whether cppyy might be workable for us.
More information about the Ns-developers