#include "action.h"
#include <iostream>
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();
}