void print_DArray_IDinfo ( DArray *array) { int i = 0; if(array->element_size > 0) { PrintVisitor* pV = print_visitor_new(); for(i = 0; i < DArray_end(array); i++) { HashmapNode* node = (HashmapNode*) DArray_get(array,i); ID_info* idi = (ID_info*)node->data; if(idi) { char* type = string_from_ID_info(idi); if(type) { switch (idi->type){ case 0: debug("Const %10s ID: %20s : Remove %d isTrigger %d isPrint %d Value %d\n\n", type, idi->id, idi->k_remove, idi->isTrigger, idi->isPrint, *(int*) idi->value); break; case 1: debug("Input %10s ID: %20s : Remove %d isTrigger %d isPrint %d\n\n", type, idi->id, idi->k_remove, idi->isTrigger, idi->isPrint); break; case 2:{ debug("Output %10s ID: %20s : Remove %d isTrigger %d isPrint %d Value:\n\n", type, idi->id, idi->k_remove, idi->isTrigger, idi->isPrint); ast* value = (ast*) idi->value; value->accept(value, pV->visitor); debug("\n"); break; } case 3:{ debug("Template %10s ID: %20s : Remove -1 isTrigger -1 isPrint -1 Value:\n", type, idi->id); debug(" Parameter: "); list_t* iter = idi->parameter; do{ PARA_info* pI = (PARA_info*) iter->data; if(pI->valuetype == 0) debug("%s: bool, ", pI->id ); else{ if(pI->valuetype == 1) debug("%s: int, ", pI->id ); else debug("%s: double, ", pI->id); } iter = iter->succ; } while (iter != idi->parameter); debug("\n"); ast* value = (ast*) idi->value; value->accept(value, pV->visitor); debug("\n\n"); break; } default: debug("error: 0-3 but was: %d\n\n", idi->type); exit(1); } } } } pV->destroy(pV); } }
void SearchVisitor::PrintResults(){ std::cout<<"Found "<< _results.size() << " results for the query "<<_query <<std::endl; PrintVisitor* pVisitor = new PrintVisitor(); for(int i=0; i<_results.size(); i++){ _results[i]->Accept(pVisitor); pVisitor->Reset(); } std::cout<<std::endl; delete pVisitor; }
void print_DArray_LinkedList( DArray *array) { int i = 0; if(array->end > 0) { debug("Bucket:\n"); PrintVisitor* pV = print_visitor_new(); for(i = 0; i < DArray_end(array); i++) { HashmapNode* node = (HashmapNode*) DArray_get(array,i); list_t* list = (list_t*)node->data; list_t* iter = list; debug("List %s:\n", node->key); do{ ID_info* idi = (ID_info*) iter->data; if(idi) { char* type = string_from_ID_info(idi); if(type) switch (idi->type){ case 0: debug(" Const %10s ID: %20s : Remove %d isTrigger %d isPrint %d Value %d\n", type, idi->id, idi->k_remove, idi->isTrigger, idi->isPrint, *(int*) idi->value); break; case 1: debug(" Input %10s ID: %20s : Remove %d isTrigger %d isPrint %d\n", type, idi->id, idi->k_remove, idi->isTrigger, idi->isPrint); break; case 2:{ debug(" Output %10s ID: %20s : Remove %d isTrigger %d isPrint %d Value:\n", type, idi->id, idi->k_remove, idi->isTrigger, idi->isPrint); ast* value = (ast*) idi->value; value->accept(value, pV->visitor); break; } case 3:{ debug(" Template %10s ID: %20s : Remove -1 isTrigger -1 isPrint -1 Value:\n", type, idi->id); ast* value = (ast*) idi->value; value->accept(value, pV->visitor); break; } default: debug(" error: 0-3 but was: %d\n", idi->type); exit(1); } } iter = iter->succ; } while(iter != list); } pV->destroy(pV); } }
int main() { Op* op3 = new Op(3); Op* op4 = new Op(4); Op* op2 = new Op(2); Add* add = new Add(op3, op4); Sqr* sqr = new Sqr(op2); Sub* sub = new Sub(add, sqr); Root* root = new Root(sub); PrintVisitor *a = new PrintVisitor(); cout << "--- PreOrder Iteration ---" << endl; PreOrderIterator* pre_itr = new PreOrderIterator(root); for(pre_itr->first(); !pre_itr->is_done(); pre_itr->next()) { pre_itr->current()->accept(a); } a->execute(); };
int main() { Op* op3 = new Op(3); Op* op4 = new Op(4); Op* op2 = new Op(2); Add* add = new Add(op3, op4); Sqr* sqr = new Sqr(op2); Sub* sub = new Sub(add, sqr); Root* root = new Root(sub); cout << "--- PreOrder Iteration ---" << endl; PrintVisitor* pVis = new PrintVisitor; PreOrderIterator* pre_itr = new PreOrderIterator(root); for(pre_itr->first(); !pre_itr->is_done(); pre_itr->next()) { pre_itr->current()->accept(pVis); } pVis->execute(); Op* op5 = new Op(5); Op* op11 = new Op(11); Add* add2 = new Add(op5, op11); Sub* sub2 = new Sub(add2, sub); Sqr* sqr2 = new Sqr(sub2); Root* root2 = new Root(sqr2); cout << "--- PreOrder Iteration 2---" << endl; PrintVisitor* pVis2 = new PrintVisitor; PreOrderIterator* pre_itr2 = new PreOrderIterator(root2); for(pre_itr2->first(); !pre_itr2->is_done(); pre_itr2->next()) { //pre_itr2->current()->print(); //cout << endl; pre_itr2->current()->accept(pVis2); } pVis2->execute(); Root* root3 = new Root(0); cout << "--- PreOrder Iteration 3---" << endl; PrintVisitor* pVis3 = new PrintVisitor; PreOrderIterator* pre_itr3 = new PreOrderIterator(root3); for(pre_itr3->first(); !pre_itr3->is_done(); pre_itr3->next()) { //pre_itr3->current()->print(); //cout << endl; pre_itr3->current()->accept(pVis3); } pVis3->execute(); Root* root4 = new Root(op4); cout << "--- PreOrder Iteration 2---" << endl; PrintVisitor* pVis4 = new PrintVisitor; PreOrderIterator* pre_itr4 = new PreOrderIterator(root4); for(pre_itr4->first(); !pre_itr4->is_done(); pre_itr4->next()) { //pre_itr4->current()->print(); //cout << endl; pre_itr4->current()->accept(pVis4); } pVis4->execute(); };