Emergency 20 Dokumentation  4.2.0
OperationMessageHandlerManager-inl.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Namespace ]
6 //[-------------------------------------------------------]
7 namespace em5
8 {
9  namespace multiplayer
10  {
11 
12  //[-------------------------------------------------------]
13  //[ Public static methods ]
14  //[-------------------------------------------------------]
15  template <typename T> T* OperationMessageHandlerManager::getHandler(bool onlyHost)
16  {
17  return static_cast<T*>(OperationMessageHandlerManager::getHandlerById(T::HANDLER_ID, onlyHost));
18  }
19 
20 
21  //[-------------------------------------------------------]
22  //[ Public methods ]
23  //[-------------------------------------------------------]
24  template <typename T>
26  {
27  return static_cast<T*>(getHandlerById(T::HANDLER_ID));
28  }
29 
31  {
32  auto iterator = mHandlerMap.find(id);
33  if (iterator == mHandlerMap.end())
34  {
35  return nullptr;
36  }
37  return iterator->second.get();
38  }
39 
40  inline const std::map<OperationMessage, std::unique_ptr<OperationMessageHandler>>& OperationMessageHandlerManager::getAllHandler() const
41  {
42  return mHandlerMap;
43  }
44 
46  {
47  mHandlerMap.emplace(id, std::unique_ptr<OperationMessageHandler>(&operationMessageHandler));
48  }
49 
50 
51 //[-------------------------------------------------------]
52 //[ Namespace ]
53 //[-------------------------------------------------------]
54  } // multiplayer
55 } // em5
Definition: ActionPriority.h:13
const std::map< OperationMessage, std::unique_ptr< OperationMessageHandler > > & getAllHandler() const
Returns the whole handler map.
Definition: OperationMessageHandlerManager-inl.h:40
EMERGENCY 5 base class for operation message handler.
Definition: OperationMessageHandler.h:46
OperationMessage
EMERGENCY 5 multiplayer operation message types.
Definition: OperationMessages.h:51
void registerHandler(OperationMessage id, OperationMessageHandler &operationMessageHandler)
Register a new handler.
Definition: OperationMessageHandlerManager-inl.h:45
static OperationMessageHandler * getHandlerById(OperationMessage id, bool onlyHost)
T * getHandler()
Return a operation message handler instance of a certain type.
Definition: OperationMessageHandlerManager-inl.h:25