[Ns-developers] finalizing the ns-3 object model
Mathieu Lacage
mathieu.lacage at sophia.inria.fr
Mon Jan 14 23:37:32 PST 2008
On Mon, 2008-01-14 at 23:16 -0800, Tom Henderson wrote:
> > void BuildAdhoc (Ptr<WifiChannel> channel, Ptr<Node> node, std::string
> > rateType, Parameters parameters)
> > {
> > Ptr<WifiNetDevice> device = ...;
> > ObjectFactory factory = ObjectFactory (rateType);
> > Ptr<WifiRateControl> rate = factory->Create
> > (parameters)->QueryInterface<WifiRateControl> ();
> > device->SetRate (rate);
> > }
> >
> > It should be trivial to hook the "rate type" string from a command-line
> > parser and to convey that directly to this BuildAdhoc function. Yes, if
> > you do all of this, you are going to lose _some_ of the automaticity of
> > the current way of doing things but the result is just vastly easier to
> > comprehend I think.
>
> Can you explain the distinction in this example between passing rateType
> and parameters separately, rather than just making rateType one of the
> parameters?
I am not sure I understand your question so, I will instead attempt to
describe this BuildAdhoc function in more details.
rateType describes the type of object to create. the parameters describe
the arguments to use to create the object. This is really useful if you
have a 'topology' API like the one we discussed privately (I am going to
send a separate email about this real soon now). i.e.:
class WifiHelper
{
public:
void SetRateControl (std::string rateControlType, Parameters
parameters) {
m_rateControlFactory = ObjectFactory (TypeId::LookupByName
(rateControlType, parameters));
}
void BuildAdhoc (NodeContainer nodes) {
for (node = nodes.begin (); node != nodes.end (); node++)
{
Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice> (node);
Ptr<RateControl> rate = m_rateControlFactory.CreateObject ();
dev->SetRateControl (rate);
}
}
private:
ObjectFactory m_rateControlFactory;
};
If your BuildAdhoc function really builds a single WifiNetDevice
instance, then, you could also pass around the RateControl instance
directly rather than pass around the type and parameters.
did I answer your question ?
Mathieu
More information about the Ns-developers
mailing list