NS3 object version of std::vector?

434 views
Skip to first unread message

Quincy

unread,
Mar 15, 2010, 2:27:59 AM3/15/10
to ns-3-users
I'd like to be able pass a std::vector into an object as an attribute,
however the relevant attribute value uses a Ptr<T>, with T having a
_Ref and _Unref functions.

Is there an NS3 object that is equivalent to/child of std::vector that
I can use? I can write one very easily, but I think I shouldn't be
duplicating code if one exists already.

Mihal Brumbulli

unread,
Mar 15, 2010, 2:51:43 PM3/15/10
to ns-3-users

Quincy

unread,
Mar 15, 2010, 7:52:19 PM3/15/10
to ns-3-users
Thanks,

I actually just want to pass in a generic std::vector (not necessarily
a vector of Ptr) into an ns3::Object as an Attribute. (ie. something
like template <typename T, typename _Alloc> class Blah : ns3::Object,
std::vector<double, _Alloc>).

Alternatively, are there anyway I can pass in an STL container or
similar (or pointer to) as Attribute to an Object?

What I'm trying to do is to pass in a mapping between an integer (from
0 to N) and a double such that the ns3::Object can look up the value
at run time. My view is that it is more appropriate to pass in the
mapping than to pass in a Callback that looks up the mapping as the
mapping should be internal to that object, and the object may want to
change the mapping during run time.

Quincy

On Mar 16, 5:51 am, Mihal Brumbulli <mbrumbu...@gmail.com> wrote:
> have a look at
>

> http://groups.google.com/group/ns-3-users/browse_thread/thread/c85ae2...

Mihal Brumbulli

unread,
Mar 16, 2010, 7:13:27 AM3/16/10
to ns-3-users
Hi,

I had the same problem some time ago. The solution I adopted was to
create e generic Container class,
based essentially on NodeContainer, but able to add any data type:

template<typename T>
class Container : public Object

This way I can use PointerValue() to pass a Container to any
Application as attribute.
Of course there may be better solutions, but this worked for me and I
did not bother to find
something better :)

Hope it helps

Reply all
Reply to author
Forward
0 new messages