Skip to content

Commit

Permalink
基本支持环形电路
Browse files Browse the repository at this point in the history
  • Loading branch information
sg-first committed Jun 16, 2019
1 parent 1ec562b commit 5aecd71
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LogicalCircuit.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.2.1, 2019-04-17T00:31:02. -->
<!-- Written by QtCreator 4.2.1, 2019-04-22T17:49:54. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
2 changes: 1 addition & 1 deletion gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
5 changes: 5 additions & 0 deletions node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 25 additions & 6 deletions node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand All @@ -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<line*> inputLine; //与g的input个数相等。每个连接需指明插槽位
bool isEval=false;
bool isEvaled=false;
bool isEvaling=false;
blist result;
gate *g;

Expand All @@ -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;
}

Expand Down Expand Up @@ -102,7 +121,7 @@ class nodeManager
static void resetChunk()
{
for(node* i : allNode)
i->isEval=false;
i->isEvaled=false;
}

public:
Expand Down

0 comments on commit 5aecd71

Please sign in to comment.