diff --git a/LogicalCircuit.pro.user b/LogicalCircuit.pro.user index 479c242..5f6f0fb 100644 --- a/LogicalCircuit.pro.user +++ b/LogicalCircuit.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/gate.h b/gate.h index ef28c53..3ec8682 100644 --- a/gate.h +++ b/gate.h @@ -205,7 +205,7 @@ class tri : public gate public: tri(string name,uint inputNum, uint outputNum=1) : gate(name,inputNum,outputNum) { isTri=true; } - const uint Q=0; + const static uint Q=0; virtual void setQ(bool q) { stat[Q]=q; } virtual bool getQ() { return stat[Q]; } blist getStat() { return stat; } diff --git a/node.cpp b/node.cpp index ea43838..d4bea71 100644 --- a/node.cpp +++ b/node.cpp @@ -11,6 +11,11 @@ line::line(string name, node *n, uint sub) : name(name), n(n), sub(sub) nodeManager::addLine(this); } +bool line::getIsEvaling() +{ + return this->n->isEvaling; +} + bool line::get() { if(isConst) diff --git a/node.h b/node.h index 1888381..f1334ce 100644 --- a/node.h +++ b/node.h @@ -10,16 +10,18 @@ class line { private: string name; - node *n; uint sub; bool isConst=false; + public: + node *n; bool constVal; line(string name, node *n,uint sub=0); line(string name,bool constVal=0) : name(name), isConst(true), constVal(constVal) {} bool get(); string getName() { return this->name; } + bool getIsEvaling(); void stru(uint tabNum=0); }; @@ -31,13 +33,28 @@ class node { blist par; for(line* i : inputLine) - par.push_back(i->get()); + { + if(i->getIsEvaling()) //检查是否有环形 + { + gate* iTri=i->n->g; + if(iTri->getIsTri()) + { + tri* t=(tri*)iTri; + par.push_back(t->getStat()[tri::Q]); + } + else + throw string("Illegal Ring Circuit"); + } + else + par.push_back(i->get()); + } return par; } public: vector inputLine; //与g的input个数相等。每个连接需指明插槽位 - bool isEval=false; + bool isEvaled=false; + bool isEvaling=false; blist result; gate *g; @@ -47,11 +64,13 @@ class node blist eval() { - if(isEval==false) + isEvaling=true; + if(isEvaled==false) { this->result=g->calu(getInputPar()); - this->isEval=true; + this->isEvaled=true; } + isEvaling=false; return this->result; } @@ -102,7 +121,7 @@ class nodeManager static void resetChunk() { for(node* i : allNode) - i->isEval=false; + i->isEvaled=false; } public: