c++ - Runtime event handler in cpp? -


working on cpp project, need runtime event handler. primary goal keep track of various events takes place in sample program , based on events specific handlers triggered.

these event triggering handlers/functions not contributing global objective of sample program, keeping track on various events in cpp sample program.

my question prossible create soemthing custom eventhandlers in cpp? if yes, there tutorial creating such custom eventhandler?

eg: event failed enter while loop. entered while loop, created object, deleted object, changed global variable etc.

the simplest form of event handler registered callback function pointer:

enum events {     failedenteringwhileloop ,     successfullyenteredwhileloop , };  typedef void(eventhandler*)(events); 

 void myeventhandler(events ev) {     switch(ev) {     case failedenteringwhileloop:         //         break;     case successfullyenteredwhileloop:         //         break;     }  } 

eventhandler evh = myeventhandler; bool whileloopentered = false; while(condition) {     if(!whileloopentered) {         whileloopentered = true;         (*evh)(successfullyenteredwhileloop);     } }  if(!whileloopentered) {     (*evh)(failedenteringwhileloop); } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -