コード例 #1
0
ファイル: OnlyList.CPP プロジェクト: SHIYUENING/topace
	int OnlyList<T>::Add(const T &data)
	{
		int pos;
		data_struct *ds;

		if(data_list.Count<=0)
		{
			ds=data_list.Append();

			pos=0;
		}
		else
		{
			pos=Find(data);

			if(pos!=-1)						//数据已存在
				return pos;

			pos=FindPos(data);

			ds=data_list.Insert(pos);
		}

		ds->flag	=data;

        return(pos);
	}
コード例 #2
0
ファイル: IndexData.CPP プロジェクト: SHIYUENING/topace
	T &_IndexData<F,T,DataStruct>::Add(const F &flag)
	{
		DataStruct *ds=data_list.Insert(FindPos(flag));

		ds->flag	=flag;

		return ds->data;
	}
コード例 #3
0
ファイル: IndexData.CPP プロジェクト: SHIYUENING/topace
	DataStruct *_IndexData<F,T,DataStruct>::Add(const F &flag,const T &data)
	{
		DataStruct *ds=data_list.Insert(FindPos(flag));

		ds->flag	=flag;
		ds->data	=data;

		return(ds);
	}
コード例 #4
0
ファイル: QKSORT.CPP プロジェクト: Rexniu/DataStructure
void QuickSort(int *a, int low,int high)
{
    int pos;
    if(low < high)
    {
        pos = FindPos(a,low,high);
        QuickSort(a,low,pos-1);
        QuickSort(a,pos+1,high);
    }
}
コード例 #5
0
ファイル: QuickSort.c プロジェクト: caizhenzhen/Lean
void QuickSort(int array[], int low, int high)
{
  int pos;

 if(low<high) 
  {
    pos = FindPos(array,low,high);
    QuickSort(array,low,pos-1);
    QuickSort(array,pos+1,high);
  }
}
コード例 #6
0
void CPlayerPlaylistBar::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    if (nIDCtl != IDC_PLAYLIST) {
        return;
    }

    int nItem = lpDrawItemStruct->itemID;
    CRect rcItem = lpDrawItemStruct->rcItem;
    POSITION pos = FindPos(nItem);
    bool fSelected = pos == m_pl.GetPos();
    CPlaylistItem& pli = m_pl.GetAt(pos);

    CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);

    if (!!m_list.GetItemState(nItem, LVIS_SELECTED)) {
        FillRect(pDC->m_hDC, rcItem, CBrush(0xf1dacc));
        FrameRect(pDC->m_hDC, rcItem, CBrush(0xc56a31));
    } else {
        FillRect(pDC->m_hDC, rcItem, CBrush(GetSysColor(COLOR_WINDOW)));
    }

    COLORREF textcolor = fSelected ? 0xff : 0;
    if (pli.m_fInvalid) {
        textcolor |= 0xA0A0A0;
    }

    CString time = !pli.m_fInvalid ? m_list.GetItemText(nItem, COL_TIME) : _T("Invalid");
    CSize timesize(0, 0);
    CPoint timept(rcItem.right, 0);
    if (time.GetLength() > 0) {
        timesize = pDC->GetTextExtent(time);
        if ((3 + timesize.cx + 3) < rcItem.Width() / 2) {
            timept = CPoint(rcItem.right - (3 + timesize.cx + 3), (rcItem.top + rcItem.bottom - timesize.cy) / 2);

            pDC->SetTextColor(textcolor);
            pDC->TextOut(timept.x, timept.y, time);
        }
    }

    CString fmt, file;
    fmt.Format(_T("%%0%dd. %%s"), (int)log10(0.1 + m_pl.GetCount()) + 1);
    file.Format(fmt, nItem + 1, m_list.GetItemText(nItem, COL_NAME));
    CSize filesize = pDC->GetTextExtent(file);
    while (3 + filesize.cx + 6 > timept.x && file.GetLength() > 3) {
        file = file.Left(file.GetLength() - 4) + _T("...");
        filesize = pDC->GetTextExtent(file);
    }

    if (file.GetLength() > 3) {
        pDC->SetTextColor(textcolor);
        pDC->TextOut(rcItem.left + 3, (rcItem.top + rcItem.bottom - filesize.cy) / 2, file);
    }
}
コード例 #7
0
void CPlayerPlaylistBar::OnLvnKeyDown(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMLVKEYDOWN pLVKeyDown = reinterpret_cast<LPNMLVKEYDOWN>(pNMHDR);

    *pResult = FALSE;

    CList<int> items;
    POSITION pos = m_list.GetFirstSelectedItemPosition();
    while (pos) {
        items.AddHead(m_list.GetNextSelectedItem(pos));
    }

    if (pLVKeyDown->wVKey == VK_DELETE && items.GetCount() > 0) {
        pos = items.GetHeadPosition();
        while (pos) {
            int i = items.GetNext(pos);
            if (m_pl.RemoveAt(FindPos(i))) {
                ((CMainFrame*)AfxGetMainWnd())->CloseMedia();
            }
            m_list.DeleteItem(i);
        }

        m_list.SetItemState(-1, 0, LVIS_SELECTED);
        m_list.SetItemState(
            max(min(items.GetTail(), m_list.GetItemCount() - 1), 0),
            LVIS_SELECTED, LVIS_SELECTED);

        ResizeListColumn();

        *pResult = TRUE;
    } else if (pLVKeyDown->wVKey == VK_SPACE && items.GetCount() == 1) {
        m_pl.SetPos(FindPos(items.GetHead()));

        ((CMainFrame*)AfxGetMainWnd())->OpenCurPlaylistItem();

        AfxGetMainWnd()->SetFocus();

        *pResult = TRUE;
    }
}
コード例 #8
0
BOOL CPlayerPlaylistBar::OnToolTipNotify(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
{
    TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pNMHDR;

    if ((HWND)pTTT->lParam != m_list.m_hWnd) {
        return FALSE;
    }

    int row = ((pNMHDR->idFrom - 1) >> 10) & 0x3fffff;
    int col = (pNMHDR->idFrom - 1) & 0x3ff;

    if (row < 0 || row >= m_pl.GetCount()) {
        return FALSE;
    }

    CPlaylistItem& pli = m_pl.GetAt(FindPos(row));

    static CString strTipText; // static string
    strTipText.Empty();

    if (col == COL_NAME) {
        POSITION pos = pli.m_fns.GetHeadPosition();
        while (pos) {
            strTipText += _T("\n") + pli.m_fns.GetNext(pos);
        }
        strTipText.Trim();

        if (pli.m_type == CPlaylistItem::device) {
            if (pli.m_vinput >= 0) {
                strTipText.AppendFormat(_T("\nVideo Input %d"), pli.m_vinput);
            }
            if (pli.m_vchannel >= 0) {
                strTipText.AppendFormat(_T("\nVideo Channel %d"), pli.m_vchannel);
            }
            if (pli.m_ainput >= 0) {
                strTipText.AppendFormat(_T("\nAudio Input %d"), pli.m_ainput);
            }
        }

        ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, (LPARAM)(int)1000);
    } else if (col == COL_TIME) {
        return FALSE;
    }

    pTTT->lpszText = (LPWSTR)(LPCWSTR)strTipText;

    *pResult = 0;

    return TRUE;    // message was handled
}
コード例 #9
0
void CPlayerPlaylistBar::SetFirstSelected()
{
    POSITION pos = m_list.GetFirstSelectedItemPosition();
    if (pos) {
        pos = FindPos(m_list.GetNextSelectedItem(pos));
    } else {
        pos = m_pl.GetTailPosition();
        POSITION org = pos;
        while (m_pl.GetNextWrap(pos).m_fInvalid && pos != org) {
            ;
        }
    }
    UpdateList();
    m_pl.SetPos(pos);
    EnsureVisible(pos);
}
コード例 #10
0
ファイル: Find.cpp プロジェクト: pedia/raidget
void RichEdit::OpenFindReplace()
{
	NextUndo();
	if(!findreplace.IsOpen()) {
		Size sz = findreplace.GetSize();
		findreplace.SetRect(GetScreenView().CenterRect(sz));
		int l, h;
		if(GetSelection(l, h)) {
			findreplace.amend.Hide();
			findreplace.ok.SetLabel(t_("Replace"));
			findreplace.Title(t_("Replace in selection"));
			findreplace.cancel <<= findreplace.Breaker(IDCANCEL);
			findreplace.ok <<= findreplace.Breaker(IDOK);
			if(findreplace.Execute() == IDOK) {
				int len = findreplace.find.GetText().GetLength();
				int rlen = findreplace.replace.GetText().GetLength();
				RichText rtext = ReplaceText();
				cursor = l;
				for(;;) {
					int pos = FindPos();
					if(pos < 0 || pos + len >= h)
						break;
					Select(pos, len);
					Remove(pos, len);
					Insert(pos, ReplaceText(), false);
					cursor += pos + rlen;
					h += rlen - len;
				}
				CancelSelection();
				Move(h, false);
			}
			FindReplaceAddHistory();
			findreplace.amend.Show();
			findreplace.ok.SetLabel(t_("Find"));
			findreplace.Title(t_("Find / Replace"));
			findreplace.cancel <<= THISBACK(CloseFindReplace);
			findreplace.ok <<= THISBACK(Find);
		}
		else {
			findreplace.Open();
			findreplace.find.SetFocus();
		}
	}
}
コード例 #11
0
void CPlayerPlaylistBar::OnNMDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)pNMHDR;

    if (lpnmlv->iItem >= 0 && lpnmlv->iSubItem >= 0) {
        CAppSettings& s = AfxGetAppSettings();
        FILE_POSITION* FilePosition = s.CurrentFilePosition();
        if (FilePosition)   {
            FilePosition->llPosition = 0;
        }

        m_pl.SetPos(FindPos(lpnmlv->iItem));
        m_list.Invalidate();
        ((CMainFrame*)AfxGetMainWnd())->OpenCurPlaylistItem();
    }

    AfxGetMainWnd()->SetFocus();

    *pResult = 0;
}
コード例 #12
0
ファイル: Find.cpp プロジェクト: pedia/raidget
void RichEdit::Find()
{
	CancelSelection();
	FindReplaceAddHistory();
	if(notfoundfw)
		Move(0, false);
	found = notfoundfw = false;
	int pos = FindPos();
	if(pos >= 0) {
		anchor = pos;
		cursor = pos + findreplace.find.GetText().GetLength();
		Finish();
		found = true;
		Size sz = findreplace.GetSize();
		Rect sw = GetScreenView();
		Rect r = sw.CenterRect(sz);
		Rect cr = GetCaretRect();
		if(cr.top < sz.cy + 2 * cr.Height()) {
			r.bottom = sw.bottom - 8;
			r.top = r.bottom - sz.cy;
		}
		else {
			r.top = sw.top + 24;
			r.bottom = r.top + sz.cy;
		}
		findreplace.SetRect(r);
		if(!findreplace.IsOpen()) {
			findreplace.Open();
		}
		SetFocus();
	}
	else {
		CancelSelection();
		CloseFindReplace();
		notfoundfw = true;
	}
}
コード例 #13
0
ファイル: graph.c プロジェクト: CMCXY0321/A-C.A
/**
 * 建立图
 * @param {Graph} 图
 * @return none
 */
void BuildGraph (Graph G) {
    int choice = 0, 
        num = 0,
        pos1,
        pos2,
        i,
        j,
        weight;
    
    char a, b, ch;
    printf("请选择建立的图的类型:1:有向图,2:有向网,3:无向图,无向网:\n");
    scanf("%d",&choice);
    getchar();
    printf("\n");                                   // 下一行
    
    if (choice == 1) {                              // 有向图
        for (i = 0; i < MAX_VERTEX_NUM; i ++) {     // 初始化弧
          for (j = 0; j < MAX_VERTEX_NUM; j ++){
            G->Arc[i][j] = 0;
          }
        }
        
        G->kind = DG; // 设置图的类型

        printf("请输入顶点(不超过10个,以#结束):\n");
        scanf("%c",&ch);
        while(ch!='#' && num <10){
          G->vertex[num] = ch;
          scanf("%c",&ch);
          num++;
        }
        
        G->vexnum = num;  // 顶点个数
        getchar();        // 清除键盘缓冲区

        printf("请输入对应的弧以a->b格式输入(以#->#结束):\n");
        scanf("%c->%c",&a,&b);
        
        while (a!='#' && b!='#') {
          printf("%c,%c",a,b);
          FindPos(G,a,b,&pos1,&pos2);
          printf("位置a:%d,位置b:%d\n",pos1,pos2);

          // 忽略不存在的顶点
          if (pos1!= -1 && pos2!= -1) {
            G->Arc[pos1][pos2] = 1;
            G->arcnum++;
          }

          scanf("%c->%c",&a,&b);
        }
        
        getchar(); // 清空
    } else if (choice == 2) {
        num = 0;  // 个数初始化
        
        for(i = 0; i < MAX_VERTEX_NUM; i++) { //初始化弧
          for(j = 0; j < MAX_VERTEX_NUM; j++) {
            G->Arc[i][j] = INFINITY;
          }
        }
        
        G->kind = DN; // 设置图的类型
        printf("请输入顶点(不超过10个,以#结束):\n");
        scanf("%c",&ch);
        
        while (ch!='#' && num <10) {
          G->vertex[num] = ch;
          scanf("%c",&ch);
          num++;
        }
        
        G->vexnum = num;  // 顶点个数

        getchar();        // 清除键盘缓冲区

        printf("请输入对应的弧以a->b:weight格式输入(以#->#:0结束):\n");
        scanf("%c->%c:%d",&a,&b,&weight);
        
        while (a!='#' && b!='#') {
          printf("%c,%c",a,b);
          FindPos(G,a,b,&pos1,&pos2);
          printf("位置a:%d,位置b:%d\n",pos1,pos2);

          if (pos1!= -1 && pos2!= -1){  
            // 忽略不存在的顶点
            G->Arc[pos1][pos2] = weight;
            G->arcnum++;
          }

          scanf("%c->%c:%d", &a, &b, &weight);
        }
        
        getchar(); // 清空
    } else if (choice == 3) {
        // 无向图
        num = 0;
        
        for (i = 0; i < MAX_VERTEX_NUM; i ++){ //初始化弧
          for(j = 0; j < MAX_VERTEX_NUM; j ++){
            G->Arc[i][j] = 0;
          }
        }
        
        G->kind = UDG; // 设置图的类型

        printf("请输入顶点(不超过10个,以#结束):\n");
        scanf("%c",&ch);
        
        while(ch!='#' && num <10){
          G->vertex[num] = ch;
          scanf("%c",&ch);
          num++;
        }
        
        G->vexnum = num;  //顶点个数

        getchar();  //清除键盘缓冲区

        printf("请输入对应的弧以a-b格式输入(以#-#结束):\n");
        scanf("%c-%c",&a,&b);
        
        while (a!='#' && b!='#') {
          printf("%c,%c",a,b);
          FindPos(G,a,b,&pos1,&pos2);
          printf("位置a:%d,位置b:%d\n",pos1,pos2);

          if(pos1!= -1 && pos2!= -1){  //忽略不存在的顶点
            G->Arc[pos1][pos2] = 1;
            G->Arc[pos2][pos1] = 1;
            G->arcnum++;
          }

          scanf("%c-%c", &a, &b);
        }
        
        getchar(); // 清空
    } else if (choice == 4) {
        // 无向网
        num = 0;  //个数初始化
        
        for (i = 0; i < MAX_VERTEX_NUM; i++){ //初始化弧
            for(j = 0;j<MAX_VERTEX_NUM; j++){
                G->Arc[i][j] = INFINITY;
            }
        }
        
        G -> kind = DN; //设置图的类型

        printf("请输入顶点(不超过10个,以#结束):\n");
        scanf("%c",&ch);
        
        while(ch!='#' && num <10){
            G->vertex[num] = ch;
            scanf("%c",&ch);
            num++;
        }
        
        G->vexnum = num;  // 顶点个数

        getchar();        // 清除键盘缓冲区

        printf("请输入对应的弧以a-b:weight格式输入(以#-#:0结束):\n");
        scanf("%c->%c:%d",&a,&b,&weight);
        
        while (a!='#' && b!='#') {
            printf("%c,%c",a,b);
            FindPos(G,a,b,&pos1,&pos2);
            printf("位置a:%d,位置b:%d\n",pos1,pos2);
            
            if(pos1!= -1 && pos2!= -1){  //忽略不存在的顶点
                G->Arc[pos1][pos2] = weight;
                G->Arc[pos2][pos1] = weight;
                G->arcnum++;
            }
            
            scanf("%c-%c:%d",&a,&b,&weight);
        }
        
        getchar(); // 清空
    } else {  // 非法输入的选择
        printf("输入非法,请输入正确的数字!!\n");
        return;
    }
}
コード例 #14
0
void CPlayerPlaylistBar::OnContextMenu(CWnd* /*pWnd*/, CPoint p)
{
    LVHITTESTINFO lvhti;
    lvhti.pt = p;
    m_list.ScreenToClient(&lvhti.pt);
    m_list.SubItemHitTest(&lvhti);

    POSITION pos = FindPos(lvhti.iItem);
    //bool fSelected = (pos == m_pl.GetPos());
    bool fOnItem = !!(lvhti.flags & LVHT_ONITEM);

    CMenu m;
    m.CreatePopupMenu();

    enum {
        M_OPEN = 1, M_ADD, M_REMOVE, M_CLEAR, M_CLIPBOARD, M_SAVEAS,
        M_SORTBYNAME, M_SORTBYPATH, M_RANDOMIZE, M_SORTBYID,
        M_SHUFFLE, M_HIDEFULLSCREEN
    };

    CAppSettings& s = AfxGetAppSettings();

    m.AppendMenu(MF_STRING | (!fOnItem ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_OPEN, ResStr(IDS_PLAYLIST_OPEN));
    if (((CMainFrame*)AfxGetMainWnd())->GetPlaybackMode() == PM_CAPTURE) {
        m.AppendMenu(MF_STRING | MF_ENABLED, M_ADD, ResStr(IDS_PLAYLIST_ADD));
    }
    m.AppendMenu(MF_STRING | (/*fSelected||*/!fOnItem ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_REMOVE, ResStr(IDS_PLAYLIST_REMOVE));
    m.AppendMenu(MF_SEPARATOR);
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_CLEAR, ResStr(IDS_PLAYLIST_CLEAR));
    m.AppendMenu(MF_SEPARATOR);
    m.AppendMenu(MF_STRING | (!fOnItem ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_CLIPBOARD, ResStr(IDS_PLAYLIST_COPYTOCLIPBOARD));
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_SAVEAS, ResStr(IDS_PLAYLIST_SAVEAS));
    m.AppendMenu(MF_SEPARATOR);
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_SORTBYNAME, ResStr(IDS_PLAYLIST_SORTBYLABEL));
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_SORTBYPATH, ResStr(IDS_PLAYLIST_SORTBYPATH));
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_RANDOMIZE, ResStr(IDS_PLAYLIST_RANDOMIZE));
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_SORTBYID, ResStr(IDS_PLAYLIST_RESTORE));
    m.AppendMenu(MF_SEPARATOR);
    m.AppendMenu(MF_STRING | MF_ENABLED | (s.bShufflePlaylistItems ? MF_CHECKED : MF_UNCHECKED), M_SHUFFLE, ResStr(IDS_PLAYLIST_SHUFFLE));
    m.AppendMenu(MF_SEPARATOR);
    m.AppendMenu(MF_STRING | MF_ENABLED | (s.bHidePlaylistFullScreen ? MF_CHECKED : MF_UNCHECKED), M_HIDEFULLSCREEN, ResStr(IDS_PLAYLIST_HIDEFS));

    CMainFrame* pMainFrm = (CMainFrame*)AfxGetMainWnd();

    int nID = (int)m.TrackPopupMenu(TPM_LEFTBUTTON | TPM_RETURNCMD, p.x, p.y, this);
    switch (nID) {
        case M_OPEN:
            m_pl.SetPos(pos);
            m_list.Invalidate();
            pMainFrm->OpenCurPlaylistItem();
            break;
        case M_ADD:
            pMainFrm->AddCurDevToPlaylist();
            m_pl.SetPos(m_pl.GetTailPosition());
            break;
        case M_REMOVE:
            if (m_pl.RemoveAt(pos)) {
                pMainFrm->CloseMedia();
            }
            m_list.DeleteItem(lvhti.iItem);
            SavePlaylist();
            break;
        case M_CLEAR:
            if (Empty()) {
                pMainFrm->CloseMedia();
            }
            break;
        case M_SORTBYID:
            m_pl.SortById();
            SetupList();
            SavePlaylist();
            break;
        case M_SORTBYNAME:
            m_pl.SortByName();
            SetupList();
            SavePlaylist();
            break;
        case M_SORTBYPATH:
            m_pl.SortByPath();
            SetupList();
            SavePlaylist();
            break;
        case M_RANDOMIZE:
            m_pl.Randomize();
            SetupList();
            SavePlaylist();
            break;
        case M_CLIPBOARD:
            if (OpenClipboard() && EmptyClipboard()) {
                CString str;

                CPlaylistItem& pli = m_pl.GetAt(pos);
                POSITION pos2 = pli.m_fns.GetHeadPosition();
                while (pos2) {
                    str += _T("\r\n") + pli.m_fns.GetNext(pos2);
                }
                str.Trim();

                if (HGLOBAL h = GlobalAlloc(GMEM_MOVEABLE, (str.GetLength() + 1) * sizeof(TCHAR))) {
                    if (TCHAR* cp = (TCHAR*)GlobalLock(h)) {
                        _tcscpy_s(cp, str.GetLength() + 1, str);
                        GlobalUnlock(h);
                        SetClipboardData(CF_UNICODETEXT, h);
                    }
                }
                CloseClipboard();
            }
            break;
        case M_SAVEAS: {
            CSaveTextFileDialog fd(
                CTextFile::ASCII, NULL, NULL,
                _T("Media Player Classic playlist (*.mpcpl)|*.mpcpl|Playlist (*.pls)|*.pls|Winamp playlist (*.m3u)|*.m3u|Windows Media playlist (*.asx)|*.asx||"),
                this);

            if (fd.DoModal() != IDOK) {
                break;
            }

            CTextFile::enc encoding = (CTextFile::enc)fd.GetEncoding();
            if (encoding == CTextFile::ASCII) {
                encoding = CTextFile::ANSI;
            }

            int idx = fd.m_pOFN->nFilterIndex;

            CPath path(fd.GetPathName());

            switch (idx) {
                case 1:
                    path.AddExtension(_T(".mpcpl"));
                    break;
                case 2:
                    path.AddExtension(_T(".pls"));
                    break;
                case 3:
                    path.AddExtension(_T(".m3u"));
                    break;
                case 4:
                    path.AddExtension(_T(".asx"));
                    break;
                default:
                    break;
            }

            bool fRemovePath = true;

            CPath p(path);
            p.RemoveFileSpec();
            CString base = (LPCTSTR)p;

            pos = m_pl.GetHeadPosition();
            while (pos && fRemovePath) {
                CPlaylistItem& pli = m_pl.GetNext(pos);

                if (pli.m_type != CPlaylistItem::file) {
                    fRemovePath = false;
                } else {
                    POSITION pos;

                    pos = pli.m_fns.GetHeadPosition();
                    while (pos && fRemovePath) {
                        CString fn = pli.m_fns.GetNext(pos);

                        CPath p(fn);
                        p.RemoveFileSpec();
                        if (base != (LPCTSTR)p) {
                            fRemovePath = false;
                        }
                    }

                    pos = pli.m_subs.GetHeadPosition();
                    while (pos && fRemovePath) {
                        CString fn = pli.m_subs.GetNext(pos);

                        CPath p(fn);
                        p.RemoveFileSpec();
                        if (base != (LPCTSTR)p) {
                            fRemovePath = false;
                        }
                    }
                }
            }

            if (idx == 1) {
                SaveMPCPlayList(path, encoding, fRemovePath);
                break;
            }

            CTextFile f;
            if (!f.Save(path, encoding)) {
                break;
            }

            if (idx == 2) {
                f.WriteString(_T("[playlist]\n"));
            } else if (idx == 4) {
                f.WriteString(_T("<ASX version = \"3.0\">\n"));
            }

            pos = m_pl.GetHeadPosition();
            CString str;
            int i;
            for (i = 0; pos; i++) {
                CPlaylistItem& pli = m_pl.GetNext(pos);

                if (pli.m_type != CPlaylistItem::file) {
                    continue;
                }

                CString fn = pli.m_fns.GetHead();

                /*
                            if (fRemovePath)
                            {
                                CPath p(path);
                                p.StripPath();
                                fn = (LPCTSTR)p;
                            }
                */

                switch (idx) {
                    case 2:
                        str.Format(_T("File%d=%s\n"), i + 1, fn);
                        break;
                    case 3:
                        str.Format(_T("%s\n"), fn);
                        break;
                    case 4:
                        str.Format(_T("<Entry><Ref href = \"%s\"/></Entry>\n"), fn);
                        break;
                    default:
                        break;
                }
                f.WriteString(str);
            }

            if (idx == 2) {
                str.Format(_T("NumberOfEntries=%d\n"), i);
                f.WriteString(str);
                f.WriteString(_T("Version=2\n"));
            } else if (idx == 4) {
                f.WriteString(_T("</ASX>\n"));
            }
        }
        break;
        case M_SHUFFLE:
            s.bShufflePlaylistItems = !s.bShufflePlaylistItems;
            break;
        case M_HIDEFULLSCREEN:
            s.bHidePlaylistFullScreen = !s.bHidePlaylistFullScreen;
            break;
        default:
            break;
    }
}
コード例 #15
0
ファイル: book.c プロジェクト: zhu-jz/rodent_code
int sBook::GetPolyglotMove(sPosition *p, int printOutput) {

   int bestMove  = 0;
   int bestScore = 0;
   int maxWeight = 0;
   int sumOfWeights = 0;
   int pos;
   polyglot_move entry[1];
   int move;
   int score;
   int values[100];
   U64 key = GetPolyglotKey(p);
   char moveString[6];

   nOfChoices = 0;

   if (bookFile != NULL && bookSize != 0) {
	  srand(Timer.GetMS() );

      for (pos = FindPos(key); pos < bookSize; pos++) {

         ReadEntry(entry,pos);
         if (entry->key != key) break;

         move = entry->move;
		 score = entry->weight;

		 // ugly hack to convert polyglot move to a real one
		 int fsq = Tsq(move);
		 int tsq = Fsq(move);

		 // correction for castling moves
		 if (fsq == E1 && tsq == H1 && p->kingSquare[WHITE] == E1) tsq = G1;
		 if (fsq == E8 && tsq == H8 && p->kingSquare[BLACK] == E8) tsq = G8;
		 if (fsq == E1 && tsq == A1 && p->kingSquare[WHITE] == E1) tsq = C1;
		 if (fsq == E8 && tsq == A8 && p->kingSquare[BLACK] == E8) tsq = C8;

		 // now we want to get a move with full data, not only from and to squares
		 int realMove = (tsq << 6) | fsq;
		 MoveToStr(realMove, moveString);
		 realMove = StrToMove(p, moveString);

		 if (maxWeight < score) maxWeight = score;
		 sumOfWeights += score;
		 moves[nOfChoices] = realMove;
		 values[nOfChoices] = score;
		 nOfChoices++;
      }

      // pick a move, filtering out those with significantly lower weight
	  for (int i = 0; i<nOfChoices; i++) {

		 // report about possible choices and rejected moves
		 if (values[i] > 1 || maxWeight == 1) {
            if (printOutput) {
		       printf("info string ");
		       PrintMove(moves[i]);
		       printf(" %d %%", (values[i] * 100) / sumOfWeights );
			   if (IsInfrequent(values[i], maxWeight)) printf(" infrequent ");
			}
		 }
		 
		 // shall we pick this move?
		 if (!IsInfrequent(values[i], maxWeight)) {
		    bestScore += values[i];
            if (my_random(bestScore) < values[i]) bestMove = moves[i];
		 }
		 
		 printf("\n");

	  }
   }
   //if (printOutput) PrintMissingMoves(p);
   return bestMove;
}
コード例 #16
0
ファイル: IndexData.CPP プロジェクト: SHIYUENING/topace
	void _IndexData<F,T,DataStruct>::Add(DataStruct *obj)
	{
		data_list.Insert(FindPos(obj->flag),obj);
	}
コード例 #17
0
void CPlayerPlaylistBar::SetSelIdx(int i)
{
    m_pl.SetPos(FindPos(i));
}