File: FileOut.cpp

package info (click to toggle)
bouml 4.21-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 73,336 kB
  • ctags: 55,459
  • sloc: cpp: 290,644; makefile: 228; sh: 13
file content (124 lines) | stat: -rw-r--r-- 3,225 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

#include "FileOut.h"
#include "UmlItem.h"

#include <qtextstream.h>
#include <qfile.h>
FileOut::FileOut(QFile * fp) : QTextStream(fp), _indent(0){
}

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::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<QCString, int>::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::ref(const UmlItem * x) {
  ((QTextStream &) *this) << "BOUML_" << ((void *) x); 
}

void FileOut::idref_datatype(const QCString & t) {
  QMap<QCString, int>::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::define_datatypes(int taggedvalue_mode) {
  QMap<QCString, int>::ConstIterator it;
  
  for (it = _datatypes.begin();
       it != _datatypes.end();
       ++it) {
    indent();
    (*this) << "<UML:DataType xmi.id=\"BOUML_datatype_"
            << it.data() << "\" name = \"";
    quote(it.key());
    (*this) << "\" visibility=\"private\" isRoot=\"false\" isLeaf=\"false\" isAbstract=\"false\"/>\n";
  }
  
  for (it = _modifiedtypes.begin();
       it != _modifiedtypes.end();
       ++it) {
    QCString k = it.key();
    int index = k.find('_');
    
    indent();
    (*this) << "<UML:DataType xmi.id=\"BOUML_basedontype_"
            << it.data() << "\" name = \"";
    quote(k.mid(index + 1));
    (*this) << "\" visibility=\"private\" isRoot=\"false\" isLeaf=\"false\" isAbstract=\"false\">\n";
    switch (taggedvalue_mode) {
    case 1:
      indent();
      (*this) << "\t<UML:ModelElement.taggedValue>\n";
      indent();
      (*this) << "\t\t<UML:TaggedValue tag=\"basedOn\" value=\"BOUML_"
	<< k.left(index) << "\"/>\n";
      indent();
      (*this) << "\t</UML:ModelElement.taggedValue>\n";
      break;
    case 2:
      indent();
      (*this) << "\t<UML:ModelElement.taggedValue>\n";
      indent();
      (*this) << "\t\t<UML:TaggedValue.tag>basedOn</UML:TaggedValue.tag>\n";
      indent();
      (*this) << "\t\t<UML:TaggedValue.value>BOUML_" << k.left(index) << "</UML:TaggedValue.value>\n";
      indent();
      (*this) << "\t</UML:ModelElement.taggedValue>\n";
      break;
    }
    indent();
    (*this) << "</UML:DataType>\n";
  }
}

void FileOut::quote(const char * s) {
 for (;;) {
   switch (*s) {
   case 0: return;
   case '<': (*this) << "&lt;"; break;
   case '>': (*this) << "&gt;"; break;
   case '"': (*this) << "&quot;"; break;
   case '&': (*this) << "&amp;"; break;
   default: (*this) << *s;
   }
   s += 1;
 }
}