#include "FileOut.h" #include "UmlItem.h" #include #include FileOut::FileOut(QFile * fp, bool lf, bool utf8) : QTextStream(fp), _lf(lf), _indent(0){ if (utf8) setEncoding(QTextStream::UnicodeUTF8); } void FileOut::indent() { QTextStream & ts = *this; for (int n = _indent; n > 0; n -= 1) ts << '\t'; } void FileOut::id(const UmlItem * x) { ((QTextStream &) *this) << " xmi:id=\"BOUML_" << ((void *) x) << '"'; } void FileOut::id_prefix(const UmlItem * x, const char * pfix) { ((QTextStream &) *this) << " xmi:id=\"" << pfix << "BOUML_" << ((void *) x) << '"'; } void FileOut::idref(const UmlItem * x) { ((QTextStream &) *this) << " xmi:idref=\"BOUML_" << ((void *) x) << '"'; } void FileOut::idref(QCString s, const UmlItem * x) { QString keys; { QTextStream keyst(&keys, IO_WriteOnly); keyst << ((void *) x) << "_" << s; } QMap::ConstIterator it = _modifiedtypes.find((const char *) keys); if (it == _modifiedtypes.end()) it = _modifiedtypes.insert((const char *) keys, _modifiedtypes.count()); ((QTextStream &) *this) << " xmi:idref=\"BOUML_basedontype_" << it.data() << '"'; } void FileOut::idref_prefix(const UmlItem * x, const char * pfix) { ((QTextStream &) *this) << " xmi:idref=\"" << pfix << "BOUML_" << ((void *) x) << '"'; } void FileOut::idref_datatype(const QCString & t) { if (t.isEmpty()) return; QMap::ConstIterator it = _datatypes.find(t); if (it == _datatypes.end()) it = _datatypes.insert(t, _datatypes.count()); ((QTextStream &) *this) << " xmi:idref=\"BOUML_datatype_" << it.data() << '"'; } void FileOut::ref(const UmlItem * x, const char * pfix1, const char * pfix2) { ((QTextStream &) *this) << ' ' << pfix1 << "=\"" << pfix2 << "BOUML_" << ((void *) x) << '"'; } void FileOut::define_datatypes(bool uml_20, bool primitive_type, bool gen_extension) { const char * pfix = (primitive_type) ? ((uml_20) ? "::ConstIterator it; for (it = _datatypes.begin(); it != _datatypes.end(); ++it) { indent(); (*this) << pfix << " xmi:id=\"BOUML_datatype_" << it.data() << "\" name = \""; quote(it.key()); (*this) << "\"/>\n"; } const char * postfix = (uml_20) ? "\n" : "\n"; for (it = _modifiedtypes.begin(); it != _modifiedtypes.end(); ++it) { QCString k = it.key(); int index = k.find('_'); indent(); (*this) << pfix << " xmi:id=\"BOUML_basedontype_" << it.data() << "\" name = \""; quote(k.mid(index + 1)); (*this) << '"'; if (gen_extension) { (*this) << ">\n"; indent(); (*this) << "\t\n"; indent(); (*this) << "\t\t\n"; indent(); (*this) << "\t\n"; indent(); (*this) << postfix; } else (*this) << "/>\n"; } } void FileOut::quote(const char * s) { for (;;) { switch (*s) { case 0: return; case '<': (*this) << "<"; break; case '>': (*this) << ">"; break; case '"': (*this) << """; break; case '&': (*this) << "&"; break; case '\n': if (_lf) (*this) << *s; else (*this) << " "; break; case '\r': if (_lf) (*this) << *s; else (*this) << " "; break; default: (*this) << *s; break; } s += 1; } }