/* * ActionRegistry.cpp * * Created on: Jan 7, 2010 * Author: crueger */ #include "Actions/ActionRegistry.hpp" #include "Actions/Action.hpp" #include "Patterns/Singleton_impl.hpp" #include #include "Helpers/Assert.hpp" #include using namespace std; ActionRegistry::ActionRegistry() { } ActionRegistry::~ActionRegistry() { map::iterator iter; for(iter=actionMap.begin();iter!=actionMap.end();++iter) { delete iter->second; } actionMap.clear(); } Action* ActionRegistry::getActionByName(const std::string name){ map::iterator iter; iter = actionMap.find(name); ASSERT(iter!=actionMap.end(),"Query for an action not stored in registry"); return iter->second; } bool ActionRegistry::isActionByNamePresent(const std::string name){ map::iterator iter; iter = actionMap.find(name); return iter!=actionMap.end(); } void ActionRegistry::registerAction(Action* action){ pair::iterator,bool> ret; ret = actionMap.insert(pair(action->getName(),action)); ASSERT(ret.second,"Two actions with the same name added to registry"); } void ActionRegistry::unregisterAction(Action* action){ actionMap.erase(action->getName()); } std::map::iterator ActionRegistry::getBeginIter() { return actionMap.begin(); } std::map::iterator ActionRegistry::getEndIter() { return actionMap.end(); } CONSTRUCT_SINGLETON(ActionRegistry)