| ios_base::register_callback | public member function |
void register_callback ( event_callback fn, int index ); |
Register event callback function
Registers the function passed as argument fn such that when an event occurs it is automatically called. index is the argument passed to fn when it is called.
If more than one callback function is registered, these are called in opposite order of registration.
The callback function must be of type compatible with member type event_callback. And it is called by an expression equivalent to:
(*fn)(ev,*this,index)
where index is the index argument used when the callback function was registered, *this is a pointer to the calling object, and ev is an object of member enum type event indicating the type of event that happened. It can be one of the following member values:
| value | event triggered |
|---|---|
| copyfmt_event | on a call to ios::copyfmt (at the moment where all format flags have been copied, but before the exception mask is) |
| erase_event | on a call to the destructor (also called by at the beginning of ios::copyfmt). |
| imbue_event | on a call to imbue (just before the function returns). |
All registered functions are called on all of the cases above. The function itself should use the ev parameter to identify which event triggered the function call and determine if it has to react.
Parameters
- fn
- Pointer to the function to be called. The event_callback member function type is defined as:
typedef void (* event_callback) (event ev, ios_base& ios, int index);
- index
- Integer value passed as parameter to the callback function. It can be used to specify some parameter value to be used within the callback function.
Return Value
noneExample
// 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 will display something similar to:
imbue_event |
See also
| ios_base::imbue | Imbue locale (public member function) |
| ios::copyfmt | Copy formatting information (public member functions) |
| ios_base::event | Type to indicate event type (public member types) |
