1 /**
2 * @file SedRange.cpp
3 * @brief Implementation of the SedRange 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/SedRange.h>
35 #include <sedml/SedListOfRanges.h>
36 #include <sbml/xml/XMLInputStream.h>
37
38 #include <sedml/SedUniformRange.h>
39 #include <sedml/SedVectorRange.h>
40 #include <sedml/SedFunctionalRange.h>
41 #include <sedml/SedDataRange.h>
42
43
44 using namespace std;
45
46
47
48 LIBSEDML_CPP_NAMESPACE_BEGIN
49
50
51
52
53 #ifdef __cplusplus
54
55
56 /*
57 * Creates a new SedRange using the given SED-ML Level and @ p version values.
58 */
SedRange(unsigned int level,unsigned int version)59 SedRange::SedRange(unsigned int level, unsigned int version)
60 : SedBase(level, version)
61 , mElementName("range")
62 {
63 setSedNamespacesAndOwn(new SedNamespaces(level, version));
64 mIdAllowedPreV4 = true;
65 }
66
67
68 /*
69 * Creates a new SedRange using the given SedNamespaces object @p sedmlns.
70 */
SedRange(SedNamespaces * sedmlns)71 SedRange::SedRange(SedNamespaces *sedmlns)
72 : SedBase(sedmlns)
73 , mElementName("range")
74 {
75 setElementNamespace(sedmlns->getURI());
76 mIdAllowedPreV4 = true;
77 }
78
79
80 /*
81 * Copy constructor for SedRange.
82 */
SedRange(const SedRange & orig)83 SedRange::SedRange(const SedRange& orig)
84 : SedBase( orig )
85 , mElementName ( orig.mElementName )
86 {
87 }
88
89
90 /*
91 * Assignment operator for SedRange.
92 */
93 SedRange&
operator =(const SedRange & rhs)94 SedRange::operator=(const SedRange& rhs)
95 {
96 if (&rhs != this)
97 {
98 SedBase::operator=(rhs);
99 mElementName = rhs.mElementName;
100 }
101
102 return *this;
103 }
104
105
106 /*
107 * Creates and returns a deep copy of this SedRange object.
108 */
109 SedRange*
clone() const110 SedRange::clone() const
111 {
112 return new SedRange(*this);
113 }
114
115
116 /*
117 * Destructor for SedRange.
118 */
~SedRange()119 SedRange::~SedRange()
120 {
121 }
122
123
124 /*
125 * Predicate returning @c true if this abstract "SedRange" is of type
126 * SedUniformRange
127 */
128 bool
isSedUniformRange() const129 SedRange::isSedUniformRange() const
130 {
131 return dynamic_cast<const SedUniformRange*>(this) != NULL;
132 }
133
134
135 /*
136 * Predicate returning @c true if this abstract "SedRange" is of type
137 * SedVectorRange
138 */
139 bool
isSedVectorRange() const140 SedRange::isSedVectorRange() const
141 {
142 return dynamic_cast<const SedVectorRange*>(this) != NULL;
143 }
144
145
146 /*
147 * Predicate returning @c true if this abstract "SedRange" is of type
148 * SedFunctionalRange
149 */
150 bool
isSedFunctionalRange() const151 SedRange::isSedFunctionalRange() const
152 {
153 return dynamic_cast<const SedFunctionalRange*>(this) != NULL;
154 }
155
156
157 /*
158 * Predicate returning @c true if this abstract "SedRange" is of type
159 * SedDataRange
160 */
161 bool
isSedDataRange() const162 SedRange::isSedDataRange() const
163 {
164 return dynamic_cast<const SedDataRange*>(this) != NULL;
165 }
166
167
168 /*
169 * Returns the XML element name of this SedRange object.
170 */
171 const std::string&
getElementName() const172 SedRange::getElementName() const
173 {
174 return mElementName;
175 }
176
177
178
179 /** @cond doxygenLibSEDMLInternal */
180
181 /*
182 * Sets the XML name of this SedRange object.
183 */
184 void
setElementName(const std::string & name)185 SedRange::setElementName(const std::string& name)
186 {
187 mElementName = name;
188 }
189
190 /** @endcond */
191
192
193 /*
194 * Returns the libSEDML type code for this SedRange object.
195 */
196 int
getTypeCode() const197 SedRange::getTypeCode() const
198 {
199 return SEDML_RANGE;
200 }
201
202
203 /*
204 * Predicate returning @c true if all the required attributes for this SedRange
205 * object have been set.
206 */
207 bool
hasRequiredAttributes() const208 SedRange::hasRequiredAttributes() const
209 {
210 bool allPresent = true;
211
212 if (isSetId() == false)
213 {
214 allPresent = false;
215 }
216
217 return allPresent;
218 }
219
220
221
222 /** @cond doxygenLibSEDMLInternal */
223
224 /*
225 * Write any contained elements
226 */
227 void
writeElements(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream & stream) const228 SedRange::writeElements(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream&
229 stream) const
230 {
231 SedBase::writeElements(stream);
232 }
233
234 /** @endcond */
235
236
237
238 /** @cond doxygenLibSEDMLInternal */
239
240 /*
241 * Accepts the given SedVisitor
242 */
243 bool
accept(SedVisitor & v) const244 SedRange::accept(SedVisitor& v) const
245 {
246 return false;
247 }
248
249 /** @endcond */
250
251
252
253 /** @cond doxygenLibSEDMLInternal */
254
255 /*
256 * Sets the parent SedDocument
257 */
258 void
setSedDocument(SedDocument * d)259 SedRange::setSedDocument(SedDocument* d)
260 {
261 SedBase::setSedDocument(d);
262 }
263
264 /** @endcond */
265
266
267
268 /** @cond doxygenLibSEDMLInternal */
269
270 /*
271 * Gets the value of the "attributeName" attribute of this SedRange.
272 */
273 int
getAttribute(const std::string & attributeName,bool & value) const274 SedRange::getAttribute(const std::string& attributeName, bool& value) const
275 {
276 int return_value = SedBase::getAttribute(attributeName, value);
277
278 return return_value;
279 }
280
281 /** @endcond */
282
283
284
285 /** @cond doxygenLibSEDMLInternal */
286
287 /*
288 * Gets the value of the "attributeName" attribute of this SedRange.
289 */
290 int
getAttribute(const std::string & attributeName,int & value) const291 SedRange::getAttribute(const std::string& attributeName, int& value) const
292 {
293 int return_value = SedBase::getAttribute(attributeName, value);
294
295 return return_value;
296 }
297
298 /** @endcond */
299
300
301
302 /** @cond doxygenLibSEDMLInternal */
303
304 /*
305 * Gets the value of the "attributeName" attribute of this SedRange.
306 */
307 int
getAttribute(const std::string & attributeName,double & value) const308 SedRange::getAttribute(const std::string& attributeName, double& value) const
309 {
310 int return_value = SedBase::getAttribute(attributeName, value);
311
312 return return_value;
313 }
314
315 /** @endcond */
316
317
318
319 /** @cond doxygenLibSEDMLInternal */
320
321 /*
322 * Gets the value of the "attributeName" attribute of this SedRange.
323 */
324 int
getAttribute(const std::string & attributeName,unsigned int & value) const325 SedRange::getAttribute(const std::string& attributeName,
326 unsigned int& value) const
327 {
328 int return_value = SedBase::getAttribute(attributeName, value);
329
330 return return_value;
331 }
332
333 /** @endcond */
334
335
336
337 /** @cond doxygenLibSEDMLInternal */
338
339 /*
340 * Gets the value of the "attributeName" attribute of this SedRange.
341 */
342 int
getAttribute(const std::string & attributeName,std::string & value) const343 SedRange::getAttribute(const std::string& attributeName,
344 std::string& value) const
345 {
346 int return_value = SedBase::getAttribute(attributeName, value);
347
348 if (return_value == LIBSEDML_OPERATION_SUCCESS)
349 {
350 return return_value;
351 }
352
353 if (attributeName == "id")
354 {
355 value = getId();
356 return_value = LIBSEDML_OPERATION_SUCCESS;
357 }
358
359 return return_value;
360 }
361
362 /** @endcond */
363
364
365
366 /** @cond doxygenLibSEDMLInternal */
367
368 /*
369 * Predicate returning @c true if this SedRange's attribute "attributeName" is
370 * set.
371 */
372 bool
isSetAttribute(const std::string & attributeName) const373 SedRange::isSetAttribute(const std::string& attributeName) const
374 {
375 bool value = SedBase::isSetAttribute(attributeName);
376
377 if (attributeName == "id")
378 {
379 value = isSetId();
380 }
381
382 return value;
383 }
384
385 /** @endcond */
386
387
388
389 /** @cond doxygenLibSEDMLInternal */
390
391 /*
392 * Sets the value of the "attributeName" attribute of this SedRange.
393 */
394 int
setAttribute(const std::string & attributeName,bool value)395 SedRange::setAttribute(const std::string& attributeName, bool value)
396 {
397 int return_value = SedBase::setAttribute(attributeName, value);
398
399 return return_value;
400 }
401
402 /** @endcond */
403
404
405
406 /** @cond doxygenLibSEDMLInternal */
407
408 /*
409 * Sets the value of the "attributeName" attribute of this SedRange.
410 */
411 int
setAttribute(const std::string & attributeName,int value)412 SedRange::setAttribute(const std::string& attributeName, int value)
413 {
414 int return_value = SedBase::setAttribute(attributeName, value);
415
416 return return_value;
417 }
418
419 /** @endcond */
420
421
422
423 /** @cond doxygenLibSEDMLInternal */
424
425 /*
426 * Sets the value of the "attributeName" attribute of this SedRange.
427 */
428 int
setAttribute(const std::string & attributeName,double value)429 SedRange::setAttribute(const std::string& attributeName, double value)
430 {
431 int return_value = SedBase::setAttribute(attributeName, value);
432
433 return return_value;
434 }
435
436 /** @endcond */
437
438
439
440 /** @cond doxygenLibSEDMLInternal */
441
442 /*
443 * Sets the value of the "attributeName" attribute of this SedRange.
444 */
445 int
setAttribute(const std::string & attributeName,unsigned int value)446 SedRange::setAttribute(const std::string& attributeName, unsigned int value)
447 {
448 int return_value = SedBase::setAttribute(attributeName, value);
449
450 return return_value;
451 }
452
453 /** @endcond */
454
455
456
457 /** @cond doxygenLibSEDMLInternal */
458
459 /*
460 * Sets the value of the "attributeName" attribute of this SedRange.
461 */
462 int
setAttribute(const std::string & attributeName,const std::string & value)463 SedRange::setAttribute(const std::string& attributeName,
464 const std::string& value)
465 {
466 int return_value = SedBase::setAttribute(attributeName, value);
467
468 if (attributeName == "id")
469 {
470 return_value = setId(value);
471 }
472
473 return return_value;
474 }
475
476 /** @endcond */
477
478
479
480 /** @cond doxygenLibSEDMLInternal */
481
482 /*
483 * Unsets the value of the "attributeName" attribute of this SedRange.
484 */
485 int
unsetAttribute(const std::string & attributeName)486 SedRange::unsetAttribute(const std::string& attributeName)
487 {
488 int value = SedBase::unsetAttribute(attributeName);
489
490 if (attributeName == "id")
491 {
492 value = unsetId();
493 }
494
495 return value;
496 }
497
498 /** @endcond */
499
500
501
502 /** @cond doxygenLibSEDMLInternal */
503
504 /*
505 * Adds the expected attributes for this element
506 */
507 void
addExpectedAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER ExpectedAttributes & attributes)508 SedRange::addExpectedAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER
509 ExpectedAttributes& attributes)
510 {
511 SedBase::addExpectedAttributes(attributes);
512
513 attributes.add("id");
514 }
515
516 /** @endcond */
517
518
519
520 /** @cond doxygenLibSEDMLInternal */
521
522 /*
523 * Reads the expected attributes into the member data variables
524 */
525 void
readAttributes(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLAttributes & attributes,const LIBSBML_CPP_NAMESPACE_QUALIFIER ExpectedAttributes & expectedAttributes)526 SedRange::readAttributes(
527 const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLAttributes&
528 attributes,
529 const LIBSBML_CPP_NAMESPACE_QUALIFIER
530 ExpectedAttributes& expectedAttributes)
531 {
532 unsigned int level = getLevel();
533 unsigned int version = getVersion();
534 unsigned int numErrs;
535 bool assigned = false;
536 SedErrorLog* log = getErrorLog();
537
538 if (log && getParentSedObject() &&
539 static_cast<SedListOfRanges*>(getParentSedObject())->size() < 2)
540 {
541 numErrs = log->getNumErrors();
542 for (int n = numErrs-1; n >= 0; n--)
543 {
544 if (log->getError(n)->getErrorId() == SedUnknownCoreAttribute)
545 {
546 const std::string details = log->getError(n)->getMessage();
547 log->remove(SedUnknownCoreAttribute);
548 log->logError(SedmlRepeatedTaskLORangesAllowedCoreAttributes, level,
549 version, details, getLine(), getColumn());
550 }
551 }
552 }
553
554 SedBase::readAttributes(attributes, expectedAttributes);
555
556 if (log)
557 {
558 numErrs = log->getNumErrors();
559
560 for (int n = numErrs-1; n >= 0; n--)
561 {
562 if (log->getError(n)->getErrorId() == SedUnknownCoreAttribute)
563 {
564 const std::string details = log->getError(n)->getMessage();
565 log->remove(SedUnknownCoreAttribute);
566 log->logError(SedmlRangeAllowedAttributes, level, version, details,
567 getLine(), getColumn());
568 }
569 }
570 }
571
572 if(!isSetId())
573 {
574 if (log)
575 {
576 std::string message = "Sedml attribute 'id' is missing from the "
577 "<SedRange> element.";
578 log->logError(SedmlRangeAllowedAttributes, level, version, message,
579 getLine(), getColumn());
580 }
581 }
582 }
583
584 /** @endcond */
585
586
587
588 /** @cond doxygenLibSEDMLInternal */
589
590 /*
591 * Writes the attributes to the stream
592 */
593 void
writeAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream & stream) const594 SedRange::writeAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream&
595 stream) const
596 {
597 SedBase::writeAttributes(stream);
598 }
599
600 /** @endcond */
601
602
603
604
605 #endif /* __cplusplus */
606
607
608 /*
609 * Creates a new SedUniformRange using the given SED-ML Level and @ p version
610 * values.
611 */
612 LIBSEDML_EXTERN
613 SedUniformRange_t *
SedRange_createUniformRange(unsigned int level,unsigned int version)614 SedRange_createUniformRange(unsigned int level, unsigned int version)
615 {
616 return new SedUniformRange(level, version);
617 }
618
619
620 /*
621 * Creates a new SedVectorRange using the given SED-ML Level and @ p version
622 * values.
623 */
624 LIBSEDML_EXTERN
625 SedVectorRange_t *
SedRange_createVectorRange(unsigned int level,unsigned int version)626 SedRange_createVectorRange(unsigned int level, unsigned int version)
627 {
628 return new SedVectorRange(level, version);
629 }
630
631
632 /*
633 * Creates a new SedFunctionalRange using the given SED-ML Level and @ p version
634 * values.
635 */
636 LIBSEDML_EXTERN
637 SedFunctionalRange_t *
SedRange_createFunctionalRange(unsigned int level,unsigned int version)638 SedRange_createFunctionalRange(unsigned int level, unsigned int version)
639 {
640 return new SedFunctionalRange(level, version);
641 }
642
643
644 /*
645 * Creates a new SedDataRange using the given SED-ML Level and @ p version
646 * values.
647 */
648 LIBSEDML_EXTERN
649 SedDataRange_t *
SedRange_createDataRange(unsigned int level,unsigned int version)650 SedRange_createDataRange(unsigned int level, unsigned int version)
651 {
652 return new SedDataRange(level, version);
653 }
654
655
656 /*
657 * Creates and returns a deep copy of this SedRange_t object.
658 */
659 LIBSEDML_EXTERN
660 SedRange_t*
SedRange_clone(const SedRange_t * sr)661 SedRange_clone(const SedRange_t* sr)
662 {
663 if (sr != NULL)
664 {
665 return static_cast<SedRange_t*>(sr->clone());
666 }
667 else
668 {
669 return NULL;
670 }
671 }
672
673
674 /*
675 * Frees this SedRange_t object.
676 */
677 LIBSEDML_EXTERN
678 void
SedRange_free(SedRange_t * sr)679 SedRange_free(SedRange_t* sr)
680 {
681 if (sr != NULL)
682 {
683 delete sr;
684 }
685 }
686
687
688 /*
689 * Returns the value of the "id" attribute of this SedRange_t.
690 */
691 LIBSEDML_EXTERN
692 char *
SedRange_getId(const SedRange_t * sr)693 SedRange_getId(const SedRange_t * sr)
694 {
695 if (sr == NULL)
696 {
697 return NULL;
698 }
699
700 return sr->getId().empty() ? NULL : safe_strdup(sr->getId().c_str());
701 }
702
703
704 /*
705 * Predicate returning @c 1 (true) if this SedRange_t's "id" attribute is set.
706 */
707 LIBSEDML_EXTERN
708 int
SedRange_isSetId(const SedRange_t * sr)709 SedRange_isSetId(const SedRange_t * sr)
710 {
711 return (sr != NULL) ? static_cast<int>(sr->isSetId()) : 0;
712 }
713
714
715 /*
716 * Sets the value of the "id" attribute of this SedRange_t.
717 */
718 LIBSEDML_EXTERN
719 int
SedRange_setId(SedRange_t * sr,const char * id)720 SedRange_setId(SedRange_t * sr, const char * id)
721 {
722 return (sr != NULL) ? sr->setId(id) : LIBSEDML_INVALID_OBJECT;
723 }
724
725
726 /*
727 * Unsets the value of the "id" attribute of this SedRange_t.
728 */
729 LIBSEDML_EXTERN
730 int
SedRange_unsetId(SedRange_t * sr)731 SedRange_unsetId(SedRange_t * sr)
732 {
733 return (sr != NULL) ? sr->unsetId() : LIBSEDML_INVALID_OBJECT;
734 }
735
736
737 /*
738 * Predicate returning @c 1 if this SedRange_t is of type SedUniformRange_t
739 */
740 LIBSEDML_EXTERN
741 int
SedRange_isSedUniformRange(const SedRange_t * sr)742 SedRange_isSedUniformRange(const SedRange_t * sr)
743 {
744 return (sr != NULL) ? static_cast<int>(sr->isSedUniformRange()) : 0;
745 }
746
747
748 /*
749 * Predicate returning @c 1 if this SedRange_t is of type SedVectorRange_t
750 */
751 LIBSEDML_EXTERN
752 int
SedRange_isSedVectorRange(const SedRange_t * sr)753 SedRange_isSedVectorRange(const SedRange_t * sr)
754 {
755 return (sr != NULL) ? static_cast<int>(sr->isSedVectorRange()) : 0;
756 }
757
758
759 /*
760 * Predicate returning @c 1 if this SedRange_t is of type SedFunctionalRange_t
761 */
762 LIBSEDML_EXTERN
763 int
SedRange_isSedFunctionalRange(const SedRange_t * sr)764 SedRange_isSedFunctionalRange(const SedRange_t * sr)
765 {
766 return (sr != NULL) ? static_cast<int>(sr->isSedFunctionalRange()) : 0;
767 }
768
769
770 /*
771 * Predicate returning @c 1 if this SedRange_t is of type SedDataRange_t
772 */
773 LIBSEDML_EXTERN
774 int
SedRange_isSedDataRange(const SedRange_t * sr)775 SedRange_isSedDataRange(const SedRange_t * sr)
776 {
777 return (sr != NULL) ? static_cast<int>(sr->isSedDataRange()) : 0;
778 }
779
780
781 /*
782 * Predicate returning @c 1 (true) if all the required attributes for this
783 * SedRange_t object have been set.
784 */
785 LIBSEDML_EXTERN
786 int
SedRange_hasRequiredAttributes(const SedRange_t * sr)787 SedRange_hasRequiredAttributes(const SedRange_t * sr)
788 {
789 return (sr != NULL) ? static_cast<int>(sr->hasRequiredAttributes()) : 0;
790 }
791
792
793
794
795 LIBSEDML_CPP_NAMESPACE_END
796
797
798