map<string, string> ParseShdFromString(const string &acc) { map<string, string> mapNameShd; P p(acc); while (true) { string markS("======"), markE("@@@@@@"); P pS(p); bool afterNextDelS = pS.OptAfterNextDelShallow(markS); P pE(pS); bool afterNextDelE = pE.OptAfterNextDelDeep(markE); if (! (afterNextDelS && afterNextDelE)) break; string shdNameSpan(pS.OptRawSpanTo(pE)); assert(shdNameSpan.size() >= markE.size() && equal(markE.begin(), markE.end(), shdNameSpan.rbegin())); string shdName(StrTrim(shdNameSpan.substr(0, shdNameSpan.size() - markE.size()))); P pContentS(pE); P pContentE(pContentS); bool afterNextDelContent = pContentE.OptAfterNextDelDeep(markS); if (afterNextDelContent) { pContentE.AdvanceN(- (int)markS.size()); mapNameShd[shdName] = StrTrim(pContentS.OptRawSpanTo(pContentE)); } else { mapNameShd[shdName] = StrTrim(pContentS.OptRawSpanToEnd()); } p = pContentE; } return mapNameShd; }
void main() { print_rules(); // production rules printf("Input string(ex. aabbccd) = "); ch = getchar(); // input string: "aabbbccd" pS(); if (!errflag && ch==END) puts("OK"); else error(); }
int main(const int argc, const char **argv) { MYLOGVERB = LOG_INFO; ModelManager *mgr = new ModelManager("Extract Patches for Hmax with Feature Learning"); mgr->exportOptions(MC_RECURSE); // required arguments // <c1patchesDir> <trainPosDir> if (mgr->parseCommandLine( (const int)argc, (const char**)argv, "<c1patchesDir> <trainPosDir>", 2, 2) == false) return 1; // Create a temp HmaxFL object to extract C1Patches std::vector<int> c1ScaleSS(2); c1ScaleSS[0] = 1; c1ScaleSS[1] = 3; std::vector<int> c1SpaceSS(2); c1SpaceSS[0] = 10; c1SpaceSS[1] = 11; // desired frame sizes [11 and 13] HmaxFL hmax(NORI,c1SpaceSS,c1ScaleSS,2,true,1.0F,1.0F,0.3F,4.05F,-0.05F,11,2); std::string c1PatchesBaseDir; std::string trainPosName; // Directory where positive images are c1PatchesBaseDir = mgr->getExtraArg(0); trainPosName = mgr->getExtraArg(1); // Extract random patches from a set of images in a positive training directory std::vector<std::string> trainPos = hmax.readDir(trainPosName); int posTrainSize = trainPos.size(); //Image<byte> inputb; Image<float> trainPosImage; std::cout << "Scanned training and testing images" << std::endl; std::vector<int> pS(4); pS[0] = 4; pS[1] = 8, pS[2] = 12; pS[3] = 16; std::srand(time(0)); for(int i=0;i<NUM_PATCHES_PER_SIZE;i++){ // Randomly select an image from the list unsigned int imInd = static_cast<unsigned int>(floor((rand()-1.0F)/RAND_MAX*posTrainSize)); trainPosImage = Raster::ReadFloat(trainPos[imInd]); // Learn the appropriate simple S2 patches from the C1 results hmax.extractRandC1Patch(c1PatchesBaseDir,trainPosImage,i,pS); } std::cout << "Completed extraction of C1 Patches" << std::endl; return 0; }
Task * pT() { Task * task = NULL; tCmd * cmd; if (cur_l->type == LEX_EOL) { waitLex(); return NULL; } else if (cur_l->type == LEX_EOF) return NULL; cmd = pS(); if (cmd == NULL) return NULL; task = newTask(); if (cur_l->type == LEX_BG) { if (glhard()) { delTask(&task); delTCmd(&cmd); return NULL; } task->modeBG = 1; } if (cur_l->type != LEX_EOL && cur_l->type != LEX_EOF) { setParserError(PE_UNEXPECTED_END_OF_COMMAND); delTask(&task); delTCmd(&cmd); return NULL; } task->root = cmd; task->cur = cmd; waitLex(); return task; }
tCmd * puL() { tCmd * cmd; if (cur_l->type == LEX_LPAREN) { if (glhard()) return NULL; cmd = pS(); if (cmd == NULL) return NULL; if (cur_l->type != LEX_RPAREN) { setParserError(PE_EXPECTED_RPAREN); delTCmd(&cmd); return NULL; } if (glhard()) { delTCmd(&cmd); return NULL; } } else { cmd = pP(); if (cmd == NULL) return NULL; } return cmd; }
STDMETHODIMP CXMLDOMDocument::load(VARIANT xmlSource, VARIANT_BOOL *isSuccessful) { ATLTRACE(_T("CXMLDOMDocument::load\n")); if (NULL == isSuccessful) return E_POINTER; *isSuccessful = VARIANT_FALSE; if (V_VT(&xmlSource) != VT_BSTR && V_VT(&xmlSource) != VT_DISPATCH && V_VT(&xmlSource) != (VT_ARRAY | VT_VARIANT) && V_VT(&xmlSource) != (VT_ARRAY | VT_UI1) && V_VT(&xmlSource) != VT_UNKNOWN) return E_INVALIDARG; // do not start another thread if there is another active if (NULL != m_hParseThread) { DWORD exitCode = 0; BOOL rc = ::GetExitCodeThread(m_hParseThread, &exitCode); if (!rc || STILL_ACTIVE == exitCode) return S_OK; ::CloseHandle(m_hParseThread); m_hParseThread = NULL; } HRESULT hr = S_OK; m_bAbort = false; m_FileName = _T(""); m_xml = _T(""); m_TmpDocument = 0; m_bThreadValidate = m_bValidate; if (V_VT(&xmlSource) == VT_BSTR) { m_FileName = V_BSTR(&xmlSource); if (0 == m_FileName.length()) return E_INVALIDARG; // see if the file is relative path if (!PathIsURL(m_FileName) && PathIsRelative(m_FileName)) { // try appending baseurl if exists _bstr_t baseURL; if (S_OK == GetBaseURL(baseURL)) { TCHAR szCurFile[MAX_PATH]; _tcscpy(szCurFile, m_FileName); // change any backslashes to slashes LPTSTR loc = _tcschr(szCurFile,_T('\\')); while (loc != NULL) { *loc = _T('/'); loc = _tcschr(szCurFile,_T('\\')); } m_FileName = baseURL + _T("/") + szCurFile; } else { TCHAR szCurDir[MAX_PATH]; GetCurrentDirectory(MAX_PATH,szCurDir); m_FileName=_bstr_t(szCurDir) + _T("\\") + m_FileName; } } } else if (V_VT(&xmlSource) == VT_UNKNOWN) { CComQIPtr<IStream,&IID_IStream> pS(V_UNKNOWN(&xmlSource)); if (!pS) return E_INVALIDARG; CComBSTR b; hr = b.ReadFromStream(pS); if (S_OK != hr) return hr; m_xml = b; if (0 == m_xml.length()) return E_INVALIDARG; } else if (V_VT(&xmlSource) == VT_DISPATCH) { CComQIPtr<IXMLDOMDocument,&IID_IXMLDOMDocument> pDoc(V_DISPATCH(&xmlSource)); if (!pDoc) return E_INVALIDARG; BSTR b = NULL; hr = pDoc->get_xml(&b); if (S_OK != hr) return hr; m_xml = b; ::SysFreeString(b); if (0 == m_xml.length()) return E_INVALIDARG; } else if (V_VT(&xmlSource) == (VT_ARRAY | VT_VARIANT)) { SAFEARRAY *pArray = reinterpret_cast<SAFEARRAY *> (xmlSource.byref); if (NULL == pArray) return E_INVALIDARG; long lLBoundVar = 0; long lUBoundVar = 0; UINT dims = ::SafeArrayGetDim(pArray); if (dims == 0) return E_INVALIDARG; hr = ::SafeArrayGetLBound(pArray, dims, &lLBoundVar); if (S_OK != hr) return hr; hr = ::SafeArrayGetUBound(pArray, dims, &lUBoundVar); if (S_OK != hr) return hr; if (lUBoundVar >= lLBoundVar) { VARIANT *pIndex = NULL; hr = ::SafeArrayAccessData(pArray, reinterpret_cast<void **> (&pIndex)); if (S_OK != hr) return hr; int length = lUBoundVar-lLBoundVar+2; BYTE *body = new BYTE[length]; for (long i = 0; i <= lUBoundVar-lLBoundVar; ++i) { VARIANT var = pIndex[i]; if (V_VT(&var) != VT_UI1) { hr = E_INVALIDARG; break; } body[i] = V_UI1(&var); } body[length-1] = 0; ::SafeArrayUnaccessData(pArray); if (S_OK != hr) { delete [] body; return hr; } m_xml = reinterpret_cast<char*> (body); delete [] body; if (0 == m_xml.length()) return E_INVALIDARG; } } else if (V_VT(&xmlSource) == (VT_ARRAY | VT_UI1)) { SAFEARRAY *pArray = reinterpret_cast<SAFEARRAY *> (xmlSource.byref); if (NULL == pArray) return E_INVALIDARG; long lLBoundVar = 0; long lUBoundVar = 0; UINT dims = ::SafeArrayGetDim(pArray); if (dims == 0) return E_INVALIDARG; hr = ::SafeArrayGetLBound(pArray, dims, &lLBoundVar); if (S_OK != hr) return hr; hr = ::SafeArrayGetUBound(pArray, dims, &lUBoundVar); if (S_OK != hr) return hr; if (lUBoundVar >= lLBoundVar) { BYTE *pIndex = NULL; hr = ::SafeArrayAccessData(pArray, reinterpret_cast<void **> (&pIndex)); if (S_OK != hr) return hr; int length = lUBoundVar-lLBoundVar+2; BYTE *body = new BYTE[length]; for (long i = 0; i <= lUBoundVar-lLBoundVar; ++i) body[i] = pIndex[i]; body[length-1] = 0; ::SafeArrayUnaccessData(pArray); m_xml = reinterpret_cast<char*> (body); delete [] body; if (0 == m_xml.length()) return E_INVALIDARG; } } UINT nthreadID = 0; m_hParseThread = reinterpret_cast<HANDLE> (_beginthreadex(NULL, 0, CXMLDOMDocument::ParseThread, (void *) this, 0, &nthreadID)); if (NULL == m_hParseThread) return S_OK; if (m_bAsync) { *isSuccessful = VARIANT_TRUE; return S_OK; } bool bWait = true; while (bWait) { DWORD dwEvt = MsgWaitForMultipleObjects(1,&m_hParseThread,FALSE,INFINITE,QS_ALLINPUT); switch(dwEvt) { case WAIT_OBJECT_0: bWait = false; break; case WAIT_OBJECT_0 + 1: { MSG msg; while(::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (WM_CLOSE == msg.message || WM_QUIT == msg.message) { bWait = false; m_bAbort = true; break; } else { PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); TranslateMessage(&msg); DispatchMessage(&msg); } } break; } default: m_bAbort = true; bWait = false; break; } } if (m_bAbort) return S_OK; if (m_bParseError) return hr; if(m_Document) delete m_Document; m_Document = m_TmpDocument; m_TmpDocument = 0; m_url = m_FileName; *isSuccessful = VARIANT_TRUE; return hr; }
STDMETHODIMP CXMLHttpRequest::send(VARIANT varBody) { ATLTRACE(_T("CXMLHttpRequest::send\n")); if (V_VT(&varBody) != VT_BSTR && V_VT(&varBody) != VT_DISPATCH && V_VT(&varBody) != (VT_ARRAY | VT_VARIANT) && V_VT(&varBody) != (VT_ARRAY | VT_UI1) && V_VT(&varBody) != VT_UNKNOWN) return E_INVALIDARG; // do not start another thread if there is another active if (NULL != m_hThread) { DWORD exitCode = 0; BOOL rc = ::GetExitCodeThread(m_hThread, &exitCode); if (!rc || STILL_ACTIVE == exitCode) return E_PENDING; ::CloseHandle(m_hThread); m_hThread = NULL; } HRESULT hr = S_OK; m_bSuccess = true; m_bAbort = false; delete [] m_pBody; m_pBody = NULL; m_lBodyLength = 0; delete [] m_pResponseBody; m_pResponseBody = NULL; m_lResponseBodyLength = 0; m_dwStatus = 0; m_StatusText = _T(""); m_ResponseHeaders = _T(""); if (V_VT(&varBody) == VT_BSTR) { _bstr_t body = V_BSTR(&varBody); m_lBodyLength = body.length() + 1; m_pBody = new BYTE[m_lBodyLength]; memset(m_pBody,0,m_lBodyLength); memcpy(m_pBody,static_cast<char*> (body),body.length()); } else if (V_VT(&varBody) == VT_UNKNOWN) { CComQIPtr<IStream,&IID_IStream> pS(V_UNKNOWN(&varBody)); if (!pS) return E_INVALIDARG; CComBSTR b; hr = b.ReadFromStream(pS); if (S_OK != hr) return hr; _bstr_t body = b; m_lBodyLength = body.length() + 1; m_pBody = new BYTE[m_lBodyLength]; memset(m_pBody,0,m_lBodyLength); memcpy(m_pBody,static_cast<char*> (body),body.length()); } else if (V_VT(&varBody) == VT_DISPATCH) { CComQIPtr<IXMLDOMDocument,&IID_IXMLDOMDocument> pDoc(V_DISPATCH(&varBody)); if (!pDoc) return E_INVALIDARG; BSTR b = NULL; hr = pDoc->get_xml(&b); if (S_OK != hr) return hr; _bstr_t body = b; ::SysFreeString(b); m_lBodyLength = body.length() + 1; m_pBody = new BYTE[m_lBodyLength]; memset(m_pBody,0,m_lBodyLength); memcpy(m_pBody,static_cast<char*> (body),body.length()); } else if (V_VT(&varBody) == (VT_ARRAY | VT_VARIANT)) { SAFEARRAY *pArray = reinterpret_cast<SAFEARRAY *> (varBody.byref); if (NULL == pArray) return E_INVALIDARG; long lLBoundVar = 0; long lUBoundVar = 0; UINT dims = ::SafeArrayGetDim(pArray); if (dims == 0) return E_INVALIDARG; hr = ::SafeArrayGetLBound(pArray, dims, &lLBoundVar); if (S_OK != hr) return hr; hr = ::SafeArrayGetUBound(pArray, dims, &lUBoundVar); if (S_OK != hr) return hr; if (lUBoundVar >= lLBoundVar) { VARIANT *pIndex = NULL; hr = ::SafeArrayAccessData(pArray, reinterpret_cast<void **> (&pIndex)); if (S_OK != hr) return hr; m_lBodyLength = lUBoundVar-lLBoundVar+1; m_pBody = new BYTE[m_lBodyLength]; for (long i = 0; i <= lUBoundVar-lLBoundVar; ++i) { VARIANT var = pIndex[i]; if (V_VT(&var) != VT_UI1) { hr = E_INVALIDARG; break; } m_pBody[i] = V_UI1(&var); } ::SafeArrayUnaccessData(pArray); if (S_OK != hr) { delete [] m_pBody; m_pBody = NULL; m_lBodyLength = 0; return hr; } } } else if (V_VT(&varBody) == (VT_ARRAY | VT_UI1)) { SAFEARRAY *pArray = reinterpret_cast<SAFEARRAY *> (varBody.byref); if (NULL == pArray) return E_INVALIDARG; long lLBoundVar = 0; long lUBoundVar = 0; UINT dims = ::SafeArrayGetDim(pArray); if (dims == 0) return E_INVALIDARG; hr = ::SafeArrayGetLBound(pArray, dims, &lLBoundVar); if (S_OK != hr) return hr; hr = ::SafeArrayGetUBound(pArray, dims, &lUBoundVar); if (S_OK != hr) return hr; if (lUBoundVar >= lLBoundVar) { BYTE *pIndex = NULL; hr = ::SafeArrayAccessData(pArray, reinterpret_cast<void **> (&pIndex)); if (S_OK != hr) return hr; m_lBodyLength = lUBoundVar-lLBoundVar+1; m_pBody = new BYTE[m_lBodyLength]; for (long i = 0; i <= lUBoundVar-lLBoundVar; ++i) m_pBody[i] = pIndex[i]; ::SafeArrayUnaccessData(pArray); } } m_HwndParent = GetParentWindow(); UINT nthreadID = 0; m_hThread = reinterpret_cast<HANDLE> (_beginthreadex(NULL, 0, CXMLHttpRequest::SendThread, (void *) this, 0, &nthreadID)); if (NULL == m_hThread) return E_FAIL; if (m_bAsync) return S_OK; bool bWait = true; while (bWait) { DWORD dwEvt = MsgWaitForMultipleObjects(1,&m_hThread,FALSE,INFINITE,QS_ALLINPUT); switch(dwEvt) { case WAIT_OBJECT_0: bWait = false; break; case WAIT_OBJECT_0 + 1: { MSG msg; while(::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (WM_CLOSE == msg.message || WM_QUIT == msg.message) { bWait = false; m_bAbort = true; break; } else { PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); TranslateMessage(&msg); DispatchMessage(&msg); } } break; } default: m_bAbort = true; bWait = false; break; } } return S_OK; }