void Ctrl::DndTargets(GdkDragContext *context) { static Index<String> text_targets; static Index<String> image_targets; ONCELOCK { GtkTargetList *target_list = gtk_target_list_new (NULL, 0); gtk_target_list_add_text_targets (target_list, 0); ToIndex(target_list, text_targets); GtkTargetList *target_list2 = gtk_target_list_new (NULL, 0); gtk_target_list_add_image_targets (target_list2, 0, TRUE); ToIndex(target_list2, image_targets); } dnd_targets.Clear(); dnd_text_target.Clear(); for(GList *list = gdk_drag_context_list_targets(context); list; list = g_list_next (list)) { String g = gdk_atom_name((GdkAtom)list->data); if(text_targets.Find(g) >= 0) { dnd_targets.Add("text"); if(dnd_text_target.IsEmpty()) dnd_text_target = g; } else if(image_targets.Find(g) >= 0) { dnd_targets.Add("image"); if(dnd_image_target.IsEmpty()) dnd_image_target = g; } else dnd_targets.Add(g); } }
String MakeBuild::OutDir(const Index<String>& cfg, const String& package, const VectorMap<String, String>& bm, bool use_target) { Index<String> excl; excl.Add(bm.Get("BUILDER", "GCC")); excl.Add("MSC"); LocalHost().AddFlags(excl); Vector<String> x; bool dbg = cfg.Find("DEBUG_FULL") >= 0 || cfg.Find("DEBUG_MINIMAL") >= 0; if(cfg.Find("DEBUG") >= 0) { excl.Add("BLITZ"); if(cfg.Find("BLITZ") < 0) x.Add("NOBLITZ"); } else if(dbg) x.Add("RELEASE"); if(use_target) excl.Add("MAIN"); for(int i = 0; i < cfg.GetCount(); i++) if(excl.Find(cfg[i]) < 0) x.Add(cfg[i]); Sort(x); for(int i = 0; i < x.GetCount(); i++) x[i] = InitCaps(x[i]); String outdir = GetVar("OUTPUT"); if(output_per_assembly) outdir = AppendFileName(outdir, GetVarsName()); if(!use_target) outdir = AppendFileName(outdir, package); outdir = AppendFileName(outdir, GetFileTitle(method) + "." + Join(x, ".")); outdir = Filter(outdir, CharFilterSlash); return outdir; }
void CodeBrowser::Load() { String find = ToUpper((String)~search); String match = ToUpper((String)~search_scope); String pm = GetPm(); Vector<String> txt; Vector<Value> ndx; Index<int> fi; Index<String> fs; for(int i = 0; i < CodeBase().GetCount(); i++) { String s = CodeBase().GetKey(i); const Array<CppItem>& n = CodeBase()[i]; if(s.GetCount()) if(MatchCib(s, match) && (MatchCib(s, find) || HasItem(n, find)) && MatchPm(n, pm)) { txt.Add(s); ndx.Add(s); } for(int i = 0; i < n.GetCount(); i++) { int f = n[i].file; if(fi.Find(f) < 0) { String s = GetFileText(GetSourceFilePath(f)); if(s.StartsWith(pm) && MatchCib(s, match) && (IsNull(find) || MatchCib(s, find) || n[i].uname.StartsWith(find))) { txt.Add(s); ndx.Add(f); fs.Add(s); fi.Add(f); } } } } const Workspace& wspc = GetIdeWorkspace(); for(int i = 0; i < wspc.GetCount(); i++) { String pn = wspc[i]; const Package& p = wspc.GetPackage(i); String pp = PackageDirectory(pn); for(int j = 0; j < p.GetCount(); j++) if(!p[j].separator) { String fn = AppendFileName(pp, p[j]); String s = GetFileText(AppendFileName(pn, p[j])); if(fs.Find(s) < 0 && (IsNull(find) || MatchCib(s, find)) && MatchCib(s, match) && MatchPm(fn, pm)) { int f = GetSourceFileIndex(SourcePath(pn, p[j])); txt.Add(s); ndx.Add(f); fs.Add(s); } } } IndexSort(txt, ndx, ScopeLess()); Value key = scope.GetKey(); int sc = scope.GetCursorSc(); scope.Clear(); for(int i = 0; i < txt.GetCount(); i++) scope.Add(IsString(ndx[i]) ? ndx[i] : Null, txt[i], ndx[i]); if(scope.FindSetCursor(key)) scope.ScCursor(sc); // clear.Enable(IsSearch()); }
bool Thread::Run(Callback _cb) { LLOG("Thread::Run"); AtomicInc(sThreadCount); if(!threadr) #ifndef CPU_BLACKFIN threadr = sMain = true; #else { threadr = true; //the sMain replacement #ifdef PLATFORM_POSIX pthread_t thid = pthread_self(); vm.Enter(); if(threadsv.Find(thid) < 0){ //thread not yet present, mark present threadsv.Add(thid); } else RLOG("BUG: Multiple Add in Mt.cpp"); vm.Leave(); #endif } #endif Detach(); Callback *cb = new Callback(_cb); #ifdef PLATFORM_WIN32 handle = (HANDLE)_beginthreadex(0, 0, sThreadRoutine, cb, 0, ((unsigned int *)(&thread_id))); #endif #ifdef PLATFORM_POSIX if(pthread_create(&handle, 0, sThreadRoutine, cb)) handle = 0; #endif return handle; }
bool IncludesFile(const String& parent_path, const String& header_path) { LTIMING("IncludesFile"); int pi = sSrcFile.Find(parent_path); int i = sSrcFile.Find(header_path); return pi >= 0 && i >= 0 && sIncludes.Find(MAKEQWORD(pi, i)) >= 0; }
PPMacro *FindPPMacro(const String& id, Index<int>& segment_id, int& segmenti) { Index<int> undef; PPMacro *r; int best; for(int pass = 0; pass < 2; pass++) { r = NULL; best = segmenti; int line = -1; int q = sAllMacros.Find(id); while(q >= 0) { PPMacro& m = sAllMacros[q]; if(m.macro.IsUndef()) { if(pass == 0 && segment_id.Find(m.segment_id) >= 0) undef.FindAdd(m.segment_id); // cancel out undefined macro... } else if(pass == 0 || m.segment_id == 0 || undef.Find(m.undef_segment_id) < 0) { int si = m.segment_id == 0 ? INT_MAX : segment_id.Find(m.segment_id); // defs macros always override if(si > best || si >= 0 && si == best && m.line > line) { best = si; line = m.line; r = &m; } } q = sAllMacros.FindNext(q); } if(undef.GetCount() == 0) break; } segmenti = best; return r; }
void Ide::ExportProject(const String& ep, bool all, bool gui, bool deletedir) { SaveFile(false); ::Workspace wspc; wspc.Scan(main); Index<String> used; HdependClearDependencies(); for(int i = 0; i < wspc.GetCount(); i++) { const Package& p = wspc.GetPackage(i); String pn = wspc[i]; for(int j = 0; j < p.GetCount(); j++) { const Package::File& f = p[j]; if(!f.separator) { String p = SourcePath(pn, f); used.FindAdd(p); Vector<String> d = HdependGetDependencies(p); for(int q = 0; q < d.GetCount(); q++) used.FindAdd(d[q]); for(int q = 0; q < f.depends.GetCount(); q++) used.FindAdd(SourcePath(pn, f.depends[q].text)); } } } if(FileExists(ep)) { if(gui && !PromptYesNo(DeQtf(ep) + " is existing file.&" "Do you want to delete it?")) return; FileDelete(ep); } if(deletedir && DirectoryExists(ep)) { if(gui && !PromptYesNo(DeQtf(ep) + " is existing directory.&" "Do you want to replace it?")) return; DeleteFolderDeep(ep); } Progress pi("Exporting project"); pi.SetTotal(wspc.GetCount()); for(int i = 0; i < wspc.GetCount(); i++) { if(gui && pi.StepCanceled()) return; CopyFolder(AppendFileName(ep, wspc[i]), PackageDirectory(wspc[i]), used, all, true); } Vector<String> upp = GetUppDirs(); for(int i = 0; i < upp.GetCount(); i++) { if(gui && pi.StepCanceled()) return; String d = upp[i]; FindFile ff(AppendFileName(d, "*")); while(ff) { if(ff.IsFile()) { String fn = ff.GetName(); String path = AppendFileName(d, fn); if(all || used.Find(path) >= 0) CopyFile(AppendFileName(ep, fn), path, true); } ff.Next(); } CopyFolder(AppendFileName(ep, wspc[i]), PackageDirectory(wspc[i]), used, all, true); } ExportMakefile(ep); }
void IndexClient() { /// .Index and client types /// In order to store elements to `Index`, they type must be `Moveable`, have deep copy and /// defined the `operator==` and a `GetHashValue` function or method to compute the hash /// code. It is recommended to use `CombineHash` to combine hash values of types that /// already provide `GetHashValue`: struct Person : Moveable<Person> { String name; String surname; unsigned GetHashValue() const { return CombineHash(name, surname); } bool operator==(const Person& b) const { return name == b.name && surname == b.surname; } Person(String name, String surname) : name(name), surname(surname) {} Person() {} }; Index<Person> p; p.Add(Person("John", "Smith")); p.Add(Person("Paul", "Carpenter")); p.Add(Person("Carl", "Engles")); DUMP(p.Find(Person("Paul", "Carpenter"))); /// }
void Ctrl::DndTargets(GdkDragContext *context) { static Index<String> text_targets; static Index<String> image_targets; static Index<String> files_targets; ONCELOCK { GtkTargetList *target_list = gtk_target_list_new (NULL, 0); gtk_target_list_add_text_targets(target_list, 0); ToIndex(target_list, text_targets); GtkTargetList *target_list2 = gtk_target_list_new (NULL, 0); gtk_target_list_add_image_targets(target_list2, 0, TRUE); ToIndex(target_list2, image_targets); GtkTargetList *target_list3 = gtk_target_list_new (NULL, 0); gtk_target_list_add_uri_targets(target_list3, 0); ToIndex(target_list3, files_targets); } dnd_targets.Clear(); dnd_text_target.Clear(); #if GTK_CHECK_VERSION(2,22,0) // No drag&drop support before 2.22, sorry... for(GList *list = gdk_drag_context_list_targets(context); list; list = g_list_next (list)) { String g = gdk_atom_name((GdkAtom)list->data); if(text_targets.Find(g) >= 0) { dnd_targets.Add("text"); if(dnd_text_target.IsEmpty()) dnd_text_target = g; } else if(image_targets.Find(g) >= 0) { dnd_targets.Add("image"); if(dnd_image_target.IsEmpty()) dnd_image_target = g; } else if(files_targets.Find(g) >= 0) { dnd_targets.Add("files"); if(dnd_files_target.IsEmpty()) dnd_files_target = g; } else dnd_targets.Add(g); } #endif }
void LogSyntax::Highlight(const wchar *s, const wchar *end, HighlightOutput& hls, CodeEditor *editor, int line, int pos) { const HlStyle& ink = hl_style[INK_NORMAL]; HlStyle err = hl_style[INK_ERROR]; err.bold = true; bool hl_line = false; bool sep_line = false; while(s < end) { int c = *s; const wchar *s0 = s; if(s + 3 <= end && (Is3(s, '-') || Is3(s, '*') || Is3(s, '=') || Is3(s, '+') || Is3(s, '#') || Is3(s, ':') || Is3(s, '%') || Is3(s, '$'))) sep_line = true; if(IsDigit(c)) s = HighlightNumber(hls, s, thousands_separator, false, false); else if(c == '\'' || c == '\"') { s++; for(;;) { if(s >= end) { hls.Put(1, ink); s = s0 + 1; break; } if(*s == c) { s++; hls.Put((int)(s - s0), hl_style[INK_CONST_STRING]); break; } s += 1 + (s[0] == '\\' && s[1] == c); } } else if(IsAlpha(c) || c == '_') { static Index<String> rws; ONCELOCK { rws << "error" << "errors" << "warning" << "warnings" << "failed" << "exit" << "fatal" << "failure" << "rejected"; } String w; while(s < end && IsAlNum(*s) || *s == '_') w.Cat(ToLower(*s++)); bool hl = rws.Find(w) >= 0; hls.Put(w.GetCount(), hl ? err : ink); hl_line = hl_line || hl; } else { bool hl = findarg(c, '[', ']', '(', ')', ':', '-', '=', '{', '}', '/', '<', '>', '*', '#', '@', '\\', '.') >= 0; hls.Put(1, hl ? hl_style[INK_OPERATOR] : ink); s++; } }
void RemoveWithParent(const String& id, Vector<int>& remove) { for(;;) { int q = parent_ids.Find(id); if(q < 0) break; RemoveWithParent(ids[q]); } ids.Unlink(q); remove.Add(q); parent_ids.Unlinke(q); }
void LoadFonts(DropList *face, Index<String>& fni, bool fixed) { for(int i = 0; i < Font::GetFaceCount(); i++) if(!!(Font::GetFaceInfo(i) & Font::FIXEDPITCH) == fixed) { String n = Font::GetFaceName(i); if(fni.Find(n) < 0) { fni.Add(n); face->Add(i, n); } } }
void RichQtfParser::FinishOldTable() { FinishCell(); Index<int> pos; Vector<int> srow; RichTable& t = Table(); Tab& b = table.Top(); for(int i = 0; i < t.GetRows(); i++) { int& s = srow.Add(); s = 0; int nx = b.rown[i]; for(int j = 0; j < nx; j++) s += t.GetSpan(i, j).cx; int xn = 0; for(int j = 0; j < nx; j++) { pos.FindAdd(xn * 10000 / s); xn += t.GetSpan(i, j).cx; } } Vector<int> h = pos.PickKeys(); if(h.GetCount() == 0) Error("table"); Sort(h); pos = pick(h); pos.Add(10000); RichTable tab; tab.SetFormat(t.GetFormat()); for(int i = 0; i < pos.GetCount() - 1; i++) { tab.AddColumn(pos[i + 1] - pos[i]); } for(int i = 0; i < t.GetRows(); i++) { int s = srow[i]; int nx = b.rown[i]; int xn = 0; int xi = 0; for(int j = 0; j < nx; j++) { Size span = t.GetSpan(i, j); xn += span.cx; int nxi = pos.Find(xn * 10000 / s); tab.SetPick(i, xi, t.GetPick(i, j)); tab.SetFormat(i, xi, t.GetFormat(i, j)); tab.SetSpan(i, xi, max(span.cy - 1, 0), nxi - xi - 1); xi = nxi; } } table.Drop(); if(table.GetCount()) table.Top().text.CatPick(pick(tab)); else target.CatPick(pick(tab)); oldtab = false; }
Thread::~Thread() { Detach(); #ifdef CPU_BLACKFIN #ifdef PLATFORM_POSIX //the static destruction replacement pthread_t thid = pthread_self(); vm.Enter(); int id = threadsv.Find(thid); if(id >= 0) threadsv.Remove(id); vm.Leave(); #endif #endif }
void GatherMethods(const String& type, VectorMap<String, bool>& inherited, bool g, Index<String>& done) { if(done.Find(type) >= 0) return; done.Add(type); int q = CodeBase().Find(type); if(q < 0) return; const Array<CppItem>& n = CodeBase()[q]; Index<String> set; for(int i = 0; i < n.GetCount(); i++) { const CppItem& m = n[i]; if(set.Find(m.qitem) < 0) { set.Add(m.qitem); if(m.IsType()) { Vector<String> base = Split(m.qptype, ';'); for(int i = 0; i < base.GetCount(); i++) GatherMethods(base[i], inherited, true, done); } if(m.IsCode() && g) { bool& virt = inherited.GetAdd(m.qitem); virt = virt || m.virt; } } } }
void SelectPackageDlg::SyncList() { String n = GetCurrentName(); int asc = alist.GetScroll(); int csc = clist.GetSbPos(); packages.Clear(); String s = ~search; int f = ~filter; Index<String> added; for(int i = 0; i < min((f & FIRST) ? 1 : data.GetCount(), data.GetCount()); i++) { const ArrayMap<String, PkData>& nest = data[i]; for(int i = 0; i < nest.GetCount(); i++) { const PkData& d = nest[i]; if(!nest.IsUnlinked(i) && d.ispackage && (!(f & MAIN) || d.main) && ToUpper(d.package + d.description + d.nest).Find(s) >= 0 && added.Find(d.package) < 0) { packages.Add() = d; added.Add(d.package); } } } Sort(packages); alist.Clear(); clist.Clear(); ListCursor(); static PackageDisplay pd, bpd; bpd.fnt.Bold(); for(int i = 0; i < packages.GetCount(); i++) { const PkInfo& pkg = packages[i]; Image icon = pkg.icon; if(IsNull(icon)) icon = pkg.main ? IdeImg::MainPackage() : IdeImg::Package(); clist.Add(pkg.package, icon); alist.Add(pkg.package, pkg.nest, pkg.description, icon); alist.SetDisplay(alist.GetCount() - 1, 0, pkg.main ? bpd : pd); } if(!alist.FindSetCursor(n)) alist.GoBegin(); if(!clist.FindSetCursor(n) && clist.GetCount()) clist.SetCursor(0); alist.ScrollTo(asc); clist.SetSbPos(csc); alist.HeaderTab(0).SetText("Package (" + AsString(alist.GetCount()) + ")"); }
String HelpTopicTextModuleTitle(String space, String nesting, String topic, Index<String>& used_names) { String title; AdjustCat(title, space, 8); CatUnder(title); if(!IsNull(nesting)) { AdjustCat(title, nesting, 16); CatUnder(title); } AdjustCat(title, topic, 32); String base = title; int i = 0; while(used_names.Find(title) >= 0) title = base + FormatInt(++i); return title; }
String Parser::SimpleType() { if(Key(tk_struct) || Key(tk_class) || Key(tk_union) || Key(tk_enum) || Key(tk_typename)) { if(lex.IsId() || lex == t_dblcolon) Name(); if(lex == '{') EatBody(); return Null; } if(Key(tk_bool) || Key(tk_float) || Key(tk_double) || Key(tk_void)) return Null; bool sgn = Key(tk_signed) || Key(tk_unsigned); if(Key(tk_long)) { Key(tk_int); return Null; } if(Key(tk_short)) { Key(tk_int); return Null; } if(Key(tk_int) || Key(tk_char) || Key(tk___int8) || Key(tk___int16) || Key(tk___int32) || Key(tk___int64)) return Null; if(sgn) return Null; const char *p = lex.Pos(); int cs = 0; Index<int> cix; Key(t_dblcolon); Check(lex.IsId(), "Name expected"); while(lex.IsId()) { if(cix.Find(lex) >= 0) cs++; else cix.Add(lex); ++lex; if(lex == '<') TemplateParams(); if(Key(t_dblcolon)) Key('~'); else break; } return cs ? String(p, lex.Pos()) : String(); }
void Load(const char *dir) { Index<String> exist; FindFile ff(AppendFileName(dir, "*.tpp")); while(ff) { if(ff.IsFolder()) { String s = GetFileTitle(ff.GetName()); group.Add(s, AttrText(TppName(s)).SetFont(StdFont().Bold())); exist.Add(s); } ff.Next(); } static const char *h[4] = { "src.tpp", "srcdoc.tpp", "srcimp.tpp", "app.tpp" }; for(int i = 0; i < __countof(h); i++) { String s = GetFileTitle(h[i]); if(exist.Find(s) < 0) group.Add(s, TppName(s) + " (new)"); } group.Add(Null, "<other new>"); group.GoBegin(); }
bool Thread::IsMain() //the calling thread is the Main Thread or the only one in App { #ifndef CPU_BLACKFIN return !threadr || sMain; #else if(!threadr) return true; #ifdef PLATFORM_POSIX //the sMain replacement pthread_t thid = pthread_self(); vm.Enter(); if(threadsv.Find(thid) >= 0) { vm.Leave(); return true; } vm.Leave(); #endif return false; #endif }
Vector<String> HelpTopicEnumTextFolders() { Index<String> out; const HelpTopicInfoMap& map = HelpTopicMap(); for(int i = 0; i < map.GetCount(); i++) { String drl = map.GetKey(i); String space, nesting, topic; HelpParseDPP(drl, space, nesting, topic); const HelpTopicInfo& info = map[i]; String folder = GetTextFolder(nesting, info.decl_module, info.text_folder); if(out.Find(folder) < 0) { out.Add(folder); LLOG("HelpTopicSave: folder = " << folder); } } Vector<String> list = out.PickKeys(); Sort(list, StdLess<String>()); return list; }
void WorkspaceWork::SavePackage() { if(IsNull(actualpackage) || actualpackage == METAPACKAGE) return; InvalidatePackageInfo(actualpackage); String pp = PackagePathA(actualpackage); RealizePath(pp); if(organizer && backup.Find(pp) < 0) { Backup& b = backup.Add(pp); FindFile ff(pp); if(ff) { b.time = ff.GetLastWriteTime(); b.data = LoadFile(pp); } else b.data = String::GetVoid(); } actual.Save(pp); String init; String mnm = Filter('_' + actualpackage + "_icpp_init_stub", CharFilterMacro); init << "#ifndef " << mnm << "\r\n"; init << "#define " << mnm << "\r\n"; Index<String> once; for(int i = 0; i < actual.uses.GetCount(); i++) { String u = actual.uses[i].text; if(once.Find(u) < 0) { once.Add(u); init << "#include \"" << actual.uses[i].text << "/init\"\r\n"; } } for(int i = 0; i < actual.GetCount(); i++) { String f = actual[i]; if(ToLower(GetFileExt(f)) == ".icpp") init << "#define BLITZ_INDEX__ " << "F" << MD5String(f) << "\r\n" << "#include \"" << f << "\"\r\n" << "#undef BLITZ_INDEX__\r\n"; } init << "#endif\r\n"; SaveChangedFile(SourcePath(actualpackage, "init"), init); }
void Ide::ConditionalBreak() { if(editfile.IsEmpty() || designer) return; int ln = editor.GetCursorLine(); String brk = editor.GetBreakpoint(ln); if(brk == "\xe") brk = "1"; Index<String> cfg = PackageConfig(IdeWorkspace(), 0, GetMethodVars(method), mainconfigparam, *CreateHost(true), *CreateBuilder(~CreateHostRunDir())); #ifdef COMPILER_MSC if(cfg.Find("MSC") >= 0) { if(EditPDBExpression("Conditional breakpoint", brk, NULL)) editor.SetBreakpoint(ln, brk); } else #endif if(EditText(brk, "Conditional breakpoint", "Condition")) editor.SetBreakpoint(ln, brk); editor.RefreshFrame(); }
void DocDir::Refresh(const String& package) { FindFile ff(DocFile(package, "dir.h")); if(!ff) { RebuildDir(package); return; } FileTime dirtime = ff.GetLastWriteTime(); ff.Search(DocFile(package, "links")); if(ff && ff.GetLastWriteTime() > dirtime) { RebuildDir(package); return; } const ArrayMap<DocKey, Entry>& p = dir.GetAdd(package); Index<String> dfn; for(int i = 0; i < p.GetCount(); i++) if(p[i].type == NORMAL || p[i].type == EXTERNAL) dfn.Add(p[i].text); ff.Search(DocFile(package, "*.dpp")); int count = 0; while(ff) { DocKey key; if(dfn.Find(ff.GetName()) >= 0) if(ff.GetLastWriteTime() > dirtime) { RebuildDir(package); return; } else count++; else if(ReadDocHeader(DocFile(package, ff.GetName()), key) >= 0) { RebuildDir(package); return; } ff.Next(); } if(count != dfn.GetCount()) RebuildDir(package); }
bool Speller::CheckOld(const WString& wstr) const { int len = wstr.GetLength(); if(len == 1) return true; if(len < 64) { String w = FromUnicode(wstr, charset); String wl = FromUnicode(ToLower(wstr), charset); int i; if(len == 2) { w.Cat(127); wl.Cat(127); } i = line.Find(ToLower(wl[0], charset) + (ToLower(wl[1], charset) << 8) + (ToLower(wl[2], charset) << 16)); if(i >= 0) { const byte *s = line[i].begin; const byte *e = line[i].end; String q; while(s < e) if(*s < dict) { if(q == w || q == wl) return true; q.Trim(*s++); } else { ASSERT(*s >= dict); const char *x = voc[(int)*s++ - dict]; q.Cat(x); } if(q == w || q == wl) return true; } } return user.Find(wstr) >= 0;; }
void GetAllMacros(Md5Stream& md5, const String& id, Index<int>& segment_id) { Vector< Tuple2<int, int> > pos; Vector<const CppMacro *> def; String r; int q = sAllMacros.Find(id); while(q >= 0) { const PPMacro& m = sAllMacros[q]; int si = segment_id.Find(m.segment_id); if(si >= 0) { pos.Add(MakeTuple(si, m.line)); def.Add(&m.macro); } q = sAllMacros.FindNext(q); } IndexSort(pos, def); int n = def.GetCount(); if(n) { md5.Put(&n, sizeof(int)); md5.Put(id); for(int i = 0; i < n; i++) md5.Put(def[i]->md5, 16); } }
void SweepPPFiles(const Index<String>& keep) { Index<int> pp_segment_id; int unlinked_count = 0; for(int i = 0; i < sPPfile.GetCount(); i++) if(sPPfile.IsUnlinked(i)) unlinked_count++; else if(keep.Find(sPPfile.GetKey(i)) < 0) { unlinked_count++; sPPfile.Unlink(i); } else { const PPFile& p = sPPfile[i]; for(int j = 0; j < p.item.GetCount(); j++) pp_segment_id.FindAdd(p.item[j].segment_id); } if(unlinked_count > sPPfile.GetCount() / 2) { CleanPP(); return; } unlinked_count = 0; for(int i = 0; i < sAllMacros.GetCount(); i++) { if(sAllMacros.IsUnlinked(i)) unlinked_count++; else if(sAllMacros[i].segment_id && pp_segment_id.Find(sAllMacros[i].segment_id) < 0) { sAllMacros.Unlink(i); unlinked_count++; } if(unlinked_count > sAllMacros.GetCount() / 2) { CleanPP(); return; } } }
void IndexTutorial() { /// .`Index` /// `Index` is the the foundation of all U++ associative operations and is one of defining /// features of U++. /// `Index` is a container very similar to the plain `Vector` (it is random access array of /// elements with fast addition at the end) with one additional feature - it is able to fast /// retrieve position of element with required value using `Find` method: Index<String> ndx; ndx.Add("alfa"); ndx.Add("beta"); ndx.Add("gamma"); ndx.Add("delta"); ndx.Add("kappa"); DUMP(ndx); DUMP(ndx.Find("beta")); /// If element is not present in `Index`, `Find` returns a negative value: DUMP(ndx.Find("something")); /// Any element can be replaced using `Set` method: ndx.Set(1, "alfa"); DUMP(ndx); /// If there are more elements with the same value, they can be iterated using `FindNext` /// method: int fi = ndx.Find("alfa"); while(fi >= 0) { DUMP(fi); fi = ndx.FindNext(fi); } /// `FindAdd` method retrieves position of element like `Find`, but if element is not /// present in `Index`, it is added: DUMP(ndx.FindAdd("one")); DUMP(ndx.FindAdd("two")); DUMP(ndx.FindAdd("three")); DUMP(ndx.FindAdd("two")); DUMP(ndx.FindAdd("three")); DUMP(ndx.FindAdd("one")); /// Removing elements from random access sequence tends to be expensive, that is why rather /// than remove, `Index` supports `Unlink` and `UnlinkKey` operations, which retain the /// element in `Index` but make it invisible for `Find` operation: ndx.Unlink(2); ndx.UnlinkKey("kappa"); DUMP(ndx.Find(ndx[2])); DUMP(ndx.Find("kappa")); /// You can test whether element at given position is unlinked using `IsUnlinked` method DUMP(ndx.IsUnlinked(1)); DUMP(ndx.IsUnlinked(2)); /// Unlinked positions can be reused by `Put` method: ndx.Put("foo"); DUMP(ndx); DUMP(ndx.Find("foo")); /// You can also remove all unlinked elements from `Index` using `Sweep` method: ndx.Sweep(); DUMP(ndx); /// Operations directly removing or inserting elements of Index are expensive, but /// available too: ndx.Remove(1); DUMP(ndx); /// ndx.RemoveKey("two"); DUMP(ndx); /// ndx.Insert(0, "insert"); DUMP(ndx); /// PickKeys operation allows you to obtain Vector of elements of Index in low /// constant time operation (while destroying source Index) Vector<String> d = ndx.PickKeys(); DUMP(d); /// Pick-assigning `Vector` to `Index` is supported as well: d[0] = "test"; ndx = pick(d); DUMP(ndx); /// }
void Select(const String& id) { selected = ids.Find(id); }
void TopicEditor::FixTopic() { String nest; if(!EditText(nest, "Fix topic", "Nest")) return; CppBase& base = CodeBase(); int q = base.Find(nest); if(q < 0) { Exclamation("Nest not found"); return; } Array<CppItem>& n = base[q]; Index<String> natural; Vector<String> link; for(int i = 0; i < n.GetCount(); i++) { const CppItem& m = n[i]; String nat; if(m.virt) nat << "virtual "; if(m.kind == CLASSFUNCTION || m.kind == CLASSFUNCTIONTEMPLATE) nat << "static "; nat << m.natural; natural.Add(nat); link.Add(MakeCodeRef(nest, n[i].qitem)); } RichText result; const RichText& txt = editor.Get(); bool started = false; int l, h; if(editor.GetSelection(l, h)) { l = txt.FindPart(l); h = txt.FindPart(h); } else { l = 0; h = txt.GetPartCount(); } for(int i = 0; i < txt.GetPartCount(); i++) if(txt.IsPara(i)) { RichPara p = txt.Get(i); if(i >= l && i < h) { WString h = p.GetText(); String nat; const wchar *s = h; while(*s) if(*s == 160 || *s == ' ') { nat.Cat(' '); while(*s == 160 || *s == ' ') s++; } else nat.Cat(*s++); int q = nat.GetCount() ? natural.Find(nat) : -1; if(q >= 0) { started = true; const CppItem& m = n[q]; RichText h = ParseQTF(styles + ("[s7; &]" + CreateQtf(link[q], n[q].name, m, GetLang(), true))); if(h.GetPartCount()) h.RemovePart(h.GetPartCount() - 1); result.CatPick(pick(h)); } else if(!started || p.GetLength()) result.Cat(p); } else result.Cat(p); } else { RichTable b; b <<= txt.GetTable(i); result.CatPick(pick(b)); } RichPara empty; result.Cat(empty); editor.BeginOp(); editor.SetSelection(0, txt.GetLength()); editor.PasteText(result); }