/** * @brief Database::recursiveFind * @param scope * @param id * @param ids */ void Database::recursiveFind(entity::SharedScope scope, const QString &id, QStringList &ids) const { if (scope->scopes().isEmpty()) { ids.clear(); return; } ids << scope->id(); if (scope->containsChildScope(id)) { ids << scope->getChildScope(id)->id(); return; } else { for (auto sc : scope->scopes()) recursiveFind(sc, id, ids); } }
/** * @brief Database::getDepthType * @param scope * @param id * @param result */ void Database::getDepthType(const entity::SharedScope &scope, const QString &id, entity::SharedType &result) const { if (scope->containsType(id)) { result = scope->type(id); return; } else if (scope->hasChildScopes()){ for (auto &&child_scope : scope->scopes()) { if (result) break; getDepthType(child_scope, id, result); } } }
/** * @brief BasicCppProjectGenerator::generateFiles * @param scope * @param directory */ void BasicCppProjectGenerator::generateFiles(const entity::SharedScope &scope, const SharedVirtualDirectory &directory) { SharedVirtualDirectory dir((m_Options & NamespacesInSubfolders) ? directory->addDirectory(scope->name().toLower()) : directory); for (auto &&t : scope->types()) { translation::Code code = m_ProjectTranslator.translate(t); m_ProjectTranslator.addNamespace(t, code); QString name(t->name().toLower()); if (!code.toSource.isEmpty()) { code.toSource.prepend(QString("#include \"%1.h\"\n\n").arg(name)); } if (!code.toHeader.isEmpty()) { if (m_Options & DefineIcludeGuard) { QString guardName = scope->name().toUpper() + "_" + t->name().toUpper() + "_H"; code.toHeader.prepend("#define " + guardName + "\n\n"); code.toHeader.prepend("#ifndef " + guardName + "\n"); code.toHeader.append("\n\n#endif // " + guardName); } else { code.toHeader.prepend("#pragma once\n\n"); } } auto addFile = [&](const QString &data, const QString &ext, QStringList §ion) { QString fname(name + ext); dir->addFile(fname)->setData(data); section.append(fname); }; if (!code.toHeader.isEmpty()) addFile(code.toHeader, ".h", m_ProfileData.headers); if (!code.toSource.isEmpty()) addFile(code.toSource, ".cpp", m_ProfileData.sources); } for (auto &&s : scope->scopes()) generateFiles(s, dir); }