| 351 | |
| 352 | template< class T > |
| 353 | void SimSet::findObjectByCallback( bool ( *fn )( T* ), Vector<T*> &foundObjects ) |
| 354 | { |
| 355 | T *curObj; |
| 356 | SimSet *curSet; |
| 357 | |
| 358 | lock(); |
| 359 | |
| 360 | // Loop through our child objects. |
| 361 | |
| 362 | SimObjectList::iterator itr = mObjectList.begin(); |
| 363 | |
| 364 | for ( ; itr != mObjectList.end(); itr++ ) |
| 365 | { |
| 366 | curObj = dynamic_cast<T*>( *itr ); |
| 367 | curSet = dynamic_cast<SimSet*>( *itr ); |
| 368 | |
| 369 | // If child object is a set, call recursively into it. |
| 370 | if ( curSet ) |
| 371 | curSet->findObjectByCallback( fn, foundObjects ); |
| 372 | |
| 373 | // Add this child object if appropriate. |
| 374 | if ( curObj && ( fn == NULL || fn( curObj ) ) ) |
| 375 | foundObjects.push_back( curObj ); |
| 376 | } |
| 377 | |
| 378 | // Add this object if appropriate. |
| 379 | curObj = dynamic_cast<T*>(this); |
| 380 | if ( curObj && ( fn == NULL || fn( curObj ) ) ) |
| 381 | foundObjects.push_back( curObj ); |
| 382 | |
| 383 | unlock(); |
| 384 | } |
| 385 | |
| 386 | /// An iterator that recursively and exhaustively traverses the contents |
| 387 | /// of a SimSet. |