Files
25Sep01_EventQueue/code/main.cpp

43 lines
1.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "EventQueue.h"
int main()
{
EventQueue queue;
/* 模拟事件数据 */
int cmd1 = 101;
std::string param1 = "事件一";
int cmd2 = 202;
std::string param2 = "事件二";
int cmd3 = 303;
std::string param3 = "事件三";
std::cout << "=== 添加事件 ===" << std::endl;
queue.EventQueue_AddEvent(cmd1, &param1); // 队尾
queue.EventQueue_AddEventToFront(cmd2, &param2); // 队头
queue.EventQueue_AddEvent(cmd3, &param3); // 队尾
/* 查看队头事件 */
int peekCmd;
void *peekParam;
if (queue.EventQueue_PeekEvent(&peekCmd, &peekParam))
{
std::cout << "[Peek] cmd=" << peekCmd
<< " param=" << *(std::string *)peekParam << std::endl;
}
std::cout << "=== 获取并移除事件 ===" << std::endl;
int getCmd;
void *getParam;
while (queue.EventQueue_GetEvent(&getCmd, &getParam))
{
std::cout << "[Get] cmd=" << getCmd
<< " param=" << *(std::string *)getParam << std::endl;
// queue.EventQueue_PopEvent(); // 队列中 Get 已经 pop 了PopEvent 可省略
}
std::cout << "=== 队列已清空 ===" << std::endl;
return 0;
}