static void triangulateHull(const int nverts, const float* verts, const int nhull, const int* hull, rcIntArray& tris) { int start = 0, left = 1, right = nhull-1; // Start from an ear with shortest perimeter. // This tends to favor well formed triangles as starting point. float dmin = 0; for (int i = 0; i < nhull; i++) { int pi = prev(i, nhull); int ni = next(i, nhull); const float* pv = &verts[hull[pi]*3]; const float* cv = &verts[hull[i]*3]; const float* nv = &verts[hull[ni]*3]; const float d = vdist2(pv,cv) + vdist2(cv,nv) + vdist2(nv,pv); if (d < dmin) { start = i; left = ni; right = pi; dmin = d; } } // Add first triangle tris.push(hull[start]); tris.push(hull[left]); tris.push(hull[right]); tris.push(0); // Triangulate the polygon by moving left or right, // depending on which triangle has shorter perimeter. // This heuristic was chose emprically, since it seems // handle tesselated straight edges well. while (next(left, nhull) != right) { // Check to see if se should advance left or right. int nleft = next(left, nhull); int nright = prev(right, nhull); const float* cvleft = &verts[hull[left]*3]; const float* nvleft = &verts[hull[nleft]*3]; const float* cvright = &verts[hull[right]*3]; const float* nvright = &verts[hull[nright]*3]; const float dleft = vdist2(cvleft, nvleft) + vdist2(nvleft, cvright); const float dright = vdist2(cvright, nvright) + vdist2(cvleft, nvright); if (dleft < dright) { tris.push(hull[left]); tris.push(hull[nleft]); tris.push(hull[right]); tris.push(0); left = nleft; } else { tris.push(hull[left]); tris.push(hull[nright]); tris.push(hull[right]); tris.push(0); right = nright; } } }
/* ANT_SOURCE_PARSER::FIRST() -------------------------- */ ANT_source_parser_token *ANT_source_parser::first(void) { return next(); }
/// Get next iteration item from the event loop context StatusCode EventSelector::next(Context& refCtxt) const { return next(refCtxt, 1); }
void lemur::file::KeyfileDocListSegmentReader::pop() { _top = next(); }
void dotag() { last_tag = current; std::string name; nextword(name); int spc = next(); if (spc == '>') unget(spc); else if (!isspace(spc)) throw CoreException("Invalid character in tag name"); if (name.empty()) throw CoreException("Empty tag name"); std::vector<KeyVal>* items; std::set<std::string> seen; tag = ConfigTag::create(name, current.filename, current.line, items); while (kv(items, seen)) { // Do nothing here (silences a GCC warning). } if (name == mandatory_tag) { // Found the mandatory tag mandatory_tag.clear(); } if (name == "include") { stack.DoInclude(tag, flags); } else if (name == "files") { for(std::vector<KeyVal>::iterator i = items->begin(); i != items->end(); i++) { stack.DoReadFile(i->first, i->second, flags, false); } } else if (name == "execfiles") { for(std::vector<KeyVal>::iterator i = items->begin(); i != items->end(); i++) { stack.DoReadFile(i->first, i->second, flags, true); } } else if (name == "define") { if (flags & FLAG_USE_COMPAT) throw CoreException("<define> tags may only be used in XML-style config (add <config format=\"xml\">)"); std::string varname = tag->getString("name"); std::string value = tag->getString("value"); if (varname.empty()) throw CoreException("Variable definition must include variable name"); stack.vars[varname] = value; } else if (name == "config") { std::string format = tag->getString("format"); if (format == "xml") flags &= ~FLAG_USE_COMPAT; else if (format == "compat") flags |= FLAG_USE_COMPAT; else if (!format.empty()) throw CoreException("Unknown configuration format " + format); } else { stack.output.insert(std::make_pair(name, tag)); } // this is not a leak; reference<> takes care of the delete tag = NULL; }
////////////////////////////// // return a random int bewteen // zero and max - 1 with uniform // dist if called with same max int RandomNumberGenerator::nexti(int max) { double D = (double)max; return (int)std::floor((next() * D)); }
void fldbld(void) { register unsigned char *r, *fr; Cell **p; wchar_t wc, sep; int i, n; if (donefld) return; if (!(recloc->tval & STR)) getsval(recloc); r = recloc->sval; /* was record! */ fr = fields; i = 0; /* number of fields accumulated here */ if ((sep = **FS) != '\0' && (next(sep, *FS, n), (*FS)[n] != '\0')) { /* it's a regular expression */ i = refldbld(r, *FS); } else if (sep == ' ') { for (i = 0; ; ) { while (*r == ' ' || *r == '\t' || *r == '\n') r++; if (*r == 0) break; i++; if (i >= MAXFLD) morefields(); if (!(fldtab[i]->tval & DONTFREE)) xfree(fldtab[i]->sval); fldtab[i]->sval = fr; fldtab[i]->tval = FLD | STR | DONTFREE; next(wc, r, n); do { do *fr++ = *r++; while (--n); next(wc, r, n); } while (wc != ' ' && wc != '\t' && wc != '\n' && wc != '\0'); *fr++ = 0; } *fr = 0; } else if (*r != 0) { /* if 0, it's a null field */ for (;;) { i++; if (i >= MAXFLD) morefields(); if (!(fldtab[i]->tval & DONTFREE)) xfree(fldtab[i]->sval); fldtab[i]->sval = fr; fldtab[i]->tval = FLD | STR | DONTFREE; while (next(wc, r, n), wc != sep && wc != '\n' && wc != '\0') { /* \n always a separator */ do *fr++ = *r++; while (--n); } *fr++ = '\0'; if (wc == '\0') break; r += n; } *fr = 0; } /*if (i >= MAXFLD) error(MM_ERROR, ":13:Record `%.20s...' has too many fields", record);*/ /* clean out junk from previous record */ cleanfld(i, maxfld); maxfld = i; donefld = 1; for (p = &fldtab[1]; p <= &fldtab[0]+maxfld; p++) (void)is2number(0, *p); setfval(nfloc, (Awkfloat) maxfld); if (dbg) for (p = &fldtab[0]; p <= &fldtab[0]+maxfld; p++) pfmt(stdout, MM_INFO, ":14:field %d: |%s|\n", p-&fldtab[0], (*p)->sval); }
DirList::DirList( const char* dirname ) { dir_ = opendir( dirname ); next(); }
wild_card_match_iterator3& operator++() { next(); return *this; }
int main(int, char**) { { typedef std::set<DefaultOnly> M; typedef std::pair<M::iterator, bool> R; M m; assert(DefaultOnly::count == 0); R r = m.emplace(); assert(r.second); assert(r.first == m.begin()); assert(m.size() == 1); assert(*m.begin() == DefaultOnly()); assert(DefaultOnly::count == 1); r = m.emplace(); assert(!r.second); assert(r.first == m.begin()); assert(m.size() == 1); assert(*m.begin() == DefaultOnly()); assert(DefaultOnly::count == 1); } assert(DefaultOnly::count == 0); { typedef std::set<Emplaceable> M; typedef std::pair<M::iterator, bool> R; M m; R r = m.emplace(); assert(r.second); assert(r.first == m.begin()); assert(m.size() == 1); assert(*m.begin() == Emplaceable()); r = m.emplace(2, 3.5); assert(r.second); assert(r.first == next(m.begin())); assert(m.size() == 2); assert(*r.first == Emplaceable(2, 3.5)); r = m.emplace(2, 3.5); assert(!r.second); assert(r.first == next(m.begin())); assert(m.size() == 2); assert(*r.first == Emplaceable(2, 3.5)); } { typedef std::set<int> M; typedef std::pair<M::iterator, bool> R; M m; R r = m.emplace(M::value_type(2)); assert(r.second); assert(r.first == m.begin()); assert(m.size() == 1); assert(*r.first == 2); } { typedef std::set<int, std::less<int>, min_allocator<int>> M; typedef std::pair<M::iterator, bool> R; M m; R r = m.emplace(M::value_type(2)); assert(r.second); assert(r.first == m.begin()); assert(m.size() == 1); assert(*r.first == 2); } return 0; }
// input: - Input file (result from TMVA) // - use of TMVA plotting TStyle void mvas( TString fin = "TMVA.root", HistType htype = MVAType, Bool_t useTMVAStyle = kTRUE ) { // set style and remove existing canvas' TMVAGlob::Initialize( useTMVAStyle ); // switches const Bool_t Save_Images = kTRUE; // checks if file with name "fin" is already open, and if not opens one TFile* file = TMVAGlob::OpenFile( fin ); // define Canvas layout here! Int_t xPad = 1; // no of plots in x Int_t yPad = 1; // no of plots in y Int_t noPad = xPad * yPad ; const Int_t width = 600; // size of canvas // this defines how many canvases we need TCanvas *c = 0; // counter variables Int_t countCanvas = 0; // search for the right histograms in full list of keys TIter next(file->GetListOfKeys()); TKey *key(0); while ((key = (TKey*)next())) { if (!TString(key->GetName()).BeginsWith("Method_")) continue; if (!gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) continue; TString methodName; TMVAGlob::GetMethodName(methodName,key); TDirectory* mDir = (TDirectory*)key->ReadObj(); TIter keyIt(mDir->GetListOfKeys()); TKey *titkey; while ((titkey = (TKey*)keyIt())) { if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom("TDirectory")) continue; TDirectory *titDir = (TDirectory *)titkey->ReadObj(); TString methodTitle; TMVAGlob::GetMethodTitle(methodTitle,titDir); cout << "--- Found directory for method: " << methodName << "::" << methodTitle << flush; TString hname = "MVA_" + methodTitle; if (htype == ProbaType ) hname += "_Proba"; else if (htype == RarityType ) hname += "_Rarity"; TH1* sig = dynamic_cast<TH1*>(titDir->Get( hname + "_S" )); TH1* bgd = dynamic_cast<TH1*>(titDir->Get( hname + "_B" )); if (sig==0 || bgd==0) { if (htype == MVAType) cout << ":\t mva distribution not available (this is normal for Cut classifier)" << endl; else if(htype == ProbaType) cout << ":\t probability distribution not available" << endl; else if(htype == RarityType) cout << ":\t rarity distribution not available" << endl; else if(htype == CompareType) cout << ":\t overtraining check not available" << endl; else cout << endl; continue; } cout << " containing " << hname << "_S/_B" << endl; // chop off useless stuff sig->SetTitle( Form("Response for classifier: %s", methodTitle.Data()) ); if (htype == ProbaType) sig->SetTitle( Form("Probability for classifier: %s", methodTitle.Data()) ); else if (htype == RarityType) sig->SetTitle( Form("Rarity for classifier: %s", methodTitle.Data()) ); else if (htype == CompareType) // sig->SetTitle( Form("Overtraining check for classifier: %s", methodTitle.Data()) ); // create new canvas TString ctitle = ((htype == MVAType) ? Form("Response %s",methodTitle.Data()) : (htype == ProbaType) ? Form("Probability %s",methodTitle.Data()) : (htype == CompareType) ? Form("Comparison %s",methodTitle.Data()) : Form("Rarity %s",methodTitle.Data())); c = new TCanvas( Form("canvas%d", countCanvas+1), ctitle, countCanvas*50+200, countCanvas*20, width, (Int_t)width*0.78 ); // set the histogram style TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd ); // normalise both signal and background TMVAGlob::NormalizeHists( sig, bgd ); // frame limits (choose judicuous x range) Float_t nrms = 10; cout << "--- Mean and RMS (S): " << sig->GetMean() << ", " << sig->GetRMS() << endl; cout << "--- Mean and RMS (B): " << bgd->GetMean() << ", " << bgd->GetRMS() << endl; Float_t xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(), bgd->GetMean() - nrms*bgd->GetRMS() ), sig->GetXaxis()->GetXmin() ); Float_t xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(), bgd->GetMean() + nrms*bgd->GetRMS() ), sig->GetXaxis()->GetXmax() ); Float_t ymin = 0; Float_t maxMult = (htype == CompareType) ? 1.3 : 1.2; Float_t ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*maxMult; // build a frame Int_t nb = 500; TString hFrameName(TString("frame") + methodTitle); TObject *o = gROOT->FindObject(hFrameName); if(o) delete o; TH2F* frame = new TH2F( hFrameName, sig->GetTitle(), nb, xmin, xmax, nb, ymin, ymax ); frame->GetXaxis()->SetTitle( methodTitle + ((htype == MVAType || htype == CompareType) ? " response" : "") ); if (htype == ProbaType ) frame->GetXaxis()->SetTitle( "Signal probability" ); else if (htype == RarityType ) frame->GetXaxis()->SetTitle( "Signal rarity" ); frame->GetYaxis()->SetTitle("(1/N) dN/dx"); TMVAGlob::SetFrameStyle( frame ); // eventually: draw the frame frame->Draw(); c->GetPad(0)->SetLeftMargin( 0.105 ); frame->GetYaxis()->SetTitleOffset( 1.2 ); // Draw legend TLegend *legend= new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.12, c->GetLeftMargin() + (htype == CompareType ? 0.40 : 0.3), 1 - c->GetTopMargin() ); legend->SetFillStyle( 1 ); legend->SetFillColor( 0 ); legend->SetTextSize ( 0.04 ); legend->AddEntry(sig,TString("Signal") + ((htype == CompareType) ? " (test sample)" : ""), "F"); legend->AddEntry(bgd,TString("Background") + ((htype == CompareType) ? " (test sample)" : ""), "F"); legend->SetBorderSize(1); legend->SetMargin( (htype == CompareType ? 0.2 : 0.3) ); legend->Draw("same"); // overlay signal and background histograms sig->Draw("samehist"); bgd->Draw("samehist"); if (htype == CompareType) { // if overtraining check, load additional histograms TH1* sigOv = 0; TH1* bgdOv = 0; TString ovname = hname += "_Train"; sigOv = dynamic_cast<TH1*>(titDir->Get( ovname + "_S" )); bgdOv = dynamic_cast<TH1*>(titDir->Get( ovname + "_B" )); if (sigOv == 0 || bgdOv == 0) { cout << "+++ Problem in \"mvas.C\": overtraining check histograms do not exist" << endl; } else { cout << "--- Found comparison histograms for overtraining check" << endl; TLegend *legend2= new TLegend( 1 - c->GetRightMargin() - 0.42, 1 - c->GetTopMargin() - 0.12, 1 - c->GetRightMargin(), 1 - c->GetTopMargin() ); legend2->SetFillStyle( 1 ); legend2->SetBorderSize(1); legend2->AddEntry(sigOv,"Signal (training sample)","P"); legend2->AddEntry(bgdOv,"Background (training sample)","P"); legend2->SetMargin( 0.1 ); legend2->Draw("same"); } // normalise both signal and background TMVAGlob::NormalizeHists( sigOv, bgdOv ); Int_t col = sig->GetLineColor(); sigOv->SetMarkerColor( col ); sigOv->SetMarkerSize( 0.7 ); sigOv->SetMarkerStyle( 20 ); sigOv->SetLineWidth( 1 ); sigOv->SetLineColor( col ); sigOv->Draw("e1same"); col = bgd->GetLineColor(); bgdOv->SetMarkerColor( col ); bgdOv->SetMarkerSize( 0.7 ); bgdOv->SetMarkerStyle( 20 ); bgdOv->SetLineWidth( 1 ); bgdOv->SetLineColor( col ); bgdOv->Draw("e1same"); ymax = TMath::Max( ymax, TMath::Max( sigOv->GetMaximum(), bgdOv->GetMaximum() )*maxMult ); frame->GetYaxis()->SetLimits( 0, ymax ); // for better visibility, plot thinner lines sig->SetLineWidth( 1 ); bgd->SetLineWidth( 1 ); // perform K-S test cout << "--- Perform Kolmogorov-Smirnov tests" << endl; Double_t kolS = sig->KolmogorovTest( sigOv ); Double_t kolB = bgd->KolmogorovTest( bgdOv ); cout << "--- Goodness of signal (background) consistency: " << kolS << " (" << kolB << ")" << endl; TString probatext = Form( "Kolmogorov-Smirnov test: signal (background) probability = %5.3g (%5.3g)", kolS, kolB ); TText* tt = new TText( 0.12, 0.74, probatext ); tt->SetNDC(); tt->SetTextSize( 0.032 ); tt->AppendPad(); } // redraw axes frame->Draw("sameaxis"); // text for overflows Int_t nbin = sig->GetNbinsX(); Double_t dxu = sig->GetBinWidth(0); Double_t dxo = sig->GetBinWidth(nbin+1); TString uoflow = Form( "U/O-flow (S,B): (%.1f, %.1f)%% / (%.1f, %.1f)%%", sig->GetBinContent(0)*dxu*100, bgd->GetBinContent(0)*dxu*100, sig->GetBinContent(nbin+1)*dxo*100, bgd->GetBinContent(nbin+1)*dxo*100 ); TText* t = new TText( 0.975, 0.115, uoflow ); t->SetNDC(); t->SetTextSize( 0.030 ); t->SetTextAngle( 90 ); t->AppendPad(); // update canvas c->Update(); // save canvas to file TMVAGlob::plot_logo(1.058); if (Save_Images) { if (htype == MVAType) TMVAGlob::imgconv( c, Form("plots/mva_%s", methodTitle.Data()) ); else if (htype == ProbaType) TMVAGlob::imgconv( c, Form("plots/proba_%s", methodTitle.Data()) ); else if (htype == CompareType) TMVAGlob::imgconv( c, Form("plots/overtrain_%s", methodTitle.Data()) ); else TMVAGlob::imgconv( c, Form("plots/rarity_%s", methodTitle.Data()) ); } countCanvas++; } cout << ""; } }
int main(int argc, char **argv) { int sts; int c; int help = 0; int oneline = 0; char *pmnsfile = PM_NS_DEFAULT; int errflag = 0; int aflag = 0; int eflag = 0; int allpmid = 0; int allindom = 0; char *filename; char *tp; char *name; int id; int next_type; char *endnum; __pmSetProgname(argv[0]); while ((c = getopt(argc, argv, "D:eHin:Opv:?")) != EOF) { switch (c) { case 'D': /* debug flag */ sts = __pmParseDebug(optarg); if (sts < 0) { fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n", pmProgname, optarg); errflag++; } else pmDebug |= sts; break; case 'e': /* help text exists? */ eflag = 1; break; case 'H': /* help text */ help = 1; break; case 'i': aflag++; allindom = 1; break; case 'n': /* alternative namespace file */ pmnsfile = optarg; break; case 'O': /* oneline text */ oneline = 1; break; case 'p': aflag++; allpmid = 1; break; case 'v': /* version 2 only these days */ version = (int)strtol(optarg, &endnum, 10); if (*endnum != '\0') { fprintf(stderr, "%s: -v requires numeric argument\n", pmProgname); errflag++; } if (version != 2) { fprintf(stderr ,"%s: deprecated option - only version 2 is supported\n" , pmProgname); errflag++; } break; case '?': default: errflag++; break; } } if (optind == argc) { fprintf(stderr, "%s: missing helpfile argument\n\n", pmProgname); errflag = 1; } if (aflag && optind < argc-1) { fprintf(stderr, "%s: metricname arguments cannot be used with -i or -p\n\n", pmProgname); errflag = 1; } if (aflag == 0 && optind == argc-1 && oneline+help != 0) { fprintf(stderr, "%s: -O or -H require metricname arguments or -i or -p\n\n", pmProgname); errflag = 1; } if (eflag && (allpmid || allindom)) { fprintf(stderr, "%s: -e cannot be used with -i or -p\n\n", pmProgname); errflag = 1; } if (errflag || optind >= argc) { fprintf(stderr, "Usage: %s helpfile\n" " %s [options] helpfile [metricname ...]\n" "\n" "Options:\n" " -e exists check, only report metrics with no help text\n" " -H display verbose help text\n" " -i process all the instance domains\n" " -n pmnsfile use an alternative PMNS\n" " -O display the one line help summary\n" " -p process all the metrics (PMIDs)\n" " -v version deprecated (only version 2 format supported)\n" "\n" "No options implies silently check internal integrity of the helpfile.\n", pmProgname, pmProgname); exit(1); } filename = argv[optind++]; if ((handle = pmdaOpenHelp(filename)) < 0) { fprintf(stderr, "pmdaOpenHelp: failed to open \"%s\": ", filename); if (handle == -EINVAL) fprintf(stderr, "Bad format, not version %d PCP help text\n", version); else fprintf(stderr, "%s\n", pmErrStr(handle)); exit(1); } if ((sts = pmLoadASCIINameSpace(pmnsfile, 1)) < 0) { fprintf(stderr, "pmLoadASCIINameSpace(%s, 1): %s\n", pmnsfile, pmErrStr(sts)); exit(1); } if (help + oneline == 0 && (optind < argc || aflag)) /* if metric names, -p or -i => -O is default */ oneline = 1; if (optind == argc && aflag == 0) /* no metric names, process all entries */ aflag = 1; if (eflag) { if (optind == argc) { sts = pmTraversePMNS("", dometric); if (sts < 0) { fprintf(stderr, "Error: pmTraversePMNS(\"\", ...): %s\n", pmErrStr(sts)); } } else { for ( ; optind < argc; optind++) { sts = pmTraversePMNS(argv[optind], dometric); if (sts < 0) fprintf(stderr, "Error: pmTraversePMNS(\"%s\", ...): %s\n", argv[optind], pmErrStr(sts)); } } exit(0); } while (optind < argc || aflag) { if (aflag) { if (next(&id, &next_type) == 0) break; #ifdef PCP_DEBUG if ((pmDebug & DBG_TRACE_APPL0) && allindom+allpmid == 0) fprintf(stderr, "next_type=%d id=0x%x\n", next_type, id); #endif if (next_type == 2) { if (!allindom) continue; printf("\nInDom %s:", pmInDomStr((pmInDom)id)); } else { char **names; if (!allpmid) continue; printf("\nPMID %s", pmIDStr((pmID)id)); sts = pmNameAll(id, &names); if (sts > 0) { printf(" "); __pmPrintMetricNames(stdout, sts, names, " or "); free(names); } putchar(':'); } } else { next_type = 1; name = argv[optind++]; if ((sts = pmLookupName(1, &name, (pmID *)&id)) < 0) { printf("\n%s: %s\n", name, pmErrStr(sts)); continue; } if (id == PM_ID_NULL) { printf("\n%s: unknown metric\n", name); continue; } printf("\nPMID %s %s:", pmIDStr((pmID)id), name); } if (oneline) { if (next_type == 1) tp = pmdaGetHelp(handle, (pmID)id, PM_TEXT_ONELINE); else tp = pmdaGetInDomHelp(handle, (pmInDom)id, PM_TEXT_ONELINE); if (tp != NULL) printf(" %s", tp); putchar('\n'); } if (help) { if (next_type == 1) tp = pmdaGetHelp(handle, (pmID)id, PM_TEXT_HELP); else tp = pmdaGetInDomHelp(handle, (pmInDom)id, PM_TEXT_HELP); if (tp != NULL && *tp) printf("%s\n", tp); } } return 0; }
int main() { { typedef std::pair<const int, double> V; typedef std::map<int, double> M; { typedef M::iterator R; V ar[] = { V(5, 5), V(7, 6), V(9, 7), V(11, 8), V(13, 9), V(15, 10), V(17, 11), V(19, 12) }; M m(ar, ar+sizeof(ar)/sizeof(ar[0])); R r = m.upper_bound(5); assert(r == next(m.begin(), 1)); r = m.upper_bound(7); assert(r == next(m.begin(), 2)); r = m.upper_bound(9); assert(r == next(m.begin(), 3)); r = m.upper_bound(11); assert(r == next(m.begin(), 4)); r = m.upper_bound(13); assert(r == next(m.begin(), 5)); r = m.upper_bound(15); assert(r == next(m.begin(), 6)); r = m.upper_bound(17); assert(r == next(m.begin(), 7)); r = m.upper_bound(19); assert(r == next(m.begin(), 8)); r = m.upper_bound(4); assert(r == next(m.begin(), 0)); r = m.upper_bound(6); assert(r == next(m.begin(), 1)); r = m.upper_bound(8); assert(r == next(m.begin(), 2)); r = m.upper_bound(10); assert(r == next(m.begin(), 3)); r = m.upper_bound(12); assert(r == next(m.begin(), 4)); r = m.upper_bound(14); assert(r == next(m.begin(), 5)); r = m.upper_bound(16); assert(r == next(m.begin(), 6)); r = m.upper_bound(18); assert(r == next(m.begin(), 7)); r = m.upper_bound(20); assert(r == next(m.begin(), 8)); } { typedef M::const_iterator R; V ar[] = { V(5, 5), V(7, 6), V(9, 7), V(11, 8), V(13, 9), V(15, 10), V(17, 11), V(19, 12) }; const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); R r = m.upper_bound(5); assert(r == next(m.begin(), 1)); r = m.upper_bound(7); assert(r == next(m.begin(), 2)); r = m.upper_bound(9); assert(r == next(m.begin(), 3)); r = m.upper_bound(11); assert(r == next(m.begin(), 4)); r = m.upper_bound(13); assert(r == next(m.begin(), 5)); r = m.upper_bound(15); assert(r == next(m.begin(), 6)); r = m.upper_bound(17); assert(r == next(m.begin(), 7)); r = m.upper_bound(19); assert(r == next(m.begin(), 8)); r = m.upper_bound(4); assert(r == next(m.begin(), 0)); r = m.upper_bound(6); assert(r == next(m.begin(), 1)); r = m.upper_bound(8); assert(r == next(m.begin(), 2)); r = m.upper_bound(10); assert(r == next(m.begin(), 3)); r = m.upper_bound(12); assert(r == next(m.begin(), 4)); r = m.upper_bound(14); assert(r == next(m.begin(), 5)); r = m.upper_bound(16); assert(r == next(m.begin(), 6)); r = m.upper_bound(18); assert(r == next(m.begin(), 7)); r = m.upper_bound(20); assert(r == next(m.begin(), 8)); } } #if TEST_STD_VER >= 11 { typedef std::pair<const int, double> V; typedef std::map<int, double, std::less<int>, min_allocator<V>> M; { typedef M::iterator R; V ar[] = { V(5, 5), V(7, 6), V(9, 7), V(11, 8), V(13, 9), V(15, 10), V(17, 11), V(19, 12) }; M m(ar, ar+sizeof(ar)/sizeof(ar[0])); R r = m.upper_bound(5); assert(r == next(m.begin(), 1)); r = m.upper_bound(7); assert(r == next(m.begin(), 2)); r = m.upper_bound(9); assert(r == next(m.begin(), 3)); r = m.upper_bound(11); assert(r == next(m.begin(), 4)); r = m.upper_bound(13); assert(r == next(m.begin(), 5)); r = m.upper_bound(15); assert(r == next(m.begin(), 6)); r = m.upper_bound(17); assert(r == next(m.begin(), 7)); r = m.upper_bound(19); assert(r == next(m.begin(), 8)); r = m.upper_bound(4); assert(r == next(m.begin(), 0)); r = m.upper_bound(6); assert(r == next(m.begin(), 1)); r = m.upper_bound(8); assert(r == next(m.begin(), 2)); r = m.upper_bound(10); assert(r == next(m.begin(), 3)); r = m.upper_bound(12); assert(r == next(m.begin(), 4)); r = m.upper_bound(14); assert(r == next(m.begin(), 5)); r = m.upper_bound(16); assert(r == next(m.begin(), 6)); r = m.upper_bound(18); assert(r == next(m.begin(), 7)); r = m.upper_bound(20); assert(r == next(m.begin(), 8)); } { typedef M::const_iterator R; V ar[] = { V(5, 5), V(7, 6), V(9, 7), V(11, 8), V(13, 9), V(15, 10), V(17, 11), V(19, 12) }; const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); R r = m.upper_bound(5); assert(r == next(m.begin(), 1)); r = m.upper_bound(7); assert(r == next(m.begin(), 2)); r = m.upper_bound(9); assert(r == next(m.begin(), 3)); r = m.upper_bound(11); assert(r == next(m.begin(), 4)); r = m.upper_bound(13); assert(r == next(m.begin(), 5)); r = m.upper_bound(15); assert(r == next(m.begin(), 6)); r = m.upper_bound(17); assert(r == next(m.begin(), 7)); r = m.upper_bound(19); assert(r == next(m.begin(), 8)); r = m.upper_bound(4); assert(r == next(m.begin(), 0)); r = m.upper_bound(6); assert(r == next(m.begin(), 1)); r = m.upper_bound(8); assert(r == next(m.begin(), 2)); r = m.upper_bound(10); assert(r == next(m.begin(), 3)); r = m.upper_bound(12); assert(r == next(m.begin(), 4)); r = m.upper_bound(14); assert(r == next(m.begin(), 5)); r = m.upper_bound(16); assert(r == next(m.begin(), 6)); r = m.upper_bound(18); assert(r == next(m.begin(), 7)); r = m.upper_bound(20); assert(r == next(m.begin(), 8)); } } #endif #if _LIBCPP_STD_VER > 11 { typedef std::pair<const int, double> V; typedef std::map<int, double, std::less<>> M; typedef M::iterator R; V ar[] = { V(5, 5), V(7, 6), V(9, 7), V(11, 8), V(13, 9), V(15, 10), V(17, 11), V(19, 12) }; M m(ar, ar+sizeof(ar)/sizeof(ar[0])); R r = m.upper_bound(5); assert(r == next(m.begin(), 1)); r = m.upper_bound(7); assert(r == next(m.begin(), 2)); r = m.upper_bound(9); assert(r == next(m.begin(), 3)); r = m.upper_bound(11); assert(r == next(m.begin(), 4)); r = m.upper_bound(13); assert(r == next(m.begin(), 5)); r = m.upper_bound(15); assert(r == next(m.begin(), 6)); r = m.upper_bound(17); assert(r == next(m.begin(), 7)); r = m.upper_bound(19); assert(r == next(m.begin(), 8)); r = m.upper_bound(4); assert(r == next(m.begin(), 0)); r = m.upper_bound(6); assert(r == next(m.begin(), 1)); r = m.upper_bound(8); assert(r == next(m.begin(), 2)); r = m.upper_bound(10); assert(r == next(m.begin(), 3)); r = m.upper_bound(12); assert(r == next(m.begin(), 4)); r = m.upper_bound(14); assert(r == next(m.begin(), 5)); r = m.upper_bound(16); assert(r == next(m.begin(), 6)); r = m.upper_bound(18); assert(r == next(m.begin(), 7)); r = m.upper_bound(20); assert(r == next(m.begin(), 8)); } { typedef PrivateConstructor PC; typedef std::map<PC, double, std::less<>> M; typedef M::iterator R; M m; m [ PC::make(5) ] = 5; m [ PC::make(7) ] = 6; m [ PC::make(9) ] = 7; m [ PC::make(11) ] = 8; m [ PC::make(13) ] = 9; m [ PC::make(15) ] = 10; m [ PC::make(17) ] = 11; m [ PC::make(19) ] = 12; R r = m.upper_bound(5); assert(r == next(m.begin(), 1)); r = m.upper_bound(7); assert(r == next(m.begin(), 2)); r = m.upper_bound(9); assert(r == next(m.begin(), 3)); r = m.upper_bound(11); assert(r == next(m.begin(), 4)); r = m.upper_bound(13); assert(r == next(m.begin(), 5)); r = m.upper_bound(15); assert(r == next(m.begin(), 6)); r = m.upper_bound(17); assert(r == next(m.begin(), 7)); r = m.upper_bound(19); assert(r == next(m.begin(), 8)); r = m.upper_bound(4); assert(r == next(m.begin(), 0)); r = m.upper_bound(6); assert(r == next(m.begin(), 1)); r = m.upper_bound(8); assert(r == next(m.begin(), 2)); r = m.upper_bound(10); assert(r == next(m.begin(), 3)); r = m.upper_bound(12); assert(r == next(m.begin(), 4)); r = m.upper_bound(14); assert(r == next(m.begin(), 5)); r = m.upper_bound(16); assert(r == next(m.begin(), 6)); r = m.upper_bound(18); assert(r == next(m.begin(), 7)); r = m.upper_bound(20); assert(r == next(m.begin(), 8)); } #endif }
size_t skip_past(CHAR_T ch) { skip_to(ch); next(); return _pos; }
static void *Sort(void *list, LessFn less, GetNextElementFn next, PutNextElementFn putnext, void *ctx) { void *p, *q, *e, *tail; int insize, nmerges, psize, qsize, i; if (list == NULL) { return NULL; } insize = 1; while (true) { p = list; list = NULL; tail = NULL; nmerges = 0; /* count number of merges we do in this pass */ while (p) { nmerges++; /* there exists a merge to be done */ /* step `insize' places along from p */ q = p; psize = 0; for (i = 0; i < insize; i++) { psize++; q = next(q); if (!q) { break; } } /* if q hasn't fallen off end, we have two lists to merge */ qsize = insize; /* now we have two lists; merge them */ while ((psize > 0) || ((qsize > 0) && q)) { /* decide whether next element of merge comes from p or q */ if (psize == 0) { /* p is empty; e must come from q. */ e = q; q = next(q); qsize--; } else if ((qsize == 0) || (!q)) { /* q is empty; e must come from p. */ e = p; p = next(p); psize--; } else if (less(p, q, ctx)) { /* First element of p is lower (or same); * e must come from p. */ e = p; p = next(p); psize--; } else { /* First element of q is lower; e must come from q. */ e = q; q = next(q); qsize--; } /* add the next element to the merged list */ if (tail) { putnext(tail, e); } else { list = e; } tail = e; } /* now p has stepped `insize' places along, and q has too */ p = q; } putnext(tail, NULL); /* If we have done only one merge, we're finished. */ if (nmerges <= 1) /* allow for nmerges==0, the empty list case */ { return list; } /* Otherwise repeat, merging lists twice the size */ insize *= 2; } }
bool Intersect(const Terrain &t, const WFMath::Point<3> &sPt, const WFMath::Vector<3>& dir, WFMath::Point<3> &intersection, WFMath::Vector<3> &normal, float &par) { //FIXME early reject using segment max //FIXME handle height point getting in a more optimal way //FIXME early reject for vertical ray // check if startpoint is below ground if (HOT(t, sPt) < 0.0) return true; float paraX=0.0, paraY=0.0; //used to store the parametric gap between grid crossings float pX, pY; //the accumulators for the parametrics as we traverse the ray float h1,h2,h3,h4,height; WFMath::Point<3> last(sPt), next(sPt); WFMath::Vector<3> nDir(dir); nDir.normalize(); float dirLen = dir.mag(); //work out where the ray first crosses an X grid line if (dir[0] != 0.0f) { paraX = 1.0f/dir[0]; float crossX = (dir[0] > 0.0f) ? gridceil(last[0]) : gridfloor(last[0]); pX = (crossX - last[0]) * paraX; pX = std::min(pX, 1.0f); } else { //parallel: never crosses pX = 1.0f; } //work out where the ray first crosses a Y grid line if (dir[1] != 0.0f) { paraY = 1.0f/dir[1]; float crossY = (dir[1] > 0.0f) ? gridceil(last[1]) : gridfloor(last[1]); pY = (crossY - sPt[1]) * paraY; pY = std::min(pY, 1.0f); } else { //parallel: never crosses pY = 1.0f; } //ensure we traverse the ray forwards paraX = std::abs(paraX); paraY = std::abs(paraY); bool endpoint = false; //check each candidate tile for an intersection while (1) { last = next; if (pX < pY) { // cross x grid line first next = sPt + (pX * dir); pX += paraX; // set x accumulator to current p } else { //cross y grid line first next = sPt + (pY * dir); if (pX == pY) { pX += paraX; //unusual case where ray crosses corner } pY += paraY; // set y accumulator to current p } //FIXME these gets could be optimized a bit float x= (dir[0] > 0) ? floor(last[0]) : floor(next[0]); float y= (dir[1] > 0) ? floor(last[1]) : floor(next[1]); h1 = t.get(x, y); h2 = t.get(x, y+1); h3 = t.get(x+1, y+1); h4 = t.get(x+1, y); height = std::max( std::max(h1, h2), std::max(h3, h4)); if ( (last[2] < height) || (next[2] < height) ) { // possible intersect with this tile if (cellIntersect(h1, h2, h3, h4, x, y, nDir, dirLen, sPt, intersection, normal, par)) { return true; } } if ((pX >= 1.0f) && (pY >= 1.0f)) { if (endpoint) { break; } else endpoint = true; } } return false; }
void makePlots_Combinations(short makePlots=0) { TString dirPlots("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/"); TFile fIn ("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU140_sf1_nz4_pt3_5oo6_14k.root"); TString sLogic ("5oo6"); TString pName("Neutrino_PU140_sf1_nz4_pt3_5oo6_14k"); TString pTitle(" PU140 SF=1 Nz=4 Pt>3 GeV/c"); TFile fIn2("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU140_sf1_nz4_pt3_6oo6_14k.root"); TString sLogic2("6oo6"); //TString pName("Neutrino_PU140_sf1_nz4_pt3_6oo6_14k"); TString pTitle(" PU140 SF=1 Nz=4 Pt>3 GeV/c"); TFile fInOR("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU140_sf1_nz4_pt3_5oo6_14k_OverlapRemoved.root"); // TFile fIn("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU200_sf1_nz4_pt3_5oo6_4k.root"); TString sLogic("5oo6"); TString pName("Neutrino_PU200_sf1_nz4_pt3_5oo6_4k"); TString pTitle(" PU200 SF=1 Nz=4 Pt>3 GeV/c"); // TFile fInOR("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU200_sf1_nz4_pt3_5oo6_4k_OverlapRemoved.root"); // TFile fIn("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU250_sf1_nz4_pt3_5oo6_4k.root"); TString sLogic("5oo6"); TString pName("Neutrino_PU250_sf1_nz4_pt3_5oo6_4k"); TString pTitle(" PU250 SF=1 Nz=4 Pt>3 GeV/c"); // TFile fInOR("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU250_sf1_nz4_pt3_5oo6_4k_OverlapRemoved.root"); TH1* h1stubsInLayer [6][2]; TH1* h1stubsInLayerOR[6][2]; TH1* h1RoadPerEvent [2]; TH1* h1RoadPerEventOR[2]; TH1* h1CombPerRoad [2]; TH1* h1CombPerRoadOR [2]; TH1* h1CombPerEvent [2]; TH1* h1CombPerEventOR[2]; TH1* h1RoadPerEvent6oo6 [2]; TH1* h1CombPerRoad6oo6 [2]; TH1* h1CombPerEvent6oo6 [2]; TString sClean[2] = {TString(""), TString("_Cleaned")}; for (unsigned short iLay=0; iLay<6; ++iLay) { TList* tl = fIn.GetListOfKeys(); TIter next(tl); TObject *obj; char cc[20]; sprintf(cc,"_%d",iLay); TString hString("h1stubsInLayer__"+sLogic+TString(cc)); while ((obj=next())) { TString hName(obj->GetName()); if (hName==hString) { for (unsigned short iClean = 0; iClean < 2; ++iClean) { char cc2[100]; h1stubsInLayer [iLay][iClean] = (TH1*) fIn .Get(hName+sClean[iClean]); sprintf(cc2,"L%d - ",iLay+5); h1stubsInLayer [iLay][iClean]->SetTitle(TString(cc2)+sLogic+pTitle); h1stubsInLayerOR[iLay][iClean] = (TH1*) fInOR.Get(hName+sClean[iClean]); if (h1stubsInLayer [iLay][iClean]==0) { std::cout << "ERROR. " << hName+sClean[iClean] << " not loaded." << std::endl; return; } if (h1stubsInLayerOR[iLay][iClean]==0) { std::cout << "ERROR. " << hName+sClean[iClean] << " overlap removed not loaded." << std::endl; return; } } } } // std::cout << h1stubsInLayer [iLay][0] << "\t" << h1stubsInLayer [iLay][1] << "\t" << h1stubsInLayerOR[iLay][0] << "\t" << h1stubsInLayerOR[iLay][1] << std::endl; } for (unsigned short iClean = 0; iClean < 2; ++iClean) { TString hString("h1RoadPerEvent_"+sLogic); h1RoadPerEvent [iClean] = (TH1*) fIn .Get(hString+sClean[iClean]); h1RoadPerEventOR[iClean] = (TH1*) fInOR.Get(hString+sClean[iClean]); hString=TString("h1CombPerRoad_")+sLogic; h1CombPerRoad [iClean] = (TH1*) fIn .Get(hString+sClean[iClean]); h1CombPerRoadOR [iClean] = (TH1*) fInOR.Get(hString+sClean[iClean]); hString=TString("h1CombPerEvent_")+sLogic; h1CombPerEvent [iClean] = (TH1*) fIn .Get(hString+sClean[iClean]); h1CombPerEventOR [iClean] = (TH1*) fInOR.Get(hString+sClean[iClean]); hString=TString("h1RoadPerEvent_"+sLogic2); h1RoadPerEvent6oo6 [iClean] = (TH1*) fIn2 .Get(hString+sClean[iClean]); hString=TString("h1CombPerRoad_")+sLogic2; h1CombPerRoad6oo6 [iClean] = (TH1*) fIn2 .Get(hString+sClean[iClean]); hString=TString("h1CombPerEvent_")+sLogic2; h1CombPerEvent6oo6 [iClean] = (TH1*) fIn2 .Get(hString+sClean[iClean]); } TString cName("cStubsPerLayer_"+sLogic+pName); TString cTitle("StubsPerLayer "+sLogic+pTitle); TCanvas* cStubsPerLayer = new TCanvas(cName,cTitle,0,0,1400,900); cStubsPerLayer->Divide(3,2); for (unsigned short iLay=0; iLay<6; ++iLay) { char cc3[100]; cStubsPerLayer->cd(iLay+1); gPad->SetLogy(); h1stubsInLayer [iLay][0]->DrawCopy(); TLegend* tl = new TLegend(0.3,0.75,0.9,0.9); sprintf(cc3,"Mean # stubs: %3.2lf",h1stubsInLayer [iLay][0]->GetMean()); TLegendEntry* tle = tl->AddEntry(h1stubsInLayer [iLay][0],cc3,"l"); tle->SetLineColor(h1stubsInLayer [iLay][0]->GetLineColor()); tle->SetLineWidth(h1stubsInLayer [iLay][0]->GetLineWidth()); tl->Draw("L"); } if (makePlots) { cStubsPerLayer->SaveAs(dirPlots+cName+"__.pdf"); cStubsPerLayer->SaveAs(dirPlots+cName+"__.png"); } for (unsigned short iLay=0; iLay<6; ++iLay) { char cc3[100]; cStubsPerLayer->cd(iLay+1); gPad->SetLogy(); h1stubsInLayerOR[iLay][0]->SetLineColor(2); h1stubsInLayerOR[iLay][0]->DrawCopy("same"); TLegend* tl = new TLegend(0.25,0.75,0.9,0.9); sprintf(cc3,"Mean # stubs: %3.2lf",h1stubsInLayer [iLay][0]->GetMean()); TLegendEntry* tle = tl->AddEntry(h1stubsInLayer [iLay][0],cc3,"l"); tle->SetLineColor(h1stubsInLayer [iLay][0]->GetLineColor()); tle->SetLineWidth(h1stubsInLayer [iLay][0]->GetLineWidth()); sprintf(cc3,"Mean # stubs Overlap Removed: %3.2lf",h1stubsInLayerOR[iLay][0]->GetMean()); tle = tl->AddEntry(h1stubsInLayerOR[iLay][0],cc3,"l"); tle->SetLineColor(h1stubsInLayerOR[iLay][0]->GetLineColor()); tle->SetLineWidth(h1stubsInLayerOR[iLay][0]->GetLineWidth()); tl->Draw("L"); } if (makePlots) { cStubsPerLayer->SaveAs(dirPlots+cName+"_OR_.pdf"); cStubsPerLayer->SaveAs(dirPlots+cName+"_OR_.png"); } cName=TString("cStubsPerLayerDsClean_")+sLogic+pName; cTitle=TString("StubsPerLayer Ds clean ")+sLogic+pTitle; TCanvas* cStubsPerLayerDsClean = new TCanvas(cName,cTitle,0,0,1400,900); cStubsPerLayerDsClean->Divide(3,2); for (unsigned short iLay=0; iLay<6; ++iLay) { char cc3[100]; cStubsPerLayerDsClean->cd(iLay+1); gPad->SetLogy(); h1stubsInLayer [iLay][0]->DrawCopy(); h1stubsInLayer [iLay][1]->SetLineColor(8); h1stubsInLayer [iLay][1]->DrawCopy("same"); TLegend* tl = new TLegend(0.25,0.75,0.9,0.9); sprintf(cc3,"Mean # stubs: %3.2lf",h1stubsInLayer [iLay][0]->GetMean()); TLegendEntry* tle = tl->AddEntry(h1stubsInLayer [iLay][0],cc3,"l"); tle->SetLineColor(h1stubsInLayer [iLay][0]->GetLineColor()); tle->SetLineWidth(h1stubsInLayer [iLay][0]->GetLineWidth()); sprintf(cc3,"Mean # stubs #Deltas clean: %3.2lf",h1stubsInLayer [iLay][1]->GetMean()); tle = tl->AddEntry(h1stubsInLayer [iLay][1],cc3,"l"); tle->SetLineColor(h1stubsInLayer [iLay][1]->GetLineColor()); tle->SetLineWidth(h1stubsInLayer [iLay][1]->GetLineWidth()); tl->Draw("L"); } if (makePlots) { cStubsPerLayerDsClean->SaveAs(dirPlots+cName+"__.pdf"); cStubsPerLayerDsClean->SaveAs(dirPlots+cName+"__.png"); } cName=TString("cStubsPerLayerDsCleanOR_")+sLogic+pName; cTitle=TString("StubsPerLayer #Deltas clean Overlap Removed ")+sLogic+pTitle; TCanvas* cStubsPerLayerDsCleanOR = new TCanvas(cName,cTitle,0,0,1400,900); cStubsPerLayerDsCleanOR->Divide(3,2); for (unsigned short iLay=0; iLay<6; ++iLay) { char cc3[100]; cStubsPerLayerDsCleanOR->cd(iLay+1); gPad->SetLogy(); h1stubsInLayer [iLay][0]->DrawCopy(); h1stubsInLayerOR[iLay][0]->SetLineColor(2); h1stubsInLayerOR[iLay][0]->DrawCopy("same"); h1stubsInLayerOR[iLay][1]->SetLineColor(6); h1stubsInLayerOR[iLay][1]->DrawCopy("same"); TLegend* tl = new TLegend(0.25,0.70,0.9,0.9); sprintf(cc3,"Mean # stubs: %3.2lf",h1stubsInLayer [iLay][0]->GetMean()); TLegendEntry* tle = tl->AddEntry(h1stubsInLayer [iLay][0],cc3,"l"); tle->SetLineColor(h1stubsInLayer [iLay][0]->GetLineColor()); tle->SetLineWidth(h1stubsInLayer [iLay][0]->GetLineWidth()); sprintf(cc3,"Mean # stubs Ov. Rem.: %3.2lf",h1stubsInLayerOR[iLay][0]->GetMean()); tle = tl->AddEntry(h1stubsInLayerOR[iLay][0],cc3,"l"); tle->SetLineColor (h1stubsInLayerOR[iLay][0]->GetLineColor()); tle->SetLineWidth (h1stubsInLayerOR[iLay][0]->GetLineWidth()); sprintf(cc3,"Mean # stubs Ds clean Ov. Rem.: %3.2lf",h1stubsInLayerOR[iLay][1]->GetMean()); tle = tl->AddEntry(h1stubsInLayerOR[iLay][1],cc3,"l"); tle->SetLineColor (h1stubsInLayerOR[iLay][1]->GetLineColor()); tle->SetLineWidth (h1stubsInLayerOR[iLay][1]->GetLineWidth()); tl->Draw("L"); } if (makePlots) { cStubsPerLayerDsCleanOR->SaveAs(dirPlots+cName+"__.pdf"); cStubsPerLayerDsCleanOR->SaveAs(dirPlots+cName+"__.png"); } const short nQuant = 4; double percentiles [nQuant] = {0.90, 0.95, 0.99, 0.999}; double xpercentiles[6][nQuant]; cName=TString("cRoadPerEvent_")+sLogic+pName; cTitle=TString("Roads per Tower "+sLogic+pTitle); TCanvas* cRoadPerEvent = new TCanvas(cName,cTitle,0,0,1400,900); cRoadPerEvent->SetLogy(); h1RoadPerEvent [0]->SetTitle(cTitle); h1RoadPerEvent [0]->DrawCopy(); // h1RoadPerEvent6oo6[0]->SetLineColor(14); // h1RoadPerEvent6oo6[0]->DrawCopy("same"); char cc3[100]; h1RoadPerEvent [0]->GetQuantiles(nQuant,xpercentiles[0],percentiles); sprintf(cc3," #mu=%3.1lf, #Lambda_{%3.1lf}=%3.1lf",h1RoadPerEvent [0]->GetMean(),percentiles[3]*100,xpercentiles[0][3]); TLegend* tl = new TLegend(0.25,0.84,0.9,0.9); TLegendEntry* tle = tl->AddEntry(h1RoadPerEvent [0],cc3,"l"); tle->SetLineColor(h1RoadPerEvent [0]->GetLineColor()); tle->SetLineWidth(h1RoadPerEvent [0]->GetLineWidth()); // h1RoadPerEvent6oo6[0]->GetQuantiles(nQuant,xpercentiles[0],percentiles); // sprintf(cc3,"# roads/tower-6/6. #mu=%3.1lf, #Lambda_{%3.1lf}=%3.1lf",h1RoadPerEvent6oo6[0]->GetMean(),percentiles[3]*100,xpercentiles[0][3]); // tle = tl->AddEntry(h1RoadPerEvent6oo6[0],cc3,"l"); // tle->SetLineColor(h1RoadPerEvent6oo6[0]->GetLineColor()); // tle->SetLineWidth(h1RoadPerEvent6oo6[0]->GetLineWidth()); tl->Draw("L"); if (makePlots) { cRoadPerEvent->SaveAs(dirPlots+cName+"__.pdf"); cRoadPerEvent->SaveAs(dirPlots+cName+"__.png"); } cName=TString("cRoadPerEvent_OR_")+sLogic+pName; cTitle=TString("Roads per Tower "+sLogic+pTitle); TCanvas* cRoadPerEventOR = new TCanvas(cName,cTitle,0,0,1400,900); cRoadPerEventOR->SetLogy(); h1RoadPerEvent [0]->SetTitle(cTitle); h1RoadPerEvent [0]->DrawCopy(); h1RoadPerEvent [0]->GetQuantiles(nQuant,xpercentiles[0],percentiles); sprintf(cc3," #mu=%3.1lf, #Lambda_{%3.1lf}=%3.1lf",h1RoadPerEvent [0]->GetMean(),percentiles[3]*100,xpercentiles[0][3]); tl = new TLegend(0.25,0.8,0.9,0.9); tle = tl->AddEntry(h1RoadPerEvent [0],cc3,"l"); tle->SetLineColor(h1RoadPerEvent [0]->GetLineColor()); tle->SetLineWidth(h1RoadPerEvent [0]->GetLineWidth()); h1RoadPerEventOR[0]->SetLineColor(2); h1RoadPerEventOR[0]->DrawCopy("same"); h1RoadPerEventOR[0]->GetQuantiles(nQuant,xpercentiles[0],percentiles); sprintf(cc3,"Ov. Masked #mu=%3.1lf, #Lambda_{%3.1lf}=%3.1lf",h1RoadPerEventOR[0]->GetMean(),percentiles[3]*100,xpercentiles[0][3]); tle = tl->AddEntry(h1RoadPerEventOR[0],cc3,"l"); tle->SetLineColor(h1RoadPerEventOR[0]->GetLineColor()); tle->SetLineWidth(h1RoadPerEventOR[0]->GetLineWidth()); tl->Draw("L"); if (makePlots) { cRoadPerEventOR->SaveAs(dirPlots+cName+"__.pdf"); cRoadPerEventOR->SaveAs(dirPlots+cName+"__.png"); } cName=TString("cCombPerRoad_")+sLogic+pName; cTitle=TString("Combinations per Road "+sLogic+pTitle); TCanvas* cCombPerRoad = new TCanvas(cName,cTitle,0,0,1400,900); cCombPerRoad->SetLogy(); h1CombPerRoad [0]->SetTitle(cTitle); h1CombPerRoad [0]->DrawCopy(); h1CombPerRoad [0]->GetQuantiles(nQuant,xpercentiles[0],percentiles); sprintf(cc3,"# combinations/road. #mu=%3.1lf, #Lambda_{%3.1lf}=%3.1lf",h1CombPerRoad [0]->GetMean(),percentiles[3]*100,xpercentiles[0][3]); tl = new TLegend(0.25,0.75,0.9,0.9); tle = tl->AddEntry(h1CombPerRoad [0],cc3,"l"); tle->SetLineColor (h1CombPerRoad [0]->GetLineColor()); tle->SetLineWidth (h1CombPerRoad [0]->GetLineWidth()); tl->Draw("L"); if (makePlots) { cCombPerRoad->SaveAs(dirPlots+cName+"__.pdf"); cCombPerRoad->SaveAs(dirPlots+cName+"__.png"); } cName=TString("cCombPerRoad_OR_")+sLogic+pName; h1CombPerRoadOR[0]->SetLineColor(2); h1CombPerRoadOR[0]->DrawCopy("same"); h1CombPerRoadOR[0]->GetQuantiles(nQuant,xpercentiles[0],percentiles); sprintf(cc3,"# combinations/road. Ov. Masked. #mu=%3.1lf, #Lambda_{%3.1lf}=%3.1lf",h1CombPerRoadOR[0]->GetMean(),percentiles[3]*100,xpercentiles[0][3]); tle = tl->AddEntry(h1CombPerRoadOR[0],cc3,"l"); tle->SetLineColor (h1CombPerRoadOR[0]->GetLineColor()); tle->SetLineWidth (h1CombPerRoadOR[0]->GetLineWidth()); tl->Draw("L"); if (makePlots) { cCombPerRoad->SaveAs(dirPlots+cName+"__.pdf"); cCombPerRoad->SaveAs(dirPlots+cName+"__.png"); } cName=TString("cCombPerRoad_OR_DsClean_")+sLogic+pName; h1CombPerRoadOR[1]->SetLineColor(8); h1CombPerRoadOR[1]->DrawCopy("same"); h1CombPerRoadOR[1]->GetQuantiles(nQuant,xpercentiles[0],percentiles); sprintf(cc3,"# combinations/road. #Deltas clean Ov. Masked #mu=%3.1lf, #Lambda_{%3.1lf}=%3.1lf",h1CombPerRoadOR[1]->GetMean(),percentiles[3]*100,xpercentiles[0][3]); tle = tl->AddEntry(h1CombPerRoadOR[1],cc3,"l"); tle->SetLineColor (h1CombPerRoadOR[1]->GetLineColor()); tle->SetLineWidth (h1CombPerRoadOR[1]->GetLineWidth()); tl->Draw("L"); if (makePlots) { cCombPerRoad->SaveAs(dirPlots+cName+"__.pdf"); cCombPerRoad->SaveAs(dirPlots+cName+"__.png"); } cName=TString("cCombPerEvent_")+sLogic+pName; cTitle=TString("Combinations per Tower "+sLogic+pTitle); TCanvas* cCombPerEvent = new TCanvas(cName,cTitle,0,0,1400,900); cCombPerEvent->SetLogy(); h1CombPerEvent [0]->SetTitle(cTitle); h1CombPerEvent [0]->DrawCopy(); h1CombPerEvent [0]->GetQuantiles(nQuant,xpercentiles[0],percentiles); sprintf(cc3," #mu=%3.1lf, #Lambda_{%3.1lf}=%3.1lf",45.7,percentiles[3]*100,772.4); tl = new TLegend(0.25,0.75,0.9,0.9); tle = tl->AddEntry(h1CombPerEvent [0],cc3,"l"); tle->SetLineColor (h1CombPerEvent [0]->GetLineColor()); tle->SetLineWidth (h1CombPerEvent [0]->GetLineWidth()); tl->Draw("L"); if (makePlots) { cCombPerEvent->SaveAs(dirPlots+cName+"__.pdf"); cCombPerEvent->SaveAs(dirPlots+cName+"__.png"); } cName=TString("cCombPerEvent_OR_")+sLogic+pName; h1CombPerEventOR[0]->SetLineColor(2); h1CombPerEventOR[0]->DrawCopy("same"); h1CombPerEventOR[0]->GetQuantiles(nQuant,xpercentiles[0],percentiles); sprintf(cc3," Ov. Masked #mu=%3.1lf, #Lambda_{%3.1lf}=%3.1lf",h1CombPerEventOR[0]->GetMean(),percentiles[3]*100,467.4); tle = tl->AddEntry(h1CombPerEventOR[0],cc3,"l"); tle->SetLineColor (h1CombPerEventOR[0]->GetLineColor()); tle->SetLineWidth (h1CombPerEventOR[0]->GetLineWidth()); tl->Draw("L"); if (makePlots) { cCombPerEvent->SaveAs(dirPlots+cName+"__.pdf"); cCombPerEvent->SaveAs(dirPlots+cName+"__.png"); } cName=TString("cCombPerEvent_OR_DsClean_")+sLogic+pName; h1CombPerEventOR[1]->SetLineColor(8); // h1CombPerEventOR[1]->SetTitle(cTitle); // h1CombPerEventOR[1]->DrawCopy(); h1CombPerEvent [0]->DrawCopy(); h1CombPerEventOR[0]->DrawCopy("same"); h1CombPerEventOR[1]->DrawCopy("same"); h1CombPerEventOR[1]->GetQuantiles(nQuant,xpercentiles[0],percentiles); sprintf(cc3,"#Deltas clean Ov. Masked #mu=%3.1lf, #Lambda_{%3.1lf}=%3.1lf",h1CombPerEventOR[1]->GetMean(),percentiles[3]*100,xpercentiles[0][3]); tle = tl->AddEntry(h1CombPerEventOR[1],cc3,"l"); tle->SetLineColor (h1CombPerEventOR[1]->GetLineColor()); tle->SetLineWidth (h1CombPerEventOR[1]->GetLineWidth()); tl->Draw("L"); if (makePlots) { cCombPerEvent->SaveAs(dirPlots+cName+"__.pdf"); cCombPerEvent->SaveAs(dirPlots+cName+"__.png"); } TFile f1("/home/rossin/Dropbox/TT/Work/figures_stubOverlapRemoval/eff_LTF_SingleMuonTest_tt27_PU0_sf1_nz4_pt3_5oo6_95c_100k/efficiency1_10dedup_ppt_sf1_nz4.root"); TFile f2("/home/rossin/Dropbox/TT/Work/figures_stubOverlapRemoval/eff_LTF_SingleMuonTest_tt27_PU0_sf1_nz4_pt3_5oo6_95c_100k_removeOverlap/efficiency1_10dedup_ppt_sf1_nz4.root"); TCanvas* c1 = (TCanvas*) f1.Get("c1"); TList* list1 = c1->GetListOfPrimitives(); TIter next1(list1); TObject* obj1; TGraphAsymmErrors* eff_graph; while ((obj1 = next1())) { std::cout << obj1->GetName() << std::endl; if (obj1->GetName()==TString("eff_graph")) eff_graph = (TGraphAsymmErrors*) obj1; } // eff_graph->GetYaxis()->SetTitle("#varepsilon"); // eff_graph->SetMinimum(0.8); TCanvas* c1OR = (TCanvas*) f2.Get("c1"); c1OR->SetName("eff_OR"); c1OR->SetTitle("eff_OR"); TList* list = c1OR->GetListOfPrimitives(); TIter next(list); TObject* obj; TGraphAsymmErrors* eff_graphOR; c1->Draw(); while ((obj = next())) { std::cout << obj->GetName() << std::endl; if (obj->GetName()==TString("eff_graph")) { eff_graphOR = (TGraphAsymmErrors*) obj; eff_graphOR->SetLineStyle (eff_graph->GetLineStyle()); eff_graphOR->SetLineWidth (eff_graph->GetLineWidth()/2); eff_graphOR->SetMarkerStyle(eff_graph->GetMarkerStyle()); eff_graphOR->SetMarkerSize (eff_graph->GetMarkerSize()); eff_graphOR->SetFillColor (eff_graph->GetFillColor()); eff_graphOR->SetFillStyle (eff_graph->GetFillStyle()); eff_graphOR->SetMarkerColor(4); eff_graphOR->SetLineColor(4); eff_graphOR->GetYaxis()->SetTitle("#varepsilon"); eff_graphOR->Draw("same p"); } } tl = new TLegend(0.4,.13,0.95,0.35); tl->AddEntry(eff_graph ,"No Overlap Removal","p"); tl->AddEntry(eff_graphOR," Overlap Removal","p"); tl->Draw(); if (makePlots) { c1->SaveAs(dirPlots+TString("totalRecoEff_OR")+"__.png"); c1->SaveAs(dirPlots+TString("totalRecoEff_OR")+"__.pdf"); } return; }
/* * next - get next token */ static int /* 1 normal, 0 failure */ next(struct vars * v) { chr c; /* errors yield an infinite sequence of failures */ if (ISERR()) return 0; /* the error has set nexttype to EOS */ /* remember flavor of last token */ v->lasttype = v->nexttype; /* REG_BOSONLY */ if (v->nexttype == EMPTY && (v->cflags & REG_BOSONLY)) { /* at start of a REG_BOSONLY RE */ RETV(SBEGIN, 0); /* same as \A */ } /* if we're nested and we've hit end, return to outer level */ if (v->savenow != NULL && ATEOS()) { v->now = v->savenow; v->stop = v->savestop; v->savenow = v->savestop = NULL; } /* skip white space etc. if appropriate (not in literal or []) */ if (v->cflags & REG_EXPANDED) switch (v->lexcon) { case L_ERE: case L_BRE: case L_EBND: case L_BBND: skip(v); break; } /* handle EOS, depending on context */ if (ATEOS()) { switch (v->lexcon) { case L_ERE: case L_BRE: case L_Q: RET(EOS); break; case L_EBND: case L_BBND: FAILW(REG_EBRACE); break; case L_BRACK: case L_CEL: case L_ECL: case L_CCL: FAILW(REG_EBRACK); break; } assert(NOTREACHED); } /* okay, time to actually get a character */ c = *v->now++; /* deal with the easy contexts, punt EREs to code below */ switch (v->lexcon) { case L_BRE: /* punt BREs to separate function */ return brenext(v, c); break; case L_ERE: /* see below */ break; case L_Q: /* literal strings are easy */ RETV(PLAIN, c); break; case L_BBND: /* bounds are fairly simple */ case L_EBND: switch (c) { case CHR('0'): case CHR('1'): case CHR('2'): case CHR('3'): case CHR('4'): case CHR('5'): case CHR('6'): case CHR('7'): case CHR('8'): case CHR('9'): RETV(DIGIT, (chr) DIGITVAL(c)); break; case CHR(','): RET(','); break; case CHR('}'): /* ERE bound ends with } */ if (INCON(L_EBND)) { INTOCON(L_ERE); if ((v->cflags & REG_ADVF) && NEXT1('?')) { v->now++; NOTE(REG_UNONPOSIX); RETV('}', 0); } RETV('}', 1); } else FAILW(REG_BADBR); break; case CHR('\\'): /* BRE bound ends with \} */ if (INCON(L_BBND) && NEXT1('}')) { v->now++; INTOCON(L_BRE); RET('}'); } else FAILW(REG_BADBR); break; default: FAILW(REG_BADBR); break; } assert(NOTREACHED); break; case L_BRACK: /* brackets are not too hard */ switch (c) { case CHR(']'): if (LASTTYPE('[')) RETV(PLAIN, c); else { INTOCON((v->cflags & REG_EXTENDED) ? L_ERE : L_BRE); RET(']'); } break; case CHR('\\'): NOTE(REG_UBBS); if (!(v->cflags & REG_ADVF)) RETV(PLAIN, c); NOTE(REG_UNONPOSIX); if (ATEOS()) FAILW(REG_EESCAPE); (DISCARD) lexescape(v); switch (v->nexttype) { /* not all escapes okay here */ case PLAIN: return 1; break; case CCLASS: switch (v->nextvalue) { case 'd': lexnest(v, brbackd, ENDOF(brbackd)); break; case 's': lexnest(v, brbacks, ENDOF(brbacks)); break; case 'w': lexnest(v, brbackw, ENDOF(brbackw)); break; default: FAILW(REG_EESCAPE); break; } /* lexnest done, back up and try again */ v->nexttype = v->lasttype; return next(v); break; } /* not one of the acceptable escapes */ FAILW(REG_EESCAPE); break; case CHR('-'): if (LASTTYPE('[') || NEXT1(']')) RETV(PLAIN, c); else RETV(RANGE, c); break; case CHR('['): if (ATEOS()) FAILW(REG_EBRACK); switch (*v->now++) { case CHR('.'): INTOCON(L_CEL); /* might or might not be locale-specific */ RET(COLLEL); break; case CHR('='): INTOCON(L_ECL); NOTE(REG_ULOCALE); RET(ECLASS); break; case CHR(':'): INTOCON(L_CCL); NOTE(REG_ULOCALE); RET(CCLASS); break; default: /* oops */ v->now--; RETV(PLAIN, c); break; } assert(NOTREACHED); break; default: RETV(PLAIN, c); break; } assert(NOTREACHED); break; case L_CEL: /* collating elements are easy */ if (c == CHR('.') && NEXT1(']')) { v->now++; INTOCON(L_BRACK); RETV(END, '.'); } else RETV(PLAIN, c); break; case L_ECL: /* ditto equivalence classes */ if (c == CHR('=') && NEXT1(']')) { v->now++; INTOCON(L_BRACK); RETV(END, '='); } else RETV(PLAIN, c); break; case L_CCL: /* ditto character classes */ if (c == CHR(':') && NEXT1(']')) { v->now++; INTOCON(L_BRACK); RETV(END, ':'); } else RETV(PLAIN, c); break; default: assert(NOTREACHED); break; } /* that got rid of everything except EREs and AREs */ assert(INCON(L_ERE)); /* deal with EREs and AREs, except for backslashes */ switch (c) { case CHR('|'): RET('|'); break; case CHR('*'): if ((v->cflags & REG_ADVF) && NEXT1('?')) { v->now++; NOTE(REG_UNONPOSIX); RETV('*', 0); } RETV('*', 1); break; case CHR('+'): if ((v->cflags & REG_ADVF) && NEXT1('?')) { v->now++; NOTE(REG_UNONPOSIX); RETV('+', 0); } RETV('+', 1); break; case CHR('?'): if ((v->cflags & REG_ADVF) && NEXT1('?')) { v->now++; NOTE(REG_UNONPOSIX); RETV('?', 0); } RETV('?', 1); break; case CHR('{'): /* bounds start or plain character */ if (v->cflags & REG_EXPANDED) skip(v); if (ATEOS() || !iscdigit(*v->now)) { NOTE(REG_UBRACES); NOTE(REG_UUNSPEC); RETV(PLAIN, c); } else { NOTE(REG_UBOUNDS); INTOCON(L_EBND); RET('{'); } assert(NOTREACHED); break; case CHR('('): /* parenthesis, or advanced extension */ if ((v->cflags & REG_ADVF) && NEXT1('?')) { NOTE(REG_UNONPOSIX); v->now++; switch (*v->now++) { case CHR(':'): /* non-capturing paren */ RETV('(', 0); break; case CHR('#'): /* comment */ while (!ATEOS() && *v->now != CHR(')')) v->now++; if (!ATEOS()) v->now++; assert(v->nexttype == v->lasttype); return next(v); break; case CHR('='): /* positive lookahead */ NOTE(REG_ULOOKAHEAD); RETV(LACON, 1); break; case CHR('!'): /* negative lookahead */ NOTE(REG_ULOOKAHEAD); RETV(LACON, 0); break; default: FAILW(REG_BADRPT); break; } assert(NOTREACHED); } if (v->cflags & REG_NOSUB) RETV('(', 0); /* all parens non-capturing */ else RETV('(', 1); break; case CHR(')'): if (LASTTYPE('(')) NOTE(REG_UUNSPEC); RETV(')', c); break; case CHR('['): /* easy except for [[:<:]] and [[:>:]] */ if (HAVE(6) && *(v->now + 0) == CHR('[') && *(v->now + 1) == CHR(':') && (*(v->now + 2) == CHR('<') || *(v->now + 2) == CHR('>')) && *(v->now + 3) == CHR(':') && *(v->now + 4) == CHR(']') && *(v->now + 5) == CHR(']')) { c = *(v->now + 2); v->now += 6; NOTE(REG_UNONPOSIX); RET((c == CHR('<')) ? '<' : '>'); } INTOCON(L_BRACK); if (NEXT1('^')) { v->now++; RETV('[', 0); } RETV('[', 1); break; case CHR('.'): RET('.'); break; case CHR('^'): RET('^'); break; case CHR('$'): RET('$'); break; case CHR('\\'): /* mostly punt backslashes to code below */ if (ATEOS()) FAILW(REG_EESCAPE); break; default: /* ordinary character */ RETV(PLAIN, c); break; } /* ERE/ARE backslash handling; backslash already eaten */ assert(!ATEOS()); if (!(v->cflags & REG_ADVF)) { /* only AREs have non-trivial escapes */ if (iscalnum(*v->now)) { NOTE(REG_UBSALNUM); NOTE(REG_UUNSPEC); } RETV(PLAIN, *v->now++); } (DISCARD) lexescape(v); if (ISERR()) FAILW(REG_EESCAPE); if (v->nexttype == CCLASS) { /* fudge at lexical level */ switch (v->nextvalue) { case 'd': lexnest(v, backd, ENDOF(backd)); break; case 'D': lexnest(v, backD, ENDOF(backD)); break; case 's': lexnest(v, backs, ENDOF(backs)); break; case 'S': lexnest(v, backS, ENDOF(backS)); break; case 'w': lexnest(v, backw, ENDOF(backw)); break; case 'W': lexnest(v, backW, ENDOF(backW)); break; default: assert(NOTREACHED); FAILW(REG_ASSERT); break; } /* lexnest done, back up and try again */ v->nexttype = v->lasttype; return next(v); } /* otherwise, lexescape has already done the work */ return !ISERR(); }
dr_main() { register int n; register struct ship *sp; int nat[NNATION]; int value = 0; (void) signal(SIGINT, SIG_IGN); (void) signal(SIGQUIT, SIG_IGN); (void) signal(SIGTSTP, SIG_IGN); if (issetuid) (void) setruid(geteuid()); if (game < 0 || game >= NSCENE) { fprintf(stderr, "DRIVER: Bad game number %d\n", game); exit(1); } cc = &scene[game]; ls = SHIP(cc->vessels); if (sync_open() < 0) { perror("driver: syncfile"); exit(1); } for (n = 0; n < NNATION; n++) nat[n] = 0; foreachship(sp) { if (sp->file == NULL && (sp->file = (struct File *)calloc(1, sizeof (struct File))) == NULL) { (void) fprintf(stderr, "DRIVER: Out of memory.\n"); exit(1); } sp->file->index = sp - SHIP(0); sp->file->loadL = L_ROUND; sp->file->loadR = L_ROUND; sp->file->readyR = R_LOADED|R_INITIAL; sp->file->readyL = R_LOADED|R_INITIAL; sp->file->stern = nat[sp->nationality]++; sp->file->dir = sp->shipdir; sp->file->row = sp->shiprow; sp->file->col = sp->shipcol; } windspeed = cc->windspeed; winddir = cc->winddir; people = 0; for (;;) { sleep(7); if (Sync() < 0) { value = 1; break; } if (next() < 0) break; unfoul(); checkup(); prizecheck(); moveall(); thinkofgrapples(); boardcomp(); compcombat(); resolve(); reload(); checksails(); if (Sync() < 0) { value = 1; break; } } sync_close(1); return value; }
void TreeDiagram::drawBoxes(FTextStream &t,Image *image, bool doBase,bool bitmap, uint baseRows,uint superRows, uint cellWidth,uint cellHeight, QCString relPath, bool generateMap) { DiagramRow *dr=first(); if (!doBase) dr=next(); bool done=FALSE; bool firstRow = doBase; while (dr && !done) { int x=0,y=0; float xf=0.0,yf=0.0; DiagramItem *di=dr->first(); if (di->isInList()) // put boxes in a list { DiagramItem *opi=0; if (doBase) di=dr->last(); while (di) { if (di->parentItem()==opi) { if (bitmap) { if (doBase) y -= cellHeight+labelVertSpacing; else y += cellHeight+labelVertSpacing; } else { if (doBase) yf += 1.0; else yf -= 1.0; } } else { if (bitmap) { x = di->xPos()*(cellWidth+labelHorSpacing)/gridWidth; if (doBase) { y = image->getHeight()- superRows*cellHeight- (superRows-1)*labelVertSpacing- di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; } else { y = (baseRows-1)*(cellHeight+labelVertSpacing)+ di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; } } else { xf = di->xPos()/(float)gridWidth; if (doBase) { yf = di->yPos()/(float)gridHeight+superRows-1; } else { yf = superRows-1-di->yPos()/(float)gridHeight; } } } opi=di->parentItem(); if (bitmap) { bool hasDocs=di->getClassDef()->isLinkable(); writeBitmapBox(di,image,x,y,cellWidth,cellHeight,firstRow, hasDocs,di->getChildren()->count()>0); if (!firstRow && generateMap) writeMapArea(t,di->getClassDef(),relPath,x,y,cellWidth,cellHeight); } else { writeVectorBox(t,di,xf,yf,di->getChildren()->count()>0); } if (doBase) di=dr->prev(); else di=dr->next(); } done=TRUE; } else // draw a tree of boxes { while (di) { if (bitmap) { x = di->xPos()*(cellWidth+labelHorSpacing)/gridWidth; if (doBase) { y = image->getHeight()- superRows*cellHeight- (superRows-1)*labelVertSpacing- di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; } else { y = (baseRows-1)*(cellHeight+labelVertSpacing)+ di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; } bool hasDocs=di->getClassDef()->isLinkable(); writeBitmapBox(di,image,x,y,cellWidth,cellHeight,firstRow,hasDocs); if (!firstRow && generateMap) writeMapArea(t,di->getClassDef(),relPath,x,y,cellWidth,cellHeight); } else { xf=di->xPos()/(float)gridWidth; if (doBase) { yf = di->yPos()/(float)gridHeight+superRows-1; } else { yf = superRows-1-di->yPos()/(float)gridHeight; } writeVectorBox(t,di,xf,yf); } di=dr->next(); } } dr=next(); firstRow=FALSE; } }
void LocalObject::fwdcopy(Space& home, bool share) { ActorLink::cast(this)->prev(copy(home,share)); next(home.pc.c.local); home.pc.c.local = this; }
void TreeDiagram::drawConnectors(FTextStream &t,Image *image, bool doBase,bool bitmap, uint baseRows,uint superRows, uint cellWidth,uint cellHeight) { DiagramRow *dr=first(); bool done=FALSE; while (dr && !done) // for each row { DiagramItem *di=dr->first(); if (di->isInList()) // row consists of list connectors { int x=0,y=0,ys=0; float xf=0.0,yf=0.0,ysf=0.0; while (di) { DiagramItem *pi=di->parentItem(); DiagramItemList *dil=pi->getChildren(); DiagramItem *last=dil->getLast(); if (di==last) // single child { if (bitmap) // draw pixels { x = di->xPos()*(cellWidth+labelHorSpacing)/gridWidth + cellWidth/2; if (doBase) // base classes { y = image->getHeight()- (superRows-1)*(cellHeight+labelVertSpacing)- di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; image->drawVertArrow(x,y,y+labelVertSpacing/2, protToColor(di->protection()), protToMask(di->protection())); } else // super classes { y = (baseRows-1)*(cellHeight+labelVertSpacing)- labelVertSpacing/2+ di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; image->drawVertLine(x,y,y+labelVertSpacing/2, protToColor(di->protection()), protToMask(di->protection())); } } else // draw vectors { t << protToString(di->protection()) << endl; if (doBase) { t << "1 " << (di->xPos()/(float)gridWidth) << " " << (di->yPos()/(float)gridHeight+superRows-1) << " in\n"; } else { t << "0 " << (di->xPos()/(float)gridWidth) << " " << ((float)superRows-0.25-di->yPos()/(float)gridHeight) << " in\n"; } } } else // multiple children, put them in a vertical list { if (bitmap) { x = di->parentItem()->xPos()* (cellWidth+labelHorSpacing)/gridWidth+cellWidth/2; if (doBase) // base classes { ys = image->getHeight()- (superRows-1)*(cellHeight+labelVertSpacing)- di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; y = ys - cellHeight/2; } else // super classes { ys = (baseRows-1)*(cellHeight+labelVertSpacing)+ di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; y = ys + cellHeight/2; } } else { xf = di->parentItem()->xPos()/(float)gridWidth; if (doBase) { ysf = di->yPos()/(float)gridHeight+superRows-1; yf = ysf + 0.5; } else { ysf = (float)superRows-0.25-di->yPos()/(float)gridHeight; yf = ysf - 0.25; } } while (di!=last) // more children to add { if (bitmap) { if (doBase) // base classes { image->drawHorzArrow(y,x,x+cellWidth/2+labelHorSpacing, protToColor(di->protection()), protToMask(di->protection())); y -= cellHeight+labelVertSpacing; } else // super classes { image->drawHorzLine(y,x,x+cellWidth/2+labelHorSpacing, protToColor(di->protection()), protToMask(di->protection())); y += cellHeight+labelVertSpacing; } } else { t << protToString(di->protection()) << endl; if (doBase) { t << "1 " << xf << " " << yf << " hedge\n"; yf += 1.0; } else { t << "0 " << xf << " " << yf << " hedge\n"; yf -= 1.0; } } di=dr->next(); } // add last horizonal line and a vertical connection line if (bitmap) { if (doBase) // base classes { image->drawHorzArrow(y,x,x+cellWidth/2+labelHorSpacing, protToColor(di->protection()), protToMask(di->protection())); image->drawVertLine(x,y,ys+labelVertSpacing/2, protToColor(getMinProtectionLevel(dil)), protToMask(getMinProtectionLevel(dil))); } else // super classes { image->drawHorzLine(y,x,x+cellWidth/2+labelHorSpacing, protToColor(di->protection()), protToMask(di->protection())); image->drawVertLine(x,ys-labelVertSpacing/2,y, protToColor(getMinProtectionLevel(dil)), protToMask(getMinProtectionLevel(dil))); } } else { t << protToString(di->protection()) << endl; if (doBase) { t << "1 " << xf << " " << yf << " hedge\n"; } else { t << "0 " << xf << " " << yf << " hedge\n"; } t << protToString(getMinProtectionLevel(dil)) << endl; if (doBase) { t << xf << " " << ysf << " " << yf << " vedge\n"; } else { t << xf << " " << (ysf + 0.25) << " " << yf << " vedge\n"; } } } di=dr->next(); } done=TRUE; // the tree is drawn now } else // normal tree connector { while (di) { int x=0,y=0; DiagramItemList *dil = di->getChildren(); DiagramItem *parent = di->parentItem(); if (parent) // item has a parent -> connect to it { if (bitmap) // draw pixels { x = di->xPos()*(cellWidth+labelHorSpacing)/gridWidth + cellWidth/2; if (doBase) // base classes { y = image->getHeight()- (superRows-1)*(cellHeight+labelVertSpacing)- di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; /* write input line */ image->drawVertArrow(x,y,y+labelVertSpacing/2, protToColor(di->protection()), protToMask(di->protection())); } else // super classes { y = (baseRows-1)*(cellHeight+labelVertSpacing)- labelVertSpacing/2+ di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; /* write output line */ image->drawVertLine(x,y,y+labelVertSpacing/2, protToColor(di->protection()), protToMask(di->protection())); } } else // draw pixels { t << protToString(di->protection()) << endl; if (doBase) { t << "1 " << di->xPos()/(float)gridWidth << " " << (di->yPos()/(float)gridHeight+superRows-1) << " in\n"; } else { t << "0 " << di->xPos()/(float)gridWidth << " " << ((float)superRows-0.25-di->yPos()/(float)gridHeight) << " in\n"; } } } if (dil->count()>0) { Protection p=getMinProtectionLevel(dil); uint mask=protToMask(p); uint col=protToColor(p); if (bitmap) { x = di->xPos()*(cellWidth+labelHorSpacing)/gridWidth + cellWidth/2; if (doBase) // base classes { y = image->getHeight()- (superRows-1)*(cellHeight+labelVertSpacing)- cellHeight-labelVertSpacing/2- di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; image->drawVertLine(x,y,y+labelVertSpacing/2-1,col,mask); } else // super classes { y = (baseRows-1)*(cellHeight+labelVertSpacing)+ cellHeight+ di->yPos()*(cellHeight+labelVertSpacing)/gridHeight; image->drawVertArrow(x,y,y+labelVertSpacing/2-1,col,mask); } } else { t << protToString(p) << endl; if (doBase) { t << "0 " << di->xPos()/(float)gridWidth << " " << (di->yPos()/(float)gridHeight+superRows-1) << " out\n"; } else { t << "1 " << di->xPos()/(float)gridWidth << " " << ((float)superRows-1.75-di->yPos()/(float)gridHeight) << " out\n"; } } /* write input line */ DiagramItem *first = dil->first(); DiagramItem *last = dil->last(); if (first!=last && !first->isInList()) /* connect with all base classes */ { if (bitmap) { int xs = first->xPos()*(cellWidth+labelHorSpacing)/gridWidth + cellWidth/2; int xe = last->xPos()*(cellWidth+labelHorSpacing)/gridWidth + cellWidth/2; if (doBase) // base classes { image->drawHorzLine(y,xs,xe,col,mask); } else // super classes { image->drawHorzLine(y+labelVertSpacing/2,xs,xe,col,mask); } } else { t << protToString(p) << endl; if (doBase) { t << first->xPos()/(float)gridWidth << " " << last->xPos()/(float)gridWidth << " " << (first->yPos()/(float)gridHeight+superRows-1) << " conn\n"; } else { t << first->xPos()/(float)gridWidth << " " << last->xPos()/(float)gridWidth << " " << ((float)superRows-first->yPos()/(float)gridHeight) << " conn\n"; } } } } di=dr->next(); } dr=next(); } } }
const char *start() { reset(); return next(); }
/* This demonstrates writing. It simply saves the two bitmaps into a binary * file. */ static void stdio_write_test(void) { FILE *fp; PACKFILE *f; BITMAP *bmp, *bmp2; /* Read the bitmaps. */ bmp = load_pcx("allegro.pcx", NULL); CHECK(bmp, "load_pcx"); bmp2 = load_pcx("mysha.pcx", NULL); CHECK(bmp2, "load_pcx"); /* Write them with out custom vtable. */ fp = fopen("expackf.out", "wb"); CHECK(fp, "writing expackf.out"); f = pack_fopen_vtable(&stdio_vtable, fp); CHECK(f, "writing with stdio"); save_tga_pf(f, bmp, NULL); save_bmp_pf(f, bmp2, NULL); destroy_bitmap(bmp); destroy_bitmap(bmp2); pack_fclose(f); /* Now read them in again with our custom vtable. */ fp = fopen("expackf.out", "rb"); CHECK(fp, "fopen"); f = pack_fopen_vtable(&stdio_vtable, fp); CHECK(f, "reading from stdio"); /* Note: in general you would need to implement a "chunking" system * that knows where the boundary of each file is. Many file format * loaders will happily read everything to the end of the file, * whereas others stop reading as soon as they have all the essential * data (e.g. there may be some metadata at the end of the file). * Concatenating bare files together only works in examples programs. */ bmp = load_tga_pf(f, NULL); CHECK(bmp, "load_tga_pf"); bmp2 = load_bmp_pf(f, NULL); CHECK(bmp2, "load_bmp_pf"); blit(bmp, screen, 0, 0, 0, 0, bmp->w, bmp->h); textprintf_ex(screen, font, bmp2->w + 8, 8, -1, -1, "\"allegro.pcx\" (as tga)"); textprintf_ex(screen, font, bmp2->w + 8, 8 + 20, -1, -1, "wrote with stdio functions"); blit(bmp2, screen, 0, 0, 0, bmp->h + 8, bmp2->w, bmp2->h); textprintf_ex(screen, font, bmp2->w + 8, bmp->h + 8, -1, -1, "\"mysha.pcx\" (as bmp)"); textprintf_ex(screen, font, bmp2->w + 8, bmp->h + 8 + 20, -1, -1, "wrote with stdio functions"); destroy_bitmap(bmp); destroy_bitmap(bmp2); pack_fclose(f); next(); }
bool kv(std::vector<KeyVal>* items, std::set<std::string>& seen) { std::string key; nextword(key); int ch = next(); if (ch == '>' && key.empty()) { return false; } else if (ch == '#' && key.empty()) { comment(); return true; } else if (ch != '=') { throw CoreException("Invalid character " + std::string(1, ch) + " in key (" + key + ")"); } std::string value; ch = next(); if (ch != '"') { throw CoreException("Invalid character in value of <" + tag->tag + ":" + key + ">"); } while (1) { ch = next(); if (ch == '&' && !(flags & FLAG_USE_COMPAT)) { std::string varname; while (1) { ch = next(); if (isalnum(ch)) varname.push_back(ch); else if (ch == ';') break; else { stack.errstr << "Invalid XML entity name in value of <" + tag->tag + ":" + key + ">\n" << "To include an ampersand or quote, use & or "\n"; throw CoreException("Parse error"); } } std::map<std::string, std::string>::iterator var = stack.vars.find(varname); if (var == stack.vars.end()) throw CoreException("Undefined XML entity reference '&" + varname + ";'"); value.append(var->second); } else if (ch == '\\' && (flags & FLAG_USE_COMPAT)) { int esc = next(); if (esc == 'n') value.push_back('\n'); else if (isalpha(esc)) throw CoreException("Unknown escape character \\" + std::string(1, esc)); else value.push_back(esc); } else if (ch == '"') break; else value.push_back(ch); } if (!seen.insert(key).second) throw CoreException("Duplicate key '" + key + "' found"); items->push_back(KeyVal(key, value)); return true; }
int RegExpTokenizer::lex() { lexemStart = pos; lexemLength = 0; int lastAcceptingPos = -1; int token = -1; QChar ch; // initial state ch = next(); if (ch.unicode() >= 1 && ch.unicode() <= 33) goto state_1; if (ch.unicode() == 34) goto state_2; if (ch.unicode() >= 35 && ch.unicode() <= 39) goto state_1; if (ch.unicode() == 40) { token = RE2NFA::TOK_LPAREN; goto found; } if (ch.unicode() == 41) { token = RE2NFA::TOK_RPAREN; goto found; } if (ch.unicode() == 42) { token = RE2NFA::TOK_STAR; goto found; } if (ch.unicode() == 43) { token = RE2NFA::TOK_PLUS; goto found; } if (ch.unicode() == 44) { token = RE2NFA::TOK_COMMA; goto found; } if (ch.unicode() == 45) goto state_1; if (ch.unicode() == 46) { token = RE2NFA::TOK_DOT; goto found; } if (ch.unicode() >= 47 && ch.unicode() <= 62) goto state_1; if (ch.unicode() == 63) { token = RE2NFA::TOK_QUESTION; goto found; } if (ch.unicode() >= 64 && ch.unicode() <= 90) goto state_1; if (ch.unicode() == 91) goto state_10; if (ch.unicode() == 92) goto state_11; if (ch.unicode() >= 93 && ch.unicode() <= 122) goto state_1; if (ch.unicode() == 123) { token = RE2NFA::TOK_LBRACE; goto found; } if (ch.unicode() == 124) { token = RE2NFA::TOK_OR; goto found; } if (ch.unicode() == 125) { token = RE2NFA::TOK_RBRACE; goto found; } if (ch.unicode() >= 126) goto state_1; goto out; state_1: lastAcceptingPos = pos; token = RE2NFA::TOK_STRING; goto out; state_2: lastAcceptingPos = pos; token = RE2NFA::TOK_STRING; ch = next(); if (ch.unicode() >= 1 && ch.unicode() <= 33) goto state_15; if (ch.unicode() == 34) goto state_16; if (ch.unicode() >= 35) goto state_15; goto out; state_10: ch = next(); if (ch.unicode() >= 1 && ch.unicode() <= 91) goto state_17; if (ch.unicode() == 92) goto state_18; if (ch.unicode() == 93) goto state_19; if (ch.unicode() >= 94) goto state_17; goto out; state_11: lastAcceptingPos = pos; token = RE2NFA::TOK_STRING; ch = next(); if (ch.unicode() >= 1) goto state_20; goto out; state_15: ch = next(); if (ch.unicode() >= 1 && ch.unicode() <= 33) goto state_15; if (ch.unicode() == 34) goto state_16; if (ch.unicode() >= 35) goto state_15; goto out; state_16: lastAcceptingPos = pos; token = RE2NFA::TOK_QUOTED_STRING; goto out; state_17: ch = next(); if (ch.unicode() >= 1 && ch.unicode() <= 91) goto state_17; if (ch.unicode() == 92) goto state_18; if (ch.unicode() == 93) goto state_19; if (ch.unicode() >= 94) goto state_17; goto out; state_18: ch = next(); if (ch.unicode() >= 1 && ch.unicode() <= 91) goto state_17; if (ch.unicode() == 92) goto state_18; if (ch.unicode() == 93) goto state_21; if (ch.unicode() >= 94) goto state_17; goto out; state_19: lastAcceptingPos = pos; token = RE2NFA::TOK_SEQUENCE; goto out; state_20: lastAcceptingPos = pos; token = RE2NFA::TOK_STRING; goto out; state_21: lastAcceptingPos = pos; token = RE2NFA::TOK_SEQUENCE; ch = next(); if (ch.unicode() >= 1 && ch.unicode() <= 91) goto state_17; if (ch.unicode() == 92) goto state_18; if (ch.unicode() == 93) goto state_19; if (ch.unicode() >= 94) goto state_17; goto out; found: lastAcceptingPos = pos; out: if (lastAcceptingPos != -1) { lexemLength = lastAcceptingPos - lexemStart; pos = lastAcceptingPos; } return token; }
void VisibleSelection::adjustSelectionToAvoidCrossingEditingBoundaries() { if (m_base.isNull() || m_start.isNull() || m_end.isNull()) return; Node* baseRoot = highestEditableRoot(m_base); Node* startRoot = highestEditableRoot(m_start); Node* endRoot = highestEditableRoot(m_end); Node* baseEditableAncestor = lowestEditableAncestor(m_base.containerNode()); // The base, start and end are all in the same region. No adjustment necessary. if (baseRoot == startRoot && baseRoot == endRoot) return; // The selection is based in editable content. if (baseRoot) { // If the start is outside the base's editable root, cap it at the start of that root. // If the start is in non-editable content that is inside the base's editable root, put it // at the first editable position after start inside the base's editable root. if (startRoot != baseRoot) { VisiblePosition first = firstEditablePositionAfterPositionInRoot(m_start, baseRoot); m_start = first.deepEquivalent(); if (m_start.isNull()) { ASSERT_NOT_REACHED(); m_start = m_end; } } // If the end is outside the base's editable root, cap it at the end of that root. // If the end is in non-editable content that is inside the base's root, put it // at the last editable position before the end inside the base's root. if (endRoot != baseRoot) { VisiblePosition last = lastEditablePositionBeforePositionInRoot(m_end, baseRoot); m_end = last.deepEquivalent(); if (m_end.isNull()) m_end = m_start; } // The selection is based in non-editable content. } else { // FIXME: Non-editable pieces inside editable content should be atomic, in the same way that editable // pieces in non-editable content are atomic. // The selection ends in editable content or non-editable content inside a different editable ancestor, // move backward until non-editable content inside the same lowest editable ancestor is reached. Node* endEditableAncestor = lowestEditableAncestor(m_end.containerNode()); if (endRoot || endEditableAncestor != baseEditableAncestor) { Position p = previousVisuallyDistinctCandidate(m_end); Node* shadowAncestor = endRoot ? endRoot->shadowAncestorNode() : 0; if (p.isNull() && endRoot && (shadowAncestor != endRoot)) p = positionAfterNode(shadowAncestor); while (p.isNotNull() && !(lowestEditableAncestor(p.containerNode()) == baseEditableAncestor && !isEditablePosition(p))) { Node* root = editableRootForPosition(p); shadowAncestor = root ? root->shadowAncestorNode() : 0; p = isAtomicNode(p.containerNode()) ? positionInParentBeforeNode(p.containerNode()) : previousVisuallyDistinctCandidate(p); if (p.isNull() && (shadowAncestor != root)) p = positionAfterNode(shadowAncestor); } VisiblePosition previous(p); if (previous.isNull()) { // The selection crosses an Editing boundary. This is a // programmer error in the editing code. Happy debugging! ASSERT_NOT_REACHED(); m_base = Position(); m_extent = Position(); validate(); return; } m_end = previous.deepEquivalent(); } // The selection starts in editable content or non-editable content inside a different editable ancestor, // move forward until non-editable content inside the same lowest editable ancestor is reached. Node* startEditableAncestor = lowestEditableAncestor(m_start.containerNode()); if (startRoot || startEditableAncestor != baseEditableAncestor) { Position p = nextVisuallyDistinctCandidate(m_start); Node* shadowAncestor = startRoot ? startRoot->shadowAncestorNode() : 0; if (p.isNull() && startRoot && (shadowAncestor != startRoot)) p = positionBeforeNode(shadowAncestor); while (p.isNotNull() && !(lowestEditableAncestor(p.containerNode()) == baseEditableAncestor && !isEditablePosition(p))) { Node* root = editableRootForPosition(p); shadowAncestor = root ? root->shadowAncestorNode() : 0; p = isAtomicNode(p.containerNode()) ? positionInParentAfterNode(p.containerNode()) : nextVisuallyDistinctCandidate(p); if (p.isNull() && (shadowAncestor != root)) p = positionBeforeNode(shadowAncestor); } VisiblePosition next(p); if (next.isNull()) { // The selection crosses an Editing boundary. This is a // programmer error in the editing code. Happy debugging! ASSERT_NOT_REACHED(); m_base = Position(); m_extent = Position(); validate(); return; } m_start = next.deepEquivalent(); } } // Correct the extent if necessary. if (baseEditableAncestor != lowestEditableAncestor(m_extent.containerNode())) m_extent = m_baseIsFirst ? m_end : m_start; }
int tc_libcxx_containers_unord_multimap_swap_swap_non_member(void) { { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef test_allocator<std::pair<const int, std::string> > Alloc; typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; C c1(0, Hash(1), Compare(1), Alloc(1, 1)); C c2(0, Hash(2), Compare(2), Alloc(1, 2)); c2.max_load_factor(2); swap(c1, c2); LIBCPP_ASSERT(c1.bucket_count() == 0); TC_ASSERT_EXPR(c1.size() == 0); TC_ASSERT_EXPR(c1.hash_function() == Hash(2)); TC_ASSERT_EXPR(c1.key_eq() == Compare(2)); TC_ASSERT_EXPR(c1.get_allocator().get_id() == 1); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); TC_ASSERT_EXPR(c1.max_load_factor() == 2); LIBCPP_ASSERT(c2.bucket_count() == 0); TC_ASSERT_EXPR(c2.size() == 0); TC_ASSERT_EXPR(c2.hash_function() == Hash(1)); TC_ASSERT_EXPR(c2.key_eq() == Compare(1)); TC_ASSERT_EXPR(c2.get_allocator().get_id() == 2); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); TC_ASSERT_EXPR(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef test_allocator<std::pair<const int, std::string> > Alloc; typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; typedef std::pair<int, std::string> P; P a2[] = { P(10, "ten"), P(20, "twenty"), P(30, "thirty"), P(40, "forty"), P(50, "fifty"), P(60, "sixty"), P(70, "seventy"), P(80, "eighty"), }; C c1(0, Hash(1), Compare(1), Alloc(1, 1)); C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2)); c2.max_load_factor(2); swap(c1, c2); TC_ASSERT_EXPR(c1.bucket_count() >= 8); TC_ASSERT_EXPR(c1.size() == 8); TC_ASSERT_EXPR(c1.find(10)->second == "ten"); TC_ASSERT_EXPR(c1.find(20)->second == "twenty"); TC_ASSERT_EXPR(c1.find(30)->second == "thirty"); TC_ASSERT_EXPR(c1.find(40)->second == "forty"); TC_ASSERT_EXPR(c1.find(50)->second == "fifty"); TC_ASSERT_EXPR(c1.find(60)->second == "sixty"); TC_ASSERT_EXPR(c1.find(70)->second == "seventy"); TC_ASSERT_EXPR(c1.find(80)->second == "eighty"); TC_ASSERT_EXPR(c1.hash_function() == Hash(2)); TC_ASSERT_EXPR(c1.key_eq() == Compare(2)); TC_ASSERT_EXPR(c1.get_allocator().get_id() == 1); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); TC_ASSERT_EXPR(c1.max_load_factor() == 2); LIBCPP_ASSERT(c2.bucket_count() == 0); TC_ASSERT_EXPR(c2.size() == 0); TC_ASSERT_EXPR(c2.hash_function() == Hash(1)); TC_ASSERT_EXPR(c2.key_eq() == Compare(1)); TC_ASSERT_EXPR(c2.get_allocator().get_id() == 2); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); TC_ASSERT_EXPR(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef test_allocator<std::pair<const int, std::string> > Alloc; typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; typedef std::pair<int, std::string> P; P a1[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1)); C c2(0, Hash(2), Compare(2), Alloc(1, 2)); c2.max_load_factor(2); swap(c1, c2); LIBCPP_ASSERT(c1.bucket_count() == 0); TC_ASSERT_EXPR(c1.size() == 0); TC_ASSERT_EXPR(c1.hash_function() == Hash(2)); TC_ASSERT_EXPR(c1.key_eq() == Compare(2)); TC_ASSERT_EXPR(c1.get_allocator().get_id() == 1); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); TC_ASSERT_EXPR(c1.max_load_factor() == 2); TC_ASSERT_EXPR(c2.bucket_count() >= 6); TC_ASSERT_EXPR(c2.size() == 6); TC_ASSERT_EXPR(c2.find(1)->second == "one"); TC_ASSERT_EXPR(next(c2.find(1))->second == "four"); TC_ASSERT_EXPR(c2.find(2)->second == "two"); TC_ASSERT_EXPR(next(c2.find(2))->second == "four"); TC_ASSERT_EXPR(c2.find(3)->second == "three"); TC_ASSERT_EXPR(c2.find(4)->second == "four"); TC_ASSERT_EXPR(c2.hash_function() == Hash(1)); TC_ASSERT_EXPR(c2.key_eq() == Compare(1)); TC_ASSERT_EXPR(c2.get_allocator().get_id() == 2); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); TC_ASSERT_EXPR(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef test_allocator<std::pair<const int, std::string> > Alloc; typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; typedef std::pair<int, std::string> P; P a1[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; P a2[] = { P(10, "ten"), P(20, "twenty"), P(30, "thirty"), P(40, "forty"), P(50, "fifty"), P(60, "sixty"), P(70, "seventy"), P(80, "eighty"), }; C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1)); C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2)); c2.max_load_factor(2); swap(c1, c2); TC_ASSERT_EXPR(c1.bucket_count() >= 8); TC_ASSERT_EXPR(c1.size() == 8); TC_ASSERT_EXPR(c1.find(10)->second == "ten"); TC_ASSERT_EXPR(c1.find(20)->second == "twenty"); TC_ASSERT_EXPR(c1.find(30)->second == "thirty"); TC_ASSERT_EXPR(c1.find(40)->second == "forty"); TC_ASSERT_EXPR(c1.find(50)->second == "fifty"); TC_ASSERT_EXPR(c1.find(60)->second == "sixty"); TC_ASSERT_EXPR(c1.find(70)->second == "seventy"); TC_ASSERT_EXPR(c1.find(80)->second == "eighty"); TC_ASSERT_EXPR(c1.hash_function() == Hash(2)); TC_ASSERT_EXPR(c1.key_eq() == Compare(2)); TC_ASSERT_EXPR(c1.get_allocator().get_id() == 1); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); TC_ASSERT_EXPR(c1.max_load_factor() == 2); TC_ASSERT_EXPR(c2.bucket_count() >= 6); TC_ASSERT_EXPR(c2.size() == 6); TC_ASSERT_EXPR(c2.find(1)->second == "one"); TC_ASSERT_EXPR(next(c2.find(1))->second == "four"); TC_ASSERT_EXPR(c2.find(2)->second == "two"); TC_ASSERT_EXPR(next(c2.find(2))->second == "four"); TC_ASSERT_EXPR(c2.find(3)->second == "three"); TC_ASSERT_EXPR(c2.find(4)->second == "four"); TC_ASSERT_EXPR(c2.hash_function() == Hash(1)); TC_ASSERT_EXPR(c2.key_eq() == Compare(1)); TC_ASSERT_EXPR(c2.get_allocator().get_id() == 2); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); TC_ASSERT_EXPR(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef other_allocator<std::pair<const int, std::string> > Alloc; typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; C c1(0, Hash(1), Compare(1), Alloc(1)); C c2(0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); swap(c1, c2); LIBCPP_ASSERT(c1.bucket_count() == 0); TC_ASSERT_EXPR(c1.size() == 0); TC_ASSERT_EXPR(c1.hash_function() == Hash(2)); TC_ASSERT_EXPR(c1.key_eq() == Compare(2)); TC_ASSERT_EXPR(c1.get_allocator() == Alloc(2)); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); TC_ASSERT_EXPR(c1.max_load_factor() == 2); LIBCPP_ASSERT(c2.bucket_count() == 0); TC_ASSERT_EXPR(c2.size() == 0); TC_ASSERT_EXPR(c2.hash_function() == Hash(1)); TC_ASSERT_EXPR(c2.key_eq() == Compare(1)); TC_ASSERT_EXPR(c2.get_allocator() == Alloc(1)); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); TC_ASSERT_EXPR(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef other_allocator<std::pair<const int, std::string> > Alloc; typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; typedef std::pair<int, std::string> P; P a2[] = { P(10, "ten"), P(20, "twenty"), P(30, "thirty"), P(40, "forty"), P(50, "fifty"), P(60, "sixty"), P(70, "seventy"), P(80, "eighty"), }; C c1(0, Hash(1), Compare(1), Alloc(1)); C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); swap(c1, c2); TC_ASSERT_EXPR(c1.bucket_count() >= 8); TC_ASSERT_EXPR(c1.size() == 8); TC_ASSERT_EXPR(c1.find(10)->second == "ten"); TC_ASSERT_EXPR(c1.find(20)->second == "twenty"); TC_ASSERT_EXPR(c1.find(30)->second == "thirty"); TC_ASSERT_EXPR(c1.find(40)->second == "forty"); TC_ASSERT_EXPR(c1.find(50)->second == "fifty"); TC_ASSERT_EXPR(c1.find(60)->second == "sixty"); TC_ASSERT_EXPR(c1.find(70)->second == "seventy"); TC_ASSERT_EXPR(c1.find(80)->second == "eighty"); TC_ASSERT_EXPR(c1.hash_function() == Hash(2)); TC_ASSERT_EXPR(c1.key_eq() == Compare(2)); TC_ASSERT_EXPR(c1.get_allocator() == Alloc(2)); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); TC_ASSERT_EXPR(c1.max_load_factor() == 2); LIBCPP_ASSERT(c2.bucket_count() == 0); TC_ASSERT_EXPR(c2.size() == 0); TC_ASSERT_EXPR(c2.hash_function() == Hash(1)); TC_ASSERT_EXPR(c2.key_eq() == Compare(1)); TC_ASSERT_EXPR(c2.get_allocator() == Alloc(1)); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); TC_ASSERT_EXPR(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef other_allocator<std::pair<const int, std::string> > Alloc; typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; typedef std::pair<int, std::string> P; P a1[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); C c2(0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); swap(c1, c2); LIBCPP_ASSERT(c1.bucket_count() == 0); TC_ASSERT_EXPR(c1.size() == 0); TC_ASSERT_EXPR(c1.hash_function() == Hash(2)); TC_ASSERT_EXPR(c1.key_eq() == Compare(2)); TC_ASSERT_EXPR(c1.get_allocator() == Alloc(2)); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); TC_ASSERT_EXPR(c1.max_load_factor() == 2); TC_ASSERT_EXPR(c2.bucket_count() >= 6); TC_ASSERT_EXPR(c2.size() == 6); TC_ASSERT_EXPR(c2.find(1)->second == "one"); TC_ASSERT_EXPR(next(c2.find(1))->second == "four"); TC_ASSERT_EXPR(c2.find(2)->second == "two"); TC_ASSERT_EXPR(next(c2.find(2))->second == "four"); TC_ASSERT_EXPR(c2.find(3)->second == "three"); TC_ASSERT_EXPR(c2.find(4)->second == "four"); TC_ASSERT_EXPR(c2.hash_function() == Hash(1)); TC_ASSERT_EXPR(c2.key_eq() == Compare(1)); TC_ASSERT_EXPR(c2.get_allocator() == Alloc(1)); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); TC_ASSERT_EXPR(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef other_allocator<std::pair<const int, std::string> > Alloc; typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; typedef std::pair<int, std::string> P; P a1[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; P a2[] = { P(10, "ten"), P(20, "twenty"), P(30, "thirty"), P(40, "forty"), P(50, "fifty"), P(60, "sixty"), P(70, "seventy"), P(80, "eighty"), }; C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); swap(c1, c2); TC_ASSERT_EXPR(c1.bucket_count() >= 8); TC_ASSERT_EXPR(c1.size() == 8); TC_ASSERT_EXPR(c1.find(10)->second == "ten"); TC_ASSERT_EXPR(c1.find(20)->second == "twenty"); TC_ASSERT_EXPR(c1.find(30)->second == "thirty"); TC_ASSERT_EXPR(c1.find(40)->second == "forty"); TC_ASSERT_EXPR(c1.find(50)->second == "fifty"); TC_ASSERT_EXPR(c1.find(60)->second == "sixty"); TC_ASSERT_EXPR(c1.find(70)->second == "seventy"); TC_ASSERT_EXPR(c1.find(80)->second == "eighty"); TC_ASSERT_EXPR(c1.hash_function() == Hash(2)); TC_ASSERT_EXPR(c1.key_eq() == Compare(2)); TC_ASSERT_EXPR(c1.get_allocator() == Alloc(2)); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); TC_ASSERT_EXPR(c1.max_load_factor() == 2); TC_ASSERT_EXPR(c2.bucket_count() >= 6); TC_ASSERT_EXPR(c2.size() == 6); TC_ASSERT_EXPR(c2.find(1)->second == "one"); TC_ASSERT_EXPR(next(c2.find(1))->second == "four"); TC_ASSERT_EXPR(c2.find(2)->second == "two"); TC_ASSERT_EXPR(next(c2.find(2))->second == "four"); TC_ASSERT_EXPR(c2.find(3)->second == "three"); TC_ASSERT_EXPR(c2.find(4)->second == "four"); TC_ASSERT_EXPR(c2.hash_function() == Hash(1)); TC_ASSERT_EXPR(c2.key_eq() == Compare(1)); TC_ASSERT_EXPR(c2.get_allocator() == Alloc(1)); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); TC_ASSERT_EXPR(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); TC_ASSERT_EXPR(c2.max_load_factor() == 1); } TC_SUCCESS_RESULT(); return 0; }
DidYouKnowDialog::DidYouKnowDialog(QWidget *parent) : QDialog(parent) { setWindowTitle(tr("Le saviez-vous ?")); //setMinimumWidth(400); list << tr("<center><b>Bienvenue sur TuxFisher</b></center><br/>" "TuxFisher est un jeu de réflexion ou vous devez manger les fishs<br/>" "sans se faire écraser par les avalanches et sans se retrouver bloqué.<br/>" "Utilisez les touches directionnelles (up, down, gauche, droite) pour vous déplacer.<br/>" "La touche [Ret. Arrière] (au dessus de [Entrer]) permet d'annuler un déplacement.<br/>" "Amusez-vous bien."); list << tr("Si vous avez fait un mouvement que vous souhaitez annuler,\n" "appuyez sur la touche [Ret. Arrière] (au dessus de [Entrer])\n" "et vous reviendrez à votre ancienne position.\n" "Vous pouvez annuler jusqu'à 20 déplacements."); list << tr("TuxFisher est un clone libre et gratuit du jeu Mr Matt, \n" "développé par J. Andrzej Wrotniak en 1996.\n" "Mr Matt et TuxFisher sont des dérivés de Boulder Dash"); list << tr("Vous pouvez activer et désactiver la music du jeu par le menu Options.\n" "Le titre de la music du jeu est Acclimate de General Fuzz.\n"); list << tr("Vous aussi vous pouvez créer des jeux pour TuxFisher \n" "grâce à l'éditeur de jeu de TuxFisher.\n" "Une fois terminé, vous pouvez mettre en ligne vos créations\n" "et les partager avec la communauté."); list << tr("Vous pouvez choisir les graphismes par le menu Options->Graphisms.\n" "Vous pouvez créer vos propres graphismes en créant un répertoire\n" "avec le nom désiré dans le répertoire \"graphismes\" du jeu.\n" "Ce répertoire doit contenir les images pour chaque case."); list << tr("Vous pouvez choisir les bruitages par le menu Options->Sons\n" "Pour désactiver les bruitages: Options->Sons->Aucun Son\n" "Vous pouvez créer vos bruitages en créant un new répertoire\n" "dans le répertoire \"sons\" du jeu."); button_close = new QPushButton(tr("Fermer"), this); button_next = new QPushButton(tr("Suivant"), this); button_previous = new QPushButton(tr("Précédent"), this); checkbox_afficher = new QCheckBox(tr("Ne plus afficher"), this); label_image = new QLabel(this); label_image->setPixmap(QPixmap(":/ressources/mainwindow/saviezvous.png")); label_text = new QLabel(this); //label_text->setWordWrap(true); qsrand(QDateTime::currentDateTime().toTime_t()); index=(qrand()%(list.count()-1))+1; loadLabel(); //label->setAlignment(Qt::AlignCenter); QHBoxLayout *layout_labels = new QHBoxLayout; layout_labels->addWidget(label_text); layout_labels->addStretch(); layout_labels->addWidget(label_image); QHBoxLayout *layout_buttons = new QHBoxLayout; layout_buttons->addWidget(checkbox_afficher); layout_buttons->addStretch(); layout_buttons->addWidget(button_close); layout_buttons->addWidget(button_previous); layout_buttons->addWidget(button_next); QVBoxLayout *layout = new QVBoxLayout; layout->addLayout(layout_labels); layout->addLayout(layout_buttons); setLayout(layout); connect( button_close, SIGNAL(clicked()), this, SLOT(accept()) ); connect( button_next, SIGNAL(clicked()), this, SLOT(next()) ); connect( button_previous, SIGNAL(clicked()), this, SLOT(previous()) ); }
inline void Inter<I,J>::init(I& i0, J& j0) { i=i0; j=j0; next(); }