1 Star 0 Fork 32

feiyuluyan/CM-Server

forked from 留天下/CM-Server 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
event.cpp 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
留天下 提交于 2019-03-03 22:47 . 好友
#include "event.h"
#include<iostream>
using namespace std;
using namespace Json;
long long int Slot::count = 0;
Slot::Slot(SlotListener* listener,const EventHandler& evh,const bool& once)
{
this->listener = listener;
this->flag=false;
this->evh = evh;
this->once = once;
this->id = count++;
}
Slot::Slot(SlotListener* listener, const std::function<void(Json::Value&)>& func, const bool& once) {
this->listener = listener;
this->flag = true;
this->func = func;
this->once = once;
this->id = count++;
}
void Slot::dispatch(Json::Value& message)
{
cout<<"Slot::dispatch"<<message.toStyledString()<<endl;
if (flag)
{
func(message);
}
else
{
cout<<"Slot::dispatch 2"<<message.toStyledString()<<endl;
(evh.handler->*evh.func)(message);
}
if (once)
this->remove();
}
bool Slot::operator==(const Slot & slot)
{
return this->id == slot.id;
}
long long int Slot::getId() const
{
return this->id;
}
void Slot::remove()
{
this->listener->removeSlot(this->getId());
}
EventHandler handler(Object* CCObject,SEL_EventFunc func)
{
EventHandler evh;
evh.handler = CCObject;
evh.func = func;
return evh;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/feiyuluyan/CM-Server.git
[email protected]:feiyuluyan/CM-Server.git
feiyuluyan
CM-Server
CM-Server
master

搜索帮助