tree: revise arguments (use Thread, ModelAction)
[c11tester.git] / tree.h
1 #ifndef __TREE_H__
2 #define __TREE_H__
3
4 #include <set>
5 #include <map>
6 #include "threads.h"
7
8 class ModelAction;
9
10 /*
11  * An n-ary tree
12  *
13  * A tree with n possible branches from each node - used for recording the
14  * execution paths we've executed / backtracked
15  */
16 class TreeNode {
17 public:
18         TreeNode(TreeNode *par = NULL, ModelAction *act = NULL);
19         ~TreeNode();
20         bool hasBeenExplored(thread_id_t id) { return children.find(id_to_int(id)) != children.end(); }
21         TreeNode * explore_child(ModelAction *act);
22         thread_id_t getNextBacktrack();
23
24         /* Return 1 if already in backtrack, 0 otherwise */
25         int setBacktrack(thread_id_t id);
26         TreeNode * getRoot();
27         static int getTotalNodes() { return TreeNode::totalNodes; }
28 private:
29         TreeNode *parent;
30         std::map<int, class TreeNode *> children;
31         std::set<int> backtrack;
32         static int totalNodes;
33 };
34
35 #endif /* __TREE_H__ */