bool QHelpDBReader::fileExists(const QString &virtualFolder, const QString &filePath, const QStringList &filterAttributes) const { if (virtualFolder.isEmpty() || filePath.isEmpty() || !m_query) return false; //SELECT COUNT(a.Name) FROM FileNameTable a, FolderTable b, FileFilterTable c, FilterAttributeTable d WHERE a.FolderId=b.Id AND b.Name='qtdoc' AND a.Name='qstring.html' AND a.FileId=c.FileId AND c.FilterAttributeId=d.Id AND d.Name='qtrefdoc' QString query; namespaceName(); if (filterAttributes.isEmpty()) { query = QString(QLatin1String("SELECT COUNT(a.Name) FROM FileNameTable a, FolderTable b " "WHERE a.FolderId=b.Id AND b.Name=\'%1\' AND a.Name=\'%2\'")).arg(quote(virtualFolder)).arg(quote(filePath)); } else { query = QString(QLatin1String("SELECT COUNT(a.Name) FROM FileNameTable a, FolderTable b, " "FileFilterTable c, FilterAttributeTable d WHERE a.FolderId=b.Id " "AND b.Name=\'%1\' AND a.Name=\'%2\' AND a.FileId=c.FileId AND " "c.FilterAttributeId=d.Id AND d.Name=\'%3\'")) .arg(quote(virtualFolder)).arg(quote(filePath)) .arg(quote(filterAttributes.first())); for (int i=1; i<filterAttributes.count(); ++i) { query.append(QString(QLatin1String(" INTERSECT SELECT COUNT(a.Name) FROM FileNameTable a, " "FolderTable b, FileFilterTable c, FilterAttributeTable d WHERE a.FolderId=b.Id " "AND b.Name=\'%1\' AND a.Name=\'%2\' AND a.FileId=c.FileId AND " "c.FilterAttributeId=d.Id AND d.Name=\'%3\'")) .arg(quote(virtualFolder)).arg(quote(filePath)) .arg(quote(filterAttributes.at(i)))); } } m_query->exec(query); if (m_query->next() && m_query->isValid() && m_query->value(0).toInt()) return true; return false; }
IComponent* ComponentBase::getOrCreateInternalComponent( const char* componentName, const char* interfaceName, const char* facetName ) { std::string fullTypeName( componentName ); // get the component if it already exists ITypeManager* tm = getSystem()->getTypes(); IType* type = tm->findType( fullTypeName ); if( type ) { assert( type->getKind() == TK_COMPONENT ); return static_cast<IComponent*>( type ); } // otherwise, create the component IType* itfType = getType( interfaceName ); assert( itfType->getKind() == TK_INTERFACE ); size_t lastDotPos = fullTypeName.rfind( '.' ); assert( lastDotPos != std::string::npos ); // componentName must be specified with a namespace std::string namespaceName( fullTypeName.substr( 0, lastDotPos ) ); std::string localTypeName( fullTypeName.substr( lastDotPos + 1 ) ); INamespace* ns = tm->findNamespace( namespaceName ); assert( ns ); // the namespace should have been created before RefPtr<ITypeBuilder> tb = ns->defineType( localTypeName, TK_COMPONENT ); tb->definePort( facetName, static_cast<IInterface*>( itfType ), true ); try { tm->getTransaction()->commit(); } catch( std::exception& ) { tm->getTransaction()->rollback(); throw; } type = tb->createType(); assert( type && type->getKind() == TK_COMPONENT ); // set the component with a basic reflector type->setReflector( BasicReflector::create( type ) ); return static_cast<IComponent*>( type ); }
QByteArray QHelpDBReader::fileData(const QString &virtualFolder, const QString &filePath) const { QByteArray ba; if (virtualFolder.isEmpty() || filePath.isEmpty() || !m_query) return ba; namespaceName(); m_query->prepare(QLatin1String("SELECT a.Data FROM FileDataTable a, FileNameTable b, FolderTable c, " "NamespaceTable d WHERE a.Id=b.FileId AND (b.Name=? OR b.Name=?) AND b.FolderId=c.Id " "AND c.Name=? AND c.NamespaceId=d.Id AND d.Name=?")); m_query->bindValue(0, filePath); m_query->bindValue(1, QString(QLatin1String("./") + filePath)); m_query->bindValue(2, virtualFolder); m_query->bindValue(3, m_namespace); m_query->exec(); if (m_query->next() && m_query->isValid()) ba = qUncompress(m_query->value(0).toByteArray()); return ba; }
void InterfaceProxy::GenerateNew(FILE *file) const { QTextStream out(file); { // begin namespace out << GenerateNamespaceName() << "_New"; out << "\n{"; out << "\n"; } out << " using boost::shared_ptr;\n"; if (m_class.qualified.contains("::")) { QByteArray className("::" + m_class.classname); QByteArray namespaceName(m_class.qualified); namespaceName.replace(className, ";"); out << " using namespace " << namespaceName << '\n'; } QByteArray classCRC = GenerateCrcString(); Utils::CRC32 crc(GenerateCrcString()); out << "\n // CRC string '"; OutputToHex(out, classCRC); out << "'\n"; // local proxy generated GenerateLocalProxyNew(out); out << "\n"; out << "\n ObjLink::RegisterObjectLinkMeta<TIntf, LocalIntfProxy>"; out << " RM(Utils::CRC32("; OutputToHex(out, crc.checksum()); out << "));"; // close namespace out << "\n\n}; // End of namespace\n"; }
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
void ClassAnalyzer::parseNamespaces(const QString& code) { m_namespaces.clear(); QVector<int> namespacePositions = positions(code, "\\snamespace\\s", true); QVector<int> openingCurlyBracketPositions = positions(code, "{"); QVector<int> closingCurlyBracketPositions = positions(code, "}"); if (openingCurlyBracketPositions.size() != closingCurlyBracketPositions.size()) { qDebug() << m_currentFile; qDebug() << "quantity of opening and closing curly brackets does not match"; qDebug() << "quantity of opening curly brackets:" << openingCurlyBracketPositions.size(); qDebug() << "quantity of closing curly brackets:" << closingCurlyBracketPositions.size(); return; } QVector<int> allCurlyBracketPositions = openingCurlyBracketPositions; allCurlyBracketPositions.append(closingCurlyBracketPositions); qSort(allCurlyBracketPositions); QMap<int, int> curlyBracketPairs; for (int i = 0; i < allCurlyBracketPositions.size(); i++) { if (openingCurlyBracketPositions.contains(allCurlyBracketPositions[i])) { int nesting = 1; for (int j = i + 1; j < allCurlyBracketPositions.size(); j++) { if (openingCurlyBracketPositions.contains(allCurlyBracketPositions[j])) { nesting++; } else { nesting--; } if (nesting == 0) { curlyBracketPairs[allCurlyBracketPositions[i]] = allCurlyBracketPositions[j]; break; } } } } //qDebug() << curlyBracketPairs; for (auto it = namespacePositions.begin(); it != namespacePositions.end(); it++) { Namespace ns; for (auto it2 = curlyBracketPairs.begin(); it2 != curlyBracketPairs.end(); it2++) { if (it2.key() > *it) { ns.setStartPosition(it2.key()); ns.setStopPosition(it2.value()); ns.setName(namespaceName(code, *it, it2.key())); m_namespaces.append(ns); break; } } } }