Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

mitk::DelegateManager Class Reference

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>

List of all members.

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.
MessageAbstractDelegateGetCommand (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 DelegateManagerGetInstance ()
 Singleton pattern.

Protected Member Functions

 DelegateManager ()
 Singleton pattern: protected Ctor.

Protected Attributes

std::map< std::string,
MessageAbstractDelegate<> * > 
m_CommandMap
 Maps IDs to Commands.

Detailed Description

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.


Constructor & Destructor Documentation

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]

Singleton pattern: protected Ctor.

Definition at line 21 of file mitkDelegateManager.cpp.

{
}

Member Function Documentation

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;
}

Member Data Documentation

std::map<std::string, MessageAbstractDelegate<>*> mitk::DelegateManager::m_CommandMap [protected]

Maps IDs to Commands.

Definition at line 76 of file mitkDelegateManager.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines