TEST_FIXTURE(UrlTagFixtureClass, FindByUrlMatch) { CHECK_EQUAL(2, DatabaseRecordsNumDb1()); wxURI toFind(wxT("http://localhost/frontend.php")); t4p::UrlTagClass urlTag; CHECK(Finder.FindByUrl(toFind, SourceDirs, urlTag)); CHECK(toFind == urlTag.Url); CHECK_EQUAL(wxT("http://localhost/frontend.php"), urlTag.Url.BuildURI()); // use filename to compare because we want this test to run on windows and on // linux without needing modifications CHECK(wxFileName(wxT("/home/user/frontend.php")) == urlTag.FileName); CHECK_EQUAL(wxT("FrontendController"), urlTag.ClassName); CHECK_EQUAL(wxT("action"), urlTag.MethodName); toFind.Create(wxT("http://localhost/index.php")); CHECK(Finder.FindByUrl(toFind, SourceDirs, urlTag)); CHECK(toFind == urlTag.Url); CHECK_EQUAL(wxT("http://localhost/index.php"), urlTag.Url.BuildURI()); // use filename to compare because we want this test to run on windows and on // linux without needing modifications CHECK(wxFileName(wxT("/home/user/welcome.php")) == urlTag.FileName); CHECK_EQUAL(wxT("WelcomeController"), urlTag.ClassName); CHECK_EQUAL(wxT("index"), urlTag.MethodName); }
int QByteArray::lastIndexOf(const char *c, int from) const { ESS_ASSERT( (from >= -1) && (from < size()) ); std::string toFind(c); return m_data.rfind(toFind, from); }
int toFind(int v) { if (root[v] == v) { /* Se o elemento for a raiz do conjunto disjunto. */ return v; } else { /* Complicado explicar com palavras, mas a ideia é fazer com que a raiz de qualquer elemento seja a raiz de todo o conjunto. */ return root[v] = toFind(root[v]); } }
ProxyManagerPtr HostedObject::getProxyManager(const SpaceID& space, const ObjectReference& oref) { Mutex::scoped_lock lock(presenceDataMutex); SpaceObjectReference toFind(space,oref); PresenceDataMap::const_iterator it = mPresenceData.find(toFind); if (it == mPresenceData.end()) return ProxyManagerPtr(); return it->second->proxyManager; }
int toUnion(int v, int u) { /* Se os elementos já pertencem ao mesmo conjunto. */ if (toFind(v) == toFind(u)) { return 0; } else { /* Como eu chamei o método toFind() antes, root[u] é a raiz do conjunto de u, e root[v] é a raiz do conjunto de v. */ root[root[v]] = root[u]; return 1; /* * Uma outra maneira de pensar é que, se não tivéssemos a otimização do toFind(), precisaríamos encontrar a raiz do conjunto de v * e, então, fazer com que a raiz da raiz de v receba u ou a raiz de u. */ // while(root[v] != v) { // v = root[v]; // } // root[v] = u; } }
// lookup. default result is "unknown". // We must look for *every* parent path because of situations like: // excluded: C:, C:\some\deep\path // include: C:\some // lookup for C:\some\deeper\path tristate_t ShellCache::CPathFilter::IsPathAllowed(LPCTSTR path, TData::const_iterator begin, TData::const_iterator end) const { tristate_t result = tristate_unknown; // handle special cases if (begin == end) return result; size_t maxLength = wcslen(path); if (maxLength == 0) return result; // look for the most specific entry, start at the root size_t pos = 0; do { LPCTSTR backslash = wcschr(path + pos + 1,L'\\'); pos = backslash == nullptr ? maxLength : backslash - path; std::pair<LPCTSTR, size_t> toFind(path, pos); TData::const_iterator iter = std::lower_bound(begin, end, toFind); // found a relevant entry? if ((iter != end) && (iter->path.length() == pos) && (_wcsnicmp(iter->path.c_str(), path, pos) == 0)) { // exact match? if (pos == maxLength) return iter->included; // parent match result = iter->subPathIncluded; // done? if (iter->hasSubFolderEntries) begin = iter; else return result; } else { // set a (potentially) closer lower limit if (iter != begin) begin = --iter; } // set a (potentially) closer upper limit end = std::upper_bound(begin, end, toFind); } while ((pos < maxLength) && (begin != end)); // nothing more specific found return result; }
/* BAD PART. NEEDS REFACTORING */ void Configurator::handleConfigurationFileLine(std::string line, int type) { std::string configurationExpressions[] = {CONFIGURATIONEXPRESSIONS}; int numberOfExpressions = sizeof(configurationExpressions) / sizeof(std::string); double value = -1; for(int i = 0; i < numberOfExpressions; i++) { std::string toFind(configurationExpressions[i]); std::size_t found = line.find(toFind); if (found != std::string::npos) { value = getNumberFromString(line); defineVariable(i, value, type); } } }
void HelpBrowser::bookmarkButton_clicked() { QString title = textBrowser->documentTitle(); QString fname(QDir::cleanPath(textBrowser->source().toLocalFile())); title = QInputDialog::getText(this, tr("New Bookmark"), tr("New Bookmark's Title:"), QLineEdit::Normal, title, 0); // user cancel if (title.isNull()) return; //TODO: start storing full paths QString toFind(fname.remove(QDir::toNativeSeparators(finalBaseDir))); toFind=toFind.mid(1, toFind.length()-1); QMapIterator<QString, QString> i(quickHelpIndex); while (i.hasNext()) { i.next(); if (i.value()==toFind) { bookmarkIndex.insert(title, qMakePair(i.key(), i.value())); bookmarksView->addTopLevelItem(new QTreeWidgetItem(bookmarksView, QStringList() << title)); } } }
void HelpBrowser::searchingInDirectory(const QString& aDir) { QDir dir(QDir::toNativeSeparators(aDir + "/")); QStringList in; in.append("*.html"); QStringList lst = dir.entryList(in); for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it) { QString fname(aDir + "/" + (*it)); QFile f(fname); if (f.open(QIODevice::ReadOnly)) { QTextStream stream(&f); QString str = stream.readAll(); int cnt = str.count(helpNav->searchingEdit->text(), Qt::CaseInsensitive); if (cnt > 0) { QString fullname = fname; QString toFind(fname.remove(finalBaseDir + "/")); QMapIterator<QString, QString> i(quickHelpIndex); while (i.hasNext()) { i.next(); if (i.value()==toFind) helpNav->searchingView->addTopLevelItem(new QTreeWidgetItem(helpNav->searchingView, QStringList() << i.key())); } } f.close(); } } // get dirs - ugly recursion in.clear(); in.append("*"); QStringList dst = dir.entryList(in, QDir::Dirs); for (QStringList::Iterator it = dst.begin(); it != dst.end(); ++it) if ((*it)!="." && (*it)!="..") searchingInDirectory(QDir::toNativeSeparators(aDir + QString((*it)) + "/")); }
TEST_FIXTURE(UrlTagFixtureClass, FindByUrlNoMatch) { wxURI toFind(wxT("http://localhost/backend.php")); t4p::UrlTagClass urlTag; CHECK_EQUAL(false, Finder.FindByUrl(toFind, SourceDirs, urlTag)); CHECK(urlTag.Url.BuildURI().IsEmpty()); }
int main(int argc, char** argv) { if (argc != 6) { std::cout << "This program takes in input glad.h and outputs the include and implementation files for OSMesa OpenGL function and regular OpenGL functions." << std::endl; std::cout << "Usage: generateGLIncludes <glad.h path> <output dir path> <namespace name> <baseFileName> <inlcude glad debug symbols>" << std::endl; std::cout << "Example: generateGLIncludes /Users/alexandre/development/Natron/Global/gladRel/include/glad/glad.h /Users/alexandre/development/Natron/Engine Natron OSGLFunctions 1" << std::endl; return 1; } QFile f(argv[1]); if ( !f.open(QIODevice::ReadOnly) ) { std::cout << "Could not open " << argv[1] << std::endl; return 1; } // Check that output path exists QDir outputDir(argv[2]); if ( !outputDir.exists() ) { std::cout << argv[2] << " does not seem to be a valid directory" << std::endl; return 1; } QString namespaceName(argv[3]); QString baseFilename(argv[4]); bool supportGladDebug; { QString supportDebugSymbolsStr(argv[5]); supportGladDebug = (bool)supportDebugSymbolsStr.toInt(); } QString absoluteDirPath = outputDir.absolutePath(); QString outputHeaderFilename = absoluteDirPath + "/" + baseFilename + ".h"; QFile of_header(outputHeaderFilename); if ( !of_header.open(QIODevice::WriteOnly) ) { std::cout << "Could not open " << outputHeaderFilename.toStdString() << std::endl; return 1; } QTextStream ots_header(&of_header); QTextStream its(&f); QString definesStr; std::list<FunctionSignature> signatures; QString functionTypedefsStr; QString prevLine; while ( !its.atEnd() ) { // Read each line of glad.h QString line = its.readLine(); { // Search for a define QString toFind = "#define GL_"; int found = line.indexOf(toFind); if (found != -1) { definesStr += line; definesStr += "\n"; } } // Search for a function QString typedefToken("typedef "); QString pfnToken("(APIENTRYP PFNGL"); int foundFuncDef = line.indexOf(typedefToken); int foundPNFToken = line.indexOf(pfnToken); if ( (foundFuncDef != -1) && (foundPNFToken != -1) ) { int pos = foundPNFToken + pfnToken.size(); int foundFirstEndParenthesis = line.indexOf(')', pos); assert(foundFirstEndParenthesis != -1); FunctionSignature signature; QString lastFuncNameCaps = line.mid(pos, foundFirstEndParenthesis - pos); signature.signature = line.mid(foundFirstEndParenthesis); // "near" and "far" are defined as macros in windows.h signature.signature.replace("GLdouble near, GLdouble far", "GLdouble nearVal, GLdouble farVal"); signature.returnType = line.mid( foundFuncDef + typedefToken.size(), foundPNFToken - 1 - ( foundFuncDef + typedefToken.size() ) ); QString funcTypeDefStr = "typedef "; funcTypeDefStr += signature.returnType; funcTypeDefStr += " (*PFNGL"; funcTypeDefStr += lastFuncNameCaps; funcTypeDefStr += signature.signature; funcTypeDefStr += "\n"; functionTypedefsStr += funcTypeDefStr; // Remove the extraneous ; at the end of the signature // Also remove the prepending ) signature.signature.remove(0, 1); signature.signature.remove(signature.signature.size() - 1, 1); signature.funcPNType = "PFNGL"; signature.funcPNType += lastFuncNameCaps; // extract parameters { int i = 1; // start after the leading ( while ( i < signature.signature.size() ) { QString param; while ( signature.signature[i] != QChar(',') && signature.signature[i] != QChar(')') ) { param.append(signature.signature[i]); ++i; } // Now only keep the name of the parameter { int j = param.size() - 1; while ( j >= 0 && param[j].isLetterOrNumber() ) { --j; } param = param.mid(j + 1); } signature.parameters.append(param); assert( signature.signature[i] == QChar(',') || signature.signature[i] == QChar(')') ); ++i; // bypass last character if ( signature.signature[i] == QChar(')') ) { break; } } } // we caught a function typedef before, we expect to read the following #define glXxxx function with the appropriate case // in release glad.h, the next line is of the type GLAPI PFNGLCOLOR4FVPROC glad_glColor4fv; // the line after that is the one we want #define glColor4fv glad_glColor4fv line = its.readLine(); assert( !its.atEnd() ); line = its.readLine(); QString toFind("#define gl"); int foundDefine = line.indexOf(toFind); if (foundDefine == -1) { std::cout << "Parser failed to find #define glXXX statement 2 lines after a function typedef, make sure that you are running this program against a release version of glad.h" << std::endl; return 1; } // Check that this is the same symbol // Remove the PROC at the end of the func def lastFuncNameCaps.remove("PROC"); int checkIndex = toFind.size(); QString symbolStart = line.mid(checkIndex); assert( symbolStart.startsWith(lastFuncNameCaps, Qt::CaseInsensitive) ); { int i = 8; // start on the g //extract the function name while ( i < line.size() && line.at(i) != QChar(' ') ) { signature.funcName.push_back( line.at(i) ); ++i; } } signatures.push_back(signature); } // if (foundFuncDef != -1 && foundPNFToken != -1) { prevLine = line; } writeHeader(ots_header); writePODs(ots_header); ots_header << definesStr << "\n" "\n"; ots_header << functionTypedefsStr << "\n" "\n"; writeStartClass(namespaceName, ots_header); // Define the singleton ots_header << " static OSGLFunctions<USEOPENGL>& getInstance()\n" " {\n" " static OSGLFunctions<USEOPENGL> instance;\n" "\n" " return instance;\n" " }\n" "\n" " // load function, implemented in _gl.h and _mesa.h\n" " void load_functions();\n" "\n" " // private constructor\n" " OSGLFunctions() { load_functions(); }\n" "\n"; // Declare member functions for (std::list<FunctionSignature>::iterator it = signatures.begin(); it != signatures.end(); ++it) { ots_header << " " << it->funcPNType << " _" << it->funcName << ";\n"; } ots_header << "\n"; ots_header << "public:\n" "\n"; ots_header << " // static non MT-safe load function that must be called once to initialize functions\n" " static void load()\n" " {\n" " (void)getInstance();\n" " }\n" "\n" " static bool isGPU()\n" " {\n" " return USEOPENGL;\n" " }\n"; for (std::list<FunctionSignature>::iterator it = signatures.begin(); it != signatures.end(); ++it) { QString lineStart = " static " + it->returnType + " " + it->funcName; QString indentedSig = it->signature; indentedSig.replace( ", ", ",\n" + QString(lineStart.size() + 1, ' ') ); ots_header << "\n" << lineStart << indentedSig << "\n" " {\n"; if (it->returnType == "void") { ots_header << " "; } else { ots_header << " return "; } ots_header << "getInstance()._" << it->funcName << "("; QStringList::const_iterator next = it->parameters.begin(); if ( !it->parameters.isEmpty() ) { ++next; } for (QStringList::const_iterator it2 = it->parameters.begin(); it2 != it->parameters.end(); ++it2) { ots_header << *it2; if ( next != it->parameters.end() ) { ots_header << ", "; ++next; } } ots_header << ");\n" " }\n"; } writeEndClass(namespaceName, ots_header); writeFooter(ots_header); writeImplementationCppFile(namespaceName, baseFilename, signatures, absoluteDirPath, "gl", true, supportGladDebug); writeImplementationCppFile(namespaceName, baseFilename, signatures, absoluteDirPath, "mesa", false, supportGladDebug); return 0; } // main