// SimInteractorRegistry.cpp #include "SimInteractorRegistry.h" #include #include "VTrack.h" using std::cerr; using std::endl; using std::pair; using trf::SurfacePtr; using trf::CrossStat; using trf::VTrack; using trf::SimInteractor; using trf::SimInteractorRegistry; //********************************************************************** void SimInteractorRegistry:: register_interactor(SurfacePtr psrf, SimInteractorPtr pinter) { pair< SurfacePtr, SimInteractorPtr > newpair(psrf,pinter); pair< interMap::iterator, bool > addpair; addpair = _imap.insert( newpair ); if( ! addpair.second ){ cerr << *(newpair.first) << " already has an interactor" << endl; abort(); } } //********************************************************************** const SurfacePtr SimInteractorRegistry::get_bsurf(const VTrack& vtrk) { const SurfacePtr& thisSurf(vtrk.get_surface()); bool found(false); pair< SurfacePtr, SimInteractorPtr > srf_inter; interMap::iterator mapIter; for( mapIter = _imap.begin(); mapIter != _imap.end(); mapIter++ ){ srf_inter = *mapIter; if( srf_inter.first->pure_equal(*thisSurf) ){ if(srf_inter.first->status(vtrk).in_bounds()){ found = true; return mapIter->first; } } } assert(found); return thisSurf; } //********************************************************************** void SimInteractorRegistry::interact(VTrack& vtrk) { const SurfacePtr& thisSurf(vtrk.get_surface()); // The surface must have some kind of interactor registered, // even if it is a null pointer, meaning no interaction. bool found(false); pair< SurfacePtr, SimInteractorPtr > srf_inter; interMap::iterator mapIter; for( mapIter = _imap.begin(); mapIter != _imap.end(); mapIter++ ){ srf_inter = *mapIter; // first member of the pair is the surface... it must be (at least // its pure part) in the map if( srf_inter.first->pure_equal(*thisSurf) ){ if(srf_inter.first->status(vtrk).in_bounds()){ // we should only get in here once... assert( !found ); found = true; SurfacePtr& useSurf = srf_inter.first; // if it is a null pointer, just beat it if( _imap[useSurf] == 0L ){ return; }else{ (_imap[useSurf])->interact( vtrk ); } } } } assert( found ); return; } //**********************************************************************