void CppRefType::compute(Q3PtrList<CppRefType> & dependencies, const WrapperStr & hdef, const WrapperStr & srcdef, WrapperStr & h_incl, WrapperStr & decl, WrapperStr & src_incl, UmlArtifact * who) { UmlPackage * pack = who->package(); WrapperStr hdir; WrapperStr srcdir; if (CppSettings::isRelativePath()) { WrapperStr empty; hdir = pack->header_path(empty); srcdir = pack->source_path(empty); } else if (CppSettings::isRootRelativePath()) hdir = srcdir = UmlPackage::rootDir(); // aze.cpp includes aze.h src_incl += "#include \""; if (CppSettings::includeWithPath()) src_incl += pack->header_path(who->name(), srcdir); else { src_incl += who->name(); src_incl += '.'; src_incl += CppSettings::headerExtension(); } src_incl += "\"\n"; h_incl = ""; // to not be WrapperStr::null decl = ""; // to not be WrapperStr::null CppRefType * ref; for (ref = dependencies.first(); ref != 0; ref = dependencies.next()) { UmlClass * cl = (ref->type.type) ? ref->type.type : UmlBaseClass::get(ref->type.explicit_type, 0); bool included = ref->included; WrapperStr hform; // form in header WrapperStr srcform; // form in source if (cl == 0) { WrapperStr in = CppSettings::include(ref->type.explicit_type); if (!in.isEmpty()) hform = srcform = in + '\n'; else // doesn't know what it is continue; } else if (cl->isCppExternal()) { QString className = cl->name(); hform = cl->cppDecl(); int index; if ((index = hform.find('\n')) == -1) // wrong form continue; hform = hform.mid(index + 1) + '\n'; for (;;) { if ((index = hform.find("${name}")) != -1) hform.replace(index, 7, cl->name()); else if ((index = hform.find("${Name}")) != -1) hform.replace(index, 7, capitalize(cl->name())); else if ((index = hform.find("${NAME}")) != -1) hform.replace(index, 7, cl->name().upper()); else if ((index = hform.find("${nAME}")) != -1) hform.replace(index, 7, cl->name().lower()); else break; } srcform = hform; } else { QString className = cl->name(); WrapperStr st = cl->cpp_stereotype(); if ((st == "enum") || (st == "typedef")) included = TRUE; UmlArtifact * art = cl->associatedArtifact(); if (art != 0) { if (art == who) // don't include itself continue; if (CppSettings::includeWithPath()) { UmlPackage * p = art->package(); hform = "#include \"" + p->header_path(art->name(), hdir) + "\"\n"; srcform = "#include \"" + p->header_path(art->name(), srcdir) + "\"\n"; } else srcform = hform = "#include \"" + art->name() + '.' + CppSettings::headerExtension() + "\"\n"; } else if (cl->parent()->kind() != aClass) { write_trace_header(); UmlCom::trace(WrapperStr(" <font color=\"red\"><b> class<i> ") + cl->name() + "</i> referenced but does not have associated <i>artifact</i></b></font><br>"); incr_warning(); continue; } } if (included) { // #include must be placed in the header file if ((h_incl.find(hform) == -1) && (hdef.find(hform) == -1)) h_incl += hform; } else if ((cl != 0) && (cl->parent()->kind() != aClass)) { // else too complicated // #include useless in header file, place it in the source file if ((src_incl.find(srcform) == -1) && (h_incl.find(hform) == -1) && (hdef.find(hform) == -1) && (srcdef.find(srcform) == -1)) src_incl += srcform; if (!cl->isCppExternal()) { // header file must contains the declaration hform = cl->decl(); if (decl.find(hform) == -1) decl += hform; if ((cl->associatedArtifact() == 0) && (cl->parent()->kind() != aClass)) { write_trace_header(); UmlCom::trace(WrapperStr(" <font color=\"red\"><b> class<i> ") + cl->name() + "</i> referenced but does not have associated <i>artifact</i></b></font><br>"); incr_warning(); } } } else if (!hform.isEmpty()) { // have the #include form but does not know if it is a class or other, // generate the #include in the header file EXCEPT if the #include is // already in the header/source file to allow to optimize the generated // code if ((src_incl.find(srcform) == -1) && (h_incl.find(hform) == -1) && (hdef.find(hform) == -1) && (srcdef.find(srcform) == -1)) h_incl += hform; } } }
void UmlArtifact::gen_app(const Q3CString & path) { Q3CString target; Q3CString pro; propertyValue("genpro target", target); propertyValue("genpro pro", pro); if (target.isEmpty()) { if ((target = name()) == "executable") target = UmlPackage::getProject()->name(); #ifdef WIN32 target += ".exe"; #endif } if (pro.isEmpty()) { pro = target; #ifdef WIN32 if (pro.right(4) == ".exe") pro.resize(pro.length() - 4); #endif QDir d(path); pro = d.absFilePath(pro + ".pro"); } Q3CString tmplt; Q3CString config; Q3CString defines; Q3CString includepath; Q3CString dependpath; Q3CString objectsdir; Q3CString footer; if (!propertyValue("genpro tmplt", tmplt)) tmplt = "app"; if (!propertyValue("genpro config", config)) config = "debug warn_on qt"; if (!propertyValue("genpro defines", defines)) defines = "WITHCPP WITHJAVA WITHPHP WITHPYTHON WITHIDL"; else if (defines.find("WITHPHP") == -1) { int n = 0; if (defines.find("WITHCPP") != -1) n += 1; if (defines.find("WITHJAVA") != -1) n += 1; if (defines.find("WITHIDL") != -1) n += 1; if (n > 1) defines += " WITHPHP WITHPYTHON"; } else if (defines.find("WITHPYTHON") == -1) { int n = 0; if (defines.find("WITHCPP") != -1) n += 1; if (defines.find("WITHJAVA") != -1) n += 1; if (defines.find("WITHIDL") != -1) n += 1; if (defines.find("WITHPHP") != -1) n += 1; if (n > 1) defines += " WITHPYTHON"; } propertyValue("genpro includepath", includepath); propertyValue("genpro dependpath", dependpath); propertyValue("genpro objectsdir", objectsdir); propertyValue("genpro footer", footer); for (;;) { Dialog dialog(this, path, pro, target, tmplt, config, defines, includepath, dependpath, objectsdir, footer); if (dialog.exec() != QDialog::Accepted) return; set_PropertyValue("genpro pro", pro); set_PropertyValue("genpro path", path); set_PropertyValue("genpro target", target); set_PropertyValue("genpro tmplt", tmplt); set_PropertyValue("genpro config", config); set_PropertyValue("genpro defines", defines); set_PropertyValue("genpro includepath", includepath); set_PropertyValue("genpro dependpath", dependpath); set_PropertyValue("genpro objectsdir", objectsdir); set_PropertyValue("genpro footer", footer); QFile f(pro); if (! f.open(QIODevice::WriteOnly)) QMessageBox::critical((QWidget *) 0, "Error", "Cannot open " + QString(pro)); else { Q3TextStream t(&f); QFileInfo tfi(target); QFileInfo pfi(pro); t << "TEMPLATE\t= " << tmplt << '\n'; t << "TARGET\t\t= " << tfi.fileName() << '\n'; if ((target.find('/') != -1) && (pro.find('/') != -1) && (tfi.dirPath(TRUE) != pfi.dirPath(TRUE))) t << "DESTDIR\t\t= " << tfi.dirPath(TRUE) << '\n'; if (! objectsdir.isEmpty()) t << "OBJECTS_DIR\t= " << objectsdir << '\n'; t << "CONFIG\t\t+= " << config << '\n'; if (!includepath.isEmpty()) t << "INCLUDEPATH\t= " << includepath << '\n'; if (!dependpath.isEmpty()) t << "DEPENDPATH\t= " << dependpath << '\n'; if (!defines.isEmpty()) t << "DEFINES\t\t= " << defines << '\n'; QString prodir = pfi.dirPath(TRUE); const Q3PtrVector<UmlArtifact> & arts = associatedArtifacts(); unsigned index; const char * sep; Q3CString ext; ext = CppSettings::headerExtension(); sep = "HEADERS\t\t= "; for (index = 0; index != arts.count(); index += 1) { UmlArtifact * art = arts[index]; if ((art->stereotype() == "source") && !art->cppHeader().isEmpty()) { QString s = art->way(prodir, TRUE); if (! s.isEmpty()) { t << sep << s << art->name() << '.' << ext; sep = " \\\n\t\t "; } } } t << '\n'; ext = CppSettings::sourceExtension(); sep = "SOURCES\t\t= "; for (index = 0; index != arts.count(); index += 1) { UmlArtifact * art = arts[index]; if ((art->stereotype() != "source") || !art->cppSource().isEmpty()) { QString s = art->way(prodir, FALSE); if (! s.isEmpty()) { t << sep << s << art->name(); if (art->stereotype() == "source") t << '.' << ext; sep = " \\\n\t\t "; } } } t << '\n' << footer << '\n'; f.close(); return; } } }