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