📄 midnode.h
字号:
pDC->MoveTo(k+5,50*j+5);
j++;
JiDian::drawlog(k,pDC,j);
}
void result(int &k,CDC*pDC,int &j)
{
JiDian::result(k,pDC,j);
guanjian=k;
Cop*p=this->getcond();
char *z="result";
pDC->TextOut(50,50*k,z);
int v=k;
char *t=new char[10];
itoa(v,t,10);
pDC->TextOut(90,50*k,t);
pDC->TextOut(1200,50*k,"选择");
pDC->TextOut(150,50*k,p->getprogl());
pDC->TextOut(180,50*k,p->getop());
pDC->TextOut(210,50*k,p->getprogr());
k++;
}
};
class leaf1:public jieDian
{
public:
jieDian *parent;
int guanjian;
void accept(Visiter *visiter)
{
visit(visiter);
}
void drawlog(int k,CDC*pDC,int j)
{
}
};
class Descartes:public JiDian
{
public:
void visit(Visiter *visiter)
{
visiter->visitDescartes(this);
}
void drawlog(int k,CDC*pDC,int j)
{
pDC->LineTo(k+5,50*j-5);
pDC->TextOut(k,50*j-3,"×");
j++;
JiDian::drawlog(k,pDC,j);
}
};
class Connection:public JiDian
{
public:
Cop *cond;
Connection()
{
cond=new Cop();
}
void setcond(Cop *condcop)
{
cond=condcop;
}
Cop* getcond()
{
return cond;
}
void visit(Visiter *visiter)
{
visiter->visitConnection(this);
}
void drawlog(int k,CDC*pDC,int j)
{
Cop*p=this->getcond();
pDC->LineTo(k+5,50*j-5);
pDC->TextOut(k,50*j,"∞");
pDC->TextOut(k+30,50*j,p->getprogl());
pDC->TextOut(k+60,50*j,p->getop());
pDC->TextOut(k+90,50*j,p->getprogr());
pDC->MoveTo(k+5,50*j+5);
j++;
JiDian::drawlog(k,pDC,j);
}
void result(int &k,CDC*pDC,int &j)
{
JiDian::result(k,pDC,j);
guanjian=k;
Cop*p=this->getcond();
char *z="result";
pDC->TextOut(50,50*k,z);
int v=k;
char *t=new char[10];
itoa(v,t,10);
pDC->TextOut(90,50*k,t);
pDC->TextOut(150,50*k,"自然连接");
pDC->TextOut(230,50*k,"result");
int vv=((JiDian*)this->left)->guanjian;
itoa(vv,t,10);
pDC->TextOut(270,50*k,t);
pDC->TextOut(310,50*j,"∞");
pDC->TextOut(350,50*k,"result");
vv=((JiDian*)this->right)->guanjian;
itoa(vv,t,10);
pDC->TextOut(390,50*k,t);
k++;
}
};
class Table:public leaf1
{
public:
char *name;
Table(char *n)
{
name=new char[strlen(n)];
strcpy(name,n);
}
char *getname()
{
return name;
}
void visit(Visiter *visiter)
{
visiter->visitTable(this);
}
void drawlog(int k,CDC*pDC,int j)
{
pDC->LineTo(k+5,50*j-5);
// pDC->MoveTo(point.x+5-50,point.y);
pDC->TextOut(k,50*j-3,name);
j++;
leaf1::drawlog(k,pDC,j);
}
void result(int &k,CDC*pDC,int &j)
{
guanjian=k;
char *z="result";
pDC->TextOut(50,50*k,z);
int v=k;
char *t=new char[10];
itoa(v,t,10);
pDC->TextOut(90,50*k,t);
pDC->TextOut(150,50*k,"Table");
pDC->TextOut(210,50*k,name);
k++;
}
};
class youhuaTreeVisiter:public Visiter
{
touYing *start;
CObList *youhua;
CObList *lian;
public:
youhuaTreeVisiter()
{
start=new touYing();
youhua=new CObList();
lian=new CObList();
}
void visit(Visiter* visiter){}
void visitDescartes(Descartes* desc){}
void visitConnection(Connection* con){}
void visittouYing(touYing* pro)
{
start=pro;
}
void visitsellistlect(sellistlect* sel)
{
char keystring1[10],keystring2[10];
int i=0;
char *pl=sel->getcond()->getprogl();
while(pl!=0)
{
keystring1[i++]=*pl;
if(*pl=='.')
{ keystring1[i-1]='\0';
break;
}
pl++;
}
char *pr=sel->getcond()->getprogr();
i=0;
while(strcmp(pr,"")!=0)
{
keystring2[i++]=*pr;
if(*pr=='.')
{
keystring2[i-1]='\0';
break;
}
pr++;
}
keystring2[i]='\0';
if(strcmp(pr,"")==0)
if(!pipei(keystring1))
{
//touYing * ty=new touYing();
//ty->keys=keystring1;
youhua->AddTail(new touYing());
touYing * ty=(touYing*)youhua->GetTail();
ty->right=NULL;
((touYing*)youhua->GetTail())->keys=new char[strlen(keystring1)+1];
strcpy(((touYing*)youhua->GetTail())->keys,keystring1);
sellistlect *e=new sellistlect();
e->setcond(sel->getcond());
((touYing*)youhua->GetTail())->left=e;
e->parent=(touYing*)youhua->GetTail();
Table * t=new Table(keystring1);
e->left=t;
e->right=NULL;
}
else
{
touYing *t=new touYing();
POSITION pos=youhua->GetHeadPosition();
while(pos)
{
touYing * p=(touYing*)youhua->GetNext(pos);
if(strcmp(p->keys,keystring1)==0)
{
t=p;
break;
}
}
sellistlect *e=new sellistlect();
e->setcond(sel->getcond());
t->right=e;
e->parent=t;
e->left=t->left;
t->left=t->right;
e->right=NULL;
t->right=NULL;
}
else
{
touYing * v=new touYing();
Connection* c=new Connection();
c->getcond()->setprogl(sel->getcond()->getprogl());
c->getcond()->setprogr(sel->getcond()->getprogr());
c->getcond()->setop(sel->getcond()->getop());
lian->AddTail(c);
v->left=c;
v->right=NULL;
c->parent=v;
if(pipei(keystring1)||pipei(keystring2))
{
int m=0,n=0;
int i=0,j=0;
touYing *t1,*t2;
POSITION pos=youhua->GetHeadPosition();
while(pos)
{
touYing *retu=(touYing*)youhua->GetNext(pos);
if(strcmp(retu->keys,keystring1)==0)
{
i=1;
t1=retu;
char *z=new char[strlen(keystring1)];
strcpy(z,keystring1);
z=strcat(z,pl);
retu->add(z);
}
if(strcmp(retu->keys,keystring2)==0)
{
j=1;
t2=retu;
char *z=new char[strlen(keystring2)];
strcpy(z,keystring2);
z=strcat(z,pr);
retu->add(z);
}
}
POSITION pos1=lian->GetHeadPosition();
while(pos1)
{
POSITION pos2=pos1;
Connection *k=(Connection *)lian->GetNext(pos1);
char *pq=k->getcond()->getprogl();
char *z=new char[strlen(keystring1)];
strcpy(z,keystring1);
z=strcat(z,pl);
char *z1=new char[strlen(keystring2)];
strcpy(z1,keystring2);
z1=strcat(z1,pr);
pq=chadian(pq);
if(strcmp(pq,keystring1)==0)
{
if(pos1)
{
c->left=k->parent;
((touYing*)k->parent)->add(z);
((touYing*)k->parent)->parent=c;
lian->RemoveAt(pos2);
m=1;
break;
}
}
if(strcmp(pq,keystring2)==0)
{
if(pos1)
{
c->right=k->parent;
((touYing*)k->parent)->add(z1);
((touYing*)k->parent)->parent=c;
lian->RemoveAt(pos2);
n=1;
break;
}
}
pq=k->getcond()->getprogr();
pq=chadian(pq);
if(strcmp(pq,keystring1)==0)
{
if(pos1)
{
c->left=k->parent;
((touYing*)k->parent)->add(z);
((touYing*)k->parent)->parent=c;
lian->RemoveAt(pos2);
m=1;
break;
}
}
if(strcmp(pq,keystring2)==0)
{
if(pos1)
{
c->right=k->parent;
((touYing*)k->parent)->add(z1);
((touYing*)k->parent)->parent=c;
lian->RemoveAt(pos2);
n=1;
break;
}
}
}
if(m==1||n==1)
{
if(m==1&&j==1)
{
c->left=t2;
// break;
}
else
if(n==1&&i==1)
{
c->left=t1;
// break;
}
}
if(m==0&&n==0)
{
if(i==1&&j==1)
{
c->left=t1;
c->right=t2;
// break;
}
else
if(j==1)
{
c->right=t2;
// break;
}
else if(i==1)
{
c->left=t1;
// break;
}
}
if((m!=1||n!=1)&&(j==0||i==0))
{
youhua->AddTail(new touYing());
touYing * ty=(touYing*)youhua->GetTail();
if(j==0)
{
((touYing*)youhua->GetTail())->keys=new char[strlen(keystring2)+1];
strcpy(((touYing*)youhua->GetTail())->keys,keystring2);
c->right=ty;
char *z=new char[strlen(keystring1)];
strcpy(z,keystring1);
z=strcat(z,pl);
ty->add(z);
}
if(i==0)
{
((touYing*)youhua->GetTail())->keys=new char[strlen(keystring1)+1];
strcpy(((touYing*)youhua->GetTail())->keys,keystring1);
c->left=ty;
char *z=new char[strlen(keystring1)];
strcpy(z,keystring1);
z=strcat(z,pl);
ty->add(z);
}
if(i!=1)
{
Table * t=new Table(keystring1);
ty->left=t;
ty->right=NULL;
}
if(j!=1)
{
Table * t=new Table(keystring2);
ty->left=t;
ty->right=NULL;
}
}
}
else
if(!pipei(keystring1)&&!pipei(keystring2))
{
touYing * ty=new touYing();
ty->keys=new char[strlen(keystring1)];
strcpy(ty->keys,keystring1);
touYing*ty1=new touYing();
ty1->keys=new char[strlen(keystring1)];
strcpy(ty1->keys,keystring2);
youhua->AddTail(ty);
youhua->AddTail(ty1);
Table * t=new Table(keystring1);
Table * t1=new Table(keystring2);
ty->left=t;
ty1->left=t1;
ty->right=NULL;
ty1->right=NULL;
c->left=ty;
c->right=ty1;
}
}
}
void visitTable(Table* tab){}
void visitCop(Cop* cond){}
bool pipei(char *ll)
{
POSITION pos=youhua->GetHeadPosition();
while(pos)
{
touYing * p=(touYing*)youhua->GetNext(pos);
if(strcmp(p->keys,ll)==0)
return true;
}
return false;
}
char* chadian(char* kk)
{
char tt[10];
int i=0;
char *vt;
while(kk!=0)
{
tt[i++]=*kk;
if(*kk=='.')
{
tt[i-1]='\0';
break;
}
kk++;
}
vt=new char[strlen(tt)];
strcpy(vt,tt);
return vt;
}
jieDian * getyouhuaTree()
{
// POSITION pos=lian->GetHeadPosition();
// while(pos)
//{
Connection * p=(Connection*)lian->GetTail();
start->left=p;
//}
return start;
}
};
class parTreeVisitor:public Visitor
{
public:
jieDian *jiedian;
touYing *kaishi;
touYing *root;
bool selectlist1,sub;
parTreeVisitor()
{
selectlist1=false;
sub=false;
kaishi=new touYing();
}
void visit(){}
void visitSFW(SFW* sfw)
{
if(!sub)
{
kaishi=new touYing();
kaishi->parent=NULL;
root=kaishi;
jiedian=kaishi;
}
}
void visitSelList(SelList* list)
{
selectlist1=true;
}
void visitFromList(FromList* list)
{
((JiDian*)jiedian)->left=new Descartes();
((JiDian*)((JiDian*)jiedian)->left)->parent=jiedian;
jiedian=((JiDian*)jiedian)->left;
((JiDian*)jiedian)->left=NULL;
}
void visitConditionList(ConditionList* list){};
void visitCondition(Condition* condition)
{
sub=true;
kaishi->right=new sellistlect();
((JiDian*)(kaishi->right))->right=NULL;
((JiDian*)(kaishi->right))->left=kaishi->left;
((JiDian*)(kaishi->left))->parent=kaishi->right;
kaishi->left=kaishi->right;
kaishi->right=NULL;
}
void visitRelation(Relation* relation)
{
((Descartes*)jiedian)->right=new Table(relation->getValue());
((leaf1*)((JiDian*)jiedian)->right)->parent=jiedian;
}
void visitQuery(Query* query){};
void visitAttri(Attri* attri)
{
if(selectlist1)
{
if(!sub)
root->add(attri->getValue());
else
((sellistlect*)kaishi->left)->getcond()->setprogr(attri->value);
selectlist1=false;
}
else
((sellistlect*)kaishi->left)->getcond()->setprogl(attri->value);
}
void visitOperator(Operator* oper)
{
if(strcmp(oper->getValue(),"(")==0){
sub = true;
}
else if(strcmp(oper->getValue(),")")==0){
sub = false;
}
else if(strcmp(oper->getValue(),"IN")==0)
{
oper->value="=";
oper->type=6;
((sellistlect*)kaishi->left)->getcond()->setop(oper->getValue());
}
else if(oper->getType()!=7)
{
((sellistlect*)kaishi->left)->getcond()->setop(oper->getValue());
}
}
void visitDigattri(DigAttri* digattri)
{
((sellistlect*)kaishi->left)->getcond()->setprogr(digattri->getValue());
}
jieDian* getLogTree()
{
return kaishi;
}
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -