[Ns-developers] [ns3] trace path documentation
Tom Henderson
tomh at tomh.org
Wed Apr 16 07:48:36 PDT 2008
Gustavo Carneiro wrote:
> On 14/04/2008, Mathieu Lacage <mathieu.lacage at sophia.inria.fr> wrote:
>>
>> On Fri, 2008-04-11 at 01:28 +0100, Gustavo Carneiro wrote:
>>
>>
>>
>>> There are a couple of issues to consider:
>>> - I had to make one API change to the attribute system: if
>>> you want to
>>> set or get a pointer of the form Ptr<T> as an attribute, you
>>> must now
>>> wrap that pointer in an instance of the Pointer class.
>>> Ptr<Queue> queue;
>>> queue = csma->GetAttribute ("TxQueue");
>>> is now:
>>> Ptr<Queue> queue;
>>> Pointer q = csma->GetAttribute ("TxQueue");
>>> queue = q.Get ();
>>>
>>> Ugh!..
>>>
>>> Can you at least rename it to PointerAttribute or something. Having
>>> both Pointer and Ptr is rather confusing.
>>>
>>> Moreover, generally I think all classes that only wrap attribute
>>> values and which have a Get() method should be renamed to FooAttribute
>>> (replace Attribute with a suffix of choice). That would make it clear
>>> when a class is only a wrapper to an actual value.
>>
>> Thinking more about this and other issues lead me to re-consider this
>> problem in light of the larger problem of trying to explain in a
>> sensible and consistent way how to set and get attributes in objects or
>> across the helper API. The issue we face in the current code and in what
>> you propose is that different attributes get a different treatment
>> because of implementation details (which make a lot of sense if you know
>> how the implementation works but which are pretty weird for a user). For
>> example, if I want to deal with a double:
>>
>> object->SetAttribute ("MyDouble", Double (10.0));
>> Double v = object->GetAttribute ("MyDouble");
>> double value = v.Get ();
>>
>> but, if I want to deal with a Vector:
>>
>> Vector v = Vector (0.0, 0.0, 0.0);
>> object->SetAttribute ("MyVector", vector);
>> v = Object->GetAttribute ("MyVector");
>>
>> The issue, here, is that you have to wrap the value you want to set or
>> get with a Double but not with a Vector.
>>
>> The only way to make the two classes of attributes behave the same is to
>> _always_ request that you use a 'wrapper' class to set or get an
>> attribute:
>>
>> object->SetAttribute ("MyDouble", DoubleAttribute (10.0));
>> object->SetAttribute ("MyVector", VectorAttribute (v));
>> DoubleAttribute v = object->GetAttribute ("MyDouble");
>> double doubleV = v.Get ();
>> VectorAttribute vec = object->GetAttribute ("MyVector);
>> Vector vectorV = vec.Get ();
>>
>> The above code is certainly verbose but it is at least very consistent
>> and avoids the problem you originally complained about. Would there be
>> complaints if I implemented that ?
>
>
> No objections from me, but maybe DoubleAttr is good enough name and shorter
> to type?...
I agree with this change to the proposal and Gustavo's proposed shortening.
Tom
More information about the Ns-developers
mailing list