?? operator.cpp
字號:
#include <stdio.h>
#include <malloc.h>#include "Floorplan.h"Operator::Operator() { myType = OperatorType;}Operator::~Operator() {}bool Operator::M3OK(bool v_found,bool h_found) { switch(myIndex) { case 'V': v_found = true; break; default: h_found = true; } if(v_found && h_found) return true; if(myNext==NULL) return false; if(myNext->myType==OperatorType) { return ((Operator *) myNext)->M3OK(v_found,h_found); } else { return ((Module *) myNext)->M3OK(v_found,h_found); }}
Rect * Operator::getRectangles() {
Rect * lRects, *rRects, *myRects;
myRects = NULL;
// int lCount, rCount; // debugging variables
// get possible configurations from children
if(myLeftChild->myType==OperatorType) {
lRects = ((Operator *) myLeftChild)->getRectangles();
} else {
lRects = ((Module *) myLeftChild)->getRectangles();
}
if(myRightChild->myType==OperatorType) {
rRects = ((Operator *) myRightChild)->getRectangles();
} else {
rRects = ((Module *) myRightChild)->getRectangles();
}
// figure out how many each child actually returned
// Rect * temp = lRects; lCount = 0;
// while(temp!=NULL) {
// lCount++;
// temp = temp->myNext;
// }
// temp = rRects; rCount = 0;
// while(temp!=NULL) {
// rCount++;
// temp = temp->myNext;
// }
// fprintf(stdout,"Child %i returned %i rectangles\n",myLeftChild->myIndex,lCount);
// fprintf(stdout,"Child %i returned %i rectangles\n",myRightChild->myIndex,rCount);
int nRects = 0; // rectangles I have generated so far
int width, height;
// fprintf(stdout,"At node %c: Starting combinations:\n",myIndex);
// now start intersecting the kids' rectangles
Rect * lCurrent, *rCurrent, *myCurrent;
myCurrent = myRects;
lCurrent = lRects;
while(lCurrent!=NULL) {
rCurrent = rRects;
while(rCurrent!=NULL) {
if(myIndex=='V') {
// widths add, heights max
width = lCurrent->x + rCurrent->x;
height = (lCurrent->y > rCurrent->y) ?
lCurrent->y : rCurrent->y;
} else {
// widths max, heights add
width = (lCurrent->x > rCurrent->x) ?
lCurrent->x : rCurrent->x;
height = lCurrent->y + rCurrent->y;
}
// add the current rectangle to the solution
// set
if(myCurrent==NULL) {
myRects = new Rect();
myRects->x = width;
myRects->y = height;
myCurrent = myRects;
} else {
myCurrent->myNext = new Rect();
myCurrent = myCurrent->myNext;
myCurrent->x = width;
myCurrent->y = height;
}
nRects++;
// fprintf(stdout,"(%i,%i) & (%i,%i) = (%i,%i)\n",
// lCurrent->x,lCurrent->y,
// rCurrent->x,rCurrent->y,
// width,height);
rCurrent = rCurrent->myNext;
}
lCurrent = lCurrent->myNext;
}
// at this point, we are done with the children's rectangle lists,
// so they should be removed
lCurrent = lRects->myNext;
while(lRects!=NULL) {
delete lRects;
lRects = lCurrent;
if(lRects!=NULL) lCurrent = lRects->myNext;
}
rCurrent = rRects->myNext;
while(rRects!=NULL) {
delete rRects;
rRects = rCurrent;
if(rRects!=NULL) rCurrent = rRects->myNext;
}
// now eliminate all inferior rectangles
myCurrent = myRects;
while(myCurrent!=NULL) {
// for each rectangle, check all other rectangles
// to see if the current rectangle is an inferior
// combination
width = myCurrent->x;
height = myCurrent->y;
lCurrent = myRects;
rCurrent = NULL; // rCurrent is rect before lCurrent
while(lCurrent!=NULL) {
if(myCurrent==lCurrent) {
rCurrent = lCurrent;
lCurrent = lCurrent->myNext;
continue; // don't compare against self
}
if(width <= lCurrent->x &&
height<= lCurrent->y) {
// this rectangle lCurrent is inferior to
// rectangle myCurrent
// fprintf(stdout,"Elminating (%i,%i) for inferiority to (%i,%i)\n",
// lCurrent->x,lCurrent->y,
// width,height);
// remove lCurrent from the list
if(lCurrent==myRects) {
myRects = myRects->myNext;
delete lCurrent;
} else if(lCurrent->myNext==NULL) {
rCurrent->myNext = NULL;
delete lCurrent;
} else {
rCurrent->myNext = lCurrent->myNext;
delete lCurrent;
}
myCurrent = myRects;
break;
}
rCurrent = lCurrent;
lCurrent = lCurrent->myNext;
}
myCurrent = myCurrent->myNext;
}
// dump rectangles
// fprintf(stdout,"After removal:\n");
// myCurrent = myRects;
// while(myCurrent!=NULL) {
// fprintf(stdout,"(%i,%i) ",myCurrent->x,myCurrent->y);
// myCurrent = myCurrent->myNext;
// }
// fprintf(stdout,"\n");
return myRects;
}/*unsigned short Operator::getHeight() { unsigned short left, right; if(myLeftChild->myType == OperatorType) { left = ((Operator *) myLeftChild)->getHeight(); } else { left = ((Module *) myLeftChild)->getHeight(); } if(myRightChild->myType == OperatorType) { right = ((Operator *) myRightChild)->getHeight(); } else { right = ((Module *) myRightChild)->getHeight(); } if(myIndex=='V') { return (left>right) ? left : right; } else { return left+right; }}unsigned short Operator::getWidth() { unsigned short left, right; if(myLeftChild->myType == OperatorType) { left = ((Operator *) myLeftChild)->getWidth(); } else { left = ((Module *) myLeftChild)->getWidth(); } if(myRightChild->myType == OperatorType) { right = ((Operator *) myRightChild)->getWidth(); } else { right = ((Module *) myRightChild)->getWidth(); } if(myIndex=='V') { return left+right; } else { return (left>right) ? left : right; }}
*/Operator * Operator::Clone() { Operator * retval; retval = new Operator(); retval->myIndex = myIndex; if(myLeftChild->myType==OperatorType) { retval->myLeftChild = ((Operator *) myLeftChild)->Clone(); } else { retval->myLeftChild = ((Module *) myLeftChild)->Clone(); } if(myRightChild->myType==OperatorType) { retval->myRightChild = ((Operator *) myRightChild)->Clone(); } else { retval->myRightChild = ((Module *) myRightChild)->Clone(); } return retval;}Module * Operator::GenerateListForward(Module * next) { myNext = next; Module * return_value; if(myLeftChild->myType==OperatorType) { if(myRightChild->myType==OperatorType) { return_value = ((Operator *) myLeftChild)->GenerateListForward( ((Operator *) myRightChild)->GenerateListForward(this)); } else { return_value = ((Operator *) myLeftChild)->GenerateListForward( ((Module *) myRightChild)->GenerateListForward(this)); } } else { if(myRightChild->myType==OperatorType) { return_value = ((Module *) myLeftChild)->GenerateListForward( ((Operator *) myRightChild)->GenerateListForward(this)); } else { return_value = ((Module *) myLeftChild)->GenerateListForward( ((Module *) myRightChild)->GenerateListForward(this)); } } return return_value;}void Operator::dumpTree() { if(myLeftChild->myType==OperatorType) { ((Operator *) myLeftChild)->dumpTree(); } else { ((Module *) myLeftChild)->dumpTree(); } if(myRightChild->myType==OperatorType) { ((Operator *) myRightChild)->dumpTree(); } else { ((Module *) myRightChild)->dumpTree(); } fprintf(stdout,"%c",myIndex);}void Operator::GenerateTree(ModuleStack * stack) { myRightChild = stack->pop(); if(myRightChild!=NULL && myRightChild->myType==OperatorType) ((Operator *) myRightChild)->GenerateTree(stack); myLeftChild = stack->pop(); if(myLeftChild!=NULL && myLeftChild->myType==OperatorType) ((Operator *) myLeftChild)->GenerateTree(stack);}void Operator::dumpList() { fprintf(stdout,"%c",myIndex); if(myNext!=NULL) { if(myNext->myType==OperatorType) { ((Operator *) myNext)->dumpList(); } else { ((Module *) myNext)->dumpList(); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -