inline BOOL Effect::GetDefaultTexture(HANDLE hObject, String &value) const { assert(hObject); EffectParam *param = ConvertParam(hObject); if(!param || !param->DefaultValue.Num()) return FALSE; BufferInputSerializer sIn(param->DefaultValue); sIn << value; return TRUE; }
vecD BenchMarkLatex::readVectorFromMatlabeFile(CStr &fileName, CStr &vecName) { ifstream fin(fileName); CV_Assert(fin.is_open()); string lineStr, token = vecName + " = ["; while (getline(fin, lineStr)) if (strncmp(_S(lineStr), _S(token), token.size() - 1) == 0) break; CV_Assert_(lineStr.size(), ("Can't load vector '%s' from: %s\n", _S(vecName), _S(fileName))); lineStr = lineStr.substr(token.size()); istringstream sIn(lineStr); vecD scores; double s; while (sIn>>s) scores.push_back(s); return scores; }
void LogViewRE::Log(LogFacility logType, LPCWSTR aName, SAFEARRAY* pVals, LPDISPATCH pOptions) { LogIntro(logType, aName); ATLASSERT(0 == pVals->rgsabound[0].lLbound); VARIANT* pVariants = (VARIANT*)pVals->pvData; // see if we can do a printf ULONG valueCount = pVals->rgsabound[0].cElements; ULONG currentValueIndex = 0; if ((valueCount > 1) && (VT_BSTR == pVariants[0].vt)) { ++currentValueIndex; CStringW sIn(pVariants[0].bstrVal), sOut; int pos = sIn.Find(L'%'); int posLast = 0; int sInLength = sIn.GetLength(); while((-1 != pos) && (pos < sInLength-1) && (currentValueIndex < valueCount)) { // add everything before sOut += sIn.Mid(posLast, (pos - posLast)); ++pos; wchar_t format = sIn[pos]; CComVariant vt(pVariants[currentValueIndex]); HRESULT hr = E_FAIL; switch(format) { case L's': // a string: change to string type and log as it is hr = vt.ChangeType(VT_BSTR); if (SUCCEEDED(hr)) { sOut += vt.bstrVal; } ++currentValueIndex; ++pos; break; case L'd': case L'i': // an integer number // check for type, set "undefined" if empty, "NaN" if can't be converted to a number { CStringW s; switch (vt.vt) { case VT_I1: case VT_I2: case VT_I4: case VT_INT: s.Format(L"%i", vt.lVal); break; case VT_UI1: case VT_UI2: case VT_UI4: case VT_UINT: s.Format(L"%u", vt.ulVal); break; case VT_EMPTY: s = L"-undefined-"; break; default: if (SUCCEEDED(vt.ChangeType(VT_UI4))) { s.Format(L"%u", vt.ulVal); } else if (SUCCEEDED(vt.ChangeType(VT_I4))) { s.Format(L"%u", vt.lVal); } else { s = L"NaN"; } break; } ++currentValueIndex; sOut += s; } ++pos; break; case L'f': // a float number // check for type, set "undefined" if empty, "NaN" if can't be converted to a number { CStringW s; switch (vt.vt) { case VT_R4: s.Format(L"%f", vt.fltVal); break; case VT_R8: s.Format(L"%f", vt.dblVal); break; case VT_EMPTY: s = L"-undefined-"; break; default: if (SUCCEEDED(vt.ChangeType(VT_R8))) { s.Format(L"%f", vt.dblVal); } else { s = L"NaN"; } break; } ++currentValueIndex; sOut += s; } ++pos; break; case L'o': // an object // check for type, set "undefined" if empty, "NaO" if can't be converted to string representation if (VT_DISPATCH == vt.vt) { CStringW s, s2; s2.Format(L"[Object at 0x%%0%ix]", sizeof(vt.pdispVal) * 2); s.Format(s2, (IUnknown*)(vt.pdispVal)); sOut += s; } else if (VT_EMPTY == vt.vt) { sOut += L"-undefined-"; } else if (SUCCEEDED(vt.ChangeType(VT_BSTR))) { sOut += vt.bstrVal; } else { sOut += L"NaO"; } ++currentValueIndex; ++pos; break; default: // all other cases: not a format spec, take it as it is sOut += L'%'; sOut += format; ++pos; break; } posLast = pos; pos = sIn.Find(L'%', pos); } // append the rest sOut += sIn.Mid(posLast); LogVariant(CComVariant(sOut)); AppendText(_T(" ")); } // log all the rest for(ULONG n = currentValueIndex; n < pVals->rgsabound[0].cElements; n++) { LogVariant(pVariants[n]); AppendText(_T(" ")); } LogExtro(); }
//-------------------------------------------------------------------------------- void CDelimFile::ParseLine(char cDelim, char cComment, bool bStripQuotes, LPCTSTR pText, CStringArray& sOut) { CString sIn(pText); sIn.TrimLeft(); sIn.TrimRight(); if(sIn.IsEmpty()) return; // if this is a comment line then // add the whole thing and return if(sIn[0] == cComment) { sOut.Add(sIn); return; } CString sTemp; for(int i = 0; i < sIn.GetLength(); i++) { // is this a quoted string if(sIn[i] == '"') { // find the closing quote int nIndex = sIn.Find('"', i + 1); // no closing quote if(nIndex == -1) { // add the remainder of the string and return sTemp = sIn.Mid(i + 1); sTemp.TrimLeft(); sTemp.TrimRight(); sOut.Add(sTemp); return; } else { // start at the quote if quotes are included // otherwise start at the next char int nOffset = bStripQuotes ? 1 : 0; int nBackset = bStripQuotes ? -1 : 1; sTemp = sIn.Mid(i + nOffset, nIndex - i + nBackset); sTemp.TrimLeft(); sTemp.TrimRight(); sOut.Add(sTemp); sTemp.Empty(); i = nIndex + 1; } } else if(sIn[i] == cDelim) { sTemp.TrimLeft(); sTemp.TrimRight(); sOut.Add(sTemp); sTemp.Empty(); } else sTemp += sIn[i]; } if(! sTemp.IsEmpty()) { sTemp.TrimLeft(); sTemp.TrimRight(); sOut.Add(sTemp); } }
bool wxGISLocalServerConnection::ProcessInputNetMessage(void) { if(!m_pSock || m_pSock->IsDisconnected()) { return false; } if (m_pSock->WaitForRead(0, WAITFOR)) { wxJSONValue value; wxJSONReader reader; #ifdef USE_STREAMS wxSocketInputStream in(*m_pSock); int numErrors = reader.Parse( in, &value ); #ifdef _DEBUG //wxString sOut; //wxJSONWriter writer(wxJSONWRITER_NONE); //writer.Write(value, sOut); //wxLogMessage(sOut); #endif // _DEBUG #else RtlZeroMemory(m_Buffer, sizeof(m_Buffer)); wxUint32 nRead(0); nRead = m_pSock->ReadMsg(m_Buffer, BUFF_SIZE).LastCount(); wxString sIn(m_Buffer, nRead); #ifdef _DEBUG wxLogDebug(wxString::Format(wxT("rcv:%d bits, %s"), nRead, sIn)); #endif // _DEBUG //m_pSock->SetTimeout(SLEEP); //m_pSock->SetFlags(wxSOCKET_WAITALL | wxSOCKET_BLOCK); int numErrors = reader.Parse( sIn, &value ); #endif // USE_STREAMS if ( numErrors > 0 ) { const wxArrayString& errors = reader.GetErrors(); wxString sErrMsg(_("Invalid input message")); for (size_t i = 0; i < errors.GetCount(); ++i) { wxString sErr = errors[i]; sErrMsg.Append(wxT("\n")); sErrMsg.Append(wxString::Format(wxT("%d. %s"), i, sErr.c_str())); } wxLogVerbose(sErrMsg); return false; } wxNetMessage msg(value); if(!msg.IsOk()) { wxLogVerbose(_("Invalid input message")); return false; } PostEvent(new wxGISNetEvent(m_nUserId, wxGISNET_MSG, msg)); return true; } return false; }