X-Git-Url: https://ruin.nu/git/?p=popboot.git;a=blobdiff_plain;f=action.cpp;h=7b7a58807f5536e436e615a82ac19b2a2373831d;hp=626eb37475bb5487756381dafcd823fd2188380f;hb=3dadaa088d9fff7ca05cbb297f3d7e88179faccb;hpb=13441470b3b895e08b4165e2154665863f1c3b33 diff --git a/action.cpp b/action.cpp index 626eb37..7b7a588 100644 --- a/action.cpp +++ b/action.cpp @@ -1,32 +1,49 @@ #include "action.h" #include using namespace std; +using namespace __gnu_cxx; -Action::Action(std::string executable, literals preconditions, literals effects){ - _executable = executable; +const literals Action::_empty; + +Action::Action(std::string name, preconditionsVector preconditions, effectsMap effects){ + _name = name; _preconditions = preconditions; _effects = effects; + _currentPrecondition = _preconditions.begin(); } Action::Action(const Action& action){ - _executable = action._executable; + _name = action._name; _preconditions = action._preconditions; _effects = action._effects; } -const literals& Action::effects() const{ - return _effects; +const literals& Action::effects(int value) const{ + effectsMap::const_iterator effects = _effects.find(value); + if (effects != _effects.end()) + return effects->second; + return _empty; } const literals& Action::preconditions() const{ - return _preconditions; + return _currentPrecondition->second; } int Action::execute() const{ - cout << "Executing: " << _executable << endl; + cout << "Executing: " << _currentPrecondition->first << endl; return 0; } -const string& Action::executable() const{ - return _executable; +const string& Action::name() const{ + return _name; +} + +bool Action::nextExecutable(){ + if (++_currentPrecondition != _preconditions.end()) + return true; + return false; +} + +void Action::reset(){ + _currentPrecondition = _preconditions.begin(); }