C++: pls help me to choose or suggest me a new one
-
Take a minute to read. I could not shorten my problem... be patient... I have a CBaseEvent class There are other two classes have derived from CBaseEvent named CSysEvent and CGuiEvent I have created a queue of CBaseEvent pointers. This queue is being processed by an event handler class. A thread is working for this. Whenever a new event adds on the queue, this thread will process the event by calling
ProcessEventFunction
. which prototyped asProcessEventFunction(CBaseEvent* pEvent)
Here comes the problem. How can I identify between System Event and GUI event? These are the possibilities I have 1. Usedynamic_cast
identify the pointer using dynamic cast. Then do the further processing depends on Sys event or GUI event. 2. Do the above check inside the thread itself and call theProcessEvent
function overloaded with GUI event and SysEvent depends on the result 3. Use two queues. One for sys event and another for GUI event. Run two threads for the same and call the overloadedProcessEvent
function depends on the queue. Here definitely I’ll face some problems with the order of the events received. I need to process the sys and GUI events in first come first serve manner. So this approach will have sync issues. The above are the solutions I have!!! Could you pls suggest one from this or a new one? Again sorry for borring you with a long question :) SaRath.
"Do Next Thing..." Understanding State Pattern in C++ -
Take a minute to read. I could not shorten my problem... be patient... I have a CBaseEvent class There are other two classes have derived from CBaseEvent named CSysEvent and CGuiEvent I have created a queue of CBaseEvent pointers. This queue is being processed by an event handler class. A thread is working for this. Whenever a new event adds on the queue, this thread will process the event by calling
ProcessEventFunction
. which prototyped asProcessEventFunction(CBaseEvent* pEvent)
Here comes the problem. How can I identify between System Event and GUI event? These are the possibilities I have 1. Usedynamic_cast
identify the pointer using dynamic cast. Then do the further processing depends on Sys event or GUI event. 2. Do the above check inside the thread itself and call theProcessEvent
function overloaded with GUI event and SysEvent depends on the result 3. Use two queues. One for sys event and another for GUI event. Run two threads for the same and call the overloadedProcessEvent
function depends on the queue. Here definitely I’ll face some problems with the order of the events received. I need to process the sys and GUI events in first come first serve manner. So this approach will have sync issues. The above are the solutions I have!!! Could you pls suggest one from this or a new one? Again sorry for borring you with a long question :) SaRath.
"Do Next Thing..." Understanding State Pattern in C++I've relied on poor man's RTTI by adding a protected member of the enum type
CBaseEvent::Type
to the base class. The enum is set in each base class constructor.CBaseEvent
has agetType()
method that returns the type of subclass. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com -
Take a minute to read. I could not shorten my problem... be patient... I have a CBaseEvent class There are other two classes have derived from CBaseEvent named CSysEvent and CGuiEvent I have created a queue of CBaseEvent pointers. This queue is being processed by an event handler class. A thread is working for this. Whenever a new event adds on the queue, this thread will process the event by calling
ProcessEventFunction
. which prototyped asProcessEventFunction(CBaseEvent* pEvent)
Here comes the problem. How can I identify between System Event and GUI event? These are the possibilities I have 1. Usedynamic_cast
identify the pointer using dynamic cast. Then do the further processing depends on Sys event or GUI event. 2. Do the above check inside the thread itself and call theProcessEvent
function overloaded with GUI event and SysEvent depends on the result 3. Use two queues. One for sys event and another for GUI event. Run two threads for the same and call the overloadedProcessEvent
function depends on the queue. Here definitely I’ll face some problems with the order of the events received. I need to process the sys and GUI events in first come first serve manner. So this approach will have sync issues. The above are the solutions I have!!! Could you pls suggest one from this or a new one? Again sorry for borring you with a long question :) SaRath.
"Do Next Thing..." Understanding State Pattern in C++Create a ProcessEventFunction on the base class CBaseEvent that is overloaded for proper processing and invoke that function.
-
Take a minute to read. I could not shorten my problem... be patient... I have a CBaseEvent class There are other two classes have derived from CBaseEvent named CSysEvent and CGuiEvent I have created a queue of CBaseEvent pointers. This queue is being processed by an event handler class. A thread is working for this. Whenever a new event adds on the queue, this thread will process the event by calling
ProcessEventFunction
. which prototyped asProcessEventFunction(CBaseEvent* pEvent)
Here comes the problem. How can I identify between System Event and GUI event? These are the possibilities I have 1. Usedynamic_cast
identify the pointer using dynamic cast. Then do the further processing depends on Sys event or GUI event. 2. Do the above check inside the thread itself and call theProcessEvent
function overloaded with GUI event and SysEvent depends on the result 3. Use two queues. One for sys event and another for GUI event. Run two threads for the same and call the overloadedProcessEvent
function depends on the queue. Here definitely I’ll face some problems with the order of the events received. I need to process the sys and GUI events in first come first serve manner. So this approach will have sync issues. The above are the solutions I have!!! Could you pls suggest one from this or a new one? Again sorry for borring you with a long question :) SaRath.
"Do Next Thing..." Understanding State Pattern in C++ -
Take a minute to read. I could not shorten my problem... be patient... I have a CBaseEvent class There are other two classes have derived from CBaseEvent named CSysEvent and CGuiEvent I have created a queue of CBaseEvent pointers. This queue is being processed by an event handler class. A thread is working for this. Whenever a new event adds on the queue, this thread will process the event by calling
ProcessEventFunction
. which prototyped asProcessEventFunction(CBaseEvent* pEvent)
Here comes the problem. How can I identify between System Event and GUI event? These are the possibilities I have 1. Usedynamic_cast
identify the pointer using dynamic cast. Then do the further processing depends on Sys event or GUI event. 2. Do the above check inside the thread itself and call theProcessEvent
function overloaded with GUI event and SysEvent depends on the result 3. Use two queues. One for sys event and another for GUI event. Run two threads for the same and call the overloadedProcessEvent
function depends on the queue. Here definitely I’ll face some problems with the order of the events received. I need to process the sys and GUI events in first come first serve manner. So this approach will have sync issues. The above are the solutions I have!!! Could you pls suggest one from this or a new one? Again sorry for borring you with a long question :) SaRath.
"Do Next Thing..." Understanding State Pattern in C++Virtual Functions ? :rolleyes: --- With best regards, A Manchester United Fan The Genius of a true fool is that he can mess up a foolproof plan!
-
Virtual Functions ? :rolleyes: --- With best regards, A Manchester United Fan The Genius of a true fool is that he can mess up a foolproof plan!
how ??? SaRath.
"Do Next Thing..." Understanding State Pattern in C++ -
Take a minute to read. I could not shorten my problem... be patient... I have a CBaseEvent class There are other two classes have derived from CBaseEvent named CSysEvent and CGuiEvent I have created a queue of CBaseEvent pointers. This queue is being processed by an event handler class. A thread is working for this. Whenever a new event adds on the queue, this thread will process the event by calling
ProcessEventFunction
. which prototyped asProcessEventFunction(CBaseEvent* pEvent)
Here comes the problem. How can I identify between System Event and GUI event? These are the possibilities I have 1. Usedynamic_cast
identify the pointer using dynamic cast. Then do the further processing depends on Sys event or GUI event. 2. Do the above check inside the thread itself and call theProcessEvent
function overloaded with GUI event and SysEvent depends on the result 3. Use two queues. One for sys event and another for GUI event. Run two threads for the same and call the overloadedProcessEvent
function depends on the queue. Here definitely I’ll face some problems with the order of the events received. I need to process the sys and GUI events in first come first serve manner. So this approach will have sync issues. The above are the solutions I have!!! Could you pls suggest one from this or a new one? Again sorry for borring you with a long question :) SaRath.
"Do Next Thing..." Understanding State Pattern in C++ -
how ??? SaRath.
"Do Next Thing..." Understanding State Pattern in C++Well not sure if this is exactly what you need, but here goes. :) Define the funtion that you want to call as a pure virtual function in
CBaseEvent
. Code their implementations inCSysEvent
andCGuiEvent
. Now whenever you want to call the function, just upcast theCBaseEvent
's pointer with eitherCSysEvent
orCGuiEvent's
address.CBaseEvent* Base ; CSysEvent Sys ; Base = &Sys ; Base->Function() ; //Calls CSysEvent's Function.
Hope this was helpful. --- With best regards, A Manchester United Fan The Genius of a true fool is that he can mess up a foolproof plan!