]> ruin.nu Git - popboot.git/blob - action.cpp
not working
[popboot.git] / action.cpp
1 #include "action.h"
2 #include <iostream>
3 using namespace std;
4 using namespace __gnu_cxx;
5
6 const literals Action::_empty;
7
8 Action::Action(std::string name, preconditionsVector preconditions, effectsMap effects){
9         _name = name;
10         _preconditions = preconditions;
11         _effects = effects;
12         _currentPrecondition = _preconditions.begin();
13 }
14
15 Action::Action(const Action& action){
16         _name = action._name;
17         _preconditions = action._preconditions;
18         _effects = action._effects;
19 }
20
21 const literals& Action::effects(int value) const{
22         effectsMap::const_iterator effects = _effects.find(value);
23         if (effects != _effects.end())
24                 return effects->second;
25         return _empty;
26 }
27
28 const literals& Action::preconditions() const{
29         return _currentPrecondition->second;
30 }
31
32 int Action::execute() const{
33         cout << "Executing: " << _currentPrecondition->first << endl;
34         return 0;
35 }
36
37 const string& Action::name() const{
38         return _name;
39 }
40
41 bool Action::nextExecutable(){
42         if (++_currentPrecondition != _preconditions.end())
43                 return true;
44         return false;
45 }
46
47 void Action::reset(){
48         _currentPrecondition = _preconditions.begin();
49 }