0024095: Eliminate compiler warning C4512 in MSVC++ with warning level 4
[occt.git] / src / LDOM / LDOM_BasicNode.cxx
1 // Created on: 2001-06-27
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21 #include <LDOM_BasicNode.hxx>
22 #include <LDOM_BasicElement.hxx>
23 #include <LDOM_BasicAttribute.hxx>
24 #include <LDOM_BasicText.hxx>
25
26 //=======================================================================
27 //function : operator =
28 //purpose  : Assignment
29 //=======================================================================
30
31 LDOM_BasicNode& LDOM_BasicNode::operator = (const LDOM_BasicNode& anOther)
32 {
33   myNodeType = anOther.getNodeType();
34   mySibling  = anOther.GetSibling();
35   return * this;
36 }
37
38 //=======================================================================
39 //function : GetSibling
40 //purpose  : also detaches NULL siblings
41 //=======================================================================
42
43 const LDOM_BasicNode * LDOM_BasicNode::GetSibling () const
44 {
45   while (mySibling)
46     if (mySibling -> isNull())
47       (const LDOM_BasicNode *&) mySibling = mySibling -> mySibling;
48     else break;
49   return mySibling;
50 }
51
52 #ifdef DEB
53 #ifndef WNT
54 //=======================================================================
55 // Debug Function for DBX: use "print -p <Variable> or pp <Variable>"
56 //=======================================================================
57 #include <LDOM_OSStream.hxx>
58 #define FLITERAL 0x10
59 #define MAX_SIBLINGS 8
60 char * db_pretty_print (const LDOM_BasicNode * aBNode, int fl, char *)
61 {
62   LDOM_OSStream out (128);
63   switch (aBNode -> getNodeType()) {
64   case LDOM_Node::ELEMENT_NODE:
65     {
66       const LDOM_BasicElement& aBElem = * (const LDOM_BasicElement *) aBNode;
67       if ((fl & FLITERAL) == 0) out << "LDOM_BasicElement: ";
68       out << '<' << aBElem.GetTagName();
69       aBNode = aBElem.GetFirstChild();
70       while (aBNode) {
71         if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE)
72           out << ' ' <<
73             db_pretty_print ((const LDOM_BasicAttribute *) aBNode, FLITERAL, 0);
74         aBNode = aBNode -> GetSibling();
75       }
76       out << '>';
77       if ((fl & FLITERAL) == 0) {
78         aBNode = aBElem.GetFirstChild();
79         int counter = MAX_SIBLINGS;
80         if (aBNode) {
81           out << endl << " == Children:" << endl;
82           while (aBNode && counter--) {
83             if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) break;
84             out << "  *(LDOM_BasicNode*)" << aBNode << " : " <<
85               db_pretty_print (aBNode, FLITERAL, 0) << endl;
86             aBNode = aBNode -> GetSibling();
87           }
88         }
89         aBNode = aBElem.GetSibling();
90         if (aBNode) {
91           out << " == Siblings:" << endl;
92           counter = MAX_SIBLINGS;
93           while (aBNode && counter--) {
94             if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) break;
95             out << "  *(LDOM_BasicNode*)" << aBNode << " : " <<
96               db_pretty_print (aBNode, FLITERAL, 0) << endl;
97             aBNode = aBNode -> GetSibling();
98           }
99         }
100       }
101       out << ends;
102       break;
103     }
104   case LDOM_Node::ATTRIBUTE_NODE:
105     {
106       const LDOM_BasicAttribute& aBAtt = * (const LDOM_BasicAttribute *) aBNode;
107       if ((fl & FLITERAL) == 0) out << "LDOM_BasicAttribute: ";
108       out << aBAtt.GetName() << '='
109         << db_pretty_print (&aBAtt.GetValue(), FLITERAL, 0) << ends;
110       break;
111     }
112   case LDOM_Node::TEXT_NODE:
113   case LDOM_Node::COMMENT_NODE:
114   case LDOM_Node::CDATA_SECTION_NODE:
115     {
116       const LDOM_BasicText& aBText = * (const LDOM_BasicText *) aBNode;
117       if ((fl & FLITERAL) == 0) out << "LDOM_BasicText: ";
118       out << db_pretty_print (&aBText.GetData(), FLITERAL, 0) << ends;
119       break;
120     }
121   default:
122     out << "UNKNOWN" << ends;
123     break;
124   }
125   return (char *)out.str();
126 }
127
128 char * db_pretty_print (const LDOM_Node * aBNode, int fl, char * c)
129 {
130   return db_pretty_print (&aBNode -> Origin(), fl, c);
131 }
132
133 #endif
134 #endif