/** * 响应鼠标单击按钮;Delete * @param CBCGPGridCtrl* pGridCtrlEdit 输入行 * @param CBCGPGridCtrl* pGridCtrlList 列表 * @return void */ void CGridCtrlOperation::OnBnClickedButtonDeleteA(CBCGPGridCtrl* pGridCtrlEdit, CBCGPGridCtrl* pGridCtrlList) { CList<int, int> ListNb; // 得到索引队列,修改操作、删除操作、颠倒操作 if(false == GetIndexListForChangeOrDeleteOrReverse(pGridCtrlEdit, pGridCtrlList, &ListNb)) { return; } while(FALSE == ListNb.IsEmpty()) { // 得到行索引号 int iRowIndex = ListNb.RemoveTail(); pGridCtrlList->RemoveRow(iRowIndex); } pGridCtrlList->AdjustLayout(); }
//************************************************************************************ void CBCGPOutlineParser::DoParse (const CString& strBuffer, const int nStartOffset, const int nEndOffset, CObList& lstResults) { ASSERT (nStartOffset >= 0); ASSERT (nEndOffset < strBuffer.GetLength ()); ASSERT (nStartOffset <= nEndOffset); m_strOut.Empty (); CList <Lexeme, Lexeme&> lstStack; Lexeme lexemStackTop (0, LT_Eps, 0, 0); lstStack.AddTail (lexemStackTop); int nOffset = nStartOffset; while (nOffset <= nEndOffset) { // Get next lexem: Lexeme lexemNext = GetNext (strBuffer, nOffset, nEndOffset); Lexeme lexemTop = lstStack.GetTail (); if (lexemNext.m_nType == LT_EndOfText) { break; } // Parser logic: switch (lexemNext.m_nType) { case LT_BlockStart: lstStack.AddTail (lexemNext); break; case LT_BlockEnd: if (lexemTop.m_nType == LT_BlockStart && lexemTop.m_nBlockType == lexemNext.m_nBlockType) { // Push Block: lstStack.RemoveTail (); Lexeme lexemRes (lexemTop.m_nBlockType, LT_CompleteBlock, lexemTop.m_nStart, lexemNext.m_nEnd); PushResult (lexemRes, lstResults); } else { lstStack.AddTail (lexemNext); } break; case LT_CompleteBlock: { // Push Comment: PushResult (lexemNext, lstResults); } break; case LT_CustomBlock: break; } } // Finish parsing: while (!lstStack.IsEmpty ()) { Lexeme lexem = lstStack.RemoveTail (); PushResult (lexem, lstResults); } }
void CRemote::Output(LPCTSTR pszName) { if ( _tcsstr( pszName, L".." ) || _tcschr( pszName, L'/' ) ) return; CString strValue = Settings.General.Path + L"\\Remote\\" + pszName + L".html"; CFile hFile; if ( ! hFile.Open( strValue, CFile::modeRead ) ) return; int nBytes = (int)hFile.GetLength(); CAutoVectorPtr< BYTE > pBytes( new BYTE[ nBytes ] ); hFile.Read( pBytes, nBytes ); hFile.Close(); LPCSTR pBody = (LPCSTR)(BYTE*)pBytes; if ( nBytes > 3 && pBytes[0] == 0xEF && pBytes[1] == 0xBB && pBytes[2] == 0xBF ) { // Skip BOM pBody += 3; nBytes -= 3; } CString strBody = UTF8Decode( pBody, nBytes ); CList<BOOL> pDisplayStack; for ( BOOL bDisplay = TRUE; ; ) { int nStart = strBody.Find( L"<%" ); if ( nStart < 0 ) { if ( bDisplay ) m_sResponse += strBody; break; } else if ( nStart >= 0 ) { if ( bDisplay && nStart > 0 ) m_sResponse += strBody.Left( nStart ); strBody = strBody.Mid( nStart + 2 ); } int nEnd = strBody.Find( L"%>" ); if ( nEnd < 0 ) break; CString strKey = strBody.Left( nEnd ); strBody = strBody.Mid( nEnd + 2 ); strKey.Trim(); ToLower( strKey ); if ( strKey.IsEmpty() ) { // Nothing } else if ( strKey.GetAt( 0 ) == L'=' && bDisplay ) { strKey = strKey.Mid( 1 ); strKey.Trim(); if ( m_pKeys.Lookup( strKey, strValue ) ) m_sResponse += strValue; } else if ( strKey.GetAt( 0 ) == L'?' ) { strKey = strKey.Mid( 1 ); strKey.Trim(); if ( strKey.IsEmpty() ) { if ( ! pDisplayStack.IsEmpty() ) bDisplay = pDisplayStack.RemoveTail(); } else { if ( strKey.GetAt( 0 ) == L'!' ) { strKey = strKey.Mid( 1 ); strKey.Trim(); if ( ! m_pKeys.Lookup( strKey, strValue ) ) strValue.Empty(); pDisplayStack.AddTail( bDisplay ); bDisplay = bDisplay && strValue.IsEmpty(); } else { if ( ! m_pKeys.Lookup( strKey, strValue ) ) strValue.Empty(); pDisplayStack.AddTail( bDisplay ); bDisplay = bDisplay && ! strValue.IsEmpty(); } } } } }
uint32_t CKademlia::CalculateKadUsersNew(){ // the idea of calculating the user count with this method is simple: // whenever we do search for any NodeID (except in certain cases were the result is not usable), // we remember the distance of the closest node we found. Because we assume all NodeIDs are distributed // equally, we can calcualte based on this distance how "filled" the possible NodesID room is and by this // calculate how many users there are. Of course this only works if we have enough samples, because // each single sample will be wrong, but the average of them should produce a usable number. To avoid // drifts caused by a a single (or more) really close or really far away hits, we do use median-average instead through // doesnt works well if we have no files to index and nothing to download and the numbers seems to be a bit too low // compared to out other method. So lets stay with the old one for now, but keeps this here as alternative if (m_liStatsEstUsersProbes.GetCount() < 10) return 0; uint32_t nMedian = 0; CList<uint32_t, uint32_t> liMedian; for (POSITION pos1 = m_liStatsEstUsersProbes.GetHeadPosition(); pos1 != NULL; ) { uint32_t nProbe = m_liStatsEstUsersProbes.GetNext(pos1); bool bInserted = false; for (POSITION pos2 = liMedian.GetHeadPosition(); pos2 != NULL; liMedian.GetNext(pos2)){ if (liMedian.GetAt(pos2) > nProbe){ liMedian.InsertBefore(pos2, nProbe); bInserted = true; break; } } if (!bInserted) liMedian.AddTail(nProbe); } // cut away 1/3 of the values - 1/6 of the top and 1/6 of the bottom to avoid spikes having too much influence, build the average of the rest int32_t nCut = liMedian.GetCount() / 6; for (int i = 0; i != nCut; i++){ liMedian.RemoveHead(); liMedian.RemoveTail(); } uint64_t nAverage = 0; for (POSITION pos1 = liMedian.GetHeadPosition(); pos1 != NULL; ) nAverage += liMedian.GetNext(pos1); nMedian = (uint32_t)(nAverage / liMedian.GetCount()); // LowIDModififier // Modify count by assuming 20% of the users are firewalled and can't be a contact for < 0.49b nodes // Modify count by actual statistics of Firewalled ratio for >= 0.49b if we are not firewalled ourself // Modify count by 40% for >= 0.49b if we are firewalled outself (the actual Firewalled count at this date on kad is 35-55%) const float fFirewalledModifyOld = 1.20F; float fFirewalledModifyNew = 0; if (CUDPFirewallTester::IsFirewalledUDP(true)) fFirewalledModifyNew = 1.40F; // we are firewalled and get get the real statistic, assume 40% firewalled >=0.49b nodes else if (GetPrefs()->StatsGetFirewalledRatio(true) > 0) { fFirewalledModifyNew = 1.0F + (CKademlia::GetPrefs()->StatsGetFirewalledRatio(true)); // apply the firewalled ratio to the modify ASSERT( fFirewalledModifyNew > 1.0F && fFirewalledModifyNew < 1.90F ); } float fNewRatio = CKademlia::GetPrefs()->StatsGetKadV8Ratio(); float fFirewalledModifyTotal = 0; if (fNewRatio > 0 && fFirewalledModifyNew > 0) // weigth the old and the new modifier based on how many new contacts we have fFirewalledModifyTotal = (fNewRatio * fFirewalledModifyNew) + ((1 - fNewRatio) * fFirewalledModifyOld); else fFirewalledModifyTotal = fFirewalledModifyOld; ASSERT( fFirewalledModifyTotal > 1.0F && fFirewalledModifyTotal < 1.90F ); return (uint32_t)((float)nMedian*fFirewalledModifyTotal); }
bool Template::ParseHelper() { // Build our master string. m_helper->m_buffer.SetCount(0, 1024); m_helper->m_outBolPos = 0; // Start copying the string in. m_helper->m_codePtr = (LPCTSTR)m_code; m_helper->m_codeBolPtr = m_helper->m_codePtr; LPCTSTR& codePtr = m_helper->m_codePtr; CharArray& buffer = m_helper->m_buffer; // Conditional stack. CList<CondInfo, CondInfo&> conditionalStack; int nestedFalseConditionals = 0; // Go 'til the end. while (*codePtr != 0) { LPCTSTR outBolPtr = buffer.GetData() + m_helper->m_outBolPos; TokenHelper helper; helper.m_tabSize = m_helper->m_tabSize; helper.m_outBolPtr = outBolPtr; helper.m_file = this; helper.m_helper = m_helper; // See if it is a command. Commands can only occur at the beginning // of a line. if (*codePtr == '!' && *(codePtr + 1) == '!' && codePtr == m_helper->m_codeBolPtr) { // Move past the exclamation points. codePtr += 2; // Is it a command comment? // !!// This is a comment. if (*codePtr == '/' && *(codePtr + 1) == '/') { // Move past the double slash. codePtr += 2; SkipToEol(codePtr); continue; } /////////////////////////////////////////////////////////////////// // Lex the command token. char command[256]; char *comPtr = command; while (*codePtr != 0) { // Is it a space? if (*codePtr == ' ') { // Break at a space. codePtr++; break; } else if (*codePtr == '\n' || *codePtr == '\r') { break; } else { // Copy the command or flag. *comPtr++ = *codePtr++; } } *comPtr = 0; /////////////////////////////////////////////////////////////////// // "Conditional" commands /////////////////////////////////////////////////////////////////// // If the last conditional was false, then we ignore until the next // endif. if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { CondInfo condInfo = conditionalStack.GetTail(); if (stricmp(command, "if") == 0) { SkipToEol(codePtr); nestedFalseConditionals++; continue; } else if (stricmp(command, "elif") == 0 || stricmp(command, "else") == 0) { // If we're in nested false conditionals, then ignore. if (nestedFalseConditionals > 0) { SkipToEol(codePtr); continue; } } else if (stricmp(command, "endif") == 0) { // If we're in nested false conditionals, then ignore. if (nestedFalseConditionals > 0) { SkipToEol(codePtr); nestedFalseConditionals--; continue; } } } if (stricmp(command, "if") == 0 || stricmp(command, "elif") == 0) { // Our CondInfo structure. CondInfo condInfo; // If the command is an elif, then pop the old state. if (tolower(command[0]) == 'e') { // The conditional stack can't be empty on an elif. if (conditionalStack.IsEmpty()) { CString err; err.Format("!!elif used with no preceding !!if."); throw TException(TException::CONDSTACK_EMPTY, err); } // Get the current conditionalStack state. We are most // interested in retaining the m_thisLevelTrue variable. condInfo = conditionalStack.GetTail(); // Remove the old state, because it was false. conditionalStack.RemoveTail(); } // if and elif are setup in this format: // !!if var [cond] [condCheck] // condCheck is only optional if cond doesn't exist. // var is required. // Get the requested dictionary entry name. CString var = ParseToken(codePtr, &helper); /* if (var.IsEmpty()) { CString err; err.Format("The variable is missing."); throw TException(TException::IF_VAR_MISSING, err); } */ CString cond = ParseToken(codePtr, &helper); CString condCheck = ParseToken(codePtr, &helper); /* if (!cond.IsEmpty() && condCheck.IsEmpty()) { CString err; err.Format("The conditional is missing."); throw TException(TException::IF_COND_CHECKVAR_MISSING, err); } */ // Check for a ! symbol. bool isNot = false; if (!var.IsEmpty() && var[0] == '!') { isNot = true; var = var.Mid(1); } // Lookup the value. CString value = var; SkipToEol(codePtr); bool result; if (cond.IsEmpty()) { if (value != "0") result = true; else result = false; } else { // There is a conditional expression. Do it. result = CheckCondition(value, cond, condCheck); } if (isNot) result ^= 1; if (tolower(command[0]) == 'e' && result) result ^= condInfo.m_thisLevelTrue; condInfo.m_curState = result; condInfo.m_thisLevelTrue |= result; // Retain the old state. conditionalStack.AddTail(condInfo); continue; } /////////////////////////////////////////////////////////////////// else if (stricmp(command, "else") == 0) { SkipToEol(codePtr); if (conditionalStack.IsEmpty()) { CString err; err.Format("!!else used with no preceding !!if."); throw TException(TException::CONDSTACK_EMPTY, err); } // Get the current conditionalStack state. We are most // interested in retaining the m_thisLevelTrue variable. CondInfo condInfo = conditionalStack.GetTail(); conditionalStack.RemoveTail(); condInfo.m_curState = condInfo.m_thisLevelTrue ^ 1; conditionalStack.AddTail(condInfo); continue; } else if (stricmp(command, "endif") == 0) { SkipToEol(codePtr); if (conditionalStack.IsEmpty()) { CString err; err.Format("!!endif used with no preceding !!if."); throw TException(TException::CONDSTACK_EMPTY, err); } conditionalStack.RemoveTail(); continue; } if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { continue; } /////////////////////////////////////////////////////////////////// // Look up the command in the map. /////////////////////////////////////////////////////////////////// WWhizTemplateCommand* commandObject = m_helper->GetCommand(command); if (commandObject) { TemplateCommandArgs args; // Found a command. Build the arg list. while (true) { CString arg = ParseToken(codePtr, &helper); if (arg.IsEmpty()) break; args.m_argList.Add(arg); } // Skip anything else. SkipToEol(codePtr); // Run the command. commandObject->Run(this, args); RefreshFileInfo(); // Parse the next part. continue; } else { CString err; err.Format("Unable to find the command [%s].", command); if (AfxMessageBox(err + "\n\nKeep executing?", MB_YESNO) == IDNO) { throw TException(TException::MISSING_COMMAND, err); } } } /////////////////////////////////////////////////////////////////////// else if (*codePtr == '@' && *(codePtr + 1) == '@') { // If we're ignoring text, then skip. if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { codePtr += 2; continue; } // Is it a line continuation? // @@backslash if (*(codePtr + 2) == '\\') { SkipToEol(codePtr); continue; } CString out; // Ugly, but we need that \0 in there. buffer.Add(0); buffer.RemoveAt(buffer.GetCount() - 1); if (ParseTag(codePtr, out, &helper)) { // Move the output string into the buffer. for (int i = 0; i < out.GetLength(); i++) buffer.Add(out[i]); } } else { // See if it is an EOL. if (*codePtr == '\n') { m_helper->m_outBolPos = buffer.GetCount() + 1; m_helper->m_codeBolPtr = codePtr + 1; } // If we're ignoring text, then skip. if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { codePtr++; continue; } // Copy it straight. buffer.Add(*codePtr++); } } // Flush what's left. FlushText(); buffer.RemoveAll(); return true; }
CSize CToolPalette::CalcButtonLocations(int nColumns, bool bCalcOnly) { if (nColumns < 1) { nColumns = 1; } bool bHorizontal = (GetCurrentAlignment () & CBRS_ORIENT_HORZ) != 0; // Toolbar layout mode CRect rectClient; GetClientRect (rectClient); EDisplayOptions edo = GetToolbarDisplayOptions (); if ((edo & eDisplayTitle) != 0) { if (!bHorizontal) { rectClient.top += m_nCaptionHeight + 4; } } int xBorders = 0; int yBorders = 0; if ((edo & eDisplayBorder) != 0) { const CRect& rectCorners = m_imgCaption.GetParams ().m_rectCorners; rectClient.left += rectCorners.left + 3; rectClient.top += rectCorners.top; xBorders = rectCorners.left + rectCorners.right; yBorders = rectCorners.top + rectCorners.bottom; } else { rectClient.left += 1; } if ((edo & eDisplaySizeControl) != 0 && bHorizontal) { const int sizeControlHeight = m_imgCaption.GetParams ().m_rectImage.Height (); yBorders += sizeControlHeight; rectClient.top += sizeControlHeight; } // Consider border area CPoint xyPos = rectClient.TopLeft (); // Current position bool bPrevSeparator = true; // Indicates that previous button was a separator. // Initial 'true' value prevents separator to appear first. CClientDC dc (this); CSize szButtonDefault (GetColumnWidth (), GetRowHeight ()); // Default button size to pass to button's OnCalculateSize method int nMaxSize = nColumns * (bHorizontal ? szButtonDefault.cy : szButtonDefault.cx) * 11 / 10; // (11/10) adds +10% space here // The toolbar height (for horizontal layout) or width (for vertical) of toolbar. CList<ButtonStripe, const ButtonStripe&> listStripes; ButtonStripe stripe; // Current stripe CBCGPToolbarButton* pButton = NULL; // Current button for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;) { pButton = (CBCGPToolbarButton*)m_Buttons.GetNext (pos); if (pButton == NULL) { break; } if (!pButton->IsVisible ()) { continue; } bool bSep = (pButton->m_nStyle & TBBS_SEPARATOR) != 0; if (bSep && bPrevSeparator) { continue; } // Layout algorithm: // ------------------- // if (separator) AddPreviousStripe, AddSeparatorStripe, BeginNewStripe // else { // AddButton // if (stripe.breadth > default_stripe_breadth) // AddPreviousStripe, BeginNewStripe, AddButton // } CSize szButton = pButton->OnCalculateSize (&dc, szButtonDefault, bHorizontal); if (bHorizontal) { } else // vertical layout { if (bSep) { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = 0; // separator length is set automatically stripe.size = szButton.cy; // cx for horz. listStripes.AddTail (stripe); stripe = ButtonStripe (); } else if (szButton.cx > nMaxSize) // this button is larger than current toolbar width { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = szButton.cx; // cy for horz. stripe.size = szButton.cy; // cx for horz. listStripes.AddTail (stripe); // stripe with a single large button stripe = ButtonStripe (); } else // usual button { if (stripe.breadth + szButton.cx <= nMaxSize) { stripe.breadth += szButton.cx; stripe.buttonCount ++; if (szButton.cy > stripe.size) stripe.size = szButton.cy; } else { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = szButton.cx; // cy for horz. stripe.size = szButton.cy; // cx for horz. } } } bPrevSeparator = bSep; } if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } if (listStripes.IsEmpty ()) { return CSize (0, 0); } if (listStripes.GetTail ().breadth == 0) // last item is separator { listStripes.RemoveTail (); } // Now calculate total size int totalLength = m_nCaptionHeight + 4; int maxBreadth = nMaxSize; POSITION posStripes = listStripes.GetHeadPosition (); while (posStripes != NULL) { stripe = listStripes.GetNext (posStripes); ASSERT (stripe.buttonCount > 0); totalLength += stripe.size; if (stripe.breadth > maxBreadth) { maxBreadth = stripe.breadth; } } if (!bCalcOnly) { CPoint ptButtonPos = rectClient.TopLeft (); posStripes = listStripes.GetHeadPosition (); stripe = ButtonStripe(); for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;) { pButton = (CBCGPToolbarButton*)m_Buttons.GetNext (pos); if (pButton == NULL) { break; } if (!pButton->IsVisible ()) { continue; } bool bSep = (pButton->m_nStyle & TBBS_SEPARATOR) != 0; if (bSep && bPrevSeparator) { continue; } CSize szButton = pButton->OnCalculateSize (&dc, szButtonDefault, bHorizontal); CRect rcButton (0, 0, 0, 0); if (stripe.buttonCount == 0) // this member is decremented below { ptButtonPos.y += stripe.size; if (posStripes == NULL) { break; } stripe = listStripes.GetNext (posStripes); ptButtonPos.x = rectClient.left + (maxBreadth - stripe.breadth) / 2; // center-alignment } if (bSep) { ASSERT (stripe.breadth == 0); ASSERT (stripe.buttonCount == 1); rcButton.left = rectClient.left; rcButton.top = ptButtonPos.y; rcButton.right = rcButton.left + maxBreadth; rcButton.bottom = rcButton.top + szButton.cy; } else { rcButton.left = ptButtonPos.x; rcButton.top = ptButtonPos.y + (stripe.size - szButton.cy) / 2; // center-alignment rcButton.right = rcButton.left + szButton.cx; rcButton.bottom = rcButton.top + szButton.cy; ptButtonPos.x += szButton.cx; } pButton->SetRect (rcButton); stripe.buttonCount --; } } if (m_bAdditionalPixel) { ++maxBreadth; } return bHorizontal ? CSize (totalLength + xBorders, maxBreadth + yBorders) : CSize (maxBreadth + xBorders, totalLength + yBorders); }