source: molecuilder/src/Actions/ActionRegistry.cpp@ 3e8325

Last change on this file since 3e8325 was 3e8325, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Added a central registry that allows access to actions by name.

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/*
2 * ActionRegistry.cpp
3 *
4 * Created on: Jan 7, 2010
5 * Author: crueger
6 */
7
8#include "Actions/ActionRegistry.hpp"
9#include "Actions/Action.hpp"
10
11#include <string>
12#include <cassert>
13#include <iostream>
14
15using namespace std;
16
17ActionRegistry *ActionRegistry::theInstance=0;
18
19ActionRegistry::ActionRegistry()
20{
21 // TODO Auto-generated constructor stub
22
23}
24
25ActionRegistry::~ActionRegistry()
26{
27 // TODO Auto-generated destructor stub
28}
29
30Action* ActionRegistry::getActionByName(const std::string name){
31 map<const string,Action*>::iterator iter;
32 iter = actionMap.find(name);
33 assert(iter!=actionMap.end() && "Query for an action not stored in registry");
34 return iter->second;
35}
36
37void ActionRegistry::registerAction(Action* action){
38 pair<map<const string,Action*>::iterator,bool> ret;
39 ret = actionMap.insert(pair<const string,Action*>(action->getName(),action));
40 assert(ret.second && "Two actions with the same name added to registry");
41}
42
43// singleton stuff
44ActionRegistry* ActionRegistry::getRegistry(){
45 if(!theInstance){
46 theInstance = new ActionRegistry();
47 }
48 return theInstance;
49}
50
51void ActionRegistry::purgeRegistry(){
52 if(theInstance){
53 delete theInstance;
54 theInstance = 0;
55 }
56}
Note: See TracBrowser for help on using the repository browser.