GetAggregateOwners

From Nsnam
Revision as of 22:31, 23 June 2008 by Tjkopena (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Often you may wish to get the "owners" of an object, the container into which it has been aggregated. For example, given the MobilityModel associated with a CourseChange event, you may wish to get a pointer to the corresponding node. The important but not obvious property to realize in this case is that aggregation in NS-3 is automatically bi-directional. When an object is aggregated to another object, the latter is also aggregated to the former. In effect, the aggregation relation is a one-to-one, reflexive, typed relation. As a result, the following code will get the "owner" node from a MobilityModel object:

void 
DecoratorManager::CourseChange (std::string foo,
                                Ptr<const MobilityModel> mobility)
{
  Ptr<Node> node = mobility->GetObject<Node>();
  NS_ASSERT(node != 0);

  // Do stuff...
}