| 1 | /*
|
|---|
| 2 | * ActionRegistry.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Jan 7, 2010
|
|---|
| 5 | * Author: crueger
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include "Helpers/MemDebug.hpp"
|
|---|
| 9 |
|
|---|
| 10 | #include "Actions/ActionRegistry.hpp"
|
|---|
| 11 | #include "Actions/Action.hpp"
|
|---|
| 12 |
|
|---|
| 13 | #include "Patterns/Singleton_impl.hpp"
|
|---|
| 14 |
|
|---|
| 15 | #include <string>
|
|---|
| 16 | #include "Helpers/Assert.hpp"
|
|---|
| 17 | #include <iostream>
|
|---|
| 18 |
|
|---|
| 19 | using namespace std;
|
|---|
| 20 |
|
|---|
| 21 | ActionRegistry::ActionRegistry()
|
|---|
| 22 | {
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | ActionRegistry::~ActionRegistry()
|
|---|
| 26 | {
|
|---|
| 27 | map<const string,Action*>::iterator iter;
|
|---|
| 28 | for(iter=actionMap.begin();iter!=actionMap.end();++iter) {
|
|---|
| 29 | delete iter->second;
|
|---|
| 30 | }
|
|---|
| 31 | actionMap.clear();
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | Action* ActionRegistry::getActionByName(const std::string name){
|
|---|
| 35 | map<const string,Action*>::iterator iter;
|
|---|
| 36 | iter = actionMap.find(name);
|
|---|
| 37 | ASSERT(iter!=actionMap.end(),"Query for an action not stored in registry");
|
|---|
| 38 | return iter->second;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | bool ActionRegistry::isActionByNamePresent(const std::string name){
|
|---|
| 42 | map<const string,Action*>::iterator iter;
|
|---|
| 43 | iter = actionMap.find(name);
|
|---|
| 44 | return iter!=actionMap.end();
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | void ActionRegistry::registerAction(Action* action){
|
|---|
| 48 | pair<map<const string,Action*>::iterator,bool> ret;
|
|---|
| 49 | ret = actionMap.insert(pair<const string,Action*>(action->getName(),action));
|
|---|
| 50 | ASSERT(ret.second,"Two actions with the same name added to registry");
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | void ActionRegistry::unregisterAction(Action* action){
|
|---|
| 54 | actionMap.erase(action->getName());
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | std::map<const std::string,Action*>::iterator ActionRegistry::getBeginIter()
|
|---|
| 58 | {
|
|---|
| 59 | return actionMap.begin();
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | std::map<const std::string,Action*>::iterator ActionRegistry::getEndIter()
|
|---|
| 63 | {
|
|---|
| 64 | return actionMap.end();
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | CONSTRUCT_SINGLETON(ActionRegistry)
|
|---|