|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __XMLUTILS_H__ |
|
20 #define __XMLUTILS_H__ |
|
21 |
|
22 #include "CmdGlobals.h" |
|
23 #ifdef __WIN__ |
|
24 #pragma warning(disable:4786) |
|
25 #endif |
|
26 |
|
27 #include <string> |
|
28 #include <xercesc/dom/DOM.hpp> |
|
29 |
|
30 #include "HANodeIterator.h" |
|
31 #include "NodeIndex.h" |
|
32 using namespace std; |
|
33 |
|
34 XERCES_CPP_NAMESPACE_USE |
|
35 |
|
36 |
|
37 #include <iostream> |
|
38 |
|
39 //#if _DEBUG |
|
40 |
|
41 |
|
42 #if 0 |
|
43 #define DEBUG_STUFF(s1) s1 |
|
44 #define DEBUG_PRINT(s1) {cout << s1 << flush;} |
|
45 #define DEBUG_PRINT_XMLCh(s1) {printXMLCh(s1);} |
|
46 |
|
47 #else |
|
48 |
|
49 #define DEBUG_STUFF(s1) |
|
50 #define DEBUG_PRINT(s1) |
|
51 #define DEBUG_PRINT_XMLCh(s1) |
|
52 |
|
53 #endif |
|
54 |
|
55 void printXMLCh(const XMLCh* s1); |
|
56 |
|
57 |
|
58 |
|
59 // The attribute types of node attributes. Is used to |
|
60 // choose between compare methods |
|
61 enum TAttributeType |
|
62 { |
|
63 ESimpleAttribute, |
|
64 EIdAttribute, |
|
65 EBooleanAttribute, |
|
66 EOptionalSimpleAttribute, |
|
67 EOptionalIdAttribute, |
|
68 ETypeAttribute, |
|
69 EOptionalTypeAttribute |
|
70 }; |
|
71 |
|
72 |
|
73 // The struct that holds the attribute name and type |
|
74 struct EntityAttributeElement |
|
75 { |
|
76 const XMLCHAR* iAttributeName; |
|
77 TAttributeType iAttributeType; |
|
78 }; |
|
79 |
|
80 // The struct that holds the entity name and list of |
|
81 // attributes that needs to be compared |
|
82 struct EntityComparisonElement |
|
83 { |
|
84 const XMLCHAR* iEntityName; |
|
85 const EntityAttributeElement* iAttributeList; |
|
86 int iAttributeCount; |
|
87 }; |
|
88 |
|
89 /** |
|
90 * Convert XMLCh to std::string |
|
91 * @param s1 XML string to convert |
|
92 * @return converted string |
|
93 */ |
|
94 string toString(const XMLCh* s1); |
|
95 |
|
96 /** |
|
97 * Comparison between different strings |
|
98 * @param s1 XML string to compare |
|
99 * @param s2 XML string to compare |
|
100 * @return true if the strings are equal |
|
101 */ |
|
102 bool Equals(const XMLCh* s1, const XMLCh* s2); |
|
103 |
|
104 /** |
|
105 * Comparison between different strings |
|
106 * @param s1 C-string to compare |
|
107 * @param s2 C-string to compare |
|
108 * @return true if the strings are equal |
|
109 */ |
|
110 bool Equals(const char* s1, const char* s2); |
|
111 |
|
112 /** |
|
113 * Comparison between different strings |
|
114 * @param s1 XML string to compare |
|
115 * @param s2 C-string to compare |
|
116 * @return true if the strings are equal |
|
117 */ |
|
118 bool Equals(const XMLCh* s1, const char* s2); |
|
119 |
|
120 /** |
|
121 * Comparison between different strings |
|
122 * @param s1 C-string to compare |
|
123 * @param s2 XML string to compare |
|
124 * @return true if the strings are equal |
|
125 */ |
|
126 bool Equals(const char* s2, const XMLCh* s1); |
|
127 |
|
128 /** |
|
129 * Sets the attribute to the node |
|
130 * @param node DOM node |
|
131 * @param attribute to set |
|
132 * @param value value to set |
|
133 */ |
|
134 void SetAttribute(DOMNode * node, const XMLCh* attribute, const XMLCh* value); |
|
135 |
|
136 /** |
|
137 * Sets the attribute to the node |
|
138 * @param node DOM node |
|
139 * @param attribute to set |
|
140 * @param value value to set |
|
141 */ |
|
142 void SetAttribute(DOMNode * node, const char* attribute, const char* value); |
|
143 |
|
144 /** |
|
145 * Gets the attribute from the node |
|
146 * @param node DOM node |
|
147 * @param attribute to get |
|
148 * @return attribute value |
|
149 */ |
|
150 const XMLCh* GetAttribute(DOMNode * node, const XMLCh* attribute); |
|
151 |
|
152 /** |
|
153 * Gets the attribute from the node |
|
154 * @param node DOM node |
|
155 * @param attribute to get |
|
156 * @return attribute value |
|
157 */ |
|
158 const XMLCh* GetAttribute(DOMNode * node, const char * attribute); |
|
159 |
|
160 /** |
|
161 * Checks for boolean attribute (values 0 or 1). Return false if not specified |
|
162 * @param node DOM node |
|
163 * @param attribute to check |
|
164 * @return false if not specified, true if attribute is boolean attribute |
|
165 */ |
|
166 bool CheckForBooleanAttribute(DOMNode * node, const XMLCh* attribute); |
|
167 |
|
168 /** |
|
169 * Checks for boolean attribute (values 0 or 1). Return false if not specified |
|
170 * @param node DOM node |
|
171 * @param attribute to check |
|
172 * @return false if not specified, true if attribute is boolean attribute |
|
173 */ |
|
174 bool CheckForBooleanAttribute(DOMNode * node, const char* attribute); |
|
175 |
|
176 /** |
|
177 * Gets the typename of the node |
|
178 * @param node DOM node |
|
179 * @return type name |
|
180 */ |
|
181 string GetTypeName(HANodeIterator node); |
|
182 |
|
183 /** |
|
184 * Determines if the node can be considered function |
|
185 * @param node DOM node |
|
186 * @return true if node is function |
|
187 */ |
|
188 bool IsFunction(HANodeIterator node); |
|
189 |
|
190 /** |
|
191 * Generates function signature. Notice that function signature does not |
|
192 * include return value or default values |
|
193 * @param node DOM node |
|
194 * @return signature |
|
195 */ |
|
196 string GenerateFunctionSignature(HANodeIterator node); |
|
197 |
|
198 /** |
|
199 * Generates fully qualified name |
|
200 * @param node DOM node |
|
201 * @return fully qualified name |
|
202 */ |
|
203 string GenerateFullyQualifiedName(HANodeIterator node); |
|
204 |
|
205 /** |
|
206 * Returns the comparison element for the element with name nodeName |
|
207 * @param nodeName name of the node |
|
208 * @return comparison element |
|
209 */ |
|
210 const EntityComparisonElement* FindComparison(const XMLCh* nodeName); |
|
211 |
|
212 /** |
|
213 * Comparers id lists |
|
214 * @param baseline baseline node |
|
215 * @param current current node |
|
216 * @param idAttributeName |
|
217 * @return true if compared lists are equal |
|
218 */ |
|
219 bool CompareIdLists(HANodeIterator baseline, HANodeIterator current,const XMLCh* idAttributeName); |
|
220 |
|
221 /** |
|
222 * Compares nodes |
|
223 * @param baseline baseline node |
|
224 * @param current current node |
|
225 * @return true if nodes are equal |
|
226 */ |
|
227 bool CompareNodes(HANodeIterator baseline, HANodeIterator current); |
|
228 |
|
229 /** |
|
230 * Compares names |
|
231 * @param baseline baseline node |
|
232 * @param current current node |
|
233 * @return true if names are equal |
|
234 */ |
|
235 bool CompareNames(HANodeIterator baseline, HANodeIterator current); |
|
236 |
|
237 /** |
|
238 * Is the node proper (to be analysed) |
|
239 * @param node node to check |
|
240 * @return true if the node is proper to analyse |
|
241 */ |
|
242 bool IsProperNode(HANodeIterator node); |
|
243 |
|
244 /** |
|
245 * Is the node named (in node index) |
|
246 * @param node node to check |
|
247 * @return true if the node is named |
|
248 */ |
|
249 bool IsNamedNode(HANodeIterator node); |
|
250 |
|
251 /** |
|
252 * Compares two file names |
|
253 * @param first first file to compare |
|
254 * @param second second file to compare |
|
255 * @return true if strings match |
|
256 */ |
|
257 bool CompareFileNames(string first,string second); |
|
258 |
|
259 |
|
260 /** |
|
261 * Compares to attributes |
|
262 * @param baseline first file to compare |
|
263 * @param current second file to compare |
|
264 * @param attributeName name of the attribute |
|
265 * @param attributeType node attribute type |
|
266 * @return true if strings match |
|
267 */ |
|
268 bool CompareAttributes(HANodeIterator baseline, HANodeIterator current, const XMLCh* attributeName, TAttributeType attributeType); |
|
269 |
|
270 /** |
|
271 * Compares to attributes |
|
272 * @param baseline first file to compare |
|
273 * @param current second file to compare |
|
274 * @param attributeName name of the attribute |
|
275 * @param attributeType node attribute type |
|
276 * @return true if strings match |
|
277 */ |
|
278 bool CompareAttributes(HANodeIterator baseline, HANodeIterator current, const char* attributeName, TAttributeType attributeType); |
|
279 |
|
280 /** |
|
281 * Return access level of the node |
|
282 * @param node node to analyse |
|
283 * @return access level of node |
|
284 */ |
|
285 TAccess CalcAccessModifier(HANodeIterator node); |
|
286 |
|
287 /** |
|
288 * Return derived access level of the node |
|
289 * @param member to check |
|
290 * @param inheritance level of member |
|
291 * @return derived access |
|
292 */ |
|
293 //TAccess CalcDerivedAccessModifier(TAccess member, TAccess inheritance); |
|
294 |
|
295 /** |
|
296 * Check if the access modifier is strightened |
|
297 * @param baseline baseline node to check |
|
298 * @param current current node to check |
|
299 * @return true if strightened |
|
300 */ |
|
301 bool CheckAccessModifier(HANodeIterator baseline,HANodeIterator current); |
|
302 |
|
303 /** |
|
304 * Check if the access modifier is strightened |
|
305 * @param baseline baseline access to check |
|
306 * @param current current access to check |
|
307 * @return true if strightened |
|
308 */ |
|
309 bool CheckAccessModifier(TAccess baseline,TAccess current); |
|
310 |
|
311 /** |
|
312 * Check if the node is anonymous |
|
313 * Return derived access level of the node |
|
314 * @param node node to check |
|
315 * @return true if anaonymous |
|
316 */ |
|
317 bool IsAnonymous(HANodeIterator node); |
|
318 |
|
319 /** |
|
320 * Check if the type is anonymous |
|
321 * @param node node to check |
|
322 * @return true if type anonymous |
|
323 */ |
|
324 bool IsAnonymousType(HANodeIterator node); |
|
325 |
|
326 /** |
|
327 * Is the node type anonymous, returns the anonymous type |
|
328 * @param node node to check |
|
329 * @param anonymousnode reference to type returned |
|
330 * @return true if anonymous node found |
|
331 */ |
|
332 |
|
333 bool FindAnonymousType(HANodeIterator node, HANodeIterator& anonymousnode); |
|
334 |
|
335 /** |
|
336 * Check if the class is derivable |
|
337 * @param node node to check |
|
338 * @return true if the class is derivable |
|
339 */ |
|
340 bool ClassIsDerivable(HANodeIterator node); |
|
341 |
|
342 /** |
|
343 * Check if the class is instantiable |
|
344 * @param node node to check |
|
345 * @return true if the class is instantiable |
|
346 */ |
|
347 bool ClassIsInstantiable(HANodeIterator node); |
|
348 |
|
349 /** |
|
350 * If returns true the primarybase includes primary base. If the subclass' offset |
|
351 * is zero, it is the primary base. |
|
352 * @param classnode node to check |
|
353 * @param primarybase returned primary base |
|
354 * @return true if the class includes primary base |
|
355 */ |
|
356 bool ClassPrimaryBase(const HANodeIterator& classnode,HANodeIterator& primarybase ); |
|
357 |
|
358 /** |
|
359 * Checks if the member memberNode is visible |
|
360 * @param memberNode node to check |
|
361 * @return true if the class is visible |
|
362 */ |
|
363 bool CheckAccessibility(HANodeIterator memberNode); |
|
364 |
|
365 /** |
|
366 * Checks if the member memberNode is visible and if the visibility is |
|
367 * through inline function |
|
368 * @param memberNode node to check |
|
369 * @param exposedByInline true if exposed by inline function |
|
370 * @return true if the class is visible |
|
371 */ |
|
372 bool CheckAccessibility(HANodeIterator memberNode, bool & exposedByInline); |
|
373 |
|
374 /** |
|
375 * Checks to see if a member with access "access" is visible from |
|
376 * class classNode |
|
377 * through inline function |
|
378 * @param classNode node to check |
|
379 * @param exposedByInline true if exposed by inline function |
|
380 * @param access access level of the node |
|
381 * @return true if the class is visible |
|
382 */ |
|
383 bool CheckAccessibility(HANodeIterator classNode, bool & exposedByInline, TAccess access); |
|
384 |
|
385 /** |
|
386 * Finds the parent node |
|
387 * through inline function |
|
388 * @param memberNode node to check |
|
389 * @param parentNode parent node context found |
|
390 * @return true if the parent node found |
|
391 */ |
|
392 bool FindParentContext(HANodeIterator memberNode, HANodeIterator& parentNode); |
|
393 |
|
394 /** |
|
395 * Gets the type size |
|
396 * through inline function |
|
397 * @param node node from which to calculate size |
|
398 * @return pointer to node size |
|
399 */ |
|
400 const XMLCh* GetSize(HANodeIterator node); |
|
401 |
|
402 |
|
403 /** |
|
404 * Orders the members of a class in different vectors |
|
405 * @param node node to search |
|
406 * @param virtualMethods vector of virtual methods |
|
407 * @param inlineMethods vector of inline methods |
|
408 * @param exportedMethods vector of exported methods |
|
409 * @param exportedVirtualMethods vector of exportedVirtualMethods |
|
410 * @param methods vector of methods |
|
411 * @param fields vector of fields pointers |
|
412 * @param others vector of others pointers |
|
413 */ |
|
414 void ClassOrderMembers(HANodeIterator node, |
|
415 vector<DOMNode*>& virtualMethods, |
|
416 vector<DOMNode*>& inlineMethods, |
|
417 vector<DOMNode*>& exportedMethods, |
|
418 vector<DOMNode*>& exportedVirtualMethods, |
|
419 vector<DOMNode*>& methods, |
|
420 vector<DOMNode*>& fields, |
|
421 vector<DOMNode*>& others); |
|
422 |
|
423 /** |
|
424 * Orders the members of a class in different vectors |
|
425 * @param node node to search |
|
426 * @param virtualMethods vector of virtual methods |
|
427 * @param inlineMethods vector of inline methods |
|
428 * @param exportedMethods vector of exported methods |
|
429 * @param methods vector of methods |
|
430 * @param fields vector of fields pointers |
|
431 * @param others vector of others pointers |
|
432 */ |
|
433 void ClassOrderMembers(HANodeIterator node, |
|
434 vector<DOMNode*>& virtualMethods, |
|
435 vector<DOMNode*>& inlineMethods, |
|
436 vector<DOMNode*>& exportedMethods, |
|
437 vector<DOMNode*>& methods, |
|
438 vector<DOMNode*>& fields, |
|
439 vector<DOMNode*>& others); |
|
440 |
|
441 /** |
|
442 * Generates virtual table |
|
443 * @param classnode classnode to generate virtual table |
|
444 * @return reference to vtable_t |
|
445 */ |
|
446 const NodeIndex::vtable_t& ClassGenerateVirtualTable(HANodeIterator& classnode); |
|
447 |
|
448 /** |
|
449 * Generates data member table |
|
450 * @param classnode node to generate data member table |
|
451 * @return refrence to dtable_t |
|
452 */ |
|
453 const NodeIndex::dtable_t& ClassGenerateDataMemberTable(const HANodeIterator& classnode); |
|
454 |
|
455 /** |
|
456 * Checks if the s1 starts with s2 |
|
457 * @param s1 node to search |
|
458 * @param s2 search string |
|
459 * @return true if s1 starts with s2 |
|
460 */ |
|
461 bool StartsWith(const XMLCh* s1, const char* s2); |
|
462 |
|
463 /** |
|
464 * Checks if the s1 starts with s2 |
|
465 * @param s1 node to search |
|
466 * @param s2 search string |
|
467 * @return true if s1 starts with s2 |
|
468 */ |
|
469 bool StartsWith(const XMLCh* s1, const XMLCh* s2); |
|
470 |
|
471 /** |
|
472 * Finds the value of attribute from the node type |
|
473 * @param node node to search |
|
474 * @param attribute attribute to search |
|
475 * @return value of the attribute if found |
|
476 */ |
|
477 const XMLCh* FindAttributeValueForType(const HANodeIterator& node, const char* attribute); |
|
478 |
|
479 /** |
|
480 * Finds the value of attribute from the node type |
|
481 * @param node node to search |
|
482 * @param attribute attribute to search |
|
483 * @return value of the attribute if found |
|
484 */ |
|
485 const XMLCh* FindAttributeValueForType(const HANodeIterator& node, const XMLCh* attribute); |
|
486 |
|
487 /** |
|
488 * Returns the base size of the class |
|
489 * @param classnode node to search |
|
490 * @param fields fields to calculate |
|
491 * @return value of class base size |
|
492 */ |
|
493 //int ClassBaseSize(const HANodeIterator& classnode, const vector<DOMNode*>& fields); |
|
494 |
|
495 /** |
|
496 * Returns the base size of the class |
|
497 * @param classnode node to search |
|
498 * @param fields fields to calculate |
|
499 * @return value of class base size |
|
500 */ |
|
501 int ClassBaseSize(const HANodeIterator& classnode, const NodeIndex::dtable_t& fields); |
|
502 |
|
503 /** |
|
504 * Returns all nodes representing XML-elements. |
|
505 */ |
|
506 void GetElementNodes(HANodeIterator node, DOMNodeList* domNodes, std::vector<DOMNode*>& elemNodes); |
|
507 |
|
508 /** |
|
509 * Reads and parses XML document into DOM. |
|
510 * @param xmlFilename Filename of the XML-document |
|
511 * @param domParser Pointer to the DOM parser is returned here. |
|
512 * @param domDocument Pointer to the DOM document is returned here. |
|
513 * @param domRootNode Pointer to the DOM root node is returned here. |
|
514 */ |
|
515 int ParseXMLFile( const string& xmlFilename, |
|
516 XERCES_CPP_NAMESPACE_QUALIFIER DOMBuilder*& domParser, |
|
517 XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument*& domDocument, |
|
518 XERCES_CPP_NAMESPACE_QUALIFIER DOMNode*& domRootNode ); |
|
519 |
|
520 /** |
|
521 * Converts the given string in lower case. |
|
522 * @param name Reference to the name string, which is to be converted. |
|
523 */ |
|
524 string& toLower(string& name); |
|
525 |
|
526 #endif |