1 // Created on: 2001-06-26
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.
22 #include <LDOM_Document.hxx>
23 #include <LDOM_MemManager.hxx>
24 #include <LDOM_BasicElement.hxx>
25 #include <LDOM_BasicText.hxx>
27 #define MEMORY_GRANULE 10000
29 //=======================================================================
30 //function : LDOM_Document()
31 //purpose : Constructor
32 //=======================================================================
34 LDOM_Document::LDOM_Document ()
36 myMemManager = new LDOM_MemManager (MEMORY_GRANULE);
39 //=======================================================================
40 //function : LDOM_Document
41 //purpose : Constructor to be used in LDOM_MemManager::Doc()
42 //=======================================================================
44 LDOM_Document::LDOM_Document (const LDOM_MemManager& aMemManager)
46 myMemManager = &aMemManager;
49 //=======================================================================
50 //function : ~LDOM_Document
51 //purpose : Destructor
52 //=======================================================================
54 LDOM_Document::~LDOM_Document ()
57 //=======================================================================
60 //=======================================================================
62 Standard_Boolean LDOM_Document::isNull () const
64 const LDOM_BasicElement * const aRootElement = myMemManager -> RootElement();
65 if (aRootElement == NULL) return Standard_True;
66 return aRootElement -> isNull();
69 //=======================================================================
70 //function : getDocumentElement
72 //=======================================================================
74 LDOM_Element LDOM_Document::getDocumentElement () const
76 return LDOM_Element (* myMemManager -> RootElement(), myMemManager);
79 //=======================================================================
80 //function : getElementsByTagName
82 //=======================================================================
84 LDOM_NodeList LDOM_Document::getElementsByTagName
85 (const LDOMString& theTagName) const
87 LDOM_NodeList aList (myMemManager);
88 LDOM_BasicElement * anElem = (LDOM_BasicElement *)myMemManager->RootElement();
89 const char * aTagString = theTagName.GetString();
91 // if (anElem -> GetTagName().equals(theTagName))
92 if (strcmp (anElem -> GetTagName(), aTagString) == 0)
93 aList.Append (* anElem);
94 anElem -> AddElementsByTagName (aList, theTagName);
99 //=======================================================================
100 //function : createDocument (static)
102 //=======================================================================
104 LDOM_Document LDOM_Document::createDocument (const LDOMString& theQualifiedName)
107 const char * aString = theQualifiedName.GetString();
108 if (strlen(aString) == 0)
109 aString = "document";
110 aDoc.myMemManager -> myRootElement =
111 & LDOM_BasicElement::Create (aString, strlen(aString), aDoc.myMemManager);
115 //=======================================================================
116 //function : createElement
118 //=======================================================================
120 LDOM_Element LDOM_Document::createElement (const LDOMString& theTagName)
122 const char * aTagString = theTagName.GetString();
123 LDOM_BasicElement& aBasicElem = LDOM_BasicElement::Create (aTagString,
126 return LDOM_Element (aBasicElem, myMemManager);
129 //=======================================================================
130 //function : createTextNode
132 //=======================================================================
134 LDOM_Text LDOM_Document::createTextNode (const LDOMString& theData)
136 LDOM_BasicText& aBasicText
137 = LDOM_BasicText::Create (LDOM_Node::TEXT_NODE,
138 LDOMString (theData, myMemManager), myMemManager);
139 return LDOM_Text (aBasicText, myMemManager);
142 //=======================================================================
143 //function : createCDATASection
145 //=======================================================================
147 LDOM_CDATASection LDOM_Document::createCDATASection (const LDOMString& theData)
149 LDOM_BasicText& aBasicText =
150 LDOM_BasicText::Create (LDOM_Node::CDATA_SECTION_NODE,
151 LDOMString (theData, myMemManager), myMemManager);
152 const LDOM_CDATASection aNewNode (aBasicText, myMemManager);
153 aNewNode.SetValueClear(); // no use to beware markup characters
157 //=======================================================================
158 //function : createComment
160 //=======================================================================
162 LDOM_Comment LDOM_Document::createComment (const LDOMString& theData)
164 LDOM_BasicText& aBasicText =
165 LDOM_BasicText::Create (LDOM_Node::COMMENT_NODE,
166 LDOMString (theData, myMemManager), myMemManager);
167 return LDOM_Comment (aBasicText, myMemManager);
170 //=======================================================================
171 //function : operator =
173 //=======================================================================
175 LDOM_Document& LDOM_Document::operator = (const LDOM_NullPtr *)
177 myMemManager = new LDOM_MemManager (MEMORY_GRANULE);
181 //=======================================================================
182 //function : operator ==
183 //purpose : Compare to NULL
184 //=======================================================================
186 Standard_Boolean LDOM_Document::operator == (const LDOM_NullPtr *) const
188 return myMemManager -> RootElement() == NULL;
191 //=======================================================================
192 //function : operator !=
193 //purpose : Compare to NULL
194 //=======================================================================
196 Standard_Boolean LDOM_Document::operator != (const LDOM_NullPtr *) const
198 return myMemManager -> RootElement() != NULL;