[Ns-developers] CreateObject and non-default constructors

Gustavo Carneiro gjcarneiro at gmail.com
Mon Jun 8 07:45:22 PDT 2009


2009/6/8 Mathieu Lacage <mathieu.lacage at sophia.inria.fr>

> hi,
>
> Recently, someone pointed out to me privately that we poorly support
> calling non-default constructors with CreateObject. In fact, we don't
> support it. I will skip over the lengthy discussion of how we ended up
> where we are today, and, instead, will get to what we could do to
> support this: 2 options (patches attached).
>
> 1. compatible option (a.patch)
> 2. less compatible option (b.patch)
>
> 1) compatible option: introduce CreateObjectNoAttributes:
>
> template <typename T>
> Ptr<T> CreateObjectNoAttributes (void);
>
> template <typename T, typename T1>
> Ptr<T> CreateObjectNoAttributes (T1 a1);
>
> template <typename T, typename T1, typename T2>
> Ptr<T> CreateObjectNoAttributes (T1 a1, T2 a2);
>
> ...
>
> It's not very pretty for something which appears to be regularly
> complained about by users.
>
> 2) less compatible option: modify CreateObject, introduce
> CreateObjectWithAttributes
>
> Despite not being fully compatible with existing code, I expect the
> fallout on users to be minimal because, frankly, no one calls
> CreateObject<> with construction-time attributes so, almost no one will
> notice this change.
>
> If I hear no comments within 2 days, I will proceed with applying these
> two patches to ns-3-dev together with the associated CHANGES.html notes.
>

I'm OK with a+b, but don't know whether I'll have time to adapt python
bindings to make use of non-default constructors, so it is likely that
python constructors will only support attributes.

Additionally, I would like to keep Python bindings simpler than C++, which
means we just call Class(...) constructor and behind the scenes the wrapper
code calls CreateObjectWhatever.  With that framework in mind, it becomes
difficult to support both types of parameters at the same time without
making one of the alternatives uglier.

So, in Python bindings side, nothing will change with a+b patches.  Is that
OK?

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