新增:实现 EventQueue 类,单线程事件队列
This commit is contained in:
46
code/EventQueue.cpp
Normal file
46
code/EventQueue.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "EventQueue.h"
|
||||
|
||||
bool EventQueue::EventQueue_AddEvent(int tInputCmd, void *pInputParam)
|
||||
{
|
||||
cmdParam.push_back(pInputParam);
|
||||
cmdList.push_back(tInputCmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EventQueue::EventQueue_AddEventToFront(int tInputCmd, void *pInputParam)
|
||||
{
|
||||
cmdParam.push_front(pInputParam);
|
||||
cmdList.push_front(tInputCmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EventQueue::EventQueue_PeekEvent(int *pOutputCmd, void **ppOutputParam)
|
||||
{
|
||||
if (cmdList.empty())
|
||||
return false;
|
||||
|
||||
(*pOutputCmd) = cmdList.front();
|
||||
(*ppOutputParam) = cmdParam.front();
|
||||
return true;
|
||||
}
|
||||
|
||||
void EventQueue::EventQueue_PopEvent(void)
|
||||
{
|
||||
if (!cmdList.empty())
|
||||
{
|
||||
cmdList.pop_front();
|
||||
cmdParam.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
bool EventQueue::EventQueue_GetEvent(int *pOutputCmd, void **ppOutputParam)
|
||||
{
|
||||
if (cmdList.empty())
|
||||
return false;
|
||||
|
||||
(*pOutputCmd) = cmdList.front();
|
||||
(*ppOutputParam) = cmdParam.front();
|
||||
cmdList.pop_front();
|
||||
cmdParam.pop_front();
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user