-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractActor.h
More file actions
43 lines (32 loc) · 1.21 KB
/
AbstractActor.h
File metadata and controls
43 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef ABSTRACTACTOR_H
#define ABSTRACTACTOR_H
#include <memory>
#include <map>
#include <functional>
#include "Executer.h"
#include "Message.h"
#include "TQueue.h"
class NotGetExecutersInActor: public std::exception {};
class AbstractActor
{
protected:
std::map<int, std::shared_ptr<AbstractExecuter> > _executers;//словарь обработчиков сообщений
TQueue<AbstractMessagePtr> _queueMessage;
public:
AbstractActor();
//выполням переданное сообщение
virtual void execute(void)=0;
//получаем сообщение
virtual void addMessage(AbstractMessagePtr message)=0;
//добовляем обработчик сообщения
template<typename... Types>
void addExecuterOnMessage(const int MessageID, std::function<void(Types...)> functor)
{
std::shared_ptr<AbstractExecuter> executer = std::make_shared<Executer<Types...> >(Executer<Types...>(functor));
_executers[MessageID]=executer;
}
};
typedef std::shared_ptr<AbstractActor> AbstractActorPtr;
template<typename T, typename... Types>
std::shared_ptr<T> getActor(Types ... args){return std::shared_ptr<T>(&args ...);}
#endif // ABSTRACTACTOR_H