std::string toString(LuaType lua_type) { switch (lua_type) { case LuaNone: return "LuaNone"; case LuaNil: return "LuaNil"; case LuaBoolean: return "LuaBoolean"; case LuaLightUserData: return "LuaLightUserData"; case LuaNumber: return "LuaNumber"; case LuaString: return "LuaString"; case LuaTable: return "LuaTable"; case LuaFunction: return "LuaFunction"; case LuaUserData: return "LuaUserData"; case LuaThread: return "LuaThread"; case LuaNumTags: return "LuaNumTags"; default: throw Exception(strFormat("Invalid LuaType value: %d", (int)lua_type)); } }
std::string FormatIP(DWORD dwIP) { sockaddr_in local; local.sin_family = AF_INET; local.sin_addr.s_addr = dwIP; return std::move(strFormat("%s", inet_ntoa(local.sin_addr))); }
CString CXTPPropertyGridItemDouble::DoubleToString(double dValue) { if (m_bUseSystemDecimalSymbol) { TRY { COleVariant oleString(dValue); oleString.ChangeType(VT_BSTR); return CString(oleString.bstrVal); } CATCH(COleException, e) { } END_CATCH } CString strFormat(m_strFormat); if (strFormat.IsEmpty()) strFormat = _T("%0.2f"); CString strValue; strValue.Format(strFormat, dValue); return strValue; }
//luaGetError std::string luaGetError(lua_State* plua_state, int err) { std::string error_str(""); if (0 == err) return error_str; std::string err_type; switch (err) { case LUA_ERRSYNTAX: //compile-time error err_type = "syntax error during pre-compilation"; break; case LUA_ERRMEM: //memory error err_type = "memory allocation error"; break; case LUA_ERRRUN: //runtime-time error err_type = "runtime error"; break; case LUA_YIELD: //thread suspend error err_type = "thread has been suspended"; break; case LUA_ERRERR: //error while running err_type = "error while running the error handler function"; break; default: err_type = "unknown"; break; } error_str = strFormat("error(%s) %s", err_type.c_str(), lua_tostring(plua_state, -1)); luaPop(plua_state, 1); return error_str; }
void CLogEngine::OnQueueServiceSink(WORD wIdentifier, void * pBuffer, WORD wDataSize) { if(wIdentifier == ID_LOG && wDataSize == sizeof(LogInfo)) { LogInfo *pTempInfo = static_cast<LogInfo*>(pBuffer); std::string strLogHead; switch(pTempInfo->_logLevel) { case Level_Normal: { strLogHead = "Normal"; break; } case Level_Warning: { strLogHead = "Warning"; break; } case Level_Exception: { strLogHead = "Exception"; break; } case Level_Debug: { strLogHead = "Debug"; break; } } std::string strLogTime; //»ñȡʱ¼ä SYSTEMTIME SystemTime; GetLocalTime(&SystemTime); strLogTime = std::move(strFormat("[%d/%02d/%02d %02d:%02d:%02d:%03d]", SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay, SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, SystemTime.wMilliseconds)); std::string strLog = std::move(strFormat("%s %s %s", strLogHead.c_str(), strLogTime.c_str(), pTempInfo->_srLog)); if(m_bLogShowFlag[pTempInfo->_logLevel]) { std::cout<<strLog<<std::endl; } } }
BOOL CXTPPropertyGridItemDate::ParseDateTime(COleDateTime& dt, LPCTSTR strValue) { if (m_strFormat.IsEmpty()) return FALSE; SYSTEMTIME sysTime; ZeroMemory(&sysTime, sizeof(SYSTEMTIME)); WORD* ptrDate[3] = {0, 0, 0}; int nResult[3] = {0, 0, 0}; CString strFormat(m_strFormat); strFormat.MakeLower(); int nIndex = -1, i = 0; for (i = 0; i < 3; i++) { nIndex = strFormat.Find(_T('%'), nIndex + 1); if (nIndex == -1 || nIndex == strFormat.GetLength() - 1) return FALSE; switch (strFormat[nIndex + 1]) { case _T('d'): ptrDate[i] = &sysTime.wDay; break; case _T('y'): ptrDate[i] = &sysTime.wYear; break; case _T('m'): case _T('b'): ptrDate[i] = &sysTime.wMonth; break; default: return FALSE; } strFormat.SetAt(nIndex + 1, _T('d')); } if (SCANF_S(strValue, strFormat, &nResult[0], &nResult[1], &nResult[2]) != 3) return FALSE; for (i = 0; i < 3; i++) { if (!ptrDate[i]) return FALSE; *ptrDate[i] = (WORD)nResult[i]; } dt = sysTime; return dt.GetStatus() == COleDateTime::valid; }
std::string luaToString(lua_State* plua_state, int index) { const char* result = lua_tostring(plua_state, index); if (!result) luaError(plua_state, strFormat("luaToString from index %d failed.", index)); return std::string(lua_tostring(plua_state, index)); }
void onAlbEventStart(const QXmlAttributes& attrs) { string strDate (convStr(attrs.value("date"))); if (!strDate.empty()) { m_albumInfo.m_strReleased = m_albumInfo.m_strReleased.empty() ? strDate : min(m_albumInfo.m_strReleased, strDate); } string strFormat (convStr(attrs.value("format"))); if (!strFormat.empty() && string::npos == m_albumInfo.m_strFormat.find(strFormat)) { addIfMissing(m_albumInfo.m_strFormat, strFormat); } }
void EWAFaviconLoader::slotRecived( QNetworkReply *pReply ) { QUrl anotherLocation = pReply->attribute( QNetworkRequest::RedirectionTargetAttribute ).toUrl(); QByteArray binaryData = pReply->readAll(); bool bNoError = QNetworkReply::NoError == pReply->error(); QString strError = pReply->errorString(); QString strReqUrl = pReply->url().toString(); int iLastDotId = strReqUrl.lastIndexOf( "." ); QString strFormat( "ICO" ); if( iLastDotId > 0 && !strReqUrl.endsWith( strFormat, Qt::CaseInsensitive ) ) { strReqUrl.right( strReqUrl.length() - 1 - iLastDotId ).toUpper(); } pReply->deleteLater(); stop(); if( anotherLocation.isValid() ) { if( anotherLocation.isRelative() ) { anotherLocation = QUrl( strReqUrl ).resolved( anotherLocation ); } qDebug() << "EWAFaviconLoader::slotRecived: redirecting from [" << strReqUrl << "] to [" << anotherLocation.toString() << "]"; setTargetUrl( anotherLocation.toString() ); start(); } else { if( bNoError ) { QPixmap pixmap = QPixmap::fromImage( QImage::fromData( binaryData, qPrintable( strFormat ) ) ); if( pixmap.isNull() ) qWarning() << "EWAFaviconLoader::slotRecived: received icon is null"; else emit signalIconRecived( QIcon( pixmap ) ); } else { qWarning() << "EWAFaviconLoader::slotRecived:" << strError; } } }
std::string memContent(char* buf, size_t bytes) { std::string str(""); for (size_t i=0; i<bytes; ++i) { if (0 != i && 0 == i%8) { if (0 == i%16) str += "\n"; else str += " "; } str += strFormat("%02x ", *((unsigned char*)(buf + i))); } return str; }
void CAudioFormatDlg::UpdateCompressFormatInterface() { if (!m_bAudioCompression) { m_ctrlEditCompressedFormatTag.SetWindowText(_T("None Available")); m_ctrlEditCompressedFormat.SetWindowText(_T(" ")); return; } CString strFormat(""); CString strFormatTag(""); BOOL res = GetFormatDescription(strFormatTag, strFormat); if (res) { m_ctrlEditCompressedFormatTag.SetWindowText(strFormatTag); m_ctrlEditCompressedFormat.SetWindowText(strFormat); } }
void CEnString::Format(LPCTSTR lpszFormat, ...) { CString strFormat(lpszFormat); if (!strFormat.IsEmpty()) { TranslateString(strFormat, NULL); va_list argList; va_start(argList, lpszFormat); CString::FormatV(strFormat, argList); va_end(argList); CompareIgnoreString(strFormat); } }
void GDIPlus::RenderText( gwen::Font* pFont, gwen::Point pos, const gwen::UnicodeString & text ) { Translate( pos.x, pos.y ); // If the font doesn't exist, or the font size should be changed if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 ) { FreeFont( pFont ); LoadFont( pFont ); } Gdiplus::StringFormat strFormat( Gdiplus::StringFormat::GenericDefault() ); Gdiplus::SolidBrush solidBrush( m_Colour ); Gdiplus::RectF r( pos.x, pos.y, 1000, 1000 ); Gdiplus::Font* pGDIFont = ( Gdiplus::Font* ) pFont->data; graphics->DrawString( text.c_str(), text.length() + 1, pGDIFont, r, &strFormat, &solidBrush ); }
double ASSISTANT::Text::GetTextWidth(const _TCHAR *textString, int textLength, LOGFONT *logFont) { if (textLength == 0) return 0; HDC hdc = ::CreateCompatibleDC(NULL); //Gdiplus::Graphics graphics(hdc); WCHAR *wcString = (WCHAR *)malloc((textLength+1)*sizeof(WCHAR)); #ifdef _UNICODE wcscpy(wcString, textString); #else MultiByteToWideChar(CP_ACP, 0, textString, textLength+1, wcString, textLength+1); #endif Gdiplus::RectF bbox; Gdiplus::Font font(hdc, logFont); Gdiplus::Graphics graphics(hdc); graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAliasGridFit); Gdiplus::StringFormat strFormat(Gdiplus::StringFormatFlagsMeasureTrailingSpaces); graphics.MeasureString(wcString, textLength, &font, Gdiplus::PointF(0.0, 0.0), &strFormat, &bbox); Gdiplus::CharacterRange charRange(0, textLength); strFormat.SetMeasurableCharacterRanges(1, &charRange); Gdiplus::Region pRangeRegion[1]; graphics.MeasureCharacterRanges(wcString, textLength, &font, bbox, &strFormat, 1, pRangeRegion); // get bounding rectangle Gdiplus::RectF rect; pRangeRegion[0].GetBounds(&rect, &graphics); if (wcString) delete wcString; ::DeleteObject(hdc); ::DeleteDC(hdc); return rect.Width; }
gwen::Point GDIPlus::MeasureText( gwen::Font* pFont, const gwen::UnicodeString & text ) { gwen::Point p( 1, 1 ); if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 ) { FreeFont( pFont ); LoadFont( pFont ); } Gdiplus::StringFormat strFormat( Gdiplus::StringFormat::GenericDefault() ); strFormat.SetFormatFlags( Gdiplus::StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() ); Gdiplus::SizeF size; Gdiplus::Graphics g( m_HWND ); Gdiplus::Font* pGDIFont = ( Gdiplus::Font* ) pFont->data; g.MeasureString( text.c_str(), -1, pGDIFont, Gdiplus::SizeF( 10000, 10000 ), &strFormat, &size ); return gwen::Point( size.Width + 1, size.Height + 1 ); }
any luaToAny(lua_State* plua_state, int index) { any a; LuaType type = luaGetType(plua_state, index); switch (type) { case LuaBoolean: a = luaToBoolean(plua_state, index); break; case LuaLightUserData: a = luaToLightUserData(plua_state, index); break; case LuaNumber: a = luaIsInteger(plua_state, index) ? luaToInteger(plua_state, index) : luaToDouble(plua_state, index); break; case LuaString: a = luaToString(plua_state, index); break; default: throw Exception(strFormat("value type (%d) cannot convert to any type", type)); break; } return a; }
/* ------------------------------------------------------------- */ LGL jx_sqlExec(PUCHAR sqlstmt , PJXNODE pSqlParms) { PNPMPARMLISTADDRP pParms = _NPMPARMLISTADDR(); LONG attrParm; LONG i; // PJXSQL pSQL = jx_sqlNewStatement (pParms->OpDescList->NbrOfParms >= 2 ? pSqlParms :NULL); PJXSQL pSQL = jx_sqlNewStatement (NULL); pSQL->rc = SQLAllocStmt(pConnection->hdbc, &pSQL->hstmt); if (pSQL->rc != SQL_SUCCESS ) { check_error (pSQL); return ON ; // we have an error } // run the statement in "sqlstr" if (pParms->OpDescList->NbrOfParms >= 2) { UCHAR sqlTempStmt[32766]; strFormat(sqlTempStmt , sqlstmt , pSqlParms); pSQL->rc = SQLExecDirect (pSQL->hstmt, sqlTempStmt , SQL_NTS); } else { pSQL->rc = SQLExecDirect (pSQL->hstmt, sqlstmt, SQL_NTS); } if (pSQL->rc != SQL_SUCCESS && pSQL->rc != SQL_NO_DATA_FOUND) { check_error (pSQL); return ON; // we have an error } jx_sqlClose (&pSQL); return OFF; }
//================================================= // Overrides //================================================= BOOL CMainDlg::OnInitDialog() { CDialog::OnInitDialog(); // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); // Add "About..." menu item to system menu. CMenu* pSysMenu = GetSystemMenu(FALSE); if(pSysMenu != NULL) { CString strAboutMenu = _T("About..."); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // Set max-length on edit boxes CEdit* pEdit = NULL; VERIFY(pEdit = (CEdit*)GetDlgItem(IDC_IMAGE_NAME)); pEdit->SetLimitText(50); // Fill combo with all supported image formats CComboBox* pCombo = NULL; VERIFY(pCombo = (CComboBox*)GetDlgItem(IDC_IMAGE_EXT)); ImageCodecInfo* pImageCodecInfo = NULL; UINT nCount = 0; // number of image encoders UINT nSize = 0; // size of the image encoder array in bytes GetImageEncodersSize(&nCount, &nSize); if(nSize > 0) { pImageCodecInfo = (ImageCodecInfo*)(malloc(nSize)); if(pImageCodecInfo != NULL) { GetImageEncoders(nCount, nSize, pImageCodecInfo); for(UINT x = 0; x < nCount; x ++) { CString strFormat(pImageCodecInfo[x].FormatDescription); int iItem = pCombo->AddString(strFormat); ASSERT(iItem != -1); CLSID* pCLSID = new CLSID; ASSERT(pCLSID); *pCLSID = pImageCodecInfo[x].Clsid; pCombo->SetItemData(iItem, (DWORD_PTR)pCLSID); // JPEG will be our default image type if(strFormat.CompareNoCase(_T("jpeg")) == 0) { m_clsidImgType = pImageCodecInfo[x].Clsid; pCombo->SetCurSel(iItem); } } free(pImageCodecInfo); } } SetControlValues(); // Start keyboard hook to capture the print screen key ActivateKeyboardHook(TRUE); return TRUE; // return TRUE unless you set the focus to a control }
CString CSPTime::FormatGmt(LPCSTR pFormat) const { CString strFormat(pFormat); return FormatGmt((LPCTSTR)strFormat); }
/* ------------------------------------------------------------- */ PJXSQL jx_sqlOpen(PUCHAR sqlstmt , PJXNODE pSqlParms) { PNPMPARMLISTADDRP pParms = _NPMPARMLISTADDR(); // LONG format = (pParms->OpDescList->NbrOfParms >= 3) ? formatP : 0; // Status & result object LONG attrParm; LONG i; // PJXSQL pSQL = jx_sqlNewStatement (pParms->OpDescList->NbrOfParms >= 2 ? pSqlParms :NULL); PJXSQL pSQL = jx_sqlNewStatement (NULL); pSQL->rc = SQLAllocStmt(pConnection->hdbc, &pSQL->hstmt); if (pSQL->rc != SQL_SUCCESS ) { check_error (pSQL); return NULL; // we have an error } attrParm = SQL_TRUE; pSQL->rc = SQLSetStmtAttr (pSQL->hstmt, SQL_ATTR_CURSOR_SCROLLABLE , &attrParm , 0); if (pSQL->rc != SQL_SUCCESS ) { check_error (pSQL); return NULL; // we have an error } /* attrParm = SQL_TRUE; pSQL->rc = SQLSetStmtAttr (pSQL->hstmt, SQL_ATTR_EXTENDED_COL_INFO , &attrParm , 0); if (pSQL->rc != SQL_SUCCESS ) { check_error (pSQL); return NULL; // we have an error } */ attrParm = SQL_CONCUR_READ_ONLY; pSQL->rc = SQLSetStmtAttr (pSQL->hstmt, SQL_ATTR_CONCURRENCY , &attrParm , 0); if (pSQL->rc != SQL_SUCCESS ) { check_error (pSQL); return NULL; // we have an error } // run the statement in "sqlstr" if (pParms->OpDescList->NbrOfParms >= 2 && pSqlParms ) { UCHAR sqlTempStmt[32766]; strFormat(sqlTempStmt , sqlstmt , pSqlParms); pSQL->sqlstmt = strdup(sqlTempStmt); } else { pSQL->sqlstmt = strdup(sqlstmt); } pSQL->rc = SQLExecDirect (pSQL->hstmt, pSQL->sqlstmt, SQL_NTS); if (pSQL->rc != SQL_SUCCESS && pSQL->rc != SQL_NO_DATA_FOUND) { check_error (pSQL); return NULL; // we have an error } // Number of rows? .. No does not work :( /* SQLGetDiagField(SQL_HANDLE_STMT,pSQL->hstmt, 0 ,SQL_DIAG_ROW_COUNT,&pSQL->rowcount,0, NULL); */ /* // Row count is only affected row in a "delete" or "update" ..TODO find a solution for select pSQL->rc = SQLRowCount (pSQL->hstmt, &pSQL->rowcount); if (pSQL->rc != SQL_SUCCESS ) { check_error (pSQL); return; // we have an error } */ pSQL->rc = SQLNumResultCols (pSQL->hstmt, &pSQL->nresultcols); if (pSQL->rc != SQL_SUCCESS ) { check_error (pSQL); return NULL; // we have an error } for (i = 0; i < pSQL->nresultcols; i++) { PJXCOL pCol = &pSQL->cols[i]; SQLDescribeCol (pSQL->hstmt, i+1, pCol->colname, sizeof (pCol->colname), &pCol->colnamelen, &pCol->coltype, &pCol->collen, &pCol->scale, &pCol->nullable); pCol->colname[pCol->colnamelen] = '\0'; if (OFF == jx_IsTrue (pConnection->pOptions ,"uppercasecolname")) { str2lower (pCol->colname , pCol->colname); } // get display label for column /**************** pSQL->rc = SQLColAttributes (hstmt, i+1, SQL_DESC_LABEL, Label , sizeof(Label) , &len , NULL); if (pSQL->rc != SQL_SUCCESS ) { check_error (pSQL); return; // we have an error } ***********/ // get display length for column SQLColAttributes (pSQL->hstmt, i+1, SQL_DESC_PRECISION, NULL, 0,NULL, &pCol->displaysize); // set column length to max of display length, and column name // length. Plus one byte for null terminator // collen[i] = max(displaysize, collen[i]); // collen[i] = max(collen[i], strlen((char *) colname) ) + 1; // printf ("%-*.*s", collen[i], collen[i], colname); // allocate memory to bind column // bind columns to program vars, converting all types to CHAR //*SQLBindCol (hstmt, i+1, SQL_C_CHAR, data[i], collen[i], &outlen[i]); switch( pCol->coltype) { case SQL_BLOB: case SQL_CLOB: // pCol->collen = pCol->displaysize * 2; // pCol->data = (SQLCHAR *) malloc (pCol->collen); pCol->collen = 1048576; // 1MEGABYTES pCol->data = (SQLCHAR *) malloc (pCol->collen); // 1MEGABYTES SQLBindCol (pSQL->hstmt, i+1, SQL_C_BINARY , pCol->data, pCol->collen, &pCol->outlen); break; case SQL_WCHAR: case SQL_WVARCHAR: case SQL_GRAPHIC: case SQL_VARGRAPHIC: pCol->collen = pCol->displaysize * 2; pCol->data = (SQLCHAR *) malloc (pCol->collen); SQLBindCol (pSQL->hstmt, i+1, pCol->coltype, pCol->data, pCol->collen, &pCol->outlen); break; default: pCol->collen = pCol->displaysize + 3; // + . and , and zero term pCol->data = (SQLCHAR *) malloc (pCol->collen); SQLBindCol (pSQL->hstmt, i+1, SQL_C_CHAR, pCol->data, pCol->collen, &pCol->outlen); break; } if (pCol->coltype >= SQL_NUMERIC && pCol->coltype <= SQL_DOUBLE) { pCol->nodeType = JX_LITERAL; } else { pCol->nodeType = JX_VALUE; } } return pSQL; }
void GString::FormatNumber(const char *szFormat, char decimal_separator, char grouping_separator, char minus_sign, const char *NaN, char zero_digit, char digit, char pattern_separator, char percent, char permille) { if (szFormat && *szFormat) { // make sure that the string is a number {0..9, '.', '-'} // if the string contains a character not in the number // subset then set the value of the string to NaN. const char *szValue = _str; if (IsNaN(szValue, '.', ',', '-')) *this = NaN; else { // it's a number, get the whole part and the fraction part int nIdx = Find('.'); GString strWhole; strWhole = (nIdx == -1) ? _str : (const char *)Left(nIdx); GString strFraction('0', (short)1); nIdx = Find('.') + 1; if (nIdx > 0) strFraction = Mid(nIdx); bool bIsNeg = (Find(minus_sign) != -1); long nWhole = abs(atol((const char *)strWhole)); long nFract = abs(atol((const char *)strFraction)); // check for % and ? if (percent == szFormat[0]) { double d = atof(_str); d *= 100; GString strTemp; strTemp.Format("%f", d); nIdx = strTemp.Find('.'); strFraction = (nIdx == -1) ? strTemp._str : (const char *)strTemp.Left(nIdx); nWhole = atol((const char *)strFraction); nFract = 0; } if (permille == szFormat[0]) { double d = atof(_str); d *= 1000; GString strTemp; strTemp.Format("%f", d); nIdx = strTemp.Find('.'); strFraction = (nIdx == -1) ? strTemp._str : (const char *)strTemp.Left(nIdx); nWhole = atol((const char *)strFraction); nFract = 0; } // if the number is negative, get the negative pattern out of the format. // if a negative pattern doesn't exist, the minus_sign will be prepended // to the positive pattern. GString strFormat(szFormat); nIdx = strFormat.Find(pattern_separator); if (bIsNeg) { if (nIdx != -1) strFormat = strFormat.Mid(nIdx + 1); else strFormat.Format("%c%s", minus_sign, (const char *)strFormat); } else { if (nIdx != -1) strFormat = strFormat.Left(nIdx); } GString strFormatWhole(strFormat); GString strFormatDecimal('#', (short)1); // determine the number of digits per group int nGroup = 0; nIdx = strFormat.Find(','); if (nIdx != -1) { nIdx++; int nNext = strFormat.Find(',', nIdx); if (nNext == -1) nNext = strFormat.Find('.', nIdx); if (nNext == -1) nNext = strFormat.Length(); nGroup = (nNext - nIdx); } // determine the number of decimals to display int nDecimals = 0; nIdx = strFormat.Find('.'); if ((nIdx != -1) && (percent != szFormat[0]) && (permille != szFormat[0])) { if (nGroup) strFormatWhole = strFormat.Mid(nIdx - nGroup, nGroup); else strFormatWhole = strFormat.Left(nIdx); nIdx++; strFormatDecimal = strFormat.Mid(nIdx); nDecimals = (strFormat.Length() - nIdx); } // Format the whole part of the number int nCount = CountOf((const char *)strFormatWhole, zero_digit); strWhole.Format("%0ld", nWhole); if (strWhole.Length() < nCount) { GString temp(zero_digit, (short)(nCount - (short)strWhole.Length())); strWhole.Format("%s%s", (const char *)temp, (const char *)strWhole); } Empty(); // add all prefix characters nIdx = 0; const char *szP = (const char *)strFormat; while (*szP) { if (*szP == digit || *szP == zero_digit || *szP == decimal_separator || *szP == grouping_separator || *szP == percent || *szP == permille) break; szP++; nIdx++; } strFormat = strFormat.Left(nIdx); strFormat.MakeReverse(); int i, j; for (i = 0, j = strWhole.Length() - 1; j >= 0; j--, i++) { if ((nGroup) && (i == nGroup)) { *this += grouping_separator; i = 0; } *this += strWhole[j]; } *this += strFormat; MakeReverse(); if (nDecimals) { *this += decimal_separator; strFraction.Format("%ld", nFract); const char *szF1 = (const char *)strFormatDecimal; const char *szF2 = (const char *)strFraction; i = 0; while (*szF1) { if (*szF2) *this += *szF2; else if (*szF1 == zero_digit) *this += zero_digit; else if (*szF1 != digit) // add all sufix characters *this += *szF1; if (*szF2) szF2++; if (*szF1) szF1++; } } if (percent == szFormat[0]) *this += percent; if (permille == szFormat[0]) *this += permille; } } }
LRESULT CExtractDlg::OnUpdateOptionsClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { if(m_currentGroup > 0) { if(m_currentGroup == 1) // Extract Molecule Count { if(IsDlgButtonChecked(IDC_RDO_EXTRACTALL) == BST_CHECKED) m_params.extractMolCount = -1; else { int val = GetDlgItemInt(IDC_EDTEXTRACTCOUNT, NULL, false); if(val <= 0) { MessageBox(_T("Value must be greater than 0."), _T("Validation Failed"), MB_OK | MB_ICONWARNING); return 0; } m_params.extractMolCount = val; } } else if(m_currentGroup == 2) // File Format { TCHAR format[50]; GetDlgItemText(IDC_EDT_FILEFORMAT, format, 50); size_t start = 0; int countPercentD = 0; tstring strFormat(format); // count the number of %d in format string while ((start = strFormat.find(_T("%d"), start)) != std::string::npos) { ++countPercentD; start += 2; } // count the number of % sign in format string size_t countPercents = std::count(strFormat.begin(), strFormat.end(), _T('%')); // make sure we have exactly ONE %d in the format if((countPercentD != 1) || (countPercents > 1)) { MessageBox(_T("Format is not correct. Format string must contain exactly one %d which will be replaced by a number during extract operation."), _T("Validation Failed"), MB_OK | MB_ICONWARNING); return 0; } // looks ok, copy to main variable _tcscpy_s(m_params.fileFormat, 50, format); } RECT rect; GetWindowRect(&rect); SetWindowPos(NULL, -1, -1, rect.right - rect.left, 170, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER); m_currentGroup = -1; // no active group UpdateLinkText(); } return 0; }
void VoxMain::run() { int modesw = 3; uint64_t cnt = 0; timeval tvchk = {0, 0}; timeval tvcur = {0, 0}; std::string datastr = ""; INFORMATION("(MAIN) start of loop"); pinMode(modesw, INPUT); pullUpDnControl(modesw, PUD_UP); gettimeofday(&tvchk, NULL); while(!m_exit) { int onoff = digitalRead(modesw); gettimeofday(&tvcur, NULL); if(onoff == LOW) { std::string retstr = ""; if(m_mode > MD5) --m_mode; else m_mode = MD1; NOTICE("mode changed: mode=%d", m_mode); if(m_mode == MD1) // control { } else if(m_mode == MD2) // vision { //if(!createProcess("/home/pi/mjpg-streamer/stop_mjpg.sh", retstr)) // ERROR("(MAIN) failed to stop mjpg-streamer"); } else if(m_mode == MD3) // voice { } Servo* servo = VoxControl::getInstance().getServo(); servo->setNeutral(); VoxPlayer::getInstance().play("", false); delay(300); } if(timeSpan(tvchk, tvcur) >= 1.0f) { cpuUsage(); tvchk.tv_sec = tvcur.tv_sec; tvchk.tv_usec = tvcur.tv_usec; } if((cnt % 100) == 0) { std::vector<std::string> addrs; getLocalIPString(addrs); m_myip = ""; for(size_t i = 0; i < addrs.size(); i++) { std::string acls = ""; extractSubString(acls, addrs[i].c_str(), 0, '.'); if(isPositiveNumber(acls)) { if(acls != "127") m_myip += addrs[i] + ", "; } } m_myip = strTrim(m_myip, " ,"); std::string retstr = ""; if(createProcess("/usr/bin/vcgencmd measure_temp", retstr)) { strRemove(retstr, "temp="); strRemove(retstr, "'C"); m_cputemp = atof(retstr.c_str()); } m_appmem = getRss(); } if((cnt % 2) == 0) { bool voice = VoxVoice::getInstance().isRunning(); datastr = strFormat("%s|%d|%d|%d|%.1f|%.1f|%.1f|%.1f|%.1f|%.1f|%.1f|%.1f|%.1f|%d|%d|%d|%.1f|%d|%d|%s|%s", m_myip.c_str(), abs(MD1 - m_mode) + 1, m_stat, VoxSensor::getInstance().isFreeze(), VoxSensor::getInstance().getTemperature(), VoxSensor::getInstance().getHumidity(), VoxSensor::getInstance().getDistF(), VoxSensor::getInstance().getDistB(), VoxSensor::getInstance().getDistL(), VoxSensor::getInstance().getDistR(), m_cpuusage, m_cputemp, (float)(m_appmem / 1024.0 / 1024.0), VoxVision::getInstance().isFollowing(), VoxVision::getInstance().getPosX(), VoxVision::getInstance().getPosY(), VoxVision::getInstance().getRadius(), VoxVision::getInstance().getBallCount(), (voice) ? VoxVoice::getInstance().readyToGo() : 0, (voice) ? VoxVoice::getInstance().getReq().c_str() : "", (voice) ? VoxVoice::getInstance().getRsp().c_str() : "" ); writeDataFile(datastr); } delay(150); ++cnt; } pinMode(modesw, OUTPUT); digitalWrite(modesw, LOW); INFORMATION("(MAIN) end of loop"); }