void PrescribedGradientBCWeak :: giveTractionElArcPos(size_t iElInd, double &oXiStart, double &oXiEnd) const { FloatArray xS, xE; giveTractionElCoord(iElInd, xS, xE); FloatArray xC; xC.beScaled(0.5, xS); xC.add(0.5, xE); int sideIndex = giveSideIndex(xC); const double nodeDistTol = 1.0e-15; ArcPosSortFunction3< bool >sortFunc(mLC, mUC, nodeDistTol, sideIndex); oXiStart = sortFunc.calcArcPos(xS); oXiEnd = sortFunc.calcArcPos(xE); }
void sort(FILE *fi,FILE *fo,void (*sortFunc)()) { int *num,i=0,j,max,chud; do{ printf("並べ替え方法を選択してください.\n|昇順---1 降順---2|"); scanf("%d",&chud); }while(!(chud==1 || chud==2)); num=(int *)calloc(getLine(fi),sizeof(int)); while(fscanf(fi,"%d",&num[i])!=EOF) i++; max=i; sortFunc(num,max,chud); for(i=0;i<max;i++){ fprintf(fo,"%d\n",num[i]); } }
void CRemoteTreeView::RefreshItem(wxTreeItemId parent, const CDirectoryListing& listing, bool will_select_parent) { SetItemImages(parent, false); wxTreeItemIdValue cookie; wxTreeItemId child = GetFirstChild(parent, cookie); if (!child || GetItemText(child).empty()) { DisplayItem(parent, listing); return; } CFilterManager filter; wxString const path = listing.path.GetPath(); wxArrayString dirs; for (unsigned int i = 0; i < listing.GetCount(); ++i) { if (!listing[i].is_dir()) continue; if (!filter.FilenameFiltered(listing[i].name, path, true, -1, false, 0, listing[i].time)) dirs.push_back(listing[i].name); } auto const& sortFunc = CFileListCtrlSortBase::GetCmpFunction(m_nameSortMode); dirs.Sort(sortFunc); bool inserted = false; child = GetLastChild(parent); wxArrayString::reverse_iterator iter = dirs.rbegin(); while (child && iter != dirs.rend()) { int cmp = sortFunc(GetItemText(child), *iter); if (!cmp) { CServerPath childPath = listing.path; childPath.AddSegment(*iter); CDirectoryListing subListing; if (m_pState->m_pEngine->CacheLookup(childPath, subListing) == FZ_REPLY_OK) { if (!GetLastChild(child) && HasSubdirs(subListing, filter)) AppendItem(child, _T(""), -1, -1); SetItemImages(child, false); } else SetItemImages(child, true); child = GetPrevSibling(child); ++iter; } else if (cmp > 0) { // Child no longer exists wxTreeItemId sel = GetSelection(); while (sel && sel != child) sel = GetItemParent(sel); wxTreeItemId prev = GetPrevSibling(child); if (!sel || will_select_parent) Delete(child); child = prev; } else if (cmp < 0) { // New directory CServerPath childPath = listing.path; childPath.AddSegment(*iter); CDirectoryListing subListing; if (m_pState->m_pEngine->CacheLookup(childPath, subListing) == FZ_REPLY_OK) { wxTreeItemId childItem = AppendItem(parent, *iter, 0, 2, 0); if (childItem) { SetItemImages(childItem, false); if (HasSubdirs(subListing, filter)) { AppendItem(childItem, _T(""), -1, -1); } } } else { wxTreeItemId childItem = AppendItem(parent, *iter, 1, 3, 0); if (childItem) { SetItemImages(childItem, true); } } ++iter; inserted = true; } } while (child) { // Child no longer exists wxTreeItemId sel = GetSelection(); while (sel && sel != child) sel = GetItemParent(sel); wxTreeItemId prev = GetPrevSibling(child); if (!sel || will_select_parent) Delete(child); child = prev; } while (iter != dirs.rend()) { CServerPath childPath = listing.path; childPath.AddSegment(*iter); CDirectoryListing subListing; if (m_pState->m_pEngine->CacheLookup(childPath, subListing) == FZ_REPLY_OK) { wxTreeItemId childItem = AppendItem(parent, *iter, 0, 2, 0); if (childItem) { SetItemImages(childItem, false); if (HasSubdirs(subListing, filter)) { AppendItem(childItem, _T(""), -1, -1); } } } else { wxTreeItemId childItem = AppendItem(parent, *iter, 1, 3, 0); if (childItem) { SetItemImages(childItem, true); } } ++iter; inserted = true; } if (inserted) SortChildren(parent); }
void CLocalTreeView::RefreshListing() { wxLogNull nullLog; const wxString separator = wxFileName::GetPathSeparator(); std::list<t_dir> dirsToCheck; #ifdef __WXMSW__ int prevErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); wxTreeItemIdValue tmp; for (auto child = GetFirstChild(m_drives, tmp); child; child = GetNextSibling(child)) { if (IsExpanded(child)) { wxString drive = GetItemText(child); int pos = drive.Find(_T(" ")); if (pos != -1) drive = drive.Left(pos); t_dir dir; dir.dir = drive + separator; dir.item = child; dirsToCheck.push_back(dir); } } #else t_dir dir; dir.dir = separator; dir.item = GetRootItem(); dirsToCheck.push_back(dir); #endif CFilterManager filter; while (!dirsToCheck.empty()) { t_dir dir = dirsToCheck.front(); dirsToCheck.pop_front(); // Step 1: Check if directory exists fz::local_filesys local_filesys; if (!local_filesys.begin_find_files(fz::to_native(dir.dir), true)) { // Dir does exist (listed in parent) but may not be accessible. // Recurse into children anyhow, they might be accessible again. wxTreeItemIdValue value; for (auto child = GetFirstChild(dir.item, value); child; child = GetNextSibling(child)) { t_dir subdir; subdir.dir = dir.dir + GetItemText(child) + separator; subdir.item = child; dirsToCheck.push_back(subdir); } continue; } // Step 2: Enumerate subdirectories on disk and sort them std::vector<wxString> dirs; fz::native_string file; static int64_t const size(-1); bool was_link; bool is_dir; int attributes; fz::datetime date; while (local_filesys.get_next_file(file, was_link, is_dir, 0, &date, &attributes)) { if (file.empty()) { wxGetApp().DisplayEncodingWarning(); continue; } wxString file_wx = file; if (filter.FilenameFiltered(file_wx, dir.dir, true, size, true, attributes, date)) continue; dirs.push_back(file_wx); } auto const& sortFunc = CFileListCtrlSortBase::GetCmpFunction(m_nameSortMode); std::sort(dirs.begin(), dirs.end(), [&](auto const& lhs, auto const& rhs) { return sortFunc(lhs, rhs) < 0; }); bool inserted = false; // Step 3: Merge list of subdirectories with subtree. wxTreeItemId child = GetLastChild(dir.item); auto iter = dirs.rbegin(); while (child || iter != dirs.rend()) { int cmp; if (child && iter != dirs.rend()) #ifdef __WXMSW__ cmp = GetItemText(child).CmpNoCase(*iter); #else cmp = GetItemText(child).Cmp(*iter); #endif else if (child) cmp = 1; else cmp = -1; if (!cmp) { // Found item with same name. Mark it for further processing if (!IsExpanded(child)) { wxString path = dir.dir + *iter + separator; if (!CheckSubdirStatus(child, path)) { t_dir subdir; subdir.dir = path; subdir.item = child; dirsToCheck.push_front(subdir); } } else { t_dir subdir; subdir.dir = dir.dir + *iter + separator; subdir.item = child; dirsToCheck.push_front(subdir); } child = GetPrevSibling(child); ++iter; } else if (cmp > 0) { // Subdirectory currently in tree no longer exists. // Delete child from tree, unless current selection // is in the subtree. wxTreeItemId sel = GetSelection(); while (sel && sel != child) sel = GetItemParent(sel); wxTreeItemId prev = GetPrevSibling(child); if (!sel) Delete(child); child = prev; } else if (cmp < 0) { // New subdirectory, add treeitem wxString fullname = dir.dir + *iter + separator; wxTreeItemId newItem = AppendItem(dir.item, *iter, GetIconIndex(iconType::dir, fullname), #ifdef __WXMSW__ -1 #else GetIconIndex(iconType::opened_dir, fullname) #endif ); CheckSubdirStatus(newItem, fullname); ++iter; inserted = true; } } if (inserted) SortChildren(dir.item); }