[Ns-developers] helper API + python

Gustavo Carneiro gjcarneiro at gmail.com
Mon Oct 20 07:40:01 PDT 2008


2008/10/20 Mathieu Lacage <mathieu.lacage at sophia.inria.fr>

> hi,
>
> So far, there is no support in the python wrapping API for implicit
> conversions based on c++ implicit conversions.


That is not true for all implicit conversions.  There are two kinds of
implicit conversions supported by C++:

  1- class MyClass { ... operator OtherClass (); }
  2- class MyClass { ... MyClass (OtherClass const &arg); }

Currently pybindgen is supporting 2 but not 1.


> For example, we have to
> write this:
>
> servers = NodeContainer ()
> servers.Create (10)
> ... do stuff
> // apply install method on only one server:
> stack.Install (NodeContainer (servers.Get (0)))
>
> In the above, we need to explicitely create a NodeContainer object to
> wrap the return type of NodeContainer.Get (which returns a Ptr<Object>).
>
> Ideally, it would be nice to be able to write this:
> stack.Install (servers.Get (0))
>
> So, there are 2 options:
> 1) add support to the python wrapper code to do the implicit conversions
> if it can
> 2) modify the underlying c++ API to make
> NodeContainer/NetDeviceContainer much more pervasive and avoid Ptr<Node>


I am not sure this is correct.  I think it is the reverse.  For instance:

class WifiHelper
{
  NetDeviceContainer Install (NodeContainer c) const;
};

If you simply extend it thus:

class WifiHelper
{
  NetDeviceContainer Install (NodeContainer c) const;
  NetDeviceContainer Install (Ptr<Node> node) const { return Install
(NodeContainer (node)); }
};

Then you no longer need the implicit conversion anymore, and you don't break
any API.


>
> 2) is a reasonably-big API change which would require quite a bit of API
> breakage at the C++ level so, I wonder if 1) is something which could be
> fixed in the near future. I would be happy to give this a shot if you
> can give me a hint as to what needs to be done to implement 1).


The problem is that giving a hint of what needs to be done is almost as much
work as doing it :|

The way it is currently supported is ugly but works, so I don't think this
is urgent.  On the other hand my time is kind of short these days.  Also you
could extend the C++ API without much effort IMHO.

I will try to evaluate the needed work over next weekend.  Sorry I can't do
it sooner.  But if you can figure something out sooner, the better ;-)

-- 
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert


More information about the Ns-developers mailing list