0023934: Compiler warnings in MS VC++ 10
[occt.git] / src / LDOM / LDOM_Node.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_MemManager.hxx>
22 #include <LDOM_BasicAttribute.hxx>
23 #include <LDOM_BasicElement.hxx>
24 #include <LDOM_BasicText.hxx>
25
26 //=======================================================================
27 //function : Origin
28 //purpose  : 
29 //=======================================================================
30
31 const LDOM_BasicNode& LDOM_Node::Origin () const
32 {
33   if (myOrigin == NULL) {
34     static LDOM_BasicNode aNullNode;
35     return aNullNode;
36   }
37   return * myOrigin;
38 }
39
40 //=======================================================================
41 //function : getOwnerDocument
42 //purpose  : 
43 //=======================================================================
44
45 const LDOM_MemManager& LDOM_Node::getOwnerDocument () const
46 {
47   return myDocument -> Self();
48 }
49
50 //=======================================================================
51 //function : operator =
52 //purpose  : Assignment
53 //=======================================================================
54
55 LDOM_Node& LDOM_Node::operator = (const LDOM_Node& theOther)
56
57   myDocument    = theOther.myDocument;
58   myOrigin      = theOther.myOrigin;
59   myLastChild   = theOther.myLastChild;
60   return * this;
61 }
62
63 //=======================================================================
64 //function : operator =
65 //purpose  : Nullify
66 //=======================================================================
67
68 LDOM_Node& LDOM_Node::operator = (const LDOM_NullPtr * /*aNull*/)
69 {
70   myDocument.Nullify();
71   myOrigin    = NULL;
72   myLastChild = NULL;
73   return * this;
74 }
75
76 //=======================================================================
77 //function : isNull
78 //purpose  : 
79 //=======================================================================
80
81 Standard_Boolean LDOM_Node::isNull () const
82 {
83   return myOrigin == NULL || myOrigin -> isNull();
84 }
85
86 //=======================================================================
87 //function : operator ==
88 //purpose  : Compare two Nodes
89 //=======================================================================
90
91 Standard_Boolean LDOM_Node::operator == (const LDOM_Node& anOther) const
92 {
93   if (isNull())
94     return anOther.isNull();
95   return myOrigin == anOther.myOrigin;
96 }
97
98 //=======================================================================
99 //function : operator !=
100 //purpose  : Compare two Nodes
101 //=======================================================================
102
103 Standard_Boolean LDOM_Node::operator != (const LDOM_Node& anOther) const
104 {
105   if (isNull())
106     return !anOther.isNull();
107   return myOrigin != anOther.myOrigin;
108 }
109
110 //=======================================================================
111 //function : getNodeType
112 //purpose  : 
113 //=======================================================================
114
115 LDOM_Node::NodeType LDOM_Node::getNodeType () const
116 {
117   return myOrigin == NULL ? UNKNOWN : myOrigin -> getNodeType();
118 }
119
120 //=======================================================================
121 //function : getNodeName
122 //purpose  : 
123 //=======================================================================
124
125 LDOMString LDOM_Node::getNodeName () const
126 {
127   switch (getNodeType()) {
128   case ELEMENT_NODE:
129     {
130       const LDOM_BasicElement& anElement= *(const LDOM_BasicElement *) myOrigin;
131       return LDOMString::CreateDirectString (anElement.GetTagName(),
132                                              myDocument -> Self());
133     }
134   case ATTRIBUTE_NODE:
135     {
136       const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
137       return LDOMString::CreateDirectString (anAttr.GetName(),
138                                              myDocument -> Self());
139     }
140   default: ;
141   }
142   return LDOMString ();
143 }
144
145 //=======================================================================
146 //function : getNodeValue
147 //purpose  : 
148 //=======================================================================
149
150 LDOMString LDOM_Node::getNodeValue () const
151 {
152   switch (getNodeType()) {
153   case ATTRIBUTE_NODE:
154     {
155       const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
156       return LDOMString (anAttr.GetValue(), myDocument -> Self());
157     }
158   case TEXT_NODE:
159   case CDATA_SECTION_NODE:
160   case COMMENT_NODE:
161     {
162       const LDOM_BasicText& aText = * (const LDOM_BasicText *) myOrigin;
163       return LDOMString (aText.GetData(), myDocument -> Self());
164     }
165   default: ;
166   }
167   return LDOMString ();
168 }
169
170 //=======================================================================
171 //function : getFirstChild
172 //purpose  : 
173 //=======================================================================
174
175 LDOM_Node LDOM_Node::getFirstChild () const
176 {
177   const NodeType aType = getNodeType ();
178   if (aType == ELEMENT_NODE) {
179     const LDOM_BasicElement& anElement = * (const LDOM_BasicElement *) myOrigin;
180     const LDOM_BasicNode * aChild = anElement.GetFirstChild();
181     if (aChild)
182       if (aChild -> getNodeType() != LDOM_Node::ATTRIBUTE_NODE)
183         return LDOM_Node (* aChild, myDocument);
184   }
185   return LDOM_Node ();
186 }
187
188 //=======================================================================
189 //function : getLastChild
190 //purpose  : 
191 //=======================================================================
192
193 LDOM_Node LDOM_Node::getLastChild () const
194 {
195   const NodeType aType = getNodeType ();
196   if (aType == ELEMENT_NODE) {
197     if (myLastChild == NULL) {
198       const LDOM_BasicElement& anElement = *(const LDOM_BasicElement*) myOrigin;
199       (const LDOM_BasicNode *&) myLastChild = anElement.GetLastChild();
200     }
201     return LDOM_Node (* myLastChild, myDocument);
202   }
203   return LDOM_Node ();
204 }
205
206 //=======================================================================
207 //function : getNextSibling
208 //purpose  : 
209 //=======================================================================
210
211 LDOM_Node LDOM_Node::getNextSibling () const
212 {
213   const LDOM_BasicNode * aSibling = myOrigin -> mySibling;
214   if (aSibling)
215     if (aSibling -> getNodeType () != ATTRIBUTE_NODE)
216       return LDOM_Node (* aSibling, myDocument);
217   return LDOM_Node ();
218 }
219
220 //=======================================================================
221 //function : removeChild
222 //purpose  : 
223 //=======================================================================
224
225 void LDOM_Node::removeChild (const LDOM_Node& aChild)
226 {
227   const NodeType aType = getNodeType ();
228   if (aType == ELEMENT_NODE) {
229     const LDOM_BasicElement& anElement = * (LDOM_BasicElement *) myOrigin;
230     if (aChild != NULL)
231       anElement.RemoveChild (aChild.myOrigin);
232     if (aChild.myOrigin == myLastChild)
233 //      myLastChild = anElement.GetLastChild();
234       myLastChild = NULL;
235   }
236 }
237
238 //=======================================================================
239 //function : appendChild
240 //purpose  : 
241 //=======================================================================
242
243 void LDOM_Node::appendChild (const LDOM_Node& aChild)
244 {
245   const NodeType aType = getNodeType ();
246   if (aType == ELEMENT_NODE && aChild != NULL) {
247     if (myLastChild) {
248       aChild.myOrigin -> SetSibling (myLastChild -> mySibling);
249       (const LDOM_BasicNode *&) myLastChild -> mySibling = aChild.myOrigin;
250     }else{
251       const LDOM_BasicElement& anElement = * (LDOM_BasicElement *) myOrigin;
252       anElement.AppendChild (aChild.myOrigin, myLastChild);
253     }
254     myLastChild = aChild.myOrigin;
255   }
256 }
257
258 //=======================================================================
259 //function : hasChildNodes
260 //purpose  : 
261 //=======================================================================
262
263 Standard_Boolean LDOM_Node::hasChildNodes () const
264 {
265   const NodeType aType = getNodeType ();
266   if (aType == ELEMENT_NODE) {
267     const LDOM_BasicElement& anElement = * (const LDOM_BasicElement *) myOrigin;
268     const LDOM_BasicNode * aChild = anElement.GetFirstChild();
269     if (aChild) return ! aChild -> isNull(); 
270   }
271   return Standard_False;
272 }
273
274 //=======================================================================
275 //function : SetValueClear
276 //purpose  : 
277 //=======================================================================
278
279 void LDOM_Node::SetValueClear () const
280 {
281   LDOMBasicString * aValue = NULL;
282   switch (getNodeType()) {
283   case ATTRIBUTE_NODE:
284     {
285       const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
286       aValue = (LDOMBasicString *) & anAttr.GetValue();
287       break;
288     }
289   case TEXT_NODE:
290   case CDATA_SECTION_NODE:
291   case COMMENT_NODE:
292     {
293       const LDOM_BasicText& aText = * (const LDOM_BasicText *) myOrigin;
294       aValue = (LDOMBasicString *) & aText.GetData();
295       break;
296     }
297   default: return;
298   }
299   if (aValue -> Type() == LDOMBasicString::LDOM_AsciiDoc)
300     aValue -> myType = LDOMBasicString::LDOM_AsciiDocClear;
301 }