1 // Created on: 2001-06-26
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_Document.hxx>
17 #include <LDOM_MemManager.hxx>
18 #include <LDOM_BasicElement.hxx>
19 #include <LDOM_BasicText.hxx>
21 #define MEMORY_GRANULE 10000
23 //=======================================================================
24 //function : LDOM_Document()
25 //purpose : Constructor
26 //=======================================================================
28 LDOM_Document::LDOM_Document ()
30 myMemManager = new LDOM_MemManager (MEMORY_GRANULE);
33 //=======================================================================
34 //function : LDOM_Document
35 //purpose : Constructor to be used in LDOM_MemManager::Doc()
36 //=======================================================================
38 LDOM_Document::LDOM_Document (const LDOM_MemManager& aMemManager)
40 myMemManager = &aMemManager;
43 //=======================================================================
44 //function : ~LDOM_Document
45 //purpose : Destructor
46 //=======================================================================
48 LDOM_Document::~LDOM_Document ()
51 //=======================================================================
54 //=======================================================================
56 Standard_Boolean LDOM_Document::isNull () const
58 const LDOM_BasicElement * const aRootElement = myMemManager -> RootElement();
59 if (aRootElement == NULL) return Standard_True;
60 return aRootElement -> isNull();
63 //=======================================================================
64 //function : getDocumentElement
66 //=======================================================================
68 LDOM_Element LDOM_Document::getDocumentElement () const
70 return LDOM_Element (* myMemManager -> RootElement(), myMemManager);
73 //=======================================================================
74 //function : getElementsByTagName
76 //=======================================================================
78 LDOM_NodeList LDOM_Document::getElementsByTagName
79 (const LDOMString& theTagName) const
81 LDOM_NodeList aList (myMemManager);
82 LDOM_BasicElement * anElem = (LDOM_BasicElement *)myMemManager->RootElement();
83 const char * aTagString = theTagName.GetString();
85 // if (anElem -> GetTagName().equals(theTagName))
86 if (strcmp (anElem -> GetTagName(), aTagString) == 0)
87 aList.Append (* anElem);
88 anElem -> AddElementsByTagName (aList, theTagName);
93 //=======================================================================
94 //function : createDocument (static)
96 //=======================================================================
98 LDOM_Document LDOM_Document::createDocument (const LDOMString& theQualifiedName)
101 const char * aString = theQualifiedName.GetString();
102 if (strlen(aString) == 0)
103 aString = "document";
104 aDoc.myMemManager -> myRootElement =
105 & LDOM_BasicElement::Create (aString, (Standard_Integer)strlen(aString), aDoc.myMemManager);
109 //=======================================================================
110 //function : createElement
112 //=======================================================================
114 LDOM_Element LDOM_Document::createElement (const LDOMString& theTagName)
116 const char * aTagString = theTagName.GetString();
117 LDOM_BasicElement& aBasicElem = LDOM_BasicElement::Create (aTagString,
118 (Standard_Integer)strlen(aTagString),
120 return LDOM_Element (aBasicElem, myMemManager);
123 //=======================================================================
124 //function : createTextNode
126 //=======================================================================
128 LDOM_Text LDOM_Document::createTextNode (const LDOMString& theData)
130 LDOM_BasicText& aBasicText
131 = LDOM_BasicText::Create (LDOM_Node::TEXT_NODE,
132 LDOMString (theData, myMemManager), myMemManager);
133 return LDOM_Text (aBasicText, myMemManager);
136 //=======================================================================
137 //function : createCDATASection
139 //=======================================================================
141 LDOM_CDATASection LDOM_Document::createCDATASection (const LDOMString& theData)
143 LDOM_BasicText& aBasicText =
144 LDOM_BasicText::Create (LDOM_Node::CDATA_SECTION_NODE,
145 LDOMString (theData, myMemManager), myMemManager);
146 const LDOM_CDATASection aNewNode (aBasicText, myMemManager);
147 aNewNode.SetValueClear(); // no use to beware markup characters
151 //=======================================================================
152 //function : createComment
154 //=======================================================================
156 LDOM_Comment LDOM_Document::createComment (const LDOMString& theData)
158 LDOM_BasicText& aBasicText =
159 LDOM_BasicText::Create (LDOM_Node::COMMENT_NODE,
160 LDOMString (theData, myMemManager), myMemManager);
161 return LDOM_Comment (aBasicText, myMemManager);
164 //=======================================================================
165 //function : operator =
167 //=======================================================================
169 LDOM_Document& LDOM_Document::operator = (const LDOM_NullPtr *)
171 myMemManager = new LDOM_MemManager (MEMORY_GRANULE);
175 //=======================================================================
176 //function : operator ==
177 //purpose : Compare to NULL
178 //=======================================================================
180 Standard_Boolean LDOM_Document::operator == (const LDOM_NullPtr *) const
182 return myMemManager -> RootElement() == NULL;
185 //=======================================================================
186 //function : operator !=
187 //purpose : Compare to NULL
188 //=======================================================================
190 Standard_Boolean LDOM_Document::operator != (const LDOM_NullPtr *) const
192 return myMemManager -> RootElement() != NULL;