ios_base::register_callback
void register_callback ( event_callback fn, int index );
ios_base
  cplusplus.com  

Register event callback function.
  Registers function fn such that when an event occurs it is called. index is passed as a parameter when fn is called.
  If more than one, registered functions are called in opposite order of registration.
  Functions are called by an expression equivalent to:
    (*fn)(ev,*this,index)
  where ev is an object of member type event with one of the following values:

copyfmt_eventon a call to copyfmt (just when all format flags have been copied, but before exception mask).
erase_eventon a call to the class destructor (also called by copyfmt at beginning).
imbue_eventon a call to imbue (just before function returns).
  The registered function is called on all the cases above.

Parameters.

fn
Pointer to the function to be called. event_callback is defined as:
  typedef void (* event_callback) (event ev, ios_base& ios, int index) ;
index
Integer value passed when callback function is called. It can be used to specify some parameter value to be used within the callback function.

Return Value.
  none

Example.

// stream callbacks
#include <iostream>
#include <fstream>
using namespace std;

void testfn (ios_base::event ev, ios_base& iosobj, int index)
{
  switch (ev)
  {
    case ios_base::copyfmt_event:
      cout << "copyfmt_event\n"; break;
    case ios_base::imbue_event:
      cout << "imbue_event\n"; break;
    case ios_base::erase_event:
      cout << "erase_event\n"; break;
  }
}

int main () {
  ofstream filestr;
  filestr.register_callback (testfn,0);
  filestr.imbue (cout.getloc());
  return 0;
}
The execution of this example shall display something similar to:
imbue_event
erase_event

See also.
  imbue, ios::copyfmt,
  event type, ios_base class


© The C++ Resources Network, 2001