示例#1
0
void tst_Q3CString::left()
{
    Q3CString a;
    a="ABCDEFGHIEfGEFG"; // 15 chars
    QCOMPARE(a.left(3),(Q3CString)"ABC");
    QVERIFY(!a.left(0).isNull());
    QCOMPARE(a.left(0),(Q3CString)"");

    Q3CString n;
    QVERIFY(n.left(3).isNull());
    QVERIFY(n.left(0).isNull());
    QVERIFY(n.left(0).isNull());
}
示例#2
0
bool ClassContainer::find_type(Q3CString type, UmlTypeSpec & typespec,
			       NDict<Class> & defined) {
  typespec.explicit_type = 0;
  
  if ((typespec.type = UmlClass::used(type)) != 0)
    return TRUE;
  
  Class * cl = defined[type];
  
  if (cl == 0) {
    int index = 0;
    
    while ((index = type.find('<', index)) != -1) {
      // goes after <...>
      int index2 = index + 1;
      unsigned level = 1;
    
      for (;;) {
	int c = type[index2++];
      
	if (c == '<')
	  level += 1;
	else if (c == 0)
	  // wrong template spec
	  return FALSE;
	else if ((c == '>') && (--level == 0)) {
	  break;
	}
      }
      
      if ((type[index2] != (char)0) && (defined[type.left(index2)] != (char)0))
	// explicit template
	index = index2;
      else if (defined[type.left(index)] != 0)
	// non explicit template, remove <>
	type.remove(index, index2 - index);
      else
	// unknown type
	return FALSE;

      typespec.type = 0;
      
      if ((cl = defined[type]) != 0)
	break;
    }
  }
  
  return ((cl != 0) && ((typespec.type = cl->get_uml()) != 0));
}
示例#3
0
文件: UmlItem.cpp 项目: SciBoy/douml
void UmlItem::write_multiplicity(FileOut & out, Q3CString s, UmlItem * who)
{
  if (!s.isEmpty()) {
    Q3CString min;
    Q3CString max;
    int index = s.find("..");
    
    if (index != -1) {
      min = s.left(index).stripWhiteSpace();
      max = s.mid(index+2).stripWhiteSpace();
    }
    else
      min = max = s.stripWhiteSpace();
    
    out.indent();
    out << "<lowerValue xmi:type=\"uml:LiteralString\"";
    out.id_prefix(who, "MULTIPLICITY_L_");
    out << " value=\"" << min << "\"/>\n";
    
    out.indent();
    out << "<upperValue xmi:type=\"uml:LiteralString\"";
    out.id_prefix(who, "MULTIPLICITY_U_");
    out << " value=\"" << max << "\"/>\n";
  }
}
示例#4
0
void UmlExitPointPseudoState::html(Q3CString pfix, unsigned int rank, unsigned int level) {
  define();

  UmlCom::message(name());

  Q3CString s = sKind();
  
  s.replace(0, 1, s.left(1).upper());
  UmlItem::html(s, (UmlDiagram *) 0);
  
  fw.write("<p>Defined in ");
  if (parent()->kind() == aRegion)
    parent()->parent()->write();
  else
    parent()->write();
  fw.write("</p>");
  
  if (reference() != 0) {
    fw.write("<p>References ");
    reference()->write();
    fw.write("</p>");
  }

  write_children(pfix, rank, level);

  unload(FALSE, FALSE);
}
示例#5
0
static void create_directory(Q3CString s)
{
  int index = 0;
  QChar sep = QDir::separator();
  
  if (sep != '/') {
    while ((index = s.find(sep, index)) != -1)
      s.replace(index++, 1, "/");
  }
  
  s = QDir::cleanDirPath(s) + "/";
  index = s.find("/");
  
  int index2;
  
  while ((index2 = s.find("/", index + 1)) != -1) {
    Q3CString s2 = s.left(index2);
    QDir sd(s2);
    
    if (!sd.exists()) {
      if (!sd.mkdir(s2)) {
	UmlCom::trace(Q3CString("<font color=\"red\"><b> cannot create directory <i>")
		      + s2 + "</i></b></font><br>");
	UmlCom::bye(n_errors() + 1);
	UmlCom::fatal_error("UmlPackage::file_path");
      }
    }
    index = index2;
  }
}
示例#6
0
文件: FileOut.cpp 项目: SciBoy/douml
void FileOut::define_datatypes(bool uml_20, bool primitive_type, bool gen_extension) {
  const char * pfix = (primitive_type) 
	? ((uml_20) ? "<ownedMember xmi:type=\"uml:PrimitiveType\""
		    : "<packagedElement xmi:type=\"uml:PrimitiveType\"")
	: ((uml_20) ? "<ownedMember xmi:type=\"uml:DataType\""
		    : "<packagedElement xmi:type=\"uml:DataType\"");

  QMap<Q3CString, int>::ConstIterator it;
  
  for (it = _datatypes.begin();
       it != _datatypes.end();
       ++it) {
    indent();
    (*this) << pfix << " xmi:id=\"BOUML_datatype_"
      << it.data() << "\" name=\"";
    quote((const char*)it.key());//[jasa] ambiguous call
    (*this) << "\"/>\n";
  }
  
  const char * postfix = 
    (uml_20) ? "</ownedMember>\n" : "</packagedElement>\n";

  for (it = _modifiedtypes.begin();
       it != _modifiedtypes.end();
       ++it) {
    Q3CString k = it.key();
    int index = k.find('_');
    
    indent();
    (*this) << pfix << " xmi:id=\"BOUML_basedontype_"
      << it.data() << "\" name = \"";
    quote((const char*)k.mid(index + 1));
    (*this) << '"';

    if (gen_extension) {
      (*this) << ">\n";
      indent();
      (*this) << "\t<xmi:Extension extender=\"Bouml\">\n";
      indent();
      (*this) << "\t\t<basedOn \"BOUML_" << k.left(index) << "\"/>\n";
      indent();
      (*this) << "\t</xmi:Extension>\n";
      indent();
      (*this) << postfix;
    }
    else
      (*this) << "/>\n";
  }
}
示例#7
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();
}
示例#8
0
文件: UmlClass.cpp 项目: SciBoy/douml
void UmlClass::write(QTextOStream & f) {
  if (isJavaExternal()) {
    Q3CString s = javaDecl().stripWhiteSpace();
    int index;
      
    if ((index = s.find("${name}")) != -1)
      s.replace(index, 7, name());
    else if ((index = s.find("${Name}")) != -1)
      s.replace(index, 7, capitalize(name()));
    else if ((index = s.find("${NAME}")) != -1)
      s.replace(index, 7, name().upper());
    else if ((index = s.find("${nAME}")) != -1)
      s.replace(index, 7, name().lower());
    
    f << s;
  }
  else {
    UmlClass * toplevel = this;
    UmlItem * p;
    Q3CString s2;
    
    while ((p = toplevel->parent())->kind() == aClass) {
      toplevel = (UmlClass *) p;
      s2 = dot + p->name() + s2;
    }
    
    UmlArtifact * cp = toplevel->associatedArtifact();
    UmlPackage * pack = (UmlPackage *)
      ((cp != 0) ? (UmlItem *) cp : (UmlItem *) toplevel)->package();
    
    if (pack != UmlArtifact::generation_package()) {
      Q3CString s = pack->javaPackage();

      if (! s.isEmpty() && (s != "java.lang") && (s.left(10) != "java.lang.")) {
	s += s2;
	
	if (JavaSettings::isForcePackagePrefixGeneration() ||
	    !UmlArtifact::generated_one()->is_imported(s, name()))
	  f << s << '.';
      }
    }
    else if (! s2.isEmpty())
      f << s2.mid(1) << '.';
    
    f << name();
  }
}
示例#9
0
QString Namespace::namespacify(Q3CString s, bool local) {
  QString r;
  int index = s.find("::");
  
  if (index == 0)
    r = ((const char *) s) + 2;
  else {
    if (index != -1) {
      QMap<Q3CString,Q3CString>::ConstIterator it = 
	Aliases.find(s.left(index));
      
      if (it != Aliases.end())
	s.replace(0, index, *it);
    }
    
    r = (Stack.isEmpty())
      ? QString(s)
      : Stack.last() + QString(s);
  }
  
  return (local)
    ? r + "\n" + Lex::filename()
    : r;
}
示例#10
0
Q3CString UmlPackage::text_path(const Q3CString & f) {
  Q3CString r = path(f);
  
  return r.left(r.length() - 1 - IdlSettings::sourceExtension().length());
}
示例#11
0
bool UmlAttribute::new_one(Class * container, const Q3CString & name,
			   const Q3CString & type, const Q3CString & modifier,
			   const Q3CString & pretype, const Q3CString & array,
			   aVisibility visibility, bool staticp, bool constp,
			   bool typenamep, bool mutablep, bool volatilep,
			   const Q3CString & bitfield, const Q3CString & value,
			   Q3CString comment, Q3CString description
#ifdef ROUNDTRIP
			   , bool roundtrip, Q3PtrList<UmlItem> & expected_order
#endif
			   )
{
#ifdef DEBUG_BOUML
  cout << "ATTRIBUTE '" << name << "' type '" << type << "' modifier '" << modifier << "' array '" << array << "'\n";
#endif
  
  if (
#ifdef REVERSE
      container->from_libp() &&
#endif
      (visibility == PrivateVisibility)) {
    Lex::finish_line();
    Lex::clear_comments();
    return TRUE;
  }
  
  UmlClass * cl = container->get_uml();
  UmlAttribute * at;
  
#ifdef ROUNDTRIP
  bool created;
  
  if (!roundtrip ||
      ((at = search_attr(cl, name)) == 0)) {
#endif
    at = UmlBaseAttribute::create(cl, name);
    
    if (at == 0) {
      UmlCom::trace(Q3CString("<font face=helvetica><b>cannot add attribute <i>")
		    + name + "</i> in <i>" + Q3CString(cl->name())
		    + "</i></b></font><br><hr>");  
      return FALSE;
    }
  
#ifdef REVERSE
# ifndef ROUNDTRIP
    Statistic::one_attribute_more();
# else
    if (roundtrip)
      container->set_updated();
    created = TRUE;
  }
  else
    created = FALSE;
# endif
#endif
  
  Lex::finish_line();
  
  comment = Lex::get_comments(comment);
  description = Lex::get_description(description);
  
  bool pfunc = (type.find('$') != -1);
  UmlTypeSpec typespec;
  Q3CString typeform;
  Q3CString stereotype;
  
  if (! pfunc) {
    typeform = (pretype.isEmpty())
      ? Q3CString("${type}")
      : pretype + " ${type}";
    
    container->compute_type(type, typespec, typeform);
  }
  else {
    typespec.explicit_type = type.simplifyWhiteSpace();
    
    int index = typespec.explicit_type.find("${name}");
    
    if (index != -1)
      typespec.explicit_type.remove(index, 7);
  }
  
  Q3CString decl = CppSettings::attributeDecl("");
  int index = decl.find("${type}");
  
  if ((index == -1) ||
      (decl.find("${const}") == -1) ||
      (decl.find("${name}") == -1) ||
      (decl.find("${mutable}") == -1) ||
      (decl.find("${volatile}") == -1) ||
      (decl.find(';') == -1)) {
    decl = "    ${comment}${static}${mutable}${volatile}${const}${type} ${name}${value};";
    index = decl.find("${type}");
  }
  
  if (pfunc)
    decl.replace(index, decl.find("${name}") + 7 - index, type);
  else {
    if (!modifier.isEmpty())
      decl.insert(index + 7, (const char*)(Q3CString(" ") + modifier));
        
    if (typeform != "${type}")
      decl.replace(index, 7, typeform);
    else if (typespec.type == 0) {
      Q3CString t = typespec.explicit_type;
      int index2;
      
      if (!t.isEmpty() &&
	  (t.at(t.length() - 1) == '>') &&
	  ((index2 = t.find('<')) > 0)) {
	stereotype = t.left(index2);
	typespec.explicit_type =
	  // may be a,b ...
	  t.mid(index2 + 1, t.length() - 2 - index2);
	decl.replace(index, 7, "${stereotype}<${type}>");
      }
    }
    
    if (!array.isEmpty())
      decl.insert(decl.find("${name}") + 7, "${multiplicity}");
    
    if (!bitfield.isEmpty())
      decl.insert(decl.find(';'), (const char *)(Q3CString(" : ") + bitfield));
  }
  
  if (typenamep) {
    int index = decl.find("${const}") + 8; // find cannot return -1
    int index2 = decl.find("${mutable}") + 10; // find cannot return -1
    int index3 = decl.find("${volatile}") + 11; // find cannot return -1
    
    if (index2 > index) index = index2;
    if (index3 > index) index = index3;
    
    decl.insert(index, "typename ");
  }
  
  if (!value.isEmpty() && ((index = decl.find("${value}")) != -1))
    decl.insert(index + 2,  "h_");
  
#ifdef ROUNDTRIP
  if (roundtrip && !created) {
    if (decl.find("${description}") != -1) {
      if (nequal(at->description(), description)) {
	at->set_Description(description);
	container->set_updated();
      }
    }
    else if (nequal(at->description(), Lex::simplify_comment(comment))) {
      at->set_Description(comment); // comment was set
      container->set_updated();
    }
          
    if (at->isReadOnly() != constp) {
      at->set_isReadOnly(constp);
      container->set_updated();
    }
    
    if (at->isCppMutable() != mutablep) {
      at->set_isCppMutable(mutablep);
      container->set_updated();
    }
    
    if (at->isVolatile() != volatilep) {
      at->set_isVolatile(volatilep);
      container->set_updated();
    }
    
    if (at->isClassMember() != staticp) {
      at->set_isClassMember(staticp);
      container->set_updated();
    }
    
    if (neq(at->multiplicity(), array)) {
      at->set_Multiplicity(array);
      container->set_updated();
    }
    
    if (!staticp) {
      Q3CString v = at->defaultValue();
      
      if (!v.isEmpty() && (((const char *) v)[0] == '='))
	v = v.mid(1);
      
      if (nequal(v, value)) {
	at->set_DefaultValue(value);
	container->set_updated();
      }
    }
    
    if (at->visibility() != visibility) {
      at->set_Visibility(visibility);
      container->set_updated();
    }
    
    if (!stereotype.isEmpty()) {
      Q3CString cppst;
      
      if (!at->stereotype().isEmpty())
	cppst = CppSettings::relationAttributeStereotype(at->stereotype());
      
      if (cppst != stereotype) {
	at->set_Stereotype(stereotype);
	container->set_updated();
      }
    }
    
    if (!at->type().equal(typespec)) {
      at->set_Type(typespec);
      container->set_updated();
    }
    
    if (neq(at->cppDecl(), decl)) {
      at->set_CppDecl(decl);
      container->set_updated();
    }
          
    at->set_usefull();
    
    expected_order.append(at);
  }
  else {
#endif
    if (!comment.isEmpty())
      at->set_Description((decl.find("${description}") != -1)
			  ? description : Lex::simplify_comment(comment));
    
    if (constp)
      at->set_isReadOnly(TRUE);
    
    if (mutablep)
      at->set_isCppMutable(TRUE);
    
    if (volatilep)
      at->set_isVolatile(TRUE);
    
    if (staticp)
      at->set_isClassMember(TRUE);
    
    if (!array.isEmpty())
      at->set_Multiplicity(array);
    
    if (! value.isEmpty())
      at->set_DefaultValue(value);
    
    at->set_Visibility(visibility);
    
    if (! stereotype.isEmpty())
      at->set_Stereotype(stereotype);
    
    at->set_Type(typespec);
    
    at->set_CppDecl(decl);
    
#ifdef ROUNDTRIP
    if (roundtrip)
      expected_order.append(at);
  }
#endif
  
  return TRUE;
}
示例#12
0
Q3CString UmlPackage::file_path(const Q3CString & f, Q3CString relto) {
  if (!dir.read) {
    dir.file = phpDir();
    dir.file_absolute = FALSE;
    
    QDir d_root(rootDir());
    
    if (dir.file.isEmpty())
      dir.file = RootDir;
    else if (QDir::isRelativePath(dir.file))
      dir.file = d_root.filePath(dir.file);
    else
      dir.file_absolute = TRUE;
   
    if (dir.file.isEmpty()) {
      UmlCom::trace(Q3CString("<font color=\"red\"><b><b> The generation directory "
			    "must be specified for the package<i> ") + name()
			    + "</i>, edit the <i> generation settings</i> (tab 'directory') "
			    "or edit the package (tab 'Php')</b></font><br>");
      UmlCom::bye(n_errors() + 1);
      UmlCom::fatal_error("UmlPackage::file_path");
    }
    
    dir.read = TRUE;
  }
  
  if (f.isEmpty())
    return dir.file;
  
  QDir d(dir.file);
  
  if (! d.exists()) {
    // create directory including the intermediates
    Q3CString s = dir.file;
    int index = 0;
    QChar sep = QDir::separator();
    
    if (sep != '/') {
      while ((index = s.find(sep, index)) != -1)
	s.replace(index++, 1, "/");
    }
    
    s = QDir::cleanDirPath(s) + "/";
    index = s.find("/");

    int index2;
    
    while ((index2 = s.find("/", index + 1)) != -1) {
      Q3CString s2 = s.left(index2);
      QDir sd(s2);
      
      if (!sd.exists()) {
	if (!sd.mkdir(s2)) {
	  UmlCom::trace(Q3CString("<font color=\"red\"><b> cannot create directory <i>")
			+ s2 + "</i></b></font><br>");
	  UmlCom::bye(n_errors() + 1);
	  UmlCom::fatal_error("UmlPackage::file_path");
	}
      }
      index = index2;
    }
  }
  
  Q3CString df = (dir.file_absolute || relto.isEmpty())
    ? Q3CString(d.filePath(f).toAscii().constData())
    : relative_path(d, relto) + f;
  
  if (PhpSettings::isRelativePath() && (df[0] != '/') && (df[0] != '.'))
    df = "./" + df;
  
  return df + Q3CString(".") + PhpSettings::sourceExtension();
}
示例#13
0
void ClassContainer::compute_type(Q3CString type, UmlTypeSpec & typespec,
				  Q3CString & typeform,
				  bool get_first_template_actual,
				  const Q3ValueList<FormalParameterList> & tmplts) {
  typespec.type = 0;
  typespec.explicit_type = 0;
  
  if (!strncmp((const char *) type, "struct ", 7) ||
      !strncmp((const char *) type, "union ", 6) ||
      !strncmp((const char *) type, "enum ", 5)) {
    typespec.explicit_type = "<complex type>";
    typeform = type;
    return;
  }
    
  int index;
  
  if (get_first_template_actual && ((index = type.find('<')) != -1)) {
    type = Lex::normalize(type);
    index = type.find('<');
    
    const char * p = type;
    
    if (strncmp(p + index + 1, "const ", 6) == 0)
      index += 6;
    
    // look at each actual in <>
    unsigned level = 1;
    int index2;
    Q3CString tf1;
    Q3CString t1;
    
    for (;;) {
      // earch for the current arg end
      for (index2 = index + 1; p[index2]; index2 += 1) {
	char c = p[index2];
	
	if ((c == ',') || (c == '*') || (c == '[') || (c == '&')) {
	  if (level == 1)
	    break;
	}
	else if (c == '<')
	  level += 1;
	else if ((c == '>') && (--level == 0))
	  break;
      }
      
      if (p[index2]) {
	Q3CString tf = type.left(index + 1) + typeform + type.mid(index2);
	Q3CString t = type.mid(index + 1, index2 - index - 1).stripWhiteSpace();
#ifdef DEBUG_BOUML
	cout << "typeform '" << tf << "' type '" << t << "'\n";
#endif
	UmlTypeSpec ts;
	
	Q3CString normalized = Lex::normalize(t);
  
	if (!find_type(normalized, ts) &&
	     (Namespace::current().isEmpty() ||
	      (normalized.at(0) == ':') || 
	      !find_type("::" + normalized, ts))) {
	  if (get_first_template_actual) {
	    get_first_template_actual = FALSE;
	    tf1 = tf;
	    t1 = t;
	  }
	  index = index2;
	}
	else {
	  // find a class
	  typeform = tf;
	  type = t;
	  typespec.type = ts.type;
	  break;
	}
      }
      else if (!get_first_template_actual) {
	// has first actual
	typeform = tf1;
	type = t1;
	break;
      }
      else {
	typespec.explicit_type = type;
	return;
      }
    }
  }

  if (! tmplts.isEmpty()) {
    Q3ValueList<FormalParameterList>::ConstIterator it1;
    
    for (it1 = tmplts.begin(); it1 != tmplts.end(); ++it1) {
      FormalParameterList::ConstIterator it2;
    
      for (it2 = (*it1).begin(); it2 != (*it1).end(); ++it2) {
	if ((*it2).name() == type) {
	  typespec.type = 0;
	  typespec.explicit_type = type;
	  return;
	}
      }
    }
  }
  
  Q3CString normalized;
  
  if (typespec.type == 0) {
    normalized = Lex::normalize(type);
    
    if (!find_type(normalized, typespec) &&
	(Namespace::current().isEmpty() ||
	 (normalized.at(0) == ':') || 
	 !find_type("::" + normalized, typespec))) {
      typespec.explicit_type = CppSettings::umlType(type);
      if (typespec.explicit_type.isEmpty()) {
	// search for equivalent forms
	if (type == "long int")
	  typespec.explicit_type = CppSettings::umlType("long");
	else if (type == "long")
	  typespec.explicit_type = CppSettings::umlType("long int");
	else if (type == "unsigned long int")
	  typespec.explicit_type = CppSettings::umlType("unsigned long");
	else if (type == "unsigned long")
	  typespec.explicit_type = CppSettings::umlType("unsigned long int");
	else if (type == "unsigned")
	  typespec.explicit_type = CppSettings::umlType("unsigned int");
	else if (type == "unsigned int")
	  typespec.explicit_type = CppSettings::umlType("unsigned");
	else if ((type == "signed") || (type == "signed int"))
	  typespec.explicit_type = CppSettings::umlType("int");
      }
      
      if (typespec.explicit_type.isEmpty()) {
	typespec.explicit_type = type; /*
	if (!Lex::identifierp(type, TRUE))
	  typespec.explicit_type = type;
	else {
	  Q3CString t = type;
	  
	  while ((index = t.find(':')) == 0)
	    t = t.mid(1);
	  
	  ClassContainer * cc = Package::unknown();
	  
	  while (index != -1) {
	    if ((cc = cc->declare_if_needed(t.left(index))) == 0) {
	      typespec.explicit_type = type;
	      return;
	    }
	    
	    while (t[index] == ':')
	      index += 1;
	    t = t.mid(index);
	    index = t.find(':');
	  }
	  
	  if (((cc = cc->declare_if_needed(t)) == 0) ||
	      ((typespec.type = ((Class *) cc)->get_uml()) == 0))
	    typespec.explicit_type = type;
	}*/
      }
      typespec.type = 0;
    }
  }
  
  if ((typespec.type != 0) &&
      !typespec.type->formals().isEmpty() &&
      (type.at(type.length() - 1) == '>') &&
      (!typespec.type->inside_its_definition() ||
       !typespec.type->is_itself((normalized.isEmpty()) ? Lex::normalize(type)
							: normalized))) {
    typespec.type = 0;
    typespec.explicit_type = type;
  }
}
示例#14
0
bool UmlRelation::new_one(Class * container, const Q3CString & name,
			  UmlClass * dest, const Q3CString & modifier, 
			  const Q3CString & pretype, const Q3CString & array, 
			  const Q3CString & typeform, aVisibility visibility,
			  bool staticp, bool constp, bool mutablep, bool volatilep, 
			  const Q3CString & value, Q3CString comment,
			  Q3CString description
#ifdef ROUNDTRIP
			  , bool roundtrip, Q3PtrList<UmlItem> & expected_order
#endif
			  )
{
#ifdef DEBUG_BOUML
  cout << "RELATION '" << name << "' from '" << cl->name() << "' to '" << dest->name()
    << "' modifier '" << modifier << "' array '" << array
      << "' typeform '" << typeform << "'\n";
#endif
  
  if (
#ifdef REVERSE
      container->from_libp() &&
#endif
      (visibility == PrivateVisibility)) {
    Lex::finish_line();
    Lex::clear_comments();
    return TRUE;
  }
  
  UmlClass * cl = container->get_uml();
  UmlRelation * rel;
  
#ifdef ROUNDTRIP
  if (roundtrip &&
      ((rel = search_rel(container, name, dest, "")) != 0)) {
    rel->set_usefull();
    expected_order.append(rel);
  }
  else {
#endif  
    rel = UmlBaseRelation::create((modifier.isEmpty() &&
				   ((typeform == "${type}") ||
				    (typeform[typeform.find("${type}") + 7] != '*')))
				  ? aDirectionalAggregationByValue
				  : aDirectionalAssociation,
				  cl, dest);
  
    if (rel == 0) {
      UmlCom::trace(Q3CString("<font face=helvetica><b>cannot add relation <i>")
		    + name + "</i> in <i>" + cl->name() + "</i> to <i>"
		    + dest->name() + "</i></b></font><br><hr>");  
      return FALSE;
    }
    
#ifdef REVERSE
# ifndef ROUNDTRIP
    Statistic::one_relation_more();
# else
    if (roundtrip) {
      expected_order.append(rel);
      container->set_updated();
      roundtrip = FALSE;
    }
  }
# endif
#endif
  
  Lex::finish_line();
  
  comment = Lex::get_comments(comment);
  description = Lex::get_description(description);
  
#ifdef ROUNDTRIP
  if (roundtrip) {
    if (rel->visibility() != visibility) {
      rel->set_Visibility(visibility);
      container->set_updated();
    }
  
    if (rel->isReadOnly() != constp) {
      rel->set_isReadOnly(constp);
      container->set_updated();
    }
    
    if (rel->isClassMember() != staticp) {
      rel->set_isClassMember(staticp);
      container->set_updated();
    }
    
    if (rel->isCppMutable() != mutablep) {
      rel->set_isCppMutable(mutablep);
      container->set_updated();
    }
    
    if (rel->isVolatile() != volatilep) {
      rel->set_isVolatile(volatilep);
      container->set_updated();
    }
  }
  else {
#endif
    rel->set_Visibility(visibility);
    if (constp) rel->set_isReadOnly(TRUE);
    if (staticp) rel->set_isClassMember(TRUE);
    if (mutablep) rel->set_isCppMutable(TRUE);
    if (volatilep) rel->set_isVolatile(TRUE);
    
#ifdef ROUNDTRIP
  }
#endif
  
  Q3CString decl;
  
  if (typeform != "${type}") {
    // array & modified are empty, pretype is empty ?
    decl = CppSettings::relationDecl(TRUE, "*");
    
    int index = typeform.find("<");	// cannot be -1
    Q3CString st = typeform.left(index);
    Q3CString st_uml = CppSettings::umlType(st);

#ifdef ROUNDTRIP
    if (roundtrip) {
      if (st_uml.isEmpty()) 
	st_uml = st;
      
      if (neq(rel->stereotype(), st_uml)) {
	rel->set_Stereotype(st_uml);
	container->set_updated();
      }
    }
    else
#endif
      rel->set_Stereotype((st_uml.isEmpty()) ? st : st_uml);
    
    int index2;
    
    if ((index2 = decl.find("<${type}>")) == -1) {
      decl = "    ${comment}${static}${mutable}${volatile}${const}${stereotype}<${type}> ${name}${value};";
      index2 = decl.find("<${type}>");
    }
    decl.replace(index2, 9, typeform.mid(index));
  }
  else {
    if (!array.isEmpty()) {
#ifdef ROUNDTRIP
    if (roundtrip) {
      if (neq(rel->multiplicity(), array)) {
	rel->set_Multiplicity(array);
	container->set_updated();
      }
    }
    else
#endif
      rel->set_Multiplicity(array);
    }
    decl = CppSettings::relationDecl(modifier != "*", array);
    
    int index;
    
    if (!pretype.isEmpty() &&
	((index = decl.find("${type}")) != 0))
      decl.insert(index,(const char*)( pretype + " "));
    
    if ((modifier == "&") && ((index = decl.find("${type}")) != 0))
      decl.insert(index + 7, " &");
  }
  
  if (! value.isEmpty()) {
    int index = decl.find("${value}");
    
    if (index != -1)
      decl.insert(index + 2,  "h_");
    
#ifdef ROUNDTRIP
    if (roundtrip) {
      if (!staticp) {
	Q3CString v = rel->defaultValue();
	
	if (!v.isEmpty() && (((const char *) v)[0] == '='))
	  v = v.mid(1);
	
	if (nequal(v, value)) {
	  rel->set_DefaultValue(value);
	  container->set_updated();
	}
      }
    }
    else
#endif
      rel->set_DefaultValue(value);
  }
  
#ifdef ROUNDTRIP
  if (roundtrip) {
    if (neq(rel->cppDecl(), decl)) {
      rel->set_CppDecl(decl);
      container->set_updated();
    }
    
    if (decl.find("${description}") != -1) {
      if (nequal(rel->description(), description)) {
	rel->set_Description(description);
	container->set_updated();
      }
    }
    else if (nequal(rel->description(), Lex::simplify_comment(comment))) {
      rel->set_Description(comment); // comment was set
      container->set_updated();
    }
    
    // role name is the right one
    return TRUE;
  }
#endif

  rel->set_CppDecl(decl);
  
  if (!comment.isEmpty())
    rel->set_Description((decl.find("${description") != -1)
			 ? description : Lex::simplify_comment(comment));
  
  return rel->set_RoleName(name);
}
示例#15
0
Q3CString UmlPackage::file_path(const Q3CString & f) {
  if (!dir.read) {
    dir.file = javaDir();
    
    if (! RootDirRead) {
      RootDirRead = TRUE;
      RootDir = JavaSettings::rootDir();

      if (!RootDir.isEmpty() && // empty -> error
	  QDir::isRelativePath(RootDir)) {
	QFileInfo f(getProject()->supportFile());
	QDir d(f.dirPath());

	RootDir = d.filePath(RootDir);
      }
    }

    QDir d_root(RootDir);
    
    if (dir.file.isEmpty())
      dir.file = RootDir;
    else if (QDir::isRelativePath(dir.file))
      dir.file = d_root.filePath(dir.file);
   
    if (dir.file.isEmpty()) {
      UmlCom::trace(Q3CString("<font color=\"red\"><b><b> The generation directory "
			    "must be specified for the package<i> ") + name()
			    + "</i>, edit the <i> generation settings</i> (tab 'directory') "
			    "or edit the package (tab 'Java')</b></font><br>");
      UmlCom::bye(n_errors() + 1);
      UmlCom::fatal_error("UmlPackage::file_path");
    }
    
    dir.read = TRUE;
  }
  
  QDir d(dir.file);
  
  if (! d.exists()) {
    // create directory including the intermediates
    Q3CString s = dir.file;
    int index = 0;
    QChar sep = QDir::separator();
    
    if (sep != '/') {
      while ((index = s.find(sep, index)) != -1)
	s.replace(index++, 1, "/");
    }
    
    s = QDir::cleanDirPath(s) + "/";
    index = s.find("/");

    int index2;
    
    while ((index2 = s.find("/", index + 1)) != -1) {
      Q3CString s2 = s.left(index2);
      QDir sd(s2);
      
      if (!sd.exists()) {
	if (!sd.mkdir(s2)) {
	  UmlCom::trace(Q3CString("<font color=\"red\"><b> cannot create directory <i>")
			+ s2 + "</i></b></font><br>");
	  UmlCom::bye(n_errors() + 1);
	  UmlCom::fatal_error("UmlPackage::file_path");
	}
      }
      index = index2;
    }
  }
  
  return Q3CString(d.filePath(f).toAscii().constData()) + Q3CString(".") + 
    JavaSettings::sourceExtension();
}
示例#16
0
文件: UmlClass.cpp 项目: SciBoy/douml
void UmlClass::write(QTextOStream & f, bool with_formals, BooL * is_template,
		     const Q3ValueList<UmlActualParameter> & actuals) {
  if (context.findRef(this) == -1) {
    if (parent()->kind() == aClass) {
      if (context.findRef((UmlClass *) parent()) == -1) {
	// parent cannot have formals, but may have actuals
	((UmlClass *) parent())->write(f, FALSE, 0, actuals);
	f << "::";
      }
    }
    else {
      UmlArtifact * cp = associatedArtifact();
      Q3CString nasp = ((UmlPackage *)
		       ((cp != 0) ? (UmlItem *) cp : (UmlItem *) this)->package())
	->cppNamespace();
      
      if (CppSettings::isForceNamespacePrefixGeneration() ||
	  (nasp != UmlArtifact::generation_package()->cppNamespace()))
	f << nasp << "::";
    }
  }
  
  Q3CString s;
  
  if (isCppExternal()) {
    s = cppDecl();
    
    int index = s.find('\n');
    
    s = (index == -1) ? s.stripWhiteSpace()
		      : s.left(index).stripWhiteSpace();
      
    if ((index = s.find("${name}")) != -1)
      s.replace(index, 7, name());
    else if ((index = s.find("${Name}")) != -1)
      s.replace(index, 7, capitalize(name()));
    else if ((index = s.find("${NAME}")) != -1)
      s.replace(index, 7, name().upper());
    else if ((index = s.find("${nAME}")) != -1)
      s.replace(index, 7, name().lower());
  }
  else 
    s = name();	// true_name
  
  if (! s.isEmpty()){
    f << s;
    
    if (is_template != 0)
      *is_template = (s.at(s.length() - 1) == '>');
  }
  else if (is_template != 0)
    *is_template = FALSE;
    
  if (with_formals) {
    Q3ValueList<UmlFormalParameter> formals = this->formals();
    
    if (! formals.isEmpty()) {
      const char * sep = "<";
      Q3ValueList<UmlFormalParameter>::ConstIterator it;
      
      for (it = formals.begin(); it != formals.end(); ++it) {
	f << sep << (*it).name();
	sep = ", ";
      }
      
      f << '>';
      
      if (is_template != 0)
	*is_template = TRUE;
    }
  }
  else if (!actuals.isEmpty()) {
    Q3ValueList<UmlActualParameter>::ConstIterator ita;
    BooL need_space = FALSE;
    bool used = FALSE;
    
    for (ita = actuals.begin(); ita != actuals.end(); ++ita) {
      if ((*ita).superClass() == this) {
	used = TRUE;
	(*ita).generate(f, need_space);
      }
    }
    
    if (used) {
      if (need_space)
	f << " >";
      else
	f << '>';
      
      if (is_template != 0)
	*is_template = TRUE;
    }
  }
}
示例#17
0
文件: UmlClass.cpp 项目: SciBoy/douml
UmlClass * UmlClass::import(File & f, UmlItem * parent, const Q3CString & knd)
{
  Q3CString s;

  if (f.read(s) != STRING)
    f.syntaxError(s, "class's name");
    
  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());

  if (ste == "CORBAConstant") {
    // not a class !
    if (!scanning) {
      if (parent->kind() == aClass)
	UmlAttribute::importIdlConstant((UmlClass *) parent, id, s, doc, prop);
      else
	importIdlConstant(parent, id, s, doc, prop);
    }
    
    if (k != ')')
      f.skipBlock();
    
    return 0;
  }

  UmlClass * cl;
  
  if (scanning) {
    if (((cl = UmlBaseClass::create(parent, s)) == 0) &&
	((cl = UmlBaseClass::create(parent, legalName(s))) == 0)) {
      UmlCom::trace("<br>cannot create class '" + s + "' in " +
		    parent->fullName());
      throw 0;
    }
    newItem(cl, id);
    
    if (!ste.isEmpty()) {
      if (ste.left(5) == "CORBA") {
	if (ste != "CORBAValue")
	  cl->set_Stereotype(ste.mid(5).lower());
      }
      else 
	cl->set_Stereotype(((ste == "Actor") || (ste == "Interface"))
			   ? ste.lower() : ste);
    }
    
    if (!doc.isEmpty())
      cl->set_Description(doc);
    
    cl->lang = None;  
  }
  else if ((cl = (UmlClass *) findItem(id, aClass)) == 0) {
    UmlCom::trace("<br>unknown class '" + s + "' in " +
		  parent->fullName());
    throw 0;
  }
  
  Q3CString art_path;
  
  for (;;) {
    switch (k) {
    case ')':
      switch (cl->lang) {
      case Cplusplus:
      case AnsiCplusplus:
      case VCplusplus:
	cl->cplusplus(prop);
	break;
      case Oracle8:
	cl->oracle8(prop);
	break;
      case Corba:
	cl->corba(prop);
	break;
      case Java:
	cl->java(prop);
	break;
      default:
	break;
      }
      
      if (!scanning) {
	cl->setProperties(prop);
	cl->unload(TRUE);
      }
      return cl;
    case ATOM:
      if (s2 == "operations")
	cl->importOperations(f);
      else if (s2 == "class_attributes")
	cl->importAttributes(f);
      else if (!scanning &&
	       ((s2 == "superclasses") ||
		(s2 == "used_nodes") ||
		(s2 == "realized_interfaces")))
	cl->importRelations(f);
      else if (s2 == "nestedClasses")
	cl->importClasses(f);
      else if (s2 == "abstract") {
	if (f.readBool())
	  cl->set_isAbstract(TRUE);
      }
      else if (s2 == "language")
	cl->lang = f.readLanguage();
      else if (s2 == "instantiation_relationship") 
	cl->importInstantiate(f);
      else if (s2 == "parameters") {
	if (knd == "Parameterized_Class")
	  cl->importFormals(f);
        else
	  cl->importActuals(f);
      }
      else if (s2 == "module") {
	if (f.read(art_path) != STRING)
	  f.syntaxError(art_path, "module's name");
      }
      else if (!scanning && (s2 == "quidu")) {
	f.read(s2);
	cl->assocArtifact(Artifact::find(s2), art_path);
      }
      else
	f.skipNextForm();
      k = f.read(s2);
      break;
    default:
      f.syntaxError(s);
    }
  }
}
示例#18
0
文件: util.cpp 项目: SciBoy/douml
Q3CString capitalize(const Q3CString & s)
{
  return (s.isEmpty())
    ? s
    : s.left(1).upper() + s.mid(1);
}
示例#19
0
bool UmlOperation::new_one(Class * container, aVisibility visibility,
			   bool finalp, bool abstractp, bool staticp,
			   Q3CString comment, Q3CString description)
{
  // 'function' was read, it is followed by :
  // ['&'] name'(' {'array' | <classname>] ['&'] '$'<varname> ['=' <value>]}* ')' '{' ... '}'
  Q3CString s = Lex::read_word();
  bool refp;
  
  if (s == "&") {
    refp = TRUE;
    s = Lex::read_word();
  }
  else
    refp = FALSE;
  
  if (s.isEmpty()) {
    Lex::premature_eof();
    return FALSE;
  }
    
  Q3CString name = s;
  
#ifdef TRACE
  QLOG_INFO() <<"OPERATION '" << name << "'\n";
#endif
  
  s = Lex::read_word();
  if (s != "(") {
    Lex::syntax_error("'(' expected rather than '" + s + "'");
    return FALSE;
  }
  
  UmlClass * cl = container->get_uml();
  UmlOperation * op;
  
#ifndef REVERSE
  if (visibility == PrivateVisibility)
    op = 0;
  else
#endif
  {
    op = UmlBaseOperation::create(cl, name);
    
    if (op == 0) {
      PhpCatWindow::trace(Q3CString("<font face=helvetica><b>cannot add operation <i>")
			   + name + "</i> in <i>" + cl->name() 
			   + "</i></b></font><br>");  
      return FALSE;
    }
    
#ifdef REVERSE
    Statistic::one_operation_more();
#endif
  }
    
  Q3CString def;
    
  if (op != 0) {
    op->set_Visibility(visibility);
    if (staticp) op->set_isClassMember(TRUE);
    if (finalp) op->set_isPhpFinal(TRUE);
  
    def = PhpSettings::operationDef();
  
    int index;
    
    if (((index = def.find("${(}")) == -1) ||
	(def.find("${)}", index + 4) == -1) ||
	((index = def.find("${name}")) == -1) ||
	(def.find("${body}") == -1)) {
      // use a definition where ${body] is not indented
      def = "  ${comment}${final}${visibility}${abstract}${static}function ${name}${(}${)}\n{\n  ${body}}\n";
      index = def.find("${name}");
    }
    
    if (refp)
      def.insert(index, "&");
    
    if ((name == cl->name()) || (name == "__construct")) {
      // constructor, remove useless ${}
      if ((index = def.find("${static}")) != -1)
	def.remove(index, 9);
      if ((index = def.find("${final}")) != -1)
	def.remove(index, 8);
      if ((index = def.find("${abstract}")) != -1)
	def.remove(index, 11);
    }
    
    if (abstractp) {
      op->set_isAbstract(TRUE);
      
      def = def.left(def.find("${)}") + 4) + ";";
    }
  }
  
  // parameters
  
  unsigned rank = 0;
  UmlParameter param;
  
  while (read_param(container, rank, param, def, op == 0)) {
    if ((op != 0) && ! op->addParameter(rank++, param)) {
      PhpCatWindow::trace(Q3CString("<font face=helvetica><b>cannot add param <i>")
			   + name + "</i> in <i>" + cl->name() 
			   + "</i></b></font><br>");  
#ifdef TRACE
      QLOG_INFO() <<"ERROR cannot add param '" << param.name << '\n';
#endif
      return FALSE;
    }
  }
  
  s = Lex::read_word();
  
  if (s.isEmpty()) {
    Lex::premature_eof();
    return FALSE;
  }
    
  // definition
  
  if (abstractp || (cl->stereotype() == "interface")) {
    if (s != ";") {
      Lex::error_near(s);
      return FALSE;
    }
#ifdef REVERSE
    if (op != 0)
      op->set_PhpBody(0);
#endif
  }
  else if (s != "{") {
    Lex::error_near(s);
    return FALSE;
  }
  else {
    Lex::mark();
    
    // goto the end of the body
    
    char c;
    int level = 1;	// '{' already read
    
    for (;;) {
      if ((c = Lex::read_word_bis()) == 0)
	return FALSE;
      else if (c == '{')
	level += 1;
      else if ((c == '}') && (--level == 0))
	break;
    }
    
#ifdef REVERSE
    if (op != 0) {
      Q3CString e = Lex::region();
      
      e.truncate(e.length() - 1);	// remove }

      // remove fist \n
      if (*((const char *) e) == '\n')
	e.remove(0, 1);
      
      // remove last spaces and tabs
      int ln = e.length();
      
      while (ln && ((e[ln - 1] == ' ') || (e[ln - 1] == '\t')))
	ln -= 1;
      e.truncate(ln);
      
      op->set_PhpBody(e);
      op->set_PhpContextualBodyIndent(FALSE);
    }
#endif
  }
  
  if ((op != 0) && (def != op->phpDecl()))
    op->set_PhpDecl(def);
  
  Lex::clear_comments();	// params & body comments
  Lex::finish_line();
  
  if ((op != 0) && !comment.isEmpty()) {
    s = (def.find("${description}") != -1) ? description : comment;
    
    UmlTypeSpec t;
    int index1;
    
    if (! (t.explicit_type = value_of(s, "@return", index1)).isEmpty()) {
      op->set_ReturnType(t);
      s.replace(index1, t.explicit_type.length(), "${type}");
    }
    
    Q3ValueList<UmlParameter> l = op->params();
    unsigned nparams = l.count();

    if (nparams != 0) {
      Q3CString varname;
      int index2;
      char xn[16];

      index1 = 0;
      rank = 0;
      
      while (!((t.explicit_type = value_of(s, "@param", index1, varname, index2))
	       .isEmpty())) {
	if (varname.isEmpty() || (varname[0] != '$')) {
	  if (rank < nparams) {
	    UmlParameter & p = l[rank];
	    
	    p.type = t;
	    op->replaceParameter(rank, p);
	  }
	}
	else {
	  varname = varname.mid(1);
	  
	  Q3ValueList<UmlParameter>::Iterator it;
	  
	  for (it = l.begin(), rank = 0; it != l.end(); ++it, rank += 1) {
	    if ((*it).name == varname) {
	      (*it).type = t;
	      op->replaceParameter(rank, *it);
	      sprintf(xn, "${p%d}", rank);
	      s.replace(index2, varname.length() + 1, xn);
	      break;
	    }
	  }
	}
	sprintf(xn, "${t%d}", rank++);
	s.replace(index1, t.explicit_type.length(), xn);
      }
    }
    op->set_Description(s);
  }
  
  return TRUE;
}