0023934: Compiler warnings in MS VC++ 10
[occt.git] / src / LDOM / LDOM_Document.cxx
1 // Created on: 2001-06-26
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
4 //
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.
9 //
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.
12 //
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.
19
20
21
22 #include <LDOM_Document.hxx>
23 #include <LDOM_MemManager.hxx>
24 #include <LDOM_BasicElement.hxx>
25 #include <LDOM_BasicText.hxx>
26
27 #define MEMORY_GRANULE 10000
28
29 //=======================================================================
30 //function : LDOM_Document()
31 //purpose  : Constructor
32 //=======================================================================
33
34 LDOM_Document::LDOM_Document ()
35 {
36   myMemManager = new LDOM_MemManager (MEMORY_GRANULE);
37 }
38
39 //=======================================================================
40 //function : LDOM_Document
41 //purpose  : Constructor to be used in LDOM_MemManager::Doc()
42 //=======================================================================
43
44 LDOM_Document::LDOM_Document (const LDOM_MemManager& aMemManager)
45 {
46   myMemManager = &aMemManager;
47 }
48
49 //=======================================================================
50 //function : ~LDOM_Document
51 //purpose  : Destructor
52 //=======================================================================
53
54 LDOM_Document::~LDOM_Document ()
55 {}
56
57 //=======================================================================
58 //function : isNull
59 //purpose  : 
60 //=======================================================================
61
62 Standard_Boolean LDOM_Document::isNull () const
63 {
64   const LDOM_BasicElement * const aRootElement = myMemManager -> RootElement();
65   if (aRootElement == NULL) return Standard_True;
66   return aRootElement -> isNull();
67 }
68
69 //=======================================================================
70 //function : getDocumentElement
71 //purpose  : 
72 //=======================================================================
73
74 LDOM_Element LDOM_Document::getDocumentElement () const
75 {
76   return LDOM_Element (* myMemManager -> RootElement(), myMemManager);
77 }
78
79 //=======================================================================
80 //function : getElementsByTagName
81 //purpose  : 
82 //=======================================================================
83
84 LDOM_NodeList LDOM_Document::getElementsByTagName
85                                         (const LDOMString& theTagName) const
86 {
87   LDOM_NodeList aList (myMemManager);
88   LDOM_BasicElement * anElem = (LDOM_BasicElement *)myMemManager->RootElement();
89   const char        * aTagString = theTagName.GetString();
90   if (anElem) {
91 //  if (anElem -> GetTagName().equals(theTagName))
92     if (strcmp (anElem -> GetTagName(), aTagString) == 0)
93       aList.Append (* anElem);
94     anElem -> AddElementsByTagName (aList, theTagName);
95   }
96   return aList;
97 }
98
99 //=======================================================================
100 //function : createDocument (static)
101 //purpose  : 
102 //=======================================================================
103
104 LDOM_Document LDOM_Document::createDocument (const LDOMString& theQualifiedName)
105 {
106   LDOM_Document aDoc;
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);
112   return aDoc;
113 }
114
115 //=======================================================================
116 //function : createElement
117 //purpose  : 
118 //=======================================================================
119
120 LDOM_Element LDOM_Document::createElement (const LDOMString& theTagName)
121 {
122   const char * aTagString = theTagName.GetString();
123   LDOM_BasicElement& aBasicElem = LDOM_BasicElement::Create (aTagString,
124                                                              strlen(aTagString),
125                                                              myMemManager);
126   return LDOM_Element (aBasicElem, myMemManager);
127 }
128
129 //=======================================================================
130 //function : createTextNode
131 //purpose  : 
132 //=======================================================================
133
134 LDOM_Text LDOM_Document::createTextNode (const LDOMString& theData)
135 {
136   LDOM_BasicText& aBasicText
137     = LDOM_BasicText::Create (LDOM_Node::TEXT_NODE,
138                               LDOMString (theData, myMemManager), myMemManager);
139   return LDOM_Text (aBasicText, myMemManager);
140 }
141
142 //=======================================================================
143 //function : createCDATASection
144 //purpose  : 
145 //=======================================================================
146
147 LDOM_CDATASection LDOM_Document::createCDATASection (const LDOMString& theData)
148 {
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
154   return aNewNode;
155 }
156
157 //=======================================================================
158 //function : createComment
159 //purpose  : 
160 //=======================================================================
161
162 LDOM_Comment LDOM_Document::createComment (const LDOMString& theData)
163 {
164   LDOM_BasicText& aBasicText =
165     LDOM_BasicText::Create (LDOM_Node::COMMENT_NODE,
166                             LDOMString (theData, myMemManager), myMemManager);
167   return LDOM_Comment (aBasicText, myMemManager);
168 }
169
170 //=======================================================================
171 //function : operator =
172 //purpose  : Nullify
173 //=======================================================================
174
175 LDOM_Document& LDOM_Document::operator = (const LDOM_NullPtr *)
176 {
177   myMemManager = new LDOM_MemManager (MEMORY_GRANULE);
178   return * this;
179 }
180
181 //=======================================================================
182 //function : operator ==
183 //purpose  : Compare to NULL
184 //=======================================================================
185
186 Standard_Boolean LDOM_Document::operator == (const LDOM_NullPtr *) const
187 {
188   return myMemManager -> RootElement() == NULL;
189 }
190
191 //=======================================================================
192 //function : operator !=
193 //purpose  : Compare to NULL
194 //=======================================================================
195
196 Standard_Boolean LDOM_Document::operator != (const LDOM_NullPtr *) const
197 {
198   return myMemManager -> RootElement() != NULL;
199 }