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_MemManager.hxx>
17 #include <LDOM_BasicAttribute.hxx>
18 #include <LDOM_BasicElement.hxx>
19 #include <LDOM_BasicText.hxx>
21 //=======================================================================
24 //=======================================================================
26 const LDOM_BasicNode& LDOM_Node::Origin () const
28 if (myOrigin == NULL) {
29 static LDOM_BasicNode aNullNode;
35 //=======================================================================
36 //function : getOwnerDocument
38 //=======================================================================
40 const LDOM_MemManager& LDOM_Node::getOwnerDocument () const
42 return myDocument -> Self();
45 //=======================================================================
46 //function : operator =
47 //purpose : Assignment
48 //=======================================================================
50 LDOM_Node& LDOM_Node::operator = (const LDOM_Node& theOther)
52 myDocument = theOther.myDocument;
53 myOrigin = theOther.myOrigin;
54 myLastChild = theOther.myLastChild;
58 //=======================================================================
59 //function : operator =
61 //=======================================================================
63 LDOM_Node& LDOM_Node::operator = (const LDOM_NullPtr * /*aNull*/)
71 //=======================================================================
74 //=======================================================================
76 Standard_Boolean LDOM_Node::isNull () const
78 return myOrigin == NULL || myOrigin -> isNull();
81 //=======================================================================
82 //function : operator ==
83 //purpose : Compare two Nodes
84 //=======================================================================
86 Standard_Boolean LDOM_Node::operator == (const LDOM_Node& anOther) const
89 return anOther.isNull();
90 return myOrigin == anOther.myOrigin;
93 //=======================================================================
94 //function : operator !=
95 //purpose : Compare two Nodes
96 //=======================================================================
98 Standard_Boolean LDOM_Node::operator != (const LDOM_Node& anOther) const
101 return !anOther.isNull();
102 return myOrigin != anOther.myOrigin;
105 //=======================================================================
106 //function : getNodeType
108 //=======================================================================
110 LDOM_Node::NodeType LDOM_Node::getNodeType () const
112 return myOrigin == NULL ? UNKNOWN : myOrigin -> getNodeType();
115 //=======================================================================
116 //function : getNodeName
118 //=======================================================================
120 LDOMString LDOM_Node::getNodeName () const
122 switch (getNodeType()) {
125 const LDOM_BasicElement& anElement= *(const LDOM_BasicElement *) myOrigin;
126 return LDOMString::CreateDirectString (anElement.GetTagName(),
127 myDocument -> Self());
131 const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
132 return LDOMString::CreateDirectString (anAttr.GetName(),
133 myDocument -> Self());
137 return LDOMString ();
140 //=======================================================================
141 //function : getNodeValue
143 //=======================================================================
145 LDOMString LDOM_Node::getNodeValue () const
147 switch (getNodeType()) {
150 const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
151 return LDOMString (anAttr.GetValue(), myDocument -> Self());
154 case CDATA_SECTION_NODE:
157 const LDOM_BasicText& aText = * (const LDOM_BasicText *) myOrigin;
158 return LDOMString (aText.GetData(), myDocument -> Self());
162 return LDOMString ();
165 //=======================================================================
166 //function : getFirstChild
168 //=======================================================================
170 LDOM_Node LDOM_Node::getFirstChild () const
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();
177 if (aChild -> getNodeType() != LDOM_Node::ATTRIBUTE_NODE)
178 return LDOM_Node (* aChild, myDocument);
183 //=======================================================================
184 //function : getLastChild
186 //=======================================================================
188 LDOM_Node LDOM_Node::getLastChild () const
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();
196 return LDOM_Node (* myLastChild, myDocument);
201 //=======================================================================
202 //function : getNextSibling
204 //=======================================================================
206 LDOM_Node LDOM_Node::getNextSibling () const
208 const LDOM_BasicNode * aSibling = myOrigin -> mySibling;
210 if (aSibling -> getNodeType () != ATTRIBUTE_NODE)
211 return LDOM_Node (* aSibling, myDocument);
215 //=======================================================================
216 //function : removeChild
218 //=======================================================================
220 void LDOM_Node::removeChild (const LDOM_Node& aChild)
222 const NodeType aType = getNodeType ();
223 if (aType == ELEMENT_NODE) {
224 const LDOM_BasicElement& anElement = * (LDOM_BasicElement *) myOrigin;
226 anElement.RemoveChild (aChild.myOrigin);
227 if (aChild.myOrigin == myLastChild)
228 // myLastChild = anElement.GetLastChild();
233 //=======================================================================
234 //function : appendChild
236 //=======================================================================
238 void LDOM_Node::appendChild (const LDOM_Node& aChild)
240 const NodeType aType = getNodeType ();
241 if (aType == ELEMENT_NODE && aChild != NULL) {
243 aChild.myOrigin -> SetSibling (myLastChild -> mySibling);
244 (const LDOM_BasicNode *&) myLastChild -> mySibling = aChild.myOrigin;
246 const LDOM_BasicElement& anElement = * (LDOM_BasicElement *) myOrigin;
247 anElement.AppendChild (aChild.myOrigin, myLastChild);
249 myLastChild = aChild.myOrigin;
253 //=======================================================================
254 //function : hasChildNodes
256 //=======================================================================
258 Standard_Boolean LDOM_Node::hasChildNodes () const
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();
266 return Standard_False;
269 //=======================================================================
270 //function : SetValueClear
272 //=======================================================================
274 void LDOM_Node::SetValueClear () const
276 LDOMBasicString * aValue = NULL;
277 switch (getNodeType()) {
280 const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
281 aValue = (LDOMBasicString *) & anAttr.GetValue();
285 case CDATA_SECTION_NODE:
288 const LDOM_BasicText& aText = * (const LDOM_BasicText *) myOrigin;
289 aValue = (LDOMBasicString *) & aText.GetData();
294 if (aValue -> Type() == LDOMBasicString::LDOM_AsciiDoc)
295 aValue -> myType = LDOMBasicString::LDOM_AsciiDocClear;