1 // Created on: 2001-06-27
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
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.
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.
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.
21 #include <LDOM_MemManager.hxx>
22 #include <LDOM_BasicAttribute.hxx>
23 #include <LDOM_BasicElement.hxx>
24 #include <LDOM_BasicText.hxx>
26 //=======================================================================
29 //=======================================================================
31 const LDOM_BasicNode& LDOM_Node::Origin () const
33 if (myOrigin == NULL) {
34 static LDOM_BasicNode aNullNode;
40 //=======================================================================
41 //function : getOwnerDocument
43 //=======================================================================
45 const LDOM_MemManager& LDOM_Node::getOwnerDocument () const
47 return myDocument -> Self();
50 //=======================================================================
51 //function : operator =
52 //purpose : Assignment
53 //=======================================================================
55 LDOM_Node& LDOM_Node::operator = (const LDOM_Node& theOther)
57 myDocument = theOther.myDocument;
58 myOrigin = theOther.myOrigin;
59 myLastChild = theOther.myLastChild;
63 //=======================================================================
64 //function : operator =
66 //=======================================================================
68 LDOM_Node& LDOM_Node::operator = (const LDOM_NullPtr * /*aNull*/)
76 //=======================================================================
79 //=======================================================================
81 Standard_Boolean LDOM_Node::isNull () const
83 return myOrigin == NULL || myOrigin -> isNull();
86 //=======================================================================
87 //function : operator ==
88 //purpose : Compare two Nodes
89 //=======================================================================
91 Standard_Boolean LDOM_Node::operator == (const LDOM_Node& anOther) const
94 return anOther.isNull();
95 return myOrigin == anOther.myOrigin;
98 //=======================================================================
99 //function : operator !=
100 //purpose : Compare two Nodes
101 //=======================================================================
103 Standard_Boolean LDOM_Node::operator != (const LDOM_Node& anOther) const
106 return !anOther.isNull();
107 return myOrigin != anOther.myOrigin;
110 //=======================================================================
111 //function : getNodeType
113 //=======================================================================
115 LDOM_Node::NodeType LDOM_Node::getNodeType () const
117 return myOrigin == NULL ? UNKNOWN : myOrigin -> getNodeType();
120 //=======================================================================
121 //function : getNodeName
123 //=======================================================================
125 LDOMString LDOM_Node::getNodeName () const
127 switch (getNodeType()) {
130 const LDOM_BasicElement& anElement= *(const LDOM_BasicElement *) myOrigin;
131 return LDOMString::CreateDirectString (anElement.GetTagName(),
132 myDocument -> Self());
136 const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
137 return LDOMString::CreateDirectString (anAttr.GetName(),
138 myDocument -> Self());
142 return LDOMString ();
145 //=======================================================================
146 //function : getNodeValue
148 //=======================================================================
150 LDOMString LDOM_Node::getNodeValue () const
152 switch (getNodeType()) {
155 const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
156 return LDOMString (anAttr.GetValue(), myDocument -> Self());
159 case CDATA_SECTION_NODE:
162 const LDOM_BasicText& aText = * (const LDOM_BasicText *) myOrigin;
163 return LDOMString (aText.GetData(), myDocument -> Self());
167 return LDOMString ();
170 //=======================================================================
171 //function : getFirstChild
173 //=======================================================================
175 LDOM_Node LDOM_Node::getFirstChild () const
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();
182 if (aChild -> getNodeType() != LDOM_Node::ATTRIBUTE_NODE)
183 return LDOM_Node (* aChild, myDocument);
188 //=======================================================================
189 //function : getLastChild
191 //=======================================================================
193 LDOM_Node LDOM_Node::getLastChild () const
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();
201 return LDOM_Node (* myLastChild, myDocument);
206 //=======================================================================
207 //function : getNextSibling
209 //=======================================================================
211 LDOM_Node LDOM_Node::getNextSibling () const
213 const LDOM_BasicNode * aSibling = myOrigin -> mySibling;
215 if (aSibling -> getNodeType () != ATTRIBUTE_NODE)
216 return LDOM_Node (* aSibling, myDocument);
220 //=======================================================================
221 //function : removeChild
223 //=======================================================================
225 void LDOM_Node::removeChild (const LDOM_Node& aChild)
227 const NodeType aType = getNodeType ();
228 if (aType == ELEMENT_NODE) {
229 const LDOM_BasicElement& anElement = * (LDOM_BasicElement *) myOrigin;
231 anElement.RemoveChild (aChild.myOrigin);
232 if (aChild.myOrigin == myLastChild)
233 // myLastChild = anElement.GetLastChild();
238 //=======================================================================
239 //function : appendChild
241 //=======================================================================
243 void LDOM_Node::appendChild (const LDOM_Node& aChild)
245 const NodeType aType = getNodeType ();
246 if (aType == ELEMENT_NODE && aChild != NULL) {
248 aChild.myOrigin -> SetSibling (myLastChild -> mySibling);
249 (const LDOM_BasicNode *&) myLastChild -> mySibling = aChild.myOrigin;
251 const LDOM_BasicElement& anElement = * (LDOM_BasicElement *) myOrigin;
252 anElement.AppendChild (aChild.myOrigin, myLastChild);
254 myLastChild = aChild.myOrigin;
258 //=======================================================================
259 //function : hasChildNodes
261 //=======================================================================
263 Standard_Boolean LDOM_Node::hasChildNodes () const
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();
271 return Standard_False;
274 //=======================================================================
275 //function : SetValueClear
277 //=======================================================================
279 void LDOM_Node::SetValueClear () const
281 LDOMBasicString * aValue = NULL;
282 switch (getNodeType()) {
285 const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
286 aValue = (LDOMBasicString *) & anAttr.GetValue();
290 case CDATA_SECTION_NODE:
293 const LDOM_BasicText& aText = * (const LDOM_BasicText *) myOrigin;
294 aValue = (LDOMBasicString *) & aText.GetData();
299 if (aValue -> Type() == LDOMBasicString::LDOM_AsciiDoc)
300 aValue -> myType = LDOMBasicString::LDOM_AsciiDocClear;