Exemple #1
0
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("&nbsp;&nbsp;&nbsp;&nbsp;<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("&nbsp;&nbsp;&nbsp;&nbsp;<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;
        }
    }
}
Exemple #2
0
UmlClass * UmlClass::auxilarily_typedef(const WrapperStr & base
#ifdef REVERSE
                                        , bool libp
# ifdef ROUNDTRIP
                                        , bool container_roundtrip
                                        , QList<UmlItem *> & container_expected_order
# endif
#endif
                                       )
{
    WrapperStr typedef_decl = CppSettings::typedefDecl();
    const QVector<UmlItem*>& children = parent()->children();
    unsigned n = children.count();
    unsigned index;

    // a typedef with the right definition already exist ?
    for (index = 0; index != n; index += 1) {
        if (children[index]->kind() == aClass) {
            UmlClass * cl = (UmlClass *) children[index];

            if ((cl->stereotype() == "typedef") &&
                (cl->cppDecl() == typedef_decl) &&
                (cl->baseType().explicit_type == base)) {
#ifdef ROUNDTRIP
                cl->set_usefull();

                if (container_roundtrip)
                    container_expected_order.append(cl);

#endif
                return cl;
            }
        }
    }

    // must create typedef with a new name
    for (;;) {
        static unsigned nty;

        QString s("typedef%1");
        s=s.arg(QString::number(++nty));


        for (index = 0; index != n; index += 1)
            if (children[index]->name() == s)
                break;

        if (index == n) {
            UmlClass * cl = UmlClass::create(parent(), s.toLatin1().constData());

            if (cl == 0) {
#ifdef REVERSE
                UmlCom::message("");
                CppCatWindow::trace(WrapperStr("<font face=helvetica><b>cannot create class <i>")
                                    + s + "</i> under <i>"
                                    + parent()->name() + "</b></font><br>");
                throw 0;
#else
                QMessageBox::critical(0, "Fatal Error",
                                      WrapperStr("<font face=helvetica><b>cannot create class <i>")
                                      + s + "</i> under <i>"
                                      + parent()->name() + "</b></font><br>");
                QApplication::exit(1);
#endif
            }

            UmlTypeSpec typespec;

            typespec.explicit_type = base;
            cl->set_Stereotype("typedef");
            cl->set_BaseType(typespec);
            cl->set_CppDecl(typedef_decl);
#ifdef REVERSE

            if (!libp)
                cl->need_artifact(Namespace::current());

# ifdef ROUNDTRIP

            if (container_roundtrip)
                container_expected_order.append(cl);

# endif
#endif

            return cl;
        }
    }
}