FindingApplications: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 17: | Line 17: | ||
</pre></code> | </pre></code> | ||
Note the specific syntax of the cast---the template is of the pointer, | Note the specific syntax of the cast---the template is of the pointer, not a <code>Ptr</code>. | ||
[[Category:Samples]] | [[Category:Samples]] |
Latest revision as of 21:21, 26 June 2008
Sometimes, you may want to find an application of a given type on a node. The Node
objects provides basic access to do this, and the TypeId
mechanism the ability to identify the application. If the application objects have TypeId
definitions, then this simple loop will find an application:
Ptr<Application> app;
Ptr<MyApp> myapp = 0;
for (uint32_t x = 0; x < node->GetNApplications(); x++) {
app = node->GetApplication(x);
if (app->GetInstanceTypeId() == MyApp::GetTypeId()) {
myapp = dynamic_cast<MyApp *> (PeekPointer(app));
break;
}
}
if (myapp != 0) {
// Do something MyApp specific with it...
}
Note the specific syntax of the cast---the template is of the pointer, not a Ptr
.