Root/
Source at commit 1322 created 12 years 8 months ago. By meklort, Add doxygen to utils folder | |
---|---|
1 | #include "graphhandler.h"␊ |
2 | ␊ |
3 | class EdgeRelationMapper␊ |
4 | {␊ |
5 | public:␊ |
6 | EdgeRelationMapper()␊ |
7 | {␊ |
8 | m_map.insert("public-inheritance", IChildNode::PublicInheritance);␊ |
9 | m_map.insert("protected-inheritance", IChildNode::ProtectedInheritance);␊ |
10 | m_map.insert("private-inheritance", IChildNode::PrivateInheritance);␊ |
11 | m_map.insert("usage", IChildNode::Usage);␊ |
12 | m_map.insert("template-instance", IChildNode::TemplateInstance);␊ |
13 | }␊ |
14 | IChildNode::NodeRelation stringToNodeRelation(const QString &nrStr)␊ |
15 | {␊ |
16 | return m_map[nrStr];␊ |
17 | }␊ |
18 | private:␊ |
19 | QMap<QString,IChildNode::NodeRelation> m_map;␊ |
20 | };␊ |
21 | ␊ |
22 | static EdgeRelationMapper *s_edgeRelationMapper;␊ |
23 | ␊ |
24 | void graphhandler_init()␊ |
25 | {␊ |
26 | s_edgeRelationMapper = new EdgeRelationMapper;␊ |
27 | }␊ |
28 | ␊ |
29 | void graphhandler_exit()␊ |
30 | {␊ |
31 | delete s_edgeRelationMapper;␊ |
32 | }␊ |
33 | ␊ |
34 | //------------------------------------------------------------------------␊ |
35 | ␊ |
36 | GraphHandler::GraphHandler(IBaseHandler *parent,const char *endTag)␊ |
37 | : m_parent(parent)␊ |
38 | {␊ |
39 | addEndHandler(endTag,this,&GraphHandler::endGraph);␊ |
40 | addStartHandler("node",this,&GraphHandler::startNode);␊ |
41 | m_nodes.setAutoDelete(TRUE);␊ |
42 | m_nodeDict = new QDict<NodeHandler>(1009);␊ |
43 | }␊ |
44 | ␊ |
45 | GraphHandler::~GraphHandler()␊ |
46 | {␊ |
47 | delete m_nodeDict;␊ |
48 | }␊ |
49 | ␊ |
50 | void GraphHandler::startGraph(const QXmlAttributes &)␊ |
51 | {␊ |
52 | debug(2,"startGraph\n");␊ |
53 | m_parent->setDelegate(this);␊ |
54 | }␊ |
55 | ␊ |
56 | void GraphHandler::endGraph()␊ |
57 | {␊ |
58 | debug(2,"endGraph\n");␊ |
59 | m_parent->setDelegate(0);␊ |
60 | }␊ |
61 | ␊ |
62 | void GraphHandler::startNode(const QXmlAttributes &attrib)␊ |
63 | {␊ |
64 | NodeHandler *n = new NodeHandler(this);␊ |
65 | n->startNode(attrib);␊ |
66 | m_nodes.append(n);␊ |
67 | m_nodeDict->insert(attrib.value("id"),n);␊ |
68 | }␊ |
69 | ␊ |
70 | INodeIterator *GraphHandler::nodes() const␊ |
71 | {␊ |
72 | return new NodeIterator(*this);␊ |
73 | }␊ |
74 | ␊ |
75 | NodeHandler *GraphHandler::getNodeById(const QString &id) const␊ |
76 | {␊ |
77 | return m_nodeDict->find(id);␊ |
78 | }␊ |
79 | ␊ |
80 | //------------------------------------------------------------------------␊ |
81 | ␊ |
82 | NodeHandler::NodeHandler(GraphHandler *gh)␊ |
83 | : m_parent(gh), m_graph(gh)␊ |
84 | {␊ |
85 | addEndHandler("node",this,&NodeHandler::endNode);␊ |
86 | addStartHandler("link",this,&NodeHandler::startLink);␊ |
87 | addEndHandler("link",this,&NodeHandler::endLink);␊ |
88 | addStartHandler("label",this,&NodeHandler::startLabel);␊ |
89 | addEndHandler("label",this,&NodeHandler::endLabel);␊ |
90 | addStartHandler("childnode",this,&NodeHandler::startChildNode);␊ |
91 | m_children.setAutoDelete(TRUE);␊ |
92 | }␊ |
93 | ␊ |
94 | NodeHandler::~NodeHandler()␊ |
95 | {␊ |
96 | }␊ |
97 | ␊ |
98 | void NodeHandler::startNode(const QXmlAttributes &attrib)␊ |
99 | {␊ |
100 | debug(2,"startNode\n");␊ |
101 | m_parent->setDelegate(this);␊ |
102 | m_id = attrib.value("id");␊ |
103 | }␊ |
104 | ␊ |
105 | void NodeHandler::endNode()␊ |
106 | {␊ |
107 | debug(2,"endNode\n");␊ |
108 | m_parent->setDelegate(0);␊ |
109 | }␊ |
110 | ␊ |
111 | void NodeHandler::startLink(const QXmlAttributes &attrib)␊ |
112 | {␊ |
113 | m_link = attrib.value("refid");␊ |
114 | }␊ |
115 | ␊ |
116 | void NodeHandler::endLink()␊ |
117 | {␊ |
118 | }␊ |
119 | ␊ |
120 | void NodeHandler::startLabel(const QXmlAttributes &/*attrib*/)␊ |
121 | {␊ |
122 | m_curString="";␊ |
123 | }␊ |
124 | ␊ |
125 | void NodeHandler::endLabel()␊ |
126 | {␊ |
127 | m_label = m_curString;␊ |
128 | }␊ |
129 | ␊ |
130 | void NodeHandler::startChildNode(const QXmlAttributes &attrib)␊ |
131 | {␊ |
132 | ChildNodeHandler *cnh = new ChildNodeHandler(this,m_graph);␊ |
133 | cnh->startChildNode(attrib);␊ |
134 | m_children.append(cnh);␊ |
135 | }␊ |
136 | ␊ |
137 | IChildNodeIterator *NodeHandler::children() const ␊ |
138 | { ␊ |
139 | return new ChildNodeIterator(*this); ␊ |
140 | }␊ |
141 | ␊ |
142 | //------------------------------------------------------------------------␊ |
143 | ␊ |
144 | ChildNodeHandler::ChildNodeHandler(IBaseHandler *parent,GraphHandler *gh)␊ |
145 | : m_parent(parent), m_graph(gh)␊ |
146 | {␊ |
147 | addEndHandler("childnode",this,&ChildNodeHandler::endChildNode);␊ |
148 | addStartHandler("edgelabel",this,&ChildNodeHandler::startEdgeLabel);␊ |
149 | m_edgeLabels.setAutoDelete(TRUE);␊ |
150 | }␊ |
151 | ␊ |
152 | ChildNodeHandler::~ChildNodeHandler()␊ |
153 | {␊ |
154 | }␊ |
155 | ␊ |
156 | void ChildNodeHandler::startChildNode(const QXmlAttributes &attrib)␊ |
157 | {␊ |
158 | debug(2,"startChildNode\n");␊ |
159 | m_id = attrib.value("refid");␊ |
160 | m_relationString = attrib.value("relation");␊ |
161 | m_relation = s_edgeRelationMapper->stringToNodeRelation(m_relationString);␊ |
162 | m_parent->setDelegate(this);␊ |
163 | }␊ |
164 | ␊ |
165 | void ChildNodeHandler::endChildNode()␊ |
166 | {␊ |
167 | debug(2,"endChildNode\n");␊ |
168 | m_parent->setDelegate(0);␊ |
169 | }␊ |
170 | ␊ |
171 | ␊ |
172 | void ChildNodeHandler::startEdgeLabel(const QXmlAttributes &attrib)␊ |
173 | {␊ |
174 | EdgeLabelHandler *elh = new EdgeLabelHandler(this);␊ |
175 | elh->startEdgeLabel(attrib);␊ |
176 | m_edgeLabels.append(elh);␊ |
177 | }␊ |
178 | ␊ |
179 | IEdgeLabelIterator *ChildNodeHandler::edgeLabels() const␊ |
180 | {␊ |
181 | return new EdgeLabelIterator(*this);␊ |
182 | }␊ |
183 | ␊ |
184 | INode *ChildNodeHandler::node() const␊ |
185 | {␊ |
186 | return m_graph->getNodeById(m_id);␊ |
187 | }␊ |
188 | ␊ |
189 | //-----------------------------------------------------------------------␊ |
190 | ␊ |
191 | EdgeLabelHandler::EdgeLabelHandler(IBaseHandler *parent)␊ |
192 | : m_parent(parent)␊ |
193 | {␊ |
194 | addEndHandler("edgelabel",this,&EdgeLabelHandler::endEdgeLabel);␊ |
195 | }␊ |
196 | ␊ |
197 | EdgeLabelHandler::~EdgeLabelHandler()␊ |
198 | {␊ |
199 | }␊ |
200 | ␊ |
201 | void EdgeLabelHandler::startEdgeLabel(const QXmlAttributes &)␊ |
202 | {␊ |
203 | m_parent->setDelegate(this);␊ |
204 | m_curString="";␊ |
205 | }␊ |
206 | ␊ |
207 | void EdgeLabelHandler::endEdgeLabel()␊ |
208 | {␊ |
209 | m_label=m_curString;␊ |
210 | m_parent->setDelegate(0);␊ |
211 | }␊ |
212 | ␊ |
213 | ␊ |
214 | ␊ |
215 | ␊ |
216 | ␊ |
217 |