19 Star 44 Fork 32

留天下 / CM-Server

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
event.cpp 1.20 KB
Copy Edit Raw Blame History
留天下 authored 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;
}
C++
1
https://gitee.com/lsylovews/CM-Server.git
git@gitee.com:lsylovews/CM-Server.git
lsylovews
CM-Server
CM-Server
master

Search