model_callbacks.cc
Go to the documentation of this file.
1 #include "stage.hh"
2 using namespace Stg;
3 using namespace std;
4 
5 
8  void* user )
9 {
10  //callbacks[address].insert( cb_t( cb, user ));
11  callbacks[type].insert( cb_t( cb, user ));
12 
13  // debug info - record the global number of registered callbacks
14  if( type == CB_UPDATE )
15  {
16  assert( world->update_cb_count >= 0 );
17  world->update_cb_count++;
18  }
19 }
20 
21 
23  model_callback_t callback )
24 {
25  set<cb_t>& callset = callbacks[type];
26  callset.erase( cb_t( callback, NULL) );
27 
28 
29  if( type == CB_UPDATE )
30  {
31  world->update_cb_count--;
32  assert( world->update_cb_count >= 0 );
33  }
34 
35  // return the number of callbacks remaining for this address. Useful
36  // for detecting when there are none.
37  return callset.size();
38 }
39 
40 
42 {
43  // maintain a list of callbacks that should be cancelled
44  vector<cb_t> doomed;
45 
46  set<cb_t>& callset = callbacks[type];
47 
48  FOR_EACH( it, callset )
49  {
50  const cb_t& cba = *it;
51  // callbacks return true if they should be cancelled
52  if( (cba.callback)( this, cba.arg ) )
53  doomed.push_back( cba );
54  }
55 
56  FOR_EACH( it, doomed )
57  callset.erase( *it );
58 
59  // return the number of callbacks remaining for this address. Useful
60  // for detecting when there are none.
61  return callset.size();
62 }
63 
64 
callback_type_t
Definition: stage.hh:1835
int CallCallbacks(callback_type_t type)
The Stage library uses its own namespace.
Definition: canvas.hh:8
int(* model_callback_t)(Model *mod, void *user)
Definition: stage.hh:568
void AddCallback(callback_type_t type, model_callback_t cb, void *user)
int RemoveCallback(callback_type_t type, model_callback_t callback)
model_callback_t callback
Definition: stage.hh:1788
#define FOR_EACH(I, C)
Definition: stage.hh:616


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 Mon Jun 10 2019 15:06:09