Esempio n. 1
0
Q3CString UmlOperation::compute_name() {
  Q3CString get_set_spec = pythonNameSpec();
  
  if (! get_set_spec.isEmpty()) {
    UmlClassMember * it;
    
    if ((it = getOf()) == 0)
      it = setOf();
    
    int index;
    Q3CString s = (it->kind() == aRelation)
      ? ((UmlRelation *) it)->roleName()
      : it->name();
    
    if ((index = get_set_spec.find("${name}")) != -1)
      get_set_spec.replace(index, 7, s);
    else if ((index = get_set_spec.find("${Name}")) != -1)
      get_set_spec.replace(index, 7, capitalize(s));
    else if ((index = s.find("${NAME}")) != -1)
      get_set_spec.replace(index, 7, s.upper());
    else if ((index = s.find("${nAME}")) != -1)
      get_set_spec.replace(index, 7, s.lower());
    
    return get_set_spec;
  }
  else
    return name();
}
Esempio n. 2
0
Q3CString UmlOperation::compute_name(Q3CString s)
{
    if (!s.isEmpty()) {
        UmlClassMember * m = getOf();

        if ((m != 0) || ((m = setOf()) != 0)) {
            Q3CString n = (m->kind() == aRelation)
                          ? ((UmlRelation *) m)->roleName()
                          : m->name();
            int index;

            if ((index = s.find("${name}")) != -1)
                return s.left(index) + n + s.mid(index + 7);
            else if ((index = s.find("${Name}")) != -1)
                return s.left(index) + n.left(1).upper() + n.mid(1) + s.mid(index + 7);
            else if ((index = s.find("${NAME}")) != -1)
                return s.left(index) + n.upper() + s.mid(index + 7);
            else
                return s;
        }
    }

    return name();
}
Esempio n. 3
0
void UmlArtifact::generate() {
  if (! managed) {
    managed = TRUE;
    
    if (stereotype() == "text") {
      generate_text();
      return;
    }
    else if (stereotype() != "source")
      return;
    
    package_of_generated_artifact = package();
    
    const Q3CString def = idlSource();
    
    if (def.isEmpty())
      return;
    
    const Q3CString & name = this->name();    
    UmlPackage * pack = package();
    Q3CString path = pack->path(name);
    Q3CString mod_start;
    Q3CString mod_end;
    Q3CString mod = pack->idlModule();
    
    if (! mod.isEmpty()) {
      int index = 0;
      int index2;
      Q3CString closed = "\n}; // module ";
      
      while ((index2 = mod.find(':', index)) != -1) {
	Q3CString mo = mod.mid(index, index2 - index);
	
	mod_start += Q3CString("module ") + mo + " {\n\n";
	closed += mo;
	mod_end = closed + "\n" + mod_end;
	closed += "::";
	mod.replace(index2, 2, "_");
	index = index2 + 1;
      }
      
      mod_start += Q3CString("module ") + mod.mid(index) + " {\n\n";
      closed += mod.mid(index);
      mod_end = closed + "\n" + mod_end;
    }
    
    UmlCom::message(name);
    if (verbose())
      UmlCom::trace(Q3CString("<hr><font face=helvetica>Generate code for <i> ")
		    + name + "</i> in <i>" + path + "</i></font><br>");
    else
      set_trace_header(Q3CString("<font face=helvetica>Generate code for <i> ")
		       + name + "</i> in <i>" + path + "</i></font><br>");
    
#if 0
    // compute dependencies
    
    Q3PtrList<CppRefType> dependencies;
#endif
    const Q3PtrVector<UmlClass> & cls = associatedClasses();
    unsigned n = cls.count();
    unsigned index;
    
#if 0
    for (index = 0; index != n; index += 1)
      cls[index]->compute_dependencies(dependencies);
#endif
    
    // generate source file
    
    QByteArray file;
    QTextOStream f(&file);
    const char * p = def;
    const char * pp = 0;
    
    for (;;) {
      if (*p == 0) {
	if (pp == 0)
	  break;
	
	// comment management done
	p = pp;
	pp = 0;
	if (*p == 0)
	  break;
      }
      
      if (*p == '@')
	manage_alias(p, f);
      else if (*p != '$')
	f << *p++;
      else if (!strncmp(p, "${comment}", 10))
	manage_comment(p, pp);
      else if (!strncmp(p, "${description}", 14))
	manage_description(p, pp);
      else if (!strncmp(p, "${name}", 7)) {
	p += 7;
	f << name;
      }
      else if (!strncmp(p, "${Name}", 7)) {
	p += 7;
	f << capitalize(name);
      }
      else if (!strncmp(p, "${NAME}", 7)) {
	p += 7;
	f << name.upper();
      }
      else if (!strncmp(p, "${nAME}", 7)) {
	p += 7;
	f << name.lower();
      }
      else if (!strncmp(p, "${module}", 9)) {
	p += 9;
	f << mod;
      }
      else if (!strncmp(p, "${MODULE}", 9)) {
	p += 9;
	f << mod.upper();
      }
      else if (!strncmp(p, "${includes}", 11)) {
	p += 11;
	/*if (!incl_computed) {
	  incl_computed = TRUE;
	  CppRefType::compute(dependencies, hdef, srcdef, h_incl, decl, incl, this);
	}
	if (!incl.isEmpty()) {
	  f << incl;
	  if (*p != '\n')
	    f << '\n';
	}
	else*/ if (*p == '\n')
	  p += 1;
      }
      else if (!strncmp(p, "${definition}", 13)) {
	p += 13;
	for (index = 0; index != n; index += 1)
	  cls[index]->generate(f);
	if (*p == '\n')
	  p += 1;
      }
      else if (!strncmp(p, "${module_start}", 15)) {
	p += 15;
	if (!mod_start.isEmpty())
	  f << mod_start;
	if (*p == '\n')
	  p += 1;
      }
      else if (!strncmp(p, "${module_end}", 13)) {
	p += 13;
	if (!mod_end.isEmpty())
	  f << mod_end;
	if (*p == '\n')
	  p += 1;
      }
      else
	// strange
	f << *p++;
    }
    
    f << '\000';
    
    if (must_be_saved(path, file)) {
      write_trace_header();
	
      FILE * fp;
      
      if ((fp = fopen((const char *) path, "wb")) == 0) {
	write_trace_header();
	UmlCom::trace(Q3CString("<font color=\"red\"><b><i> ")
		      + name + " : </i> cannot open <i> " 
		      + path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>"
		      + pack->name() + "</i> Idl directory specification</b></font><br>");
	incr_error();
      }
      else {
	fputs((const char *) file, fp);
	fclose(fp);
      }
    }
    else if (get_trace_header().isEmpty())
      UmlCom::trace(Q3CString("<font face=helvetica><i> ")
		    + path + "</i> not modified</font><br>");
  }
}
Esempio n. 4
0
void tst_Q3CString::upper()
{
    Q3CString a;
    a="Text";
    QCOMPARE(a.upper(),(Q3CString)"TEXT");
}