]> ruin.nu Git - popboot.git/blob - node.h
Spelling fix in inittab
[popboot.git] / node.h
1 #ifndef __node_h__
2 #define __node_h__
3
4 #include <vector>
5 #include <utility>
6 #include "action.h"
7
8 /**
9  * A node in the plan graph, corresponds to a single action.
10  */
11 class Node {
12
13         public:
14                 /**
15                  * Creates a node for the given action.
16                  */
17                 Node(const Action* action);
18
19                 /**
20                  * Creates an empty, non-functional, node.
21                  */
22                 Node();
23
24                 /**
25                  * Creates a copy of the given node.
26                  */
27                 Node(const Node& node);
28                 virtual ~Node(){}
29
30                 /**
31                  * Add a child node, which will be executed after this node.
32                  */
33                 void addChild(Node* node);
34
35                 /**
36                  * Returns the action this node corresponds to.
37                  */
38                 const Action* action() const;
39
40                 /**
41                  * Execute this node, and hence the corresponding action.
42                  * Sets the effects achieved.
43                  *
44                  * If _executed is true or _preconditions.size() > 0 this method will
45                  * just return.
46                  */
47                 void execute();
48
49                 /**
50                  * Checks if this node has been executed or not.
51                  */
52                 bool executed() const;
53
54                 /**
55                  * Returns the effects that was achieved from execution.
56                  */
57                 const Literals& effects() const;
58
59                 /**
60                  * Satisfy a single condition.
61                  */
62                 bool satisfyCondition(std::string effect);
63
64                 /**
65                  * Satisfies a list of conditions.
66                  */
67                 bool satisfyConditions(const Literals& effects);
68
69                 /**
70                  * Returns all the children to this node.
71                  */
72                 const std::vector<Node*>& children() const;
73
74                 /**
75                  * Returns the unsatisfied preconditions.
76                  */
77                 const Preconditions& preconditions() const;
78
79         protected:
80                 //! The action this node corresponds to.
81                 const Action* _action;
82                 //! The list of children to this node.
83                 std::vector<Node*> _children;
84                 //! The, so far, unsatisfied preconditions.
85                 Preconditions _preconditions;
86                 //! Will be true if this node has been executed.
87                 bool _executed;
88                 //! The effects which were achieved by the execution.
89                 Literals _effects;
90 };
91
92 /**
93  * Class which is used as the start node in the plan graph.
94  */
95 class StartNode :public Node {
96         public:
97                 StartNode(const Literals& init);
98                 ~StartNode(){delete _action;}
99 };
100
101 /**
102  * Class which is used as the end node in the plan graph.
103  */
104 class EndNode :public Node {
105         public:
106                 EndNode(const Literals& goal);
107                 ~EndNode(){delete _action;}
108 };
109
110 #endif