model_callbacks.cc
Go to the documentation of this file.
00001 #include "stage.hh"
00002 using namespace Stg;
00003 using namespace std;
00004 
00005 
00006 void Model::AddCallback( callback_type_t type, 
00007                                                                                                  model_callback_t cb, 
00008                                                                                                  void* user )
00009 {
00010   //callbacks[address].insert( cb_t( cb, user ));       
00011         callbacks[type].insert( cb_t( cb, user ));
00012 
00013         // debug info - record the global number of registered callbacks
00014         if( type == CB_UPDATE )
00015                 {
00016                         assert( world->update_cb_count >= 0 );
00017                         world->update_cb_count++;
00018                 }
00019 }
00020 
00021 
00022 int Model::RemoveCallback( callback_type_t type,
00023                                                                                                          model_callback_t callback )
00024 {
00025         set<cb_t>& callset = callbacks[type];   
00026         callset.erase( cb_t( callback, NULL) );
00027 
00028         
00029         if( type == CB_UPDATE )
00030                 {
00031                         world->update_cb_count--;
00032                         assert( world->update_cb_count >= 0 );
00033                 }
00034         
00035         // return the number of callbacks remaining for this address. Useful
00036         // for detecting when there are none.
00037         return callset.size();
00038 }
00039 
00040 
00041 int Model::CallCallbacks( callback_type_t type )
00042 {
00043         // maintain a list of callbacks that should be cancelled
00044         vector<cb_t> doomed;
00045         
00046         set<cb_t>& callset = callbacks[type];
00047         
00048         FOR_EACH( it, callset )
00049           {  
00050                         const cb_t& cba = *it;  
00051                         // callbacks return true if they should be cancelled
00052                         if( (cba.callback)( this, cba.arg ) )
00053                                 doomed.push_back( cba );
00054           }      
00055         
00056         FOR_EACH( it, doomed )
00057                 callset.erase( *it );
00058 
00059         // return the number of callbacks remaining for this address. Useful
00060         // for detecting when there are none.
00061         return callset.size();
00062 }
00063 
00064 


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Thu Aug 27 2015 15:20:57