void UmlClass::uml2cpp(bool rec) { if (isCppExternal()) set_CppDecl(CppSettings::externalClassDecl()); else { QCString st = CppSettings::classStereotype(stereotype()); UmlItem * pack = parent()->parent(); while (pack->kind() != aPackage) pack = pack->parent(); if ((st == "stereotype") || (st == "metaclass") || (pack->stereotype() == "profile")) { set_CppDecl(""); return; } if (st == "enum") set_CppDecl(CppSettings::enumDecl()); else if (st == "union") set_CppDecl(CppSettings::unionDecl()); else if (st == "struct") set_CppDecl(CppSettings::structDecl()); else if (st == "typedef") set_CppDecl(CppSettings::typedefDecl()); else if (st == "ignored") { set_CppDecl(""); return; } else set_CppDecl(CppSettings::classDecl()); if (rec) { const QVector<UmlItem> ch = children(); unsigned n = ch.size(); for (unsigned i = 0; i != n; i += 1) ch[i]->uml2cpp(rec); } if (parent()->kind() == aClassView) { // not nested UmlArtifact * art = artifact(); art->set_CppSource(CppSettings::sourceContent()); art->set_CppHeader(CppSettings::headerContent()); } } }
void UmlClass::generate() { if (! managed) { managed = TRUE; if (!isCppExternal() && !cppDecl().isEmpty()) { if (associatedArtifact() == 0) { if (verbose()) UmlCom::trace(Q3CString("<hr><font face=helvetica><i> ") + name() + " : </i> does not have associated <i>artifact</i></font><br>"); } else if (cppDecl().isEmpty()) { if (verbose()) UmlCom::trace(Q3CString("<hr><font face=helvetica>class <i>") + name() + "</i> has an empty C++ definition</font><br>"); } else associatedArtifact()->generate(); } } }
void UmlClass::write(QTextOStream & f, bool with_formals, BooL * is_template, const Q3ValueList<UmlActualParameter> & actuals) { if (context.findRef(this) == -1) { if (parent()->kind() == aClass) { if (context.findRef((UmlClass *) parent()) == -1) { // parent cannot have formals, but may have actuals ((UmlClass *) parent())->write(f, FALSE, 0, actuals); f << "::"; } } else { UmlArtifact * cp = associatedArtifact(); Q3CString nasp = ((UmlPackage *) ((cp != 0) ? (UmlItem *) cp : (UmlItem *) this)->package()) ->cppNamespace(); if (CppSettings::isForceNamespacePrefixGeneration() || (nasp != UmlArtifact::generation_package()->cppNamespace())) f << nasp << "::"; } } Q3CString s; if (isCppExternal()) { s = cppDecl(); int index = s.find('\n'); s = (index == -1) ? s.stripWhiteSpace() : s.left(index).stripWhiteSpace(); if ((index = s.find("${name}")) != -1) s.replace(index, 7, name()); else if ((index = s.find("${Name}")) != -1) s.replace(index, 7, capitalize(name())); else if ((index = s.find("${NAME}")) != -1) s.replace(index, 7, name().upper()); else if ((index = s.find("${nAME}")) != -1) s.replace(index, 7, name().lower()); } else s = name(); // true_name if (! s.isEmpty()){ f << s; if (is_template != 0) *is_template = (s.at(s.length() - 1) == '>'); } else if (is_template != 0) *is_template = FALSE; if (with_formals) { Q3ValueList<UmlFormalParameter> formals = this->formals(); if (! formals.isEmpty()) { const char * sep = "<"; Q3ValueList<UmlFormalParameter>::ConstIterator it; for (it = formals.begin(); it != formals.end(); ++it) { f << sep << (*it).name(); sep = ", "; } f << '>'; if (is_template != 0) *is_template = TRUE; } } else if (!actuals.isEmpty()) { Q3ValueList<UmlActualParameter>::ConstIterator ita; BooL need_space = FALSE; bool used = FALSE; for (ita = actuals.begin(); ita != actuals.end(); ++ita) { if ((*ita).superClass() == this) { used = TRUE; (*ita).generate(f, need_space); } } if (used) { if (need_space) f << " >"; else f << '>'; if (is_template != 0) *is_template = TRUE; } } }