ActionFactory.cpp
Go to the documentation of this file.
00001 #include "ActionFactory.h"
00002 
00003 #include "actasp/Action.h"
00004 #include <boost/config/no_tr1/complex.hpp>
00005 
00006 using namespace std;
00007 using namespace actasp;
00008 
00009 namespace bwi_krexec {
00010 
00011 bool ActionFactory::simulation(false);
00012 
00013 ActionFactory::ActionFactory(Action* act) {
00014 
00015         //TODO warn if action already there
00016         bothActions().insert( make_pair(act->getName(),act));
00017 
00018 }
00019 
00020 ActionFactory::ActionFactory(actasp::Action *act, bool simulation) {
00021         
00022         if(simulation)
00023                 simulatedActions().insert( make_pair(act->getName(),act));
00024         else
00025                 realActions().insert( make_pair(act->getName(),act));
00026 }
00027 
00028 
00029 Action* ActionFactory::byName(const std::string& name) throw (std::runtime_error) {
00030         
00031         map<string, Action*>::const_iterator actIt = bothActions().find(name);
00032         
00033         if(actIt == actions().end()) {
00034                 
00035                 ActionMap &inUse = (simulation)? simulatedActions() : realActions();
00036                         
00037                 actIt = inUse.find(name);
00038                 if(actIt == inUse.end())
00039                         throw runtime_error("No action with name " + name);
00040         }
00041 
00042         return actIt->second->clone();
00043 }
00044 
00045 ActionFactory::ActionMap ActionFactory::actions() {
00046         ActionFactory::ActionMap actions; 
00047         if(simulation)
00048                 actions.insert(simulatedActions().begin(),simulatedActions().end());
00049         else
00050                 actions.insert(realActions().begin(),realActions().end());
00051   
00052   actions.insert(bothActions().begin(),bothActions().end());
00053         
00054         return actions;
00055 }
00056 
00057 ActionFactory::ActionMap &ActionFactory::realActions() {
00058         static ActionFactory::ActionMap realAct;
00059         return realAct;
00060 }
00061 
00062 ActionFactory::ActionMap &ActionFactory::simulatedActions() {
00063         static ActionFactory::ActionMap simulAct;
00064         return simulAct;
00065 }
00066 
00067 ActionFactory::ActionMap &ActionFactory::bothActions() {
00068         static ActionFactory::ActionMap bothAct;
00069         return bothAct;
00070 }
00071 
00072 void ActionFactory::setSimulation(bool value) {
00073         simulation = value;
00074 }
00075 
00076         
00077 }


bwi_kr_execution
Author(s): Matteo Leonetti, Piyush Khandelwal
autogenerated on Thu Jun 6 2019 17:57:36