Exemple #1
0
void UmlCom::send_cmd(const void * id, OnInstanceCmd cmd, const Q3PtrVector<UmlClass> & l1, const Q3PtrVector<UmlClass> & l2, const Q3PtrVector<UmlClass> & l3)
{
#ifdef TRACE
    cout << "UmlCom::send_cmd(id, " << cmd << ", const Q3PtrVector<UmlClass> & l1, const Q3PtrVector<UmlClass> & l2, const Q3PtrVector<UmlClass> & l3)\n";
#endif

    write_char(onInstanceCmd);
    write_id(id);
    write_char(cmd);

    unsigned n;
    unsigned i;

    n = l1.count();
    write_unsigned(n);

    for (i = 0; i != n; i += 1)
        write_id(((UmlBaseItem *) l1[i])->_identifier);

    n = l2.count();
    write_unsigned(n);

    for (i = 0; i != n; i += 1)
        write_id(((UmlBaseItem *) l2[i])->_identifier);

    n = l3.count();
    write_unsigned(n);

    for (i = 0; i != n; i += 1)
        write_id(((UmlBaseItem *) l3[i])->_identifier);

    flush();
}
void UmlJunctionPseudoState::generate(UmlClass * machine, UmlClass * anystate, UmlState * state) {
  // create an operation because a priori shared
  if (_oper.isEmpty())
    _oper.sprintf("_junction%d", ++_rank);

  UmlClass * cl = state->assocClass();
  UmlOperation * junction;
  
  if (((junction = (UmlOperation *) cl->getChild(anOperation, _oper)) == 0) &&
      ((junction = UmlBaseOperation::create(cl, _oper)) == 0)) {
    UmlCom::trace("Error : cannot create operation '" + _oper 
		  + "' in class '" + cl->name() + "'<br>");
    throw 0;
  }

  junction->defaultDef();
  junction->setComment("implement a junction, through an operation because shared, internal");
  junction->setType("void", "${type}");
  junction->addParam(0, InputOutputDirection, "stm", machine);
  junction->setParams("${t0} & ${p0}");
  
  Q3CString body;
  const Q3PtrVector<UmlItem> ch = children();
  Q3PtrList<UmlTransition> trs;
  unsigned index;
  
  for (index = 0; index != ch.count(); index += 1)
    if (ch[index]->kind() == aTransition)
      // theo mandatory
      trs.append((UmlTransition *) ch[index]);
    
  UmlTransition::generate(trs, machine, anystate, state, body, "  ", FALSE);
  
  junction->set_CppBody(body);
}
Exemple #3
0
void UmlTransition::generate(UmlClass * machine, UmlClass * anystate, UmlState * state)
{
    if (_already_managed)
        return;

    Q3CString s = triggerName();

    // group transitions having the same trigger
    const Q3PtrVector<UmlItem> ch = parent()->children();
    unsigned index = ch.findRef(this);
    Q3PtrList<UmlTransition> trs;
    UmlTransition * tr_no_guard = 0;

    if (cppGuard().isEmpty())
        tr_no_guard = this;
    else
        trs.append(this);

    while (++index != ch.count()) {
        if ((ch[index]->kind() == aTransition) &&
            (((UmlTransition *) ch[index])->triggerName() == s)) {
            if (!((UmlTransition *) ch[index])->cppGuard().isEmpty())
                trs.append((UmlTransition *) ch[index]);
            else if (tr_no_guard != 0) {
                UmlCom::trace("Error : several transitions from '" + parent()->name()
                              + "' don't have guard");
                throw 0;
            }
            else
                tr_no_guard = (UmlTransition *) ch[index];

            ((UmlTransition *) ch[index])->_already_managed = TRUE;
        }
    }

    if (tr_no_guard != 0)
        // place it at end
        trs.append(tr_no_guard);

    // made the trigger

    UmlOperation * trg = state->assocClass()->trigger(s, machine, anystate);
    Q3CString body;

    if (s == "create") {
        // manage entry
        if (!state->cppEntryBehavior().isEmpty())
            body = "  _doentry(stm);\n";
    }

    if (!state->cppDoActivity().isEmpty())
        // state do activity before each event except create
        body += "  _do(stm);\n";

    bool completion = (s == "_completion");

    if (!completion && state->isLeaf() && state->hasCompletion())
        // manage completion
        body += "  if (_completion(stm)) return;\n";

    UmlTransition::generate(trs, machine, anystate, state,
                            body, "  ", completion);

    trg->set_CppBody(body);
}
Exemple #4
0
void UmlRelation::import(File & f)
{
  if (scanning)
    f.skipBlock();
  else {
    Q3CString s;
    
    if (f.read(s) != STRING)
      f.syntaxError(s, "relation's name");
    else if (*s == '$')
      // unnamed
      s = "";
    
    Q3CString id;
    Q3CString ste;
    Q3CString doc;
    Q3Dict<Q3CString> prop;
    Q3CString s2;
    int k;
    
    do {
      k = f.readDefinitionBeginning(s2, id, ste, doc, prop);
    } while (id.isEmpty());
    
    for (;;) {
      if (k == ATOM) {
	if (s2 == "roles")
	  break;
	f.skipNextForm();
	k = f.read(s2);
      }
      else
	f.syntaxError(s);
    }
    
    f.read("(");
    f.read("list");
    f.read("role_list");
    
    Role role_1; 
    Role role_2; 
    Role * role1 = &role_1; 
    Role * role2 = &role_2; 
    
    role_1.import(f);
    role_2.import(f);
    
    UmlRelation * r = 0; 
    bool bidir = role_1.is_navigable && role_2.is_navigable;

    // place information in the logical side !
    bool b = role_1.is_aggregate;

    role_1.is_aggregate = role_2.is_aggregate;
    role_2.is_aggregate = b;

    role_1.is_aggregate |= role_1.is_byvalue;
    role_2.is_aggregate |= role_2.is_byvalue;

    if (bidir && role_2.is_aggregate) {
      // manage bouml limitation : only role1 may be an aggregate
      if (role_1.is_aggregate)
        bidir = FALSE;
      else {
	// exchange roles
	role1 = &role_2;
	role2 = &role_1;
      }
    }

    if ((role1->target != 0) && (role2->target != 0)) { 
      if (role1->is_navigable) {
	r = UmlRelation::create(role1->rel_kind(bidir), role2->target, role1->target);
	
	if (r == 0) {
	  UmlCom::trace("<br>cannot create relation '" + role1->name + "' from '" +
			role2->target->fullName() + "' to '" +
			role1->target->fullName() + "'");
	  f.read(")");
	  f.skipBlock();
	  return;
	}
	
	if (!ste.isEmpty())
	  r->set_Stereotype(ste);
	
	if (! s.isEmpty())
	  r->set_Name(s);
	
	r->import(role1);
      }
      
      if (role2->is_navigable) {
	if (bidir) {
	  const Q3PtrVector<UmlItem> ch = role2->target->children();
	  
	  r = (UmlRelation *) ch.at(ch.count() - 1);
	}
	else {
	  r = UmlRelation::create(role2->rel_kind(FALSE),role1->target, role2->target);
	  
	  if (r == 0) {
	    UmlCom::trace("<br>cannot create relation '" + role2->name +
			  "' from '" +
			  role1->target->fullName() + "' to '" +
			  role2->target->fullName() + "'");
	    f.read(")");
	    f.skipBlock();
	    return;
	  }
	  
	  if (!ste.isEmpty())
	    r->set_Stereotype(ste);
	   
	  if (! s.isEmpty()) 
	    r->set_Name(s); 
	}
	  
	r->import(role2);
      }
    }

    f.read(")");
    f.skipBlock();
  }
}