1 /**
2  * @file SedRemoveXML.cpp
3  * @brief Implementation of the SedRemoveXML class.
4  * @author DEVISER
5  *
6  * <!--------------------------------------------------------------------------
7  * This file is part of libSEDML. Please visit http://sed-ml.org for more
8  * information about SED-ML. The latest version of libSEDML can be found on
9  * github: https://github.com/fbergmann/libSEDML/
10  *
11 
12  * Copyright (c) 2013-2019, Frank T. Bergmann
13  * All rights reserved.
14  *
15 
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions are met:
18  *
19 
20  * 1. Redistributions of source code must retain the above copyright notice,
21  * this
22  * list of conditions and the following disclaimer.
23  * 2. Redistributions in binary form must reproduce the above copyright notice,
24  * this list of conditions and the following disclaimer in the documentation
25  * and/or other materials provided with the distribution.
26  *
27  * This library is free software; you can redistribute it and/or modify it
28  * under the terms of the GNU Lesser General Public License as published by the
29  * Free Software Foundation. A copy of the license agreement is provided in the
30  * file named "LICENSE.txt" included with this software distribution and also
31  * available online as http://sbml.org/software/libsbml/license.html
32  * ------------------------------------------------------------------------ -->
33  */
34 #include <sedml/SedRemoveXML.h>
35 #include <sbml/xml/XMLInputStream.h>
36 
37 
38 using namespace std;
39 
40 
41 
42 LIBSEDML_CPP_NAMESPACE_BEGIN
43 
44 
45 
46 
47 #ifdef __cplusplus
48 
49 
50 /*
51  * Creates a new SedRemoveXML using the given SED-ML Level and @ p version
52  * values.
53  */
SedRemoveXML(unsigned int level,unsigned int version)54 SedRemoveXML::SedRemoveXML(unsigned int level, unsigned int version)
55   : SedChange(level, version)
56 {
57   setSedNamespacesAndOwn(new SedNamespaces(level, version));
58 }
59 
60 
61 /*
62  * Creates a new SedRemoveXML using the given SedNamespaces object @p sedmlns.
63  */
SedRemoveXML(SedNamespaces * sedmlns)64 SedRemoveXML::SedRemoveXML(SedNamespaces *sedmlns)
65   : SedChange(sedmlns)
66 {
67   setElementNamespace(sedmlns->getURI());
68 }
69 
70 
71 /*
72  * Copy constructor for SedRemoveXML.
73  */
SedRemoveXML(const SedRemoveXML & orig)74 SedRemoveXML::SedRemoveXML(const SedRemoveXML& orig)
75   : SedChange( orig )
76 {
77 }
78 
79 
80 /*
81  * Assignment operator for SedRemoveXML.
82  */
83 SedRemoveXML&
operator =(const SedRemoveXML & rhs)84 SedRemoveXML::operator=(const SedRemoveXML& rhs)
85 {
86   if (&rhs != this)
87   {
88     SedChange::operator=(rhs);
89   }
90 
91   return *this;
92 }
93 
94 
95 /*
96  * Creates and returns a deep copy of this SedRemoveXML object.
97  */
98 SedRemoveXML*
clone() const99 SedRemoveXML::clone() const
100 {
101   return new SedRemoveXML(*this);
102 }
103 
104 
105 /*
106  * Destructor for SedRemoveXML.
107  */
~SedRemoveXML()108 SedRemoveXML::~SedRemoveXML()
109 {
110 }
111 
112 
113 /*
114  * Returns the XML element name of this SedRemoveXML object.
115  */
116 const std::string&
getElementName() const117 SedRemoveXML::getElementName() const
118 {
119   static const string name = "removeXML";
120   return name;
121 }
122 
123 
124 /*
125  * Returns the libSEDML type code for this SedRemoveXML object.
126  */
127 int
getTypeCode() const128 SedRemoveXML::getTypeCode() const
129 {
130   return SEDML_CHANGE_REMOVEXML;
131 }
132 
133 
134 /*
135  * Predicate returning @c true if all the required attributes for this
136  * SedRemoveXML object have been set.
137  */
138 bool
hasRequiredAttributes() const139 SedRemoveXML::hasRequiredAttributes() const
140 {
141   bool allPresent = SedChange::hasRequiredAttributes();
142 
143   return allPresent;
144 }
145 
146 
147 
148 /** @cond doxygenLibSEDMLInternal */
149 
150 /*
151  * Write any contained elements
152  */
153 void
writeElements(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream & stream) const154 SedRemoveXML::writeElements(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream&
155   stream) const
156 {
157   SedChange::writeElements(stream);
158 }
159 
160 /** @endcond */
161 
162 
163 
164 /** @cond doxygenLibSEDMLInternal */
165 
166 /*
167  * Accepts the given SedVisitor
168  */
169 bool
accept(SedVisitor & v) const170 SedRemoveXML::accept(SedVisitor& v) const
171 {
172   return false;
173 }
174 
175 /** @endcond */
176 
177 
178 
179 /** @cond doxygenLibSEDMLInternal */
180 
181 /*
182  * Sets the parent SedDocument
183  */
184 void
setSedDocument(SedDocument * d)185 SedRemoveXML::setSedDocument(SedDocument* d)
186 {
187   SedChange::setSedDocument(d);
188 }
189 
190 /** @endcond */
191 
192 
193 
194 /** @cond doxygenLibSEDMLInternal */
195 
196 /*
197  * Gets the value of the "attributeName" attribute of this SedRemoveXML.
198  */
199 int
getAttribute(const std::string & attributeName,bool & value) const200 SedRemoveXML::getAttribute(const std::string& attributeName,
201                            bool& value) const
202 {
203   int return_value = SedChange::getAttribute(attributeName, value);
204 
205   return return_value;
206 }
207 
208 /** @endcond */
209 
210 
211 
212 /** @cond doxygenLibSEDMLInternal */
213 
214 /*
215  * Gets the value of the "attributeName" attribute of this SedRemoveXML.
216  */
217 int
getAttribute(const std::string & attributeName,int & value) const218 SedRemoveXML::getAttribute(const std::string& attributeName, int& value) const
219 {
220   int return_value = SedChange::getAttribute(attributeName, value);
221 
222   return return_value;
223 }
224 
225 /** @endcond */
226 
227 
228 
229 /** @cond doxygenLibSEDMLInternal */
230 
231 /*
232  * Gets the value of the "attributeName" attribute of this SedRemoveXML.
233  */
234 int
getAttribute(const std::string & attributeName,double & value) const235 SedRemoveXML::getAttribute(const std::string& attributeName,
236                            double& value) const
237 {
238   int return_value = SedChange::getAttribute(attributeName, value);
239 
240   return return_value;
241 }
242 
243 /** @endcond */
244 
245 
246 
247 /** @cond doxygenLibSEDMLInternal */
248 
249 /*
250  * Gets the value of the "attributeName" attribute of this SedRemoveXML.
251  */
252 int
getAttribute(const std::string & attributeName,unsigned int & value) const253 SedRemoveXML::getAttribute(const std::string& attributeName,
254                            unsigned int& value) const
255 {
256   int return_value = SedChange::getAttribute(attributeName, value);
257 
258   return return_value;
259 }
260 
261 /** @endcond */
262 
263 
264 
265 /** @cond doxygenLibSEDMLInternal */
266 
267 /*
268  * Gets the value of the "attributeName" attribute of this SedRemoveXML.
269  */
270 int
getAttribute(const std::string & attributeName,std::string & value) const271 SedRemoveXML::getAttribute(const std::string& attributeName,
272                            std::string& value) const
273 {
274   int return_value = SedChange::getAttribute(attributeName, value);
275 
276   return return_value;
277 }
278 
279 /** @endcond */
280 
281 
282 
283 /** @cond doxygenLibSEDMLInternal */
284 
285 /*
286  * Predicate returning @c true if this SedRemoveXML's attribute "attributeName"
287  * is set.
288  */
289 bool
isSetAttribute(const std::string & attributeName) const290 SedRemoveXML::isSetAttribute(const std::string& attributeName) const
291 {
292   bool value = SedChange::isSetAttribute(attributeName);
293 
294   return value;
295 }
296 
297 /** @endcond */
298 
299 
300 
301 /** @cond doxygenLibSEDMLInternal */
302 
303 /*
304  * Sets the value of the "attributeName" attribute of this SedRemoveXML.
305  */
306 int
setAttribute(const std::string & attributeName,bool value)307 SedRemoveXML::setAttribute(const std::string& attributeName, bool value)
308 {
309   int return_value = SedChange::setAttribute(attributeName, value);
310 
311   return return_value;
312 }
313 
314 /** @endcond */
315 
316 
317 
318 /** @cond doxygenLibSEDMLInternal */
319 
320 /*
321  * Sets the value of the "attributeName" attribute of this SedRemoveXML.
322  */
323 int
setAttribute(const std::string & attributeName,int value)324 SedRemoveXML::setAttribute(const std::string& attributeName, int value)
325 {
326   int return_value = SedChange::setAttribute(attributeName, value);
327 
328   return return_value;
329 }
330 
331 /** @endcond */
332 
333 
334 
335 /** @cond doxygenLibSEDMLInternal */
336 
337 /*
338  * Sets the value of the "attributeName" attribute of this SedRemoveXML.
339  */
340 int
setAttribute(const std::string & attributeName,double value)341 SedRemoveXML::setAttribute(const std::string& attributeName, double value)
342 {
343   int return_value = SedChange::setAttribute(attributeName, value);
344 
345   return return_value;
346 }
347 
348 /** @endcond */
349 
350 
351 
352 /** @cond doxygenLibSEDMLInternal */
353 
354 /*
355  * Sets the value of the "attributeName" attribute of this SedRemoveXML.
356  */
357 int
setAttribute(const std::string & attributeName,unsigned int value)358 SedRemoveXML::setAttribute(const std::string& attributeName,
359                            unsigned int value)
360 {
361   int return_value = SedChange::setAttribute(attributeName, value);
362 
363   return return_value;
364 }
365 
366 /** @endcond */
367 
368 
369 
370 /** @cond doxygenLibSEDMLInternal */
371 
372 /*
373  * Sets the value of the "attributeName" attribute of this SedRemoveXML.
374  */
375 int
setAttribute(const std::string & attributeName,const std::string & value)376 SedRemoveXML::setAttribute(const std::string& attributeName,
377                            const std::string& value)
378 {
379   int return_value = SedChange::setAttribute(attributeName, value);
380 
381   return return_value;
382 }
383 
384 /** @endcond */
385 
386 
387 
388 /** @cond doxygenLibSEDMLInternal */
389 
390 /*
391  * Unsets the value of the "attributeName" attribute of this SedRemoveXML.
392  */
393 int
unsetAttribute(const std::string & attributeName)394 SedRemoveXML::unsetAttribute(const std::string& attributeName)
395 {
396   int value = SedChange::unsetAttribute(attributeName);
397 
398   return value;
399 }
400 
401 /** @endcond */
402 
403 
404 
405 /** @cond doxygenLibSEDMLInternal */
406 
407 /*
408  * Creates a new object from the next XMLToken on the XMLInputStream
409  */
410 SedBase*
createObject(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream & stream)411 SedRemoveXML::createObject(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream&
412   stream)
413 {
414   SedBase* obj = SedChange::createObject(stream);
415 
416   connectToChild();
417 
418   return obj;
419 }
420 
421 /** @endcond */
422 
423 
424 
425 /** @cond doxygenLibSEDMLInternal */
426 
427 /*
428  * Adds the expected attributes for this element
429  */
430 void
addExpectedAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER ExpectedAttributes & attributes)431 SedRemoveXML::addExpectedAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER
432   ExpectedAttributes& attributes)
433 {
434   SedChange::addExpectedAttributes(attributes);
435 }
436 
437 /** @endcond */
438 
439 
440 
441 /** @cond doxygenLibSEDMLInternal */
442 
443 /*
444  * Reads the expected attributes into the member data variables
445  */
446 void
readAttributes(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLAttributes & attributes,const LIBSBML_CPP_NAMESPACE_QUALIFIER ExpectedAttributes & expectedAttributes)447 SedRemoveXML::readAttributes(
448                              const LIBSBML_CPP_NAMESPACE_QUALIFIER
449                                XMLAttributes& attributes,
450                              const LIBSBML_CPP_NAMESPACE_QUALIFIER
451                                ExpectedAttributes& expectedAttributes)
452 {
453   unsigned int level = getLevel();
454   unsigned int version = getVersion();
455   unsigned int numErrs;
456   bool assigned = false;
457   SedErrorLog* log = getErrorLog();
458 
459   SedChange::readAttributes(attributes, expectedAttributes);
460 
461   if (log)
462   {
463     numErrs = log->getNumErrors();
464 
465     for (int n = numErrs-1; n >= 0; n--)
466     {
467       if (log->getError(n)->getErrorId() == SedUnknownCoreAttribute)
468       {
469         const std::string details = log->getError(n)->getMessage();
470         log->remove(SedUnknownCoreAttribute);
471         log->logError(SedmlChangeAllowedAttributes, level, version, details,
472           getLine(), getColumn());
473       }
474     }
475   }
476 }
477 
478 /** @endcond */
479 
480 
481 
482 /** @cond doxygenLibSEDMLInternal */
483 
484 /*
485  * Writes the attributes to the stream
486  */
487 void
writeAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream & stream) const488 SedRemoveXML::writeAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream&
489   stream) const
490 {
491   SedChange::writeAttributes(stream);
492 }
493 
494 /** @endcond */
495 
496 
497 
498 
499 #endif /* __cplusplus */
500 
501 
502 /*
503  * Creates a new SedRemoveXML_t using the given SED-ML Level and @ p version
504  * values.
505  */
506 LIBSEDML_EXTERN
507 SedRemoveXML_t *
SedRemoveXML_create(unsigned int level,unsigned int version)508 SedRemoveXML_create(unsigned int level, unsigned int version)
509 {
510   return new SedRemoveXML(level, version);
511 }
512 
513 
514 /*
515  * Creates and returns a deep copy of this SedRemoveXML_t object.
516  */
517 LIBSEDML_EXTERN
518 SedRemoveXML_t*
SedRemoveXML_clone(const SedRemoveXML_t * srxml)519 SedRemoveXML_clone(const SedRemoveXML_t* srxml)
520 {
521   if (srxml != NULL)
522   {
523     return static_cast<SedRemoveXML_t*>(srxml->clone());
524   }
525   else
526   {
527     return NULL;
528   }
529 }
530 
531 
532 /*
533  * Frees this SedRemoveXML_t object.
534  */
535 LIBSEDML_EXTERN
536 void
SedRemoveXML_free(SedRemoveXML_t * srxml)537 SedRemoveXML_free(SedRemoveXML_t* srxml)
538 {
539   if (srxml != NULL)
540   {
541     delete srxml;
542   }
543 }
544 
545 
546 /*
547  * Predicate returning @c 1 (true) if all the required attributes for this
548  * SedRemoveXML_t object have been set.
549  */
550 LIBSEDML_EXTERN
551 int
SedRemoveXML_hasRequiredAttributes(const SedRemoveXML_t * srxml)552 SedRemoveXML_hasRequiredAttributes(const SedRemoveXML_t * srxml)
553 {
554   return (srxml != NULL) ? static_cast<int>(srxml->hasRequiredAttributes()) :
555     0;
556 }
557 
558 
559 
560 
561 LIBSEDML_CPP_NAMESPACE_END
562 
563 
564