]> ruin.nu Git - popboot.git/blobdiff - node.cpp
Spelling fix in inittab
[popboot.git] / node.cpp
index 83b3334a7dab9b6095e1d1907a35ac808d9d6bc9..24da8b1dd60c36d9575151630ca3e990905b9ef2 100644 (file)
--- a/node.cpp
+++ b/node.cpp
@@ -34,19 +34,22 @@ bool Node::executed() const{
 const Literals& Node::effects() const{
        return _effects;
 }
-void Node::satisfyCondition(std::string effect){
+
+bool Node::satisfyCondition(std::string effect){
        _preconditions.erase(_preconditions.find(effect));
+       return _preconditions.size() == 0 && !_executed;
 }
 
-void Node::execute(const Literals& effects){
-       cerr << "Executing: " << _action->name() << endl;
+bool Node::satisfyConditions(const Literals& effects){
        for (Literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
-               cerr << "Satisfied effect: " << *effect << endl;
                _preconditions.erase(_preconditions.find(*effect));
        }
-       cerr << "Number of preconditions left: " << _preconditions.size() << endl;
+       return _preconditions.size() == 0 && !_executed;
+}
+
+void Node::execute(){
        if(_executed)
-               cerr << "Already executed" << endl;
+               cerr << "Already executed " << _action->name() << endl;
        if ((_preconditions.size() != 0) || _executed)
                return;
 
@@ -54,17 +57,21 @@ void Node::execute(const Literals& effects){
        int value = _action->execute();
        _effects = _action->effects(value);
 
-       cerr << "Got returnvalue: " << value << ", number of effects: " << _effects.size() << endl;
-
-       for(vector<Node*>::iterator child = _children.begin(); child != _children.end(); ++child){
-               (*child)->execute(_effects);
-       }
 }
 
+const std::vector<Node*>& Node::children() const{
+       return _children;
+}
 StartNode::StartNode(const Literals& init){
        EffectsMap initial;
        initial[0] = init;
        _action = new Action("start",Preconditions(),"", initial);
+       _executed = true;
+       _effects = init;
+}
+
+const Preconditions& Node::preconditions() const{
+       return _preconditions;
 }
 
 EndNode::EndNode(const Literals& goal){