Renames the mitk::MessageAbstractDelegate, which is a Functor to a simple function with no params, to "Command". This should emphasize that it is not used as an event function but rather as a command. More...
#include <mitkDelegateManager.h>
Public Member Functions | |
void | SetCommand (const std::string &_CommandID, MessageAbstractDelegate<> *) |
Adds or overwrites a Command. *Attention*: This is class is the owner of the Command. Thus whenever a command is overwritten, the old Command is deleted! | |
bool | RemoveCommand (const std::string &_CommandID) |
Removes and *deletes* the Command with the given id. | |
MessageAbstractDelegate * | GetCommand (const std::string &_CommandID) const |
Returns the Command with the given id or NULL if the _CommandID is unknown. | |
virtual | ~DelegateManager () |
Dtor: Deletes all commands and clears m_CommandMap. | |
Static Public Member Functions | |
static DelegateManager * | GetInstance () |
Singleton pattern. | |
Protected Member Functions | |
DelegateManager () | |
Singleton pattern: protected Ctor. | |
Protected Attributes | |
std::map< std::string, MessageAbstractDelegate<> * > | m_CommandMap |
Maps IDs to Commands. |
Renames the mitk::MessageAbstractDelegate, which is a Functor to a simple function with no params, to "Command". This should emphasize that it is not used as an event function but rather as a command.
A class that stores commands (= mitk::Message) via a unique identifier. One could also say it is an Event Multiplexer.
Definition at line 44 of file mitkDelegateManager.h.
mitk::DelegateManager::~DelegateManager | ( | ) | [virtual] |
Dtor: Deletes all commands and clears m_CommandMap.
Definition at line 63 of file mitkDelegateManager.cpp.
{ // delete all commands for(std::map<std::string, MessageAbstractDelegate<>*>::iterator it=m_CommandMap.begin(); it!=m_CommandMap.end() ; it++) { delete it->second; it->second = 0; } m_CommandMap.clear(); }
mitk::DelegateManager::DelegateManager | ( | ) | [protected] |
mitk::MessageAbstractDelegate * mitk::DelegateManager::GetCommand | ( | const std::string & | _CommandID ) | const |
Returns the Command with the given id or NULL if the _CommandID is unknown.
Definition at line 57 of file mitkDelegateManager.cpp.
{ std::map<std::string, MessageAbstractDelegate<>*>::const_iterator it = m_CommandMap.find(_CommandID); return (it == m_CommandMap.end()) ? 0: it->second; }
mitk::DelegateManager * mitk::DelegateManager::GetInstance | ( | ) | [static] |
Singleton pattern.
Definition at line 24 of file mitkDelegateManager.cpp.
{ static mitk::DelegateManager _DelegateManager; return &_DelegateManager; }
bool mitk::DelegateManager::RemoveCommand | ( | const std::string & | _CommandID ) |
Removes and *deletes* the Command with the given id.
Definition at line 44 of file mitkDelegateManager.cpp.
{ MessageAbstractDelegate<>* _ExistingCommand = this->GetCommand(_CommandID); if(_ExistingCommand) { m_CommandMap.erase(_CommandID); delete _ExistingCommand; _ExistingCommand = 0; return true; } return false; }
void mitk::DelegateManager::SetCommand | ( | const std::string & | _CommandID, |
mitk::MessageAbstractDelegate<> * | _Command | ||
) |
Adds or overwrites a Command. *Attention*: This is class is the owner of the Command. Thus whenever a command is overwritten, the old Command is deleted!
Definition at line 30 of file mitkDelegateManager.cpp.
{ MessageAbstractDelegate<>* _ExistingCommand = this->GetCommand(_CommandID); // delete existing MessageAbstractDelegate for id, but only if the existing MessageAbstractDelegate is not the same as the // MessageAbstractDelegate parameter if(_ExistingCommand && _ExistingCommand != _Command) { m_CommandMap.erase(_CommandID); delete _ExistingCommand; _ExistingCommand = 0; } m_CommandMap[_CommandID] = _Command; }
std::map<std::string, MessageAbstractDelegate<>*> mitk::DelegateManager::m_CommandMap [protected] |
Maps IDs to Commands.
Definition at line 76 of file mitkDelegateManager.h.