Esempio n. 1
0
UmlOperation *  UmlOperation::already_exist_from_id(Class * container, Q3CString & body)
{
    const char * BodyPrefix = "// Bouml preserved body begin ";
    const char * BodyPostfix = "// Bouml preserved body end ";
    const int BodyPrefixLength = 30;
    const int BodyPostfixLength = 28;

    int index = body.find(BodyPrefix);

    if (index != -1) {
        const char * b1 = ((const char *) body) + index + BodyPrefixLength;
        char * b2;
        long id = strtol(b1, &b2, 16);

        if (b2 != (b1 + 8)) {
            QString err = "<font color =\"red\"> Error in " + Lex::filename() +
                          " before line " + QString::number(Lex::line_number()) +
                          " : invalid preserve body identifier</font><br>";

            UmlCom::trace(err);
            throw 0;
        }

        if (*b2 == '\r')
            b2 += 1;
        if (*b2 == '\n')
            b2 += 1;
        else {
            QString err = "<font color =\"red\"> Error in " + Lex::filename() +
                          " before line " + QString::number(Lex::line_number()) +
                          " : invalid preserve body block, end of line expected</font><br>";

            UmlCom::trace(err);
            throw 0;
        }

        const char * e;

        if (((e = strstr(b2, BodyPostfix)) == 0) ||
                (strncmp(e + BodyPostfixLength, b1, 8) != 0)) {
            QString err = "<font color =\"red\"> Error in " + Lex::filename() +
                          " before line " + QString::number(Lex::line_number()) +
                          " : invalid preserve body block, wrong balanced</font><br>";

            UmlCom::trace(err);
            throw 0;
        }

        while ((e != b2) && (e[-1] != '\n'))
            e -= 1;

        body = body.mid(b2 - (const char *) body, e - b2);

        UmlOperation * op = (UmlOperation *) UmlBaseItem::from_id((unsigned) id, anOperation);

        if (op != 0) {
            if (!op->is_useless()) {
                QString err = "<font color =\"red\"> Error in " + Lex::filename() +
                              " before line " + QString::number(Lex::line_number()) +
                              " : preserve body block identifier used twice</font><br>";

                UmlCom::trace(err);
                throw 0;
            }

            if ((op->parent() == container->get_uml()) &&
                    // currently get/set are removed then recreated
                    (op->getOf() == 0) &&
                    (op->setOf() == 0))
                return op;
        }
    }

    return 0;
}
Esempio n. 2
0
void UmlOperation::import(File & f, UmlClass * parent)
{
    QByteArray s;

    if (f.read(s) != STRING)
        f.syntaxError(s, "operations's name");

    QByteArray id;
    QByteArray ste;
    QByteArray doc;
    QHash<QByteArray, QByteArray*> prop;
    QByteArray s2;
    int k;

    do {
        k = f.readDefinitionBeginning(s2, id, ste, doc, prop);
    }
    while (id.isEmpty());

    UmlOperation * x;

    if (scanning) {
        QByteArray name;

        if (s.left(8) != "operator")
            name = (s.at(0) == '~')
                   ? ("~" + legalName(s.mid(1)))
                   : legalName(s);
        else
            name = s;

        if ((x = UmlBaseOperation::create(parent, name)) == 0) {
            UmlCom::trace("<br>cannot create operation '" + s + "' in " +
                          parent->fullName());
            throw 0;
        }

        newItem(x, id);

        if (!ste.isEmpty()) {
            bool managed = FALSE;
            QStringList l = QString(ste).split(",");

            for (QStringList::Iterator it = l.begin();
                 it != l.end();
                 ++it) {
                if ((*it) == "const") {
                    managed = TRUE;
                    x->set_isCppConst(TRUE);
                }
                else if ((*it) == "abstract") {
                    managed = TRUE;
                    x->set_isAbstract(TRUE);
                    x->set_isCppVirtual(TRUE);
                }
                else if ((*it) == "virtual") {
                    managed = TRUE;
                    x->set_isCppVirtual(TRUE);
                }
                else if ((*it) == "static") {
                    managed = TRUE;
                    x->set_isClassMember(TRUE);
                }
            }

            if (!managed)
                x->set_Stereotype(ste);
        }

        if (!doc.isEmpty())
            x->set_Description(doc);
    }
    else if ((x = (UmlOperation *) findItem(id, anOperation)) == 0) {
        UmlCom::trace("<br>unknown operation '" + s + "' in " +
                      parent->fullName());
        throw 0;
    }
    else {
        switch (((UmlClass *) x->parent())->language()) {
        case Cplusplus:
        case AnsiCplusplus:
        case VCplusplus:
            x->cplusplus(prop);
            break;

        case Oracle8:
            x->oracle8(prop);
            break;

        case Corba:
            x->corba(prop);
            break;

        case Java:
            x->java(prop);
            break;

        default:
            break;
        }

        x->setProperties(prop);
    }

    f.unread(k, s2);
    x->import(f);
}