]> ruin.nu Git - popboot.git/blobdiff - action.cpp
not working
[popboot.git] / action.cpp
index 2508b5c9fcdbd7cd56a1f6c3414a41977eb59ed4..7b7a58807f5536e436e615a82ac19b2a2373831d 100644 (file)
@@ -1,3 +1,49 @@
 #include "action.h"
+#include <iostream>
+using namespace std;
+using namespace __gnu_cxx;
 
+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){
+       _name = action._name;
+       _preconditions = action._preconditions;
+       _effects = action._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 _currentPrecondition->second;
+}
+
+int Action::execute() const{
+       cout << "Executing: " << _currentPrecondition->first << endl;
+       return 0;
+}
+
+const string& Action::name() const{
+       return _name;
+}
+
+bool Action::nextExecutable(){
+       if (++_currentPrecondition != _preconditions.end())
+               return true;
+       return false;
+}
+
+void Action::reset(){
+       _currentPrecondition = _preconditions.begin();
+}