b311480e |
1 | // Created on: 2001-06-27 |
2 | // Created by: Alexander GRIGORIEV |
973c2be1 |
3 | // Copyright (c) 2001-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #include <LDOM_BasicNode.hxx> |
17 | #include <LDOM_BasicElement.hxx> |
18 | #include <LDOM_BasicAttribute.hxx> |
19 | #include <LDOM_BasicText.hxx> |
20 | |
21 | //======================================================================= |
22 | //function : operator = |
23 | //purpose : Assignment |
24 | //======================================================================= |
25 | |
26 | LDOM_BasicNode& LDOM_BasicNode::operator = (const LDOM_BasicNode& anOther) |
27 | { |
28 | myNodeType = anOther.getNodeType(); |
29 | mySibling = anOther.GetSibling(); |
30 | return * this; |
31 | } |
32 | |
33 | //======================================================================= |
34 | //function : GetSibling |
35 | //purpose : also detaches NULL siblings |
36 | //======================================================================= |
37 | |
38 | const LDOM_BasicNode * LDOM_BasicNode::GetSibling () const |
39 | { |
40 | while (mySibling) |
41 | if (mySibling -> isNull()) |
42 | (const LDOM_BasicNode *&) mySibling = mySibling -> mySibling; |
43 | else break; |
44 | return mySibling; |
45 | } |
46 | |
0797d9d3 |
47 | #ifdef OCCT_DEBUG |
57c28b61 |
48 | #ifndef _MSC_VER |
7fd59977 |
49 | //======================================================================= |
50 | // Debug Function for DBX: use "print -p <Variable> or pp <Variable>" |
51 | //======================================================================= |
52 | #include <LDOM_OSStream.hxx> |
53 | #define FLITERAL 0x10 |
54 | #define MAX_SIBLINGS 8 |
55 | char * db_pretty_print (const LDOM_BasicNode * aBNode, int fl, char *) |
56 | { |
57 | LDOM_OSStream out (128); |
58 | switch (aBNode -> getNodeType()) { |
59 | case LDOM_Node::ELEMENT_NODE: |
60 | { |
61 | const LDOM_BasicElement& aBElem = * (const LDOM_BasicElement *) aBNode; |
62 | if ((fl & FLITERAL) == 0) out << "LDOM_BasicElement: "; |
63 | out << '<' << aBElem.GetTagName(); |
64 | aBNode = aBElem.GetFirstChild(); |
65 | while (aBNode) { |
66 | if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) |
67 | out << ' ' << |
68 | db_pretty_print ((const LDOM_BasicAttribute *) aBNode, FLITERAL, 0); |
69 | aBNode = aBNode -> GetSibling(); |
70 | } |
71 | out << '>'; |
72 | if ((fl & FLITERAL) == 0) { |
73 | aBNode = aBElem.GetFirstChild(); |
74 | int counter = MAX_SIBLINGS; |
75 | if (aBNode) { |
04232180 |
76 | out << std::endl << " == Children:" << std::endl; |
7fd59977 |
77 | while (aBNode && counter--) { |
78 | if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) break; |
79 | out << " *(LDOM_BasicNode*)" << aBNode << " : " << |
04232180 |
80 | db_pretty_print (aBNode, FLITERAL, 0) << std::endl; |
7fd59977 |
81 | aBNode = aBNode -> GetSibling(); |
82 | } |
83 | } |
84 | aBNode = aBElem.GetSibling(); |
85 | if (aBNode) { |
04232180 |
86 | out << " == Siblings:" << std::endl; |
7fd59977 |
87 | counter = MAX_SIBLINGS; |
88 | while (aBNode && counter--) { |
89 | if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) break; |
90 | out << " *(LDOM_BasicNode*)" << aBNode << " : " << |
04232180 |
91 | db_pretty_print (aBNode, FLITERAL, 0) << std::endl; |
7fd59977 |
92 | aBNode = aBNode -> GetSibling(); |
93 | } |
94 | } |
95 | } |
04232180 |
96 | out << std::ends; |
7fd59977 |
97 | break; |
98 | } |
99 | case LDOM_Node::ATTRIBUTE_NODE: |
100 | { |
101 | const LDOM_BasicAttribute& aBAtt = * (const LDOM_BasicAttribute *) aBNode; |
102 | if ((fl & FLITERAL) == 0) out << "LDOM_BasicAttribute: "; |
103 | out << aBAtt.GetName() << '=' |
04232180 |
104 | << db_pretty_print (&aBAtt.GetValue(), FLITERAL, 0) << std::ends; |
7fd59977 |
105 | break; |
106 | } |
107 | case LDOM_Node::TEXT_NODE: |
108 | case LDOM_Node::COMMENT_NODE: |
109 | case LDOM_Node::CDATA_SECTION_NODE: |
110 | { |
111 | const LDOM_BasicText& aBText = * (const LDOM_BasicText *) aBNode; |
112 | if ((fl & FLITERAL) == 0) out << "LDOM_BasicText: "; |
04232180 |
113 | out << db_pretty_print (&aBText.GetData(), FLITERAL, 0) << std::ends; |
7fd59977 |
114 | break; |
115 | } |
116 | default: |
04232180 |
117 | out << "UNKNOWN" << std::ends; |
7fd59977 |
118 | break; |
119 | } |
120 | return (char *)out.str(); |
121 | } |
122 | |
123 | char * db_pretty_print (const LDOM_Node * aBNode, int fl, char * c) |
124 | { |
125 | return db_pretty_print (&aBNode -> Origin(), fl, c); |
126 | } |
127 | |
128 | #endif |
129 | #endif |