Exemplo n.º 1
0
UmlOperation * UmlOperation::cpp2Python(UmlClass * python, UmlClass * cpp,
					 const char * cppname,
					 const char * pythonname)
{
  if (pythonname == 0)
    pythonname = cppname;
  
  UmlOperation * from = cpp->get_operation(cppname);
  
  if (from == 0) {
    QCString err = QCString("cannot find operation '") + 
      cppname + QCString("' in class '") + cpp->name()
	+ QCString("'<br>\n");
    UmlCom::trace(err);
    throw 0;
  }
  
  UmlOperation * to = UmlBaseOperation::create(python, pythonname);
  
  if (to == 0) {
    QCString err = QCString("cannot create operation '") + 
      pythonname + QCString("' in class '") + python->name()
	+ QCString("'<br>\n");
    UmlCom::trace(err);
    throw 0;
  }
  
  UmlCom::trace("add operation " + python->name() + "::" + pythonname + "<br>\n");

  to->set_Description(::cpp2Python(from->description()));
  to->set_ReturnType(from->returnType());
  to->set_isClassMember(from->isClassMember());
  to->set_Visibility(from->visibility());
  to->set_CppVisibility(from->cppVisibility());
  
  const QValueList<UmlParameter> params = from->params();
  unsigned index;
  
  for (index = 0; index != params.count(); index += 1)
    to->addParameter(index, params[index]);
  
  const QValueList<UmlTypeSpec> exceptions = from->exceptions();
  
  for (index = 0; index != exceptions.count(); index += 1)
    to->addException(index, exceptions[index]);
  
  to->set_isCppVirtual(from->isCppVirtual());
  to->set_isCppConst(from->isCppConst());
  to->set_isCppInline(from->isCppInline());
  to->set_CppDecl(::cpp2Python(from->cppDecl()));
  to->set_CppDef(::cpp2Python(from->cppDef()));
  to->set_CppBody(::cpp2Python(from->cppBody()));
  
  to->set_isJavaFinal(from->isJavaFinal());
  to->set_JavaDef(from->javaDef());
  to->set_JavaBody(::cpp2Python(from->javaBody()));
  
  return to;
}
Exemplo n.º 2
0
void UmlClass::addDestructor(bool virt)
{
    TRACE_FUNCTION;
    UmlOperation * op = UmlOperation::create(this, "~" + name());

    if (op == 0)
        UmlCom::trace("can't add destructor");
    else {
        if (virt)
            op->set_isCppVirtual(TRUE);

        QByteArray s;
        int index;

        // remove the useless "${type} " mainly to remove the space

        s = op->cppDecl();

        if (s.isEmpty())
            s = CppSettings::operationDecl();

        if ((index = s.indexOf("${type} ")) != -1) {
            s.remove(index, 8);
            op->set_CppDecl(s);
        }

        s = op->cppDef();

        if (s.isEmpty())
            s = CppSettings::operationDef();

        if ((index = s.indexOf("${type} ")) != -1) {
            s.remove(index, 8);
            op->set_CppDef(s);
        }
    }
}
Exemplo n.º 3
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);
}