GetAggregateOwners
Jump to navigation
Jump to 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...
}