1 // Created on: 2001-06-27
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <LDOM_BasicNode.hxx>
17 #include <LDOM_BasicElement.hxx>
18 #include <LDOM_BasicAttribute.hxx>
19 #include <LDOM_BasicText.hxx>
21 //=======================================================================
22 //function : operator =
23 //purpose : Assignment
24 //=======================================================================
26 LDOM_BasicNode& LDOM_BasicNode::operator = (const LDOM_BasicNode& anOther)
28 myNodeType = anOther.getNodeType();
29 mySibling = anOther.GetSibling();
33 //=======================================================================
34 //function : GetSibling
35 //purpose : also detaches NULL siblings
36 //=======================================================================
38 const LDOM_BasicNode * LDOM_BasicNode::GetSibling () const
41 if (mySibling -> isNull())
42 (const LDOM_BasicNode *&) mySibling = mySibling -> mySibling;
49 //=======================================================================
50 // Debug Function for DBX: use "print -p <Variable> or pp <Variable>"
51 //=======================================================================
52 #include <LDOM_OSStream.hxx>
54 #define MAX_SIBLINGS 8
55 char * db_pretty_print (const LDOM_BasicNode * aBNode, int fl, char *)
57 LDOM_OSStream out (128);
58 switch (aBNode -> getNodeType()) {
59 case LDOM_Node::ELEMENT_NODE:
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();
66 if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE)
68 db_pretty_print ((const LDOM_BasicAttribute *) aBNode, FLITERAL, 0);
69 aBNode = aBNode -> GetSibling();
72 if ((fl & FLITERAL) == 0) {
73 aBNode = aBElem.GetFirstChild();
74 int counter = MAX_SIBLINGS;
76 out << std::endl << " == Children:" << std::endl;
77 while (aBNode && counter--) {
78 if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) break;
79 out << " *(LDOM_BasicNode*)" << aBNode << " : " <<
80 db_pretty_print (aBNode, FLITERAL, 0) << std::endl;
81 aBNode = aBNode -> GetSibling();
84 aBNode = aBElem.GetSibling();
86 out << " == Siblings:" << std::endl;
87 counter = MAX_SIBLINGS;
88 while (aBNode && counter--) {
89 if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) break;
90 out << " *(LDOM_BasicNode*)" << aBNode << " : " <<
91 db_pretty_print (aBNode, FLITERAL, 0) << std::endl;
92 aBNode = aBNode -> GetSibling();
99 case LDOM_Node::ATTRIBUTE_NODE:
101 const LDOM_BasicAttribute& aBAtt = * (const LDOM_BasicAttribute *) aBNode;
102 if ((fl & FLITERAL) == 0) out << "LDOM_BasicAttribute: ";
103 out << aBAtt.GetName() << '='
104 << db_pretty_print (&aBAtt.GetValue(), FLITERAL, 0) << std::ends;
107 case LDOM_Node::TEXT_NODE:
108 case LDOM_Node::COMMENT_NODE:
109 case LDOM_Node::CDATA_SECTION_NODE:
111 const LDOM_BasicText& aBText = * (const LDOM_BasicText *) aBNode;
112 if ((fl & FLITERAL) == 0) out << "LDOM_BasicText: ";
113 out << db_pretty_print (&aBText.GetData(), FLITERAL, 0) << std::ends;
117 out << "UNKNOWN" << std::ends;
120 return (char *)out.str();
123 char * db_pretty_print (const LDOM_Node * aBNode, int fl, char * c)
125 return db_pretty_print (&aBNode -> Origin(), fl, c);