0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / LDOM / LDOM_Document.cxx
1 // Created on: 2001-06-26
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <LDOM_Document.hxx>
17 #include <LDOM_MemManager.hxx>
18 #include <LDOM_BasicElement.hxx>
19 #include <LDOM_BasicText.hxx>
20
21 #define MEMORY_GRANULE 10000
22
23 //=======================================================================
24 //function : LDOM_Document()
25 //purpose  : Constructor
26 //=======================================================================
27
28 LDOM_Document::LDOM_Document ()
29 {
30   myMemManager = new LDOM_MemManager (MEMORY_GRANULE);
31 }
32
33 //=======================================================================
34 //function : LDOM_Document
35 //purpose  : Constructor to be used in LDOM_MemManager::Doc()
36 //=======================================================================
37
38 LDOM_Document::LDOM_Document (const LDOM_MemManager& aMemManager)
39 {
40   myMemManager = &aMemManager;
41 }
42
43 //=======================================================================
44 //function : ~LDOM_Document
45 //purpose  : Destructor
46 //=======================================================================
47
48 LDOM_Document::~LDOM_Document ()
49 {}
50
51 //=======================================================================
52 //function : isNull
53 //purpose  : 
54 //=======================================================================
55
56 Standard_Boolean LDOM_Document::isNull () const
57 {
58   const LDOM_BasicElement * const aRootElement = myMemManager -> RootElement();
59   if (aRootElement == NULL) return Standard_True;
60   return aRootElement -> isNull();
61 }
62
63 //=======================================================================
64 //function : getDocumentElement
65 //purpose  : 
66 //=======================================================================
67
68 LDOM_Element LDOM_Document::getDocumentElement () const
69 {
70   return LDOM_Element (* myMemManager -> RootElement(), myMemManager);
71 }
72
73 //=======================================================================
74 //function : getElementsByTagName
75 //purpose  : 
76 //=======================================================================
77
78 LDOM_NodeList LDOM_Document::getElementsByTagName
79                                         (const LDOMString& theTagName) const
80 {
81   LDOM_NodeList aList (myMemManager);
82   LDOM_BasicElement * anElem = (LDOM_BasicElement *)myMemManager->RootElement();
83   const char        * aTagString = theTagName.GetString();
84   if (anElem) {
85 //  if (anElem -> GetTagName().equals(theTagName))
86     if (strcmp (anElem -> GetTagName(), aTagString) == 0)
87       aList.Append (* anElem);
88     anElem -> AddElementsByTagName (aList, theTagName);
89   }
90   return aList;
91 }
92
93 //=======================================================================
94 //function : createDocument (static)
95 //purpose  : 
96 //=======================================================================
97
98 LDOM_Document LDOM_Document::createDocument (const LDOMString& theQualifiedName)
99 {
100   LDOM_Document aDoc;
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);
106   return aDoc;
107 }
108
109 //=======================================================================
110 //function : createElement
111 //purpose  : 
112 //=======================================================================
113
114 LDOM_Element LDOM_Document::createElement (const LDOMString& theTagName)
115 {
116   const char * aTagString = theTagName.GetString();
117   LDOM_BasicElement& aBasicElem = LDOM_BasicElement::Create (aTagString,
118                                                              (Standard_Integer)strlen(aTagString),
119                                                              myMemManager);
120   return LDOM_Element (aBasicElem, myMemManager);
121 }
122
123 //=======================================================================
124 //function : createTextNode
125 //purpose  : 
126 //=======================================================================
127
128 LDOM_Text LDOM_Document::createTextNode (const LDOMString& theData)
129 {
130   LDOM_BasicText& aBasicText
131     = LDOM_BasicText::Create (LDOM_Node::TEXT_NODE,
132                               LDOMString (theData, myMemManager), myMemManager);
133   return LDOM_Text (aBasicText, myMemManager);
134 }
135
136 //=======================================================================
137 //function : createCDATASection
138 //purpose  : 
139 //=======================================================================
140
141 LDOM_CDATASection LDOM_Document::createCDATASection (const LDOMString& theData)
142 {
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
148   return aNewNode;
149 }
150
151 //=======================================================================
152 //function : createComment
153 //purpose  : 
154 //=======================================================================
155
156 LDOM_Comment LDOM_Document::createComment (const LDOMString& theData)
157 {
158   LDOM_BasicText& aBasicText =
159     LDOM_BasicText::Create (LDOM_Node::COMMENT_NODE,
160                             LDOMString (theData, myMemManager), myMemManager);
161   return LDOM_Comment (aBasicText, myMemManager);
162 }
163
164 //=======================================================================
165 //function : operator =
166 //purpose  : Nullify
167 //=======================================================================
168
169 LDOM_Document& LDOM_Document::operator = (const LDOM_NullPtr *)
170 {
171   myMemManager = new LDOM_MemManager (MEMORY_GRANULE);
172   return * this;
173 }
174
175 //=======================================================================
176 //function : operator ==
177 //purpose  : Compare to NULL
178 //=======================================================================
179
180 Standard_Boolean LDOM_Document::operator == (const LDOM_NullPtr *) const
181 {
182   return myMemManager -> RootElement() == NULL;
183 }
184
185 //=======================================================================
186 //function : operator !=
187 //purpose  : Compare to NULL
188 //=======================================================================
189
190 Standard_Boolean LDOM_Document::operator != (const LDOM_NullPtr *) const
191 {
192   return myMemManager -> RootElement() != NULL;
193 }