I want to implement a timer queuing system using the C ++ STL container adapter.
My problem is that I sometimes want to cancel the timer, but there is no interface which allows me to easily remove an item in the Priority_AQ which is not the top item.
Any suggestions ?.
Thank you for your help
I once had the same scenario and Did the following:
- I typed in
std :: priority_queue
in the structurestd :: vector & lt; Handler & gt;
(In my casehandler
wasboost :: function
, it can also be an indicator for the interface or function) - Timer When adding, I will get a free index of the handler vector 1 and store the handler on that index. Store the time in the index and priority_ area. Return to the token to cancel the pointer
- To cancel a timer, pass the received indicator when you add it.
- At that time (when
boost :: function
callclear
, if using pointer, set it to zero) - To callback the timer, get your handler index from the priority queue and check the handler vector - if the handler is empty () / navel at that place, the timer has been canceled. The Handler Index is free < Sup> 2
1 a free index To find the fastest, I add at the end of a separate std :: stack
when you add a timer used to index and vector stack is empty; Otherwise pop the top index and use it.
2 Here's the point when you press the index in the free index stack
The whole thing is difficult and error prone, especially if your timer callback Need to add or cancel the timer
Comments
Post a Comment