Ejemplo n.º 1
0
void UmlClassMember::generate_visibility(aVisibility & current_visibility,
        QTextStream & f_h, bool ahead,
        const WrapperStr & indent)
{
    aVisibility v = (cppVisibility() == DefaultVisibility)
                    ? visibility() : cppVisibility();

    if (v == PackageVisibility)
        v = PublicVisibility;

    if (v != current_visibility) {
        current_visibility = v;

        if (!ahead)
            f_h << '\n';

        f_h << indent << CppSettings::visibilityIndent();

        switch (v) {
        case PublicVisibility:
            f_h << "public:\n";
            break;

        case ProtectedVisibility:
            f_h << "protected:\n";
            break;

        default:
            f_h << "private:\n";
            break;
        }
    }
}
Ejemplo n.º 2
0
bool UmlOperation::write_if_needed(FileOut & out) {
  QCString decl;

  switch (_lang) {
  case Uml:
    parent()->write(out);
    out.indent();
    out << "<UML:Operation name=\"";
    out.quote(name());
    break;
  case Cpp:
    decl = cppDecl();
    
    if (decl.isEmpty())
      return FALSE;
    remove_comments(decl);
    parent()->write(out);
    out.indent();
    out << "<UML:Operation name=\"";
    out.quote(true_name(cppDecl()));
    break;
  default: // Java
    decl = javaDecl();
    
    if (decl.isEmpty())
      return FALSE;
    remove_comments(decl);    
    parent()->write(out);
    out.indent();
    out << "<UML:Operation name=\"";
    out.quote(true_name(javaDecl()));
    break;
  }
  out << '"';
  out.id(this);
  
  switch (_lang) {
  case Uml:
    write_visibility(out);
    break;
  case Cpp:
    write_visibility(out, 
		     (cppVisibility() == DefaultVisibility)
		     ? visibility() : cppVisibility());
    break;
  default: // Java
    if (javaDecl().find("${visibility}") != -1)
      write_visibility(out, visibility());
    break;
  }
  write_scope(out);
  out << " isAbstract=\""
      << ((isAbstract()) ? "true" : "false")
      << "\">\n";
  
  out.indent(+1);

  write_stereotype(out);
  write_annotation(out);
  write_description_properties(out);
  
  out.indent();
  out << "<UML:BehavioralFeature.parameter>\n";
  out.indent(+1);

  write_return_type(out, decl);

  if (_lang == Uml)
    write_uml_params(out);
  else
    write_cpp_java_params(out, decl);

  out.indent(-1);
  out.indent();
  out << "</UML:BehavioralFeature.parameter>\n";
  
  out.indent(-1);
  out.indent();
  out << "</UML:Operation>\n";

  unload();
 
  return TRUE;
}
Ejemplo n.º 3
0
void UmlOperation::gen_cpp_decl(QByteArray s, bool descr)
{
    const char * p = bypass_comment(s);

    if (! descr) {
        write((cppVisibility() == DefaultVisibility)
              ? visibility() : cppVisibility(),
              cppLanguage);
        fw.write(": ");
        p = bypass_comment(s);
    }
    else
        p = s;

    const QList<UmlParameter> & pa = params();
    unsigned npa = pa.count();
    unsigned rank;

    while (*p) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${friend}", 9)) {
            p += 9;

            if (isCppFriend())
                fw.write("friend ");
        }
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember())
                fw.write("static ");
        }
        else if (!strncmp(p, "${inline}", 9)) {
            p += 9;

            if (isCppInline())
                fw.write("inline ");
        }
        else if (!strncmp(p, "${virtual}", 10)) {
            p += 10;

            if (isCppVirtual())
                fw.write("virtual ");
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;
            write(returnType(), cppLanguage);
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(compute_name(cppNameSpec()));
        }
        else if (!strncmp(p, "${(}", 4)) {
            p += 4;
            fw.write('(');
        }
        else if (!strncmp(p, "${)}", 4)) {
            p += 4;
            fw.write(')');
        }
        else if (!strncmp(p, "${const}", 8)) {
            p += 8;

            if (isCppConst())
                fw.write(" const");
        }
        else if (!strncmp(p, "${volatile}", 11)) {
            p += 11;

            if (isVolatile())
                fw.write(" volatile");
        }
        else if (!strncmp(p, "${throw}", 8)) {
            p += 8;

            const char * sep = " throw (";
            QList<UmlTypeSpec> e = exceptions();
            unsigned n = e.count();
            unsigned index2;

            for (index2 = 0; index2 != n; index2 += 1) {
                fw.write(sep);
                sep = ", ";
                write(e[index2], cppLanguage);
            }

            if (index2 != 0)
                fw.write(')');
            else if (CppSettings::operationForceThrow())
                fw.write(" throw ()");
        }
        else if (sscanf(p, "${t%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa)
                write(pa[rank].type, cppLanguage);
            else
                fw.write("???");
        }
        else if (sscanf(p, "${p%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < pa.count())
                writeq(pa[rank].name);
            else
                fw.write("???");
        }
        else if (sscanf(p, "${v%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank >= pa.count())
                fw.write("???");
            else if (! pa[rank].default_value.isEmpty()) {
                fw.write(" = ");
                writeq(pa[rank].default_value);
            }
        }
        else if (!strncmp(p, "${abstract}", 11)) {
            if (isAbstract())
                fw.write("= 0 ");

            break;
        }
        else if (!strncmp(p, "${stereotype}", 13)) {
            p += 13;
            // get/set relation with multiplicity > 1
            UmlClassMember * m = getOf();

            if ((m != 0) || ((m = setOf()) != 0))
                writeq(CppSettings::relationAttributeStereotype(m->stereotype()));
        }
        else if (!strncmp(p, "${association}", 14)) {
            p += 14;
            // get/set relation with multiplicity > 1
            UmlClassMember * m = getOf();

            if (((m != 0) || ((m = setOf()) != 0)) &&
                (m->kind() == aRelation))
                write(((UmlRelation *) m)->association(), cppLanguage);
        }
        else if (*p == '\r')
            p += 1;
        else if (*p == '\n') {
            if (descr) {
                fw.write("<br />");
                p += 1;
            }
            else {
                fw.write(' ');

                do
                    p += 1;

                while ((*p != 0) && (*p <= ' '));
            }
        }
        else if ((*p == '{') || (*p == ';')) {
            if (descr)
                fw.write(*p++);
            else
                break;
        }
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
Ejemplo n.º 4
0
void UmlRelation::generate_inherit(const char *& sep, QTextStream & f_h,
                                   const Q3ValueList<UmlActualParameter> & actuals,
                                   const WrapperStr & cl_stereotype)
{
    switch (relationKind()) {
    default:
        break;

    case aGeneralisation:
    case aRealization:
        if ((cl_stereotype == "union") || (cl_stereotype == "enum")) {
            write_trace_header();
            UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>")
                          + cl_stereotype + "</i> cannot inherits</b></font><br>");
            incr_warning();
            return;
        }
        else if (cl_stereotype == "typedef") {
            write_trace_header();
            UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>a <i>typedef</i> cannot inherits</b></font><br>");
            incr_warning();
            return;
        }

        UmlClass * role_type = roleType();
        const WrapperStr & other_stereotype = role_type->stereotype();

        if ((other_stereotype == "union") ||
            (other_stereotype == "enum")) {
            write_trace_header();
            UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot inherits an <i>")
                          + other_stereotype + "</i></b></font><br>");
            incr_warning();
            return;
        }

        f_h << sep;
        sep = ", ";

        if (cppVirtualInheritance())
            f_h << "virtual ";

        aVisibility visibility = (cppVisibility() == DefaultVisibility)
                                 ? this->visibility() : cppVisibility();

        switch (visibility) {
        case PublicVisibility:
        case PackageVisibility:
            f_h << "public ";
            break;

        case ProtectedVisibility:
            f_h << "protected ";
            break;

        default:
            f_h  << "private ";
        }

        const char * p = cppDecl();

        while (*p) {
            if (!strncmp(p, "${type}", 7)) {
                role_type->write(f_h, FALSE, 0, actuals);
                p += 7;
            }
            else if (*p == '@')
                manage_alias(p, f_h);
            else
                f_h << toLocale(p);
        }
    }
}
Ejemplo n.º 5
0
void UmlRelation::gen_cpp_decl(QByteArray s, bool descr)
{
    const char * p;

    if (! descr) {
        write((cppVisibility() == DefaultVisibility)
              ? visibility() : cppVisibility(),
              cppLanguage);
        fw.write(": ");
        p = bypass_comment(s);
    }
    else
        p = s;

    while (*p) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember())
                fw.write("static ");
        }
        else if (!strncmp(p, "${const}", 8)) {
            p += 8;

            if (isReadOnly())
                fw.write("const ");
        }
        else if (!strncmp(p, "${mutable}", 10)) {
            p += 10;

            if (isCppMutable())
                fw.write("mutable ");
        }
        else if (!strncmp(p, "${volatile}", 11)) {
            p += 11;

            if (isVolatile())
                fw.write("volatile ");
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;
            roleType()->write();
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(roleName());
        }
        else if (!strncmp(p, "${multiplicity}", 15)) {
            p += 15;

            QByteArray m = multiplicity();

            if (m.isEmpty() || (((const char *) m)[0] != '[')) {
                fw.write("[");
                writeq(m);
                fw.write("]");
            }
            else
                writeq(m);
        }
        else if (!strncmp(p, "${stereotype}", 13)) {
            p += 13;
            writeq(CppSettings::relationAttributeStereotype(stereotype()));
        }
        else if (!strncmp(p, "${value}", 8) || !strncmp(p, "${h_value}", 10)) {
            break;
        }
        else if (!strncmp(p, "${association}", 14)) {
            p += 14;
            write(association(), cppLanguage);
        }
        else if (*p == '\r')
            p += 1;
        else if (*p == '\n') {
            if (descr) {
                fw.write("<br />");
                p += 1;
            }
            else {
                fw.write(' ');

                do
                    p += 1;

                while ((*p != 0) && (*p <= ' '));
            }
        }
        else if (*p == ';') {
            if (descr)
                fw.write(*p++);
            else
                break;
        }
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
Ejemplo n.º 6
0
bool UmlAttribute::write_if_needed(FileOut & out)
{
    switch (_lang) {
    case Uml:
        parent()->write(out);
        out.indent();
        out << "<UML:Attribute name=\"" << name() << '"';
        break;

    case Cpp:
        if (cppDecl().isEmpty())
            return FALSE;

        parent()->write(out);
        out.indent();
        out << "<UML:Attribute name=\"" << true_name(cppDecl()) << '"';
        break;

    default: // Java
        if (javaDecl().isEmpty())
            return FALSE;

        parent()->write(out);
        out.indent();
        out << "<UML:Attribute name=\"" << true_name(javaDecl()) << '"';
        break;
    }

    out.id(this);

    switch (_lang) {
    case Uml:
        write_visibility(out);
        break;

    case Cpp:
        write_visibility(out,
                         (cppVisibility() == DefaultVisibility)
                         ? visibility() : cppVisibility());
        break;

    default: // Java
        if (javaDecl().find("${visibility}") != -1)
            write_visibility(out, visibility());

        break;
    }

    write_scope(out);
    out << ">\n";
    out.indent(+1);

    const UmlTypeSpec & t = type();

    if ((t.type != 0) || !t.explicit_type.isEmpty()) {
        out.indent();
        out << "<UML:StructuralFeature.type>\n";
        out.indent();
        out << "\t<UML:DataType";

        switch (_lang) {
        case Uml:
            if (t.type != 0)
                out.idref(t.type);
            else
                out.idref_datatype(t.explicit_type);

            break;

        case Cpp:
            write_cpp_type(out);
            break;

        default: // java
            write_java_type(out);
        }

        out << "/>\n";
        out.indent();
        out << "</UML:StructuralFeature.type>\n";
    }

    write_stereotype(out);
    write_annotation(out);
    write_description_properties(out);

    out.indent(-1);
    out.indent();
    out << "</UML:Attribute>\n";

    unload();

    return TRUE;
}