You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
#ifndef DEPTREE_H |
|
#define DEPTREE_H |
|
#include <set> |
|
#include <vector> |
|
#include <string> |
|
#include <pthread.h> |
|
#include <time.h> |
|
#include "globals.h" |
|
|
|
class DepTree |
|
{ |
|
typedef std::vector<DepTree*> LeafVector; |
|
typedef std::map<std::string,DepTree*> DepTreeVars; |
|
typedef std::set<DepTree*> NodeVector; |
|
typedef std::set<const DepTree*> CallStack; |
|
enum NodeType {NOTDEF,ROOT,SAVE,PRINT,VAR}; |
|
|
|
typedef struct |
|
{ |
|
const DepTree* root; |
|
int exitcode; |
|
LeafVector leafs; |
|
pthread_mutex_t leaf_mtx; |
|
pthread_mutex_t root_mtx; |
|
pthread_mutex_t tree_mtx; |
|
} thread_params; |
|
NodeVector parents; |
|
NodeVector childrens; |
|
NodeType type; |
|
std::string name; |
|
ExecExpr exe; |
|
|
|
int CreateNodeFromVar(const std::string& v, VarType& vars, DepTreeVars& dvars, CallStack& callstack); |
|
int CreateNodeFromSP(NodeType list, VarType& vars, ExecExpr& exp, DepTreeVars& dvars); |
|
LeafVector FindLeafNodes() const; |
|
public: |
|
DepTree():type(DepTree::NOTDEF) {} |
|
DepTree(const DepTree&) = delete; |
|
~DepTree() |
|
{ |
|
for(auto& i:parents) i->childrens.erase(this); |
|
for(auto& i:childrens) |
|
{ |
|
i->parents.erase(this); |
|
if(i->parents.size()==0) delete i; |
|
} |
|
} |
|
|
|
int CreateTree(ExecType& save, ExecType& print, VarType& vars); |
|
int EvaluateTree(unsigned int nthreads); |
|
void DumpTree() const; |
|
int CheckFunctions() const; |
|
friend void* TreeEvaluateM(void* arg); |
|
friend void* TreeEvaluate (void* arg); |
|
}; |
|
|
|
#endif
|
|
|