Difference between revisions of "GetAggregateOwners"

From Nsnam
Jump to: navigation, search
 
 
Line 1: Line 1:
 +
Often you may wish to get the "owners" of an object, the container into which it has been aggregated.  For example, given the <code>MobilityModel</code> associated with a <code>CourseChange</code> 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 <code>MobilityModel</code> object:
  
 +
<code><pre>
 +
void
 +
DecoratorManager::CourseChange (std::string foo,
 +
                                Ptr<const MobilityModel> mobility)
 +
{
 +
  Ptr<Node> node = mobility->GetObject<Node>();
 +
  NS_ASSERT(node != 0);
 +
 +
  // Do stuff...
 +
}
 +
</pre></code>
  
 
[[Category:Samples]]
 
[[Category:Samples]]

Latest revision as of 22:31, 23 June 2008

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...
}