Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/ActionRegistry.cpp

    r112b09 rb2d8d0  
    11/*
    2  * ActionRegistry.cpp
     2 * Registry<Action>.cpp
    33 *
    44 *  Created on: Jan 7, 2010
     
    99
    1010#include "Actions/ActionRegistry.hpp"
    11 #include "Actions/Action.hpp"
     11#include "Patterns/Singleton_impl.hpp"
     12#include "Patterns/Registry_impl.hpp"
    1213
    13 #include "Patterns/Singleton_impl.hpp"
     14/** Constructor for class ActionRegistry.
     15 */
     16ActionRegistry::ActionRegistry()
     17{}
    1418
    15 #include <string>
    16 #include "Helpers/Assert.hpp"
    17 #include <iostream>
     19/** Destructor for class ActionRegistry.
     20 */
     21ActionRegistry::~ActionRegistry()
     22{}
    1823
    19 using namespace std;
    20 
    21 ActionRegistry::ActionRegistry()
     24/** Just passes on call to Registry<Action>::getByName().
     25 * \param name name of Action
     26 * \return pointer to Action
     27 */
     28Action* ActionRegistry::getActionByName(const std::string name)
    2229{
     30  return getByName(name);
    2331}
    2432
    25 ActionRegistry::~ActionRegistry()
     33/** Just passes on call to Registry<Action>::isPresentByName().
     34 * \param name name of Action
     35 * \return true - Action instance present, false - not
     36 */
     37bool ActionRegistry::isActionPresentByName(const std::string name)
    2638{
    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 void ActionRegistry::registerAction(Action* action){
    42   pair<map<const string,Action*>::iterator,bool> ret;
    43   ret = actionMap.insert(pair<const string,Action*>(action->getName(),action));
    44   ASSERT(ret.second,"Two actions with the same name added to registry");
    45 }
    46 
    47 void ActionRegistry::unregisterAction(Action* action){
    48   actionMap.erase(action->getName());
    49 }
    50 
    51 std::map<const std::string,Action*>::iterator ActionRegistry::getBeginIter()
    52 {
    53   return actionMap.begin();
    54 }
    55 
    56 std::map<const std::string,Action*>::iterator ActionRegistry::getEndIter()
    57 {
    58   return actionMap.end();
     39  return isPresentByName(name);
    5940}
    6041
    6142CONSTRUCT_SINGLETON(ActionRegistry)
     43CONSTRUCT_REGISTRY(Action)
Note: See TracChangeset for help on using the changeset viewer.