SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
ProtocolHandlerRegistry.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <unordered_map>
7 #include "IProtocolHandler.h"
8 
9 namespace ai {
10 
12 private:
13  typedef std::unordered_map<ProtocolId, IProtocolHandler*> ProtocolHandlers;
14  ProtocolHandlers _registry;
15 
17  }
18 
19 public:
20  static ProtocolHandlerRegistry& get() {
21  static ProtocolHandlerRegistry _instance;
22  return _instance;
23  }
24 
25  virtual ~ProtocolHandlerRegistry() {
26  _registry.clear();
27  }
28 
29  inline void registerHandler(const ProtocolId& type, IProtocolHandler* handler) {
30  _registry.insert(std::make_pair(type, handler));
31  }
32 
33  inline IProtocolHandler* getHandler(const IProtocolMessage& msg) {
34  ProtocolHandlers::iterator i = _registry.find(msg.getId());
35  if (i != _registry.end())
36  return i->second;
37 
38  return nullptr;
39  }
40 };
41 
42 }
Definition: ProtocolHandlerRegistry.h:11
A protocol message is used for the serialization of the ai states for remote debugging.
Definition: IProtocolMessage.h:60
Interface for the execution of assigned IProtocolMessage.
Definition: IProtocolHandler.h:19