1 /**
2 * @file DiffusionCoefficient.cpp
3 * @brief Implementation of the DiffusionCoefficient class.
4 * @author SBMLTeam
5 *
6 * <!--------------------------------------------------------------------------
7 * This file is part of libSBML. Please visit http://sbml.org for more
8 * information about SBML, and the latest version of libSBML.
9 *
10 * Copyright (C) 2020 jointly by the following organizations:
11 * 1. California Institute of Technology, Pasadena, CA, USA
12 * 2. University of Heidelberg, Heidelberg, Germany
13 * 3. University College London, London, UK
14 *
15 * Copyright (C) 2019 jointly by the following organizations:
16 * 1. California Institute of Technology, Pasadena, CA, USA
17 * 2. University of Heidelberg, Heidelberg, Germany
18 *
19 * Copyright (C) 2013-2018 jointly by the following organizations:
20 * 1. California Institute of Technology, Pasadena, CA, USA
21 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
22 * 3. University of Heidelberg, Heidelberg, Germany
23 *
24 * Copyright (C) 2009-2013 jointly by the following organizations:
25 * 1. California Institute of Technology, Pasadena, CA, USA
26 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
27 *
28 * Copyright (C) 2006-2008 by the California Institute of Technology,
29 * Pasadena, CA, USA
30 *
31 * Copyright (C) 2002-2005 jointly by the following organizations:
32 * 1. California Institute of Technology, Pasadena, CA, USA
33 * 2. Japan Science and Technology Agency, Japan
34 *
35 * This library is free software; you can redistribute it and/or modify it
36 * under the terms of the GNU Lesser General Public License as published by the
37 * Free Software Foundation. A copy of the license agreement is provided in the
38 * file named "LICENSE.txt" included with this software distribution and also
39 * available online as http://sbml.org/software/libsbml/license.html
40 * ------------------------------------------------------------------------ -->
41 */
42 #include <sbml/packages/spatial/sbml/DiffusionCoefficient.h>
43 #include <sbml/packages/spatial/validator/SpatialSBMLError.h>
44
45
46 using namespace std;
47
48
49
50 LIBSBML_CPP_NAMESPACE_BEGIN
51
52
53
54
55 #ifdef __cplusplus
56
57
58 /*
59 * Creates a new DiffusionCoefficient using the given SBML Level, Version and
60 * “spatial” package version.
61 */
DiffusionCoefficient(unsigned int level,unsigned int version,unsigned int pkgVersion)62 DiffusionCoefficient::DiffusionCoefficient(unsigned int level,
63 unsigned int version,
64 unsigned int pkgVersion)
65 : SBase(level, version)
66 , mVariable ("")
67 , mType (SPATIAL_DIFFUSIONKIND_INVALID)
68 , mCoordinateReference1 (SPATIAL_COORDINATEKIND_INVALID)
69 , mCoordinateReference2 (SPATIAL_COORDINATEKIND_INVALID)
70 {
71 setSBMLNamespacesAndOwn(new SpatialPkgNamespaces(level, version,
72 pkgVersion));
73 }
74
75
76 /*
77 * Creates a new DiffusionCoefficient using the given SpatialPkgNamespaces
78 * object.
79 */
DiffusionCoefficient(SpatialPkgNamespaces * spatialns)80 DiffusionCoefficient::DiffusionCoefficient(SpatialPkgNamespaces *spatialns)
81 : SBase(spatialns)
82 , mVariable ("")
83 , mType (SPATIAL_DIFFUSIONKIND_INVALID)
84 , mCoordinateReference1 (SPATIAL_COORDINATEKIND_INVALID)
85 , mCoordinateReference2 (SPATIAL_COORDINATEKIND_INVALID)
86 {
87 setElementNamespace(spatialns->getURI());
88 loadPlugins(spatialns);
89 }
90
91
92 /*
93 * Copy constructor for DiffusionCoefficient.
94 */
DiffusionCoefficient(const DiffusionCoefficient & orig)95 DiffusionCoefficient::DiffusionCoefficient(const DiffusionCoefficient& orig)
96 : SBase( orig )
97 , mVariable ( orig.mVariable )
98 , mType ( orig.mType )
99 , mCoordinateReference1 ( orig.mCoordinateReference1 )
100 , mCoordinateReference2 ( orig.mCoordinateReference2 )
101 {
102 }
103
104
105 /*
106 * Assignment operator for DiffusionCoefficient.
107 */
108 DiffusionCoefficient&
operator =(const DiffusionCoefficient & rhs)109 DiffusionCoefficient::operator=(const DiffusionCoefficient& rhs)
110 {
111 if (&rhs != this)
112 {
113 SBase::operator=(rhs);
114 mVariable = rhs.mVariable;
115 mType = rhs.mType;
116 mCoordinateReference1 = rhs.mCoordinateReference1;
117 mCoordinateReference2 = rhs.mCoordinateReference2;
118 }
119
120 return *this;
121 }
122
123
124 /*
125 * Creates and returns a deep copy of this DiffusionCoefficient object.
126 */
127 DiffusionCoefficient*
clone() const128 DiffusionCoefficient::clone() const
129 {
130 return new DiffusionCoefficient(*this);
131 }
132
133
134 /*
135 * Destructor for DiffusionCoefficient.
136 */
~DiffusionCoefficient()137 DiffusionCoefficient::~DiffusionCoefficient()
138 {
139 }
140
141
142 /*
143 * Returns the value of the "variable" attribute of this DiffusionCoefficient.
144 */
145 const std::string&
getVariable() const146 DiffusionCoefficient::getVariable() const
147 {
148 return mVariable;
149 }
150
151
152 /*
153 * Returns the value of the "type" attribute of this DiffusionCoefficient.
154 */
155 DiffusionKind_t
getType() const156 DiffusionCoefficient::getType() const
157 {
158 return mType;
159 }
160
161
162 /*
163 * Returns the value of the "type" attribute of this DiffusionCoefficient.
164 */
165 std::string
getTypeAsString() const166 DiffusionCoefficient::getTypeAsString() const
167 {
168 return DiffusionKind_toString(mType);
169 }
170
171
172 /*
173 * Returns the value of the "coordinateReference1" attribute of this
174 * DiffusionCoefficient.
175 */
176 CoordinateKind_t
getCoordinateReference1() const177 DiffusionCoefficient::getCoordinateReference1() const
178 {
179 return mCoordinateReference1;
180 }
181
182
183 /*
184 * Returns the value of the "coordinateReference1" attribute of this
185 * DiffusionCoefficient.
186 */
187 const std::string&
getCoordinateReference1AsString() const188 DiffusionCoefficient::getCoordinateReference1AsString() const
189 {
190 static const std::string code_str =
191 CoordinateKind_toString(mCoordinateReference1);
192 return code_str;
193 }
194
195
196 /*
197 * Returns the value of the "coordinateReference2" attribute of this
198 * DiffusionCoefficient.
199 */
200 CoordinateKind_t
getCoordinateReference2() const201 DiffusionCoefficient::getCoordinateReference2() const
202 {
203 return mCoordinateReference2;
204 }
205
206
207 /*
208 * Returns the value of the "coordinateReference2" attribute of this
209 * DiffusionCoefficient.
210 */
211 std::string
getCoordinateReference2AsString() const212 DiffusionCoefficient::getCoordinateReference2AsString() const
213 {
214 std::string code_str = CoordinateKind_toString(mCoordinateReference2);
215 return code_str;
216 }
217
218
219 /*
220 * Predicate returning @c true if this DiffusionCoefficient's "variable"
221 * attribute is set.
222 */
223 bool
isSetVariable() const224 DiffusionCoefficient::isSetVariable() const
225 {
226 return (mVariable.empty() == false);
227 }
228
229
230 /*
231 * Predicate returning @c true if this DiffusionCoefficient's "type" attribute
232 * is set.
233 */
234 bool
isSetType() const235 DiffusionCoefficient::isSetType() const
236 {
237 return (mType != SPATIAL_DIFFUSIONKIND_INVALID);
238 }
239
240
241 /*
242 * Predicate returning @c true if this DiffusionCoefficient's
243 * "coordinateReference1" attribute is set.
244 */
245 bool
isSetCoordinateReference1() const246 DiffusionCoefficient::isSetCoordinateReference1() const
247 {
248 return (mCoordinateReference1 != SPATIAL_COORDINATEKIND_INVALID);
249 }
250
251
252 /*
253 * Predicate returning @c true if this DiffusionCoefficient's
254 * "coordinateReference2" attribute is set.
255 */
256 bool
isSetCoordinateReference2() const257 DiffusionCoefficient::isSetCoordinateReference2() const
258 {
259 return (mCoordinateReference2 != SPATIAL_COORDINATEKIND_INVALID);
260 }
261
262
263 /*
264 * Sets the value of the "variable" attribute of this DiffusionCoefficient.
265 */
266 int
setVariable(const std::string & variable)267 DiffusionCoefficient::setVariable(const std::string& variable)
268 {
269 if (!(SyntaxChecker::isValidInternalSId(variable)))
270 {
271 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
272 }
273 else
274 {
275 mVariable = variable;
276 return LIBSBML_OPERATION_SUCCESS;
277 }
278 }
279
280
281 /*
282 * Sets the value of the "type" attribute of this DiffusionCoefficient.
283 */
284 int
setType(const DiffusionKind_t type)285 DiffusionCoefficient::setType(const DiffusionKind_t type)
286 {
287 if (DiffusionKind_isValid(type) == 0)
288 {
289 mType = SPATIAL_DIFFUSIONKIND_INVALID;
290 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
291 }
292 else
293 {
294 mType = type;
295 return LIBSBML_OPERATION_SUCCESS;
296 }
297 }
298
299
300 /*
301 * Sets the value of the "type" attribute of this DiffusionCoefficient.
302 */
303 int
setType(const std::string & type)304 DiffusionCoefficient::setType(const std::string& type)
305 {
306 mType = DiffusionKind_fromString(type.c_str());
307
308 if (mType == SPATIAL_DIFFUSIONKIND_INVALID)
309 {
310 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
311 }
312
313 return LIBSBML_OPERATION_SUCCESS;
314 }
315
316
317 /*
318 * Sets the value of the "coordinateReference1" attribute of this
319 * DiffusionCoefficient.
320 */
321 int
setCoordinateReference1(const CoordinateKind_t coordinateReference1)322 DiffusionCoefficient::setCoordinateReference1(const CoordinateKind_t
323 coordinateReference1)
324 {
325 if (CoordinateKind_isValid(coordinateReference1) == 0)
326 {
327 mCoordinateReference1 = SPATIAL_COORDINATEKIND_INVALID;
328 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
329 }
330 else
331 {
332 mCoordinateReference1 = coordinateReference1;
333 return LIBSBML_OPERATION_SUCCESS;
334 }
335 }
336
337
338 /*
339 * Sets the value of the "coordinateReference1" attribute of this
340 * DiffusionCoefficient.
341 */
342 int
setCoordinateReference1(const std::string & coordinateReference1)343 DiffusionCoefficient::setCoordinateReference1(const std::string&
344 coordinateReference1)
345 {
346 if (CoordinateKind_isValidString(coordinateReference1.c_str()) == 0)
347 {
348 mCoordinateReference1 = SPATIAL_COORDINATEKIND_INVALID;
349 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
350 }
351 else
352 {
353 mCoordinateReference1 =
354 CoordinateKind_fromString(coordinateReference1.c_str());
355 return LIBSBML_OPERATION_SUCCESS;
356 }
357 }
358
359
360 /*
361 * Sets the value of the "coordinateReference2" attribute of this
362 * DiffusionCoefficient.
363 */
364 int
setCoordinateReference2(const CoordinateKind_t coordinateReference2)365 DiffusionCoefficient::setCoordinateReference2(const CoordinateKind_t
366 coordinateReference2)
367 {
368 if (CoordinateKind_isValid(coordinateReference2) == 0)
369 {
370 mCoordinateReference2 = SPATIAL_COORDINATEKIND_INVALID;
371 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
372 }
373 else
374 {
375 mCoordinateReference2 = coordinateReference2;
376 return LIBSBML_OPERATION_SUCCESS;
377 }
378 }
379
380
381 /*
382 * Sets the value of the "coordinateReference2" attribute of this
383 * DiffusionCoefficient.
384 */
385 int
setCoordinateReference2(const std::string & coordinateReference2)386 DiffusionCoefficient::setCoordinateReference2(const std::string&
387 coordinateReference2)
388 {
389 mCoordinateReference2 =
390 CoordinateKind_fromString(coordinateReference2.c_str());
391
392 if (mCoordinateReference2 == SPATIAL_COORDINATEKIND_INVALID)
393 {
394 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
395 }
396
397 return LIBSBML_OPERATION_SUCCESS;
398 }
399
400
401 /*
402 * Unsets the value of the "variable" attribute of this DiffusionCoefficient.
403 */
404 int
unsetVariable()405 DiffusionCoefficient::unsetVariable()
406 {
407 mVariable.erase();
408
409 if (mVariable.empty() == true)
410 {
411 return LIBSBML_OPERATION_SUCCESS;
412 }
413 else
414 {
415 return LIBSBML_OPERATION_FAILED;
416 }
417 }
418
419
420 /*
421 * Unsets the value of the "type" attribute of this DiffusionCoefficient.
422 */
423 int
unsetType()424 DiffusionCoefficient::unsetType()
425 {
426 mType = SPATIAL_DIFFUSIONKIND_INVALID;
427 return LIBSBML_OPERATION_SUCCESS;
428 }
429
430
431 /*
432 * Unsets the value of the "coordinateReference1" attribute of this
433 * DiffusionCoefficient.
434 */
435 int
unsetCoordinateReference1()436 DiffusionCoefficient::unsetCoordinateReference1()
437 {
438 mCoordinateReference1 = SPATIAL_COORDINATEKIND_INVALID;
439 return LIBSBML_OPERATION_SUCCESS;
440 }
441
442
443 /*
444 * Unsets the value of the "coordinateReference2" attribute of this
445 * DiffusionCoefficient.
446 */
447 int
unsetCoordinateReference2()448 DiffusionCoefficient::unsetCoordinateReference2()
449 {
450 mCoordinateReference2 = SPATIAL_COORDINATEKIND_INVALID;
451 return LIBSBML_OPERATION_SUCCESS;
452 }
453
454
455 /*
456 * @copydoc doc_renamesidref_common
457 */
458 void
renameSIdRefs(const std::string & oldid,const std::string & newid)459 DiffusionCoefficient::renameSIdRefs(const std::string& oldid,
460 const std::string& newid)
461 {
462 if (isSetVariable() && mVariable == oldid)
463 {
464 setVariable(newid);
465 }
466 }
467
468
469 /*
470 * Returns the XML element name of this DiffusionCoefficient object.
471 */
472 const std::string&
getElementName() const473 DiffusionCoefficient::getElementName() const
474 {
475 static const string name = "diffusionCoefficient";
476 return name;
477 }
478
479
480 /*
481 * Returns the libSBML type code for this DiffusionCoefficient object.
482 */
483 int
getTypeCode() const484 DiffusionCoefficient::getTypeCode() const
485 {
486 return SBML_SPATIAL_DIFFUSIONCOEFFICIENT;
487 }
488
489
490 /*
491 * Predicate returning @c true if all the required attributes for this
492 * DiffusionCoefficient object have been set.
493 */
494 bool
hasRequiredAttributes() const495 DiffusionCoefficient::hasRequiredAttributes() const
496 {
497 bool allPresent = true;
498
499 if (isSetVariable() == false)
500 {
501 allPresent = false;
502 }
503
504 if (isSetType() == false)
505 {
506 allPresent = false;
507 }
508
509 return allPresent;
510 }
511
512
513
514 /** @cond doxygenLibsbmlInternal */
515
516 /*
517 * Write any contained elements
518 */
519 void
writeElements(XMLOutputStream & stream) const520 DiffusionCoefficient::writeElements(XMLOutputStream& stream) const
521 {
522 SBase::writeElements(stream);
523
524 SBase::writeExtensionElements(stream);
525 }
526
527 /** @endcond */
528
529
530
531 /** @cond doxygenLibsbmlInternal */
532
533 /*
534 * Accepts the given SBMLVisitor
535 */
536 bool
accept(SBMLVisitor & v) const537 DiffusionCoefficient::accept(SBMLVisitor& v) const
538 {
539 return v.visit(*this);
540 }
541
542 /** @endcond */
543
544
545
546 /** @cond doxygenLibsbmlInternal */
547
548 /*
549 * Sets the parent SBMLDocument
550 */
551 void
setSBMLDocument(SBMLDocument * d)552 DiffusionCoefficient::setSBMLDocument(SBMLDocument* d)
553 {
554 SBase::setSBMLDocument(d);
555 }
556
557 /** @endcond */
558
559
560
561 /** @cond doxygenLibsbmlInternal */
562
563 /*
564 * Enables/disables the given package with this element
565 */
566 void
enablePackageInternal(const std::string & pkgURI,const std::string & pkgPrefix,bool flag)567 DiffusionCoefficient::enablePackageInternal(const std::string& pkgURI,
568 const std::string& pkgPrefix,
569 bool flag)
570 {
571 SBase::enablePackageInternal(pkgURI, pkgPrefix, flag);
572 }
573
574 /** @endcond */
575
576
577
578 /** @cond doxygenLibsbmlInternal */
579
580 /*
581 * Gets the value of the "attributeName" attribute of this
582 * DiffusionCoefficient.
583 */
584 int
getAttribute(const std::string & attributeName,bool & value) const585 DiffusionCoefficient::getAttribute(const std::string& attributeName,
586 bool& value) const
587 {
588 int return_value = SBase::getAttribute(attributeName, value);
589
590 return return_value;
591 }
592
593 /** @endcond */
594
595
596
597 /** @cond doxygenLibsbmlInternal */
598
599 /*
600 * Gets the value of the "attributeName" attribute of this
601 * DiffusionCoefficient.
602 */
603 int
getAttribute(const std::string & attributeName,int & value) const604 DiffusionCoefficient::getAttribute(const std::string& attributeName,
605 int& value) const
606 {
607 int return_value = SBase::getAttribute(attributeName, value);
608
609 return return_value;
610 }
611
612 /** @endcond */
613
614
615
616 /** @cond doxygenLibsbmlInternal */
617
618 /*
619 * Gets the value of the "attributeName" attribute of this
620 * DiffusionCoefficient.
621 */
622 int
getAttribute(const std::string & attributeName,double & value) const623 DiffusionCoefficient::getAttribute(const std::string& attributeName,
624 double& value) const
625 {
626 int return_value = SBase::getAttribute(attributeName, value);
627
628 return return_value;
629 }
630
631 /** @endcond */
632
633
634
635 /** @cond doxygenLibsbmlInternal */
636
637 /*
638 * Gets the value of the "attributeName" attribute of this
639 * DiffusionCoefficient.
640 */
641 int
getAttribute(const std::string & attributeName,unsigned int & value) const642 DiffusionCoefficient::getAttribute(const std::string& attributeName,
643 unsigned int& value) const
644 {
645 int return_value = SBase::getAttribute(attributeName, value);
646
647 return return_value;
648 }
649
650 /** @endcond */
651
652
653
654 /** @cond doxygenLibsbmlInternal */
655
656 /*
657 * Gets the value of the "attributeName" attribute of this
658 * DiffusionCoefficient.
659 */
660 int
getAttribute(const std::string & attributeName,std::string & value) const661 DiffusionCoefficient::getAttribute(const std::string& attributeName,
662 std::string& value) const
663 {
664 int return_value = SBase::getAttribute(attributeName, value);
665
666 if (return_value == LIBSBML_OPERATION_SUCCESS)
667 {
668 return return_value;
669 }
670
671 if (attributeName == "variable")
672 {
673 value = getVariable();
674 return_value = LIBSBML_OPERATION_SUCCESS;
675 }
676 else if (attributeName == "type")
677 {
678 value = getTypeAsString();
679 return_value = LIBSBML_OPERATION_SUCCESS;
680 }
681 else if (attributeName == "coordinateReference1")
682 {
683 value = getCoordinateReference1AsString();
684 return_value = LIBSBML_OPERATION_SUCCESS;
685 }
686 else if (attributeName == "coordinateReference2")
687 {
688 value = getCoordinateReference2AsString();
689 return_value = LIBSBML_OPERATION_SUCCESS;
690 }
691
692 return return_value;
693 }
694
695 /** @endcond */
696
697
698
699 /** @cond doxygenLibsbmlInternal */
700
701 /*
702 * Predicate returning @c true if this DiffusionCoefficient's attribute
703 * "attributeName" is set.
704 */
705 bool
isSetAttribute(const std::string & attributeName) const706 DiffusionCoefficient::isSetAttribute(const std::string& attributeName) const
707 {
708 bool value = SBase::isSetAttribute(attributeName);
709
710 if (attributeName == "variable")
711 {
712 value = isSetVariable();
713 }
714 else if (attributeName == "type")
715 {
716 value = isSetType();
717 }
718 else if (attributeName == "coordinateReference1")
719 {
720 value = isSetCoordinateReference1();
721 }
722 else if (attributeName == "coordinateReference2")
723 {
724 value = isSetCoordinateReference2();
725 }
726
727 return value;
728 }
729
730 /** @endcond */
731
732
733
734 /** @cond doxygenLibsbmlInternal */
735
736 /*
737 * Sets the value of the "attributeName" attribute of this
738 * DiffusionCoefficient.
739 */
740 int
setAttribute(const std::string & attributeName,bool value)741 DiffusionCoefficient::setAttribute(const std::string& attributeName,
742 bool value)
743 {
744 int return_value = SBase::setAttribute(attributeName, value);
745
746 return return_value;
747 }
748
749 /** @endcond */
750
751
752
753 /** @cond doxygenLibsbmlInternal */
754
755 /*
756 * Sets the value of the "attributeName" attribute of this
757 * DiffusionCoefficient.
758 */
759 int
setAttribute(const std::string & attributeName,int value)760 DiffusionCoefficient::setAttribute(const std::string& attributeName,
761 int value)
762 {
763 int return_value = SBase::setAttribute(attributeName, value);
764
765 return return_value;
766 }
767
768 /** @endcond */
769
770
771
772 /** @cond doxygenLibsbmlInternal */
773
774 /*
775 * Sets the value of the "attributeName" attribute of this
776 * DiffusionCoefficient.
777 */
778 int
setAttribute(const std::string & attributeName,double value)779 DiffusionCoefficient::setAttribute(const std::string& attributeName,
780 double value)
781 {
782 int return_value = SBase::setAttribute(attributeName, value);
783
784 return return_value;
785 }
786
787 /** @endcond */
788
789
790
791 /** @cond doxygenLibsbmlInternal */
792
793 /*
794 * Sets the value of the "attributeName" attribute of this
795 * DiffusionCoefficient.
796 */
797 int
setAttribute(const std::string & attributeName,unsigned int value)798 DiffusionCoefficient::setAttribute(const std::string& attributeName,
799 unsigned int value)
800 {
801 int return_value = SBase::setAttribute(attributeName, value);
802
803 return return_value;
804 }
805
806 /** @endcond */
807
808
809
810 /** @cond doxygenLibsbmlInternal */
811
812 /*
813 * Sets the value of the "attributeName" attribute of this
814 * DiffusionCoefficient.
815 */
816 int
setAttribute(const std::string & attributeName,const std::string & value)817 DiffusionCoefficient::setAttribute(const std::string& attributeName,
818 const std::string& value)
819 {
820 int return_value = SBase::setAttribute(attributeName, value);
821
822 if (attributeName == "variable")
823 {
824 return_value = setVariable(value);
825 }
826 else if (attributeName == "type")
827 {
828 return_value = setType(value);
829 }
830 else if (attributeName == "coordinateReference1")
831 {
832 return_value = setCoordinateReference1(value);
833 }
834 else if (attributeName == "coordinateReference2")
835 {
836 return_value = setCoordinateReference2(value);
837 }
838
839 return return_value;
840 }
841
842 /** @endcond */
843
844
845
846 /** @cond doxygenLibsbmlInternal */
847
848 /*
849 * Unsets the value of the "attributeName" attribute of this
850 * DiffusionCoefficient.
851 */
852 int
unsetAttribute(const std::string & attributeName)853 DiffusionCoefficient::unsetAttribute(const std::string& attributeName)
854 {
855 int value = SBase::unsetAttribute(attributeName);
856
857 if (attributeName == "variable")
858 {
859 value = unsetVariable();
860 }
861 else if (attributeName == "type")
862 {
863 value = unsetType();
864 }
865 else if (attributeName == "coordinateReference1")
866 {
867 value = unsetCoordinateReference1();
868 }
869 else if (attributeName == "coordinateReference2")
870 {
871 value = unsetCoordinateReference2();
872 }
873
874 return value;
875 }
876
877 /** @endcond */
878
879
880
881 /** @cond doxygenLibsbmlInternal */
882
883 /*
884 * Adds the expected attributes for this element
885 */
886 void
addExpectedAttributes(ExpectedAttributes & attributes)887 DiffusionCoefficient::addExpectedAttributes(ExpectedAttributes& attributes)
888 {
889 SBase::addExpectedAttributes(attributes);
890
891 attributes.add("variable");
892
893 attributes.add("type");
894
895 attributes.add("coordinateReference1");
896
897 attributes.add("coordinateReference2");
898 }
899
900 /** @endcond */
901
902
903
904 /** @cond doxygenLibsbmlInternal */
905
906 /*
907 * Reads the expected attributes into the member data variables
908 */
909 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)910 DiffusionCoefficient::readAttributes(const XMLAttributes& attributes,
911 const ExpectedAttributes&
912 expectedAttributes)
913 {
914 unsigned int level = getLevel();
915 unsigned int version = getVersion();
916 unsigned int pkgVersion = getPackageVersion();
917 unsigned int numErrs;
918 bool assigned = false;
919 SBMLErrorLog* log = getErrorLog();
920
921 SBase::readAttributes(attributes, expectedAttributes);
922
923 if (log)
924 {
925 numErrs = log->getNumErrors();
926
927 for (int n = numErrs-1; n >= 0; n--)
928 {
929 if (log->getError(n)->getErrorId() == UnknownPackageAttribute)
930 {
931 const std::string details = log->getError(n)->getMessage();
932 log->remove(UnknownPackageAttribute);
933 log->logPackageError("spatial",
934 SpatialDiffusionCoefficientAllowedAttributes, pkgVersion, level,
935 version, details, getLine(), getColumn());
936 }
937 else if (log->getError(n)->getErrorId() == UnknownCoreAttribute)
938 {
939 const std::string details = log->getError(n)->getMessage();
940 log->remove(UnknownCoreAttribute);
941 log->logPackageError("spatial",
942 SpatialDiffusionCoefficientAllowedCoreAttributes, pkgVersion, level,
943 version, details, getLine(), getColumn());
944 }
945 }
946 }
947
948 //
949 // variable SIdRef (use = "required" )
950 //
951
952 assigned = attributes.readInto("variable", mVariable);
953
954 if (assigned == true)
955 {
956 if (mVariable.empty() == true)
957 {
958 logEmptyString(mVariable, level, version, "<DiffusionCoefficient>");
959 }
960 else if (SyntaxChecker::isValidSBMLSId(mVariable) == false)
961 {
962 std::string msg = "The variable attribute on the <" + getElementName() +
963 ">";
964 if (isSetId())
965 {
966 msg += " with id '" + getId() + "'";
967 }
968
969 msg += " is '" + mVariable + "', which does not conform to the syntax.";
970 log->logPackageError("spatial",
971 SpatialDiffusionCoefficientVariableMustBeSpecies, pkgVersion, level,
972 version, msg, getLine(), getColumn());
973 }
974 }
975 else
976 {
977 std::string message = "Spatial attribute 'variable' is missing from the "
978 "<DiffusionCoefficient> element.";
979 log->logPackageError("spatial",
980 SpatialDiffusionCoefficientAllowedAttributes, pkgVersion, level, version,
981 message, getLine(), getColumn());
982 }
983
984 //
985 // type enum (use = "required" )
986 //
987
988 std::string type;
989 assigned = attributes.readInto("type", type);
990
991 if (assigned == true)
992 {
993 if (type.empty() == true)
994 {
995 logEmptyString(type, level, version, "<DiffusionCoefficient>");
996 }
997 else
998 {
999 mType = DiffusionKind_fromString(type.c_str());
1000
1001 if (DiffusionKind_isValid(mType) == 0)
1002 {
1003 std::string msg = "The type on the <DiffusionCoefficient> ";
1004
1005 if (isSetId())
1006 {
1007 msg += "with id '" + getId() + "'";
1008 }
1009
1010 msg += "is '" + type + "', which is not a valid option.";
1011
1012 log->logPackageError("spatial",
1013 SpatialDiffusionCoefficientTypeMustBeDiffusionKindEnum, pkgVersion,
1014 level, version, msg, getLine(), getColumn());
1015 }
1016 }
1017 }
1018 else
1019 {
1020 std::string message = "Spatial attribute 'type' is missing.";
1021 log->logPackageError("spatial",
1022 SpatialDiffusionCoefficientAllowedAttributes, pkgVersion, level, version,
1023 message, getLine(), getColumn());
1024 }
1025
1026 //
1027 // coordinateReference1 enum (use = "optional" )
1028 //
1029
1030 std::string coordinateReference1;
1031 assigned = attributes.readInto("coordinateReference1", coordinateReference1);
1032
1033 if (assigned == true)
1034 {
1035 if (coordinateReference1.empty() == true)
1036 {
1037 logEmptyString(coordinateReference1, level, version,
1038 "<DiffusionCoefficient>");
1039 }
1040 else
1041 {
1042 mCoordinateReference1 =
1043 CoordinateKind_fromString(coordinateReference1.c_str());
1044
1045 if (CoordinateKind_isValid(mCoordinateReference1) == 0)
1046 {
1047 std::string msg = "The coordinateReference1 on the "
1048 "<DiffusionCoefficient> ";
1049
1050 if (isSetId())
1051 {
1052 msg += "with id '" + getId() + "'";
1053 }
1054
1055 msg += "is '" + coordinateReference1 + "', which is not a valid "
1056 "option.";
1057
1058 log->logPackageError("spatial", SpatialDiffusionCoefficientCoordinateReference1MustBeCoordinateKindEnum,
1059 pkgVersion, level, version, msg, getLine(), getColumn());
1060 }
1061 }
1062 }
1063
1064 //
1065 // coordinateReference2 enum (use = "optional" )
1066 //
1067
1068 std::string coordinateReference2;
1069 assigned = attributes.readInto("coordinateReference2", coordinateReference2);
1070
1071 if (assigned == true)
1072 {
1073 if (coordinateReference2.empty() == true)
1074 {
1075 logEmptyString(coordinateReference2, level, version,
1076 "<DiffusionCoefficient>");
1077 }
1078 else
1079 {
1080 mCoordinateReference2 =
1081 CoordinateKind_fromString(coordinateReference2.c_str());
1082
1083 if (CoordinateKind_isValid(mCoordinateReference2) == 0)
1084 {
1085 std::string msg = "The coordinateReference2 on the "
1086 "<DiffusionCoefficient> ";
1087
1088 if (isSetId())
1089 {
1090 msg += "with id '" + getId() + "'";
1091 }
1092
1093 msg += "is '" + coordinateReference2 + "', which is not a valid "
1094 "option.";
1095
1096 log->logPackageError("spatial", SpatialDiffusionCoefficientCoordinateReference2MustBeCoordinateKindEnum,
1097 pkgVersion, level, version, msg, getLine(), getColumn());
1098 }
1099 }
1100 }
1101 }
1102
1103 /** @endcond */
1104
1105
1106
1107 /** @cond doxygenLibsbmlInternal */
1108
1109 /*
1110 * Writes the attributes to the stream
1111 */
1112 void
writeAttributes(XMLOutputStream & stream) const1113 DiffusionCoefficient::writeAttributes(XMLOutputStream& stream) const
1114 {
1115 SBase::writeAttributes(stream);
1116
1117 if (isSetVariable() == true)
1118 {
1119 stream.writeAttribute("variable", getPrefix(), mVariable);
1120 }
1121
1122 if (isSetType() == true)
1123 {
1124 stream.writeAttribute("type", getPrefix(), DiffusionKind_toString(mType));
1125 }
1126
1127 if (isSetCoordinateReference1() == true)
1128 {
1129 stream.writeAttribute("coordinateReference1", getPrefix(),
1130 CoordinateKind_toString(mCoordinateReference1));
1131 }
1132
1133 if (isSetCoordinateReference2() == true)
1134 {
1135 stream.writeAttribute("coordinateReference2", getPrefix(),
1136 CoordinateKind_toString(mCoordinateReference2));
1137 }
1138
1139 SBase::writeExtensionAttributes(stream);
1140 }
1141
1142 /** @endcond */
1143
1144
1145
1146
1147 #endif /* __cplusplus */
1148
1149
1150 /*
1151 * Creates a new DiffusionCoefficient_t using the given SBML Level, Version and
1152 * “spatial” package version.
1153 */
1154 LIBSBML_EXTERN
1155 DiffusionCoefficient_t *
DiffusionCoefficient_create(unsigned int level,unsigned int version,unsigned int pkgVersion)1156 DiffusionCoefficient_create(unsigned int level,
1157 unsigned int version,
1158 unsigned int pkgVersion)
1159 {
1160 return new DiffusionCoefficient(level, version, pkgVersion);
1161 }
1162
1163
1164 /*
1165 * Creates and returns a deep copy of this DiffusionCoefficient_t object.
1166 */
1167 LIBSBML_EXTERN
1168 DiffusionCoefficient_t*
DiffusionCoefficient_clone(const DiffusionCoefficient_t * dc)1169 DiffusionCoefficient_clone(const DiffusionCoefficient_t* dc)
1170 {
1171 if (dc != NULL)
1172 {
1173 return static_cast<DiffusionCoefficient_t*>(dc->clone());
1174 }
1175 else
1176 {
1177 return NULL;
1178 }
1179 }
1180
1181
1182 /*
1183 * Frees this DiffusionCoefficient_t object.
1184 */
1185 LIBSBML_EXTERN
1186 void
DiffusionCoefficient_free(DiffusionCoefficient_t * dc)1187 DiffusionCoefficient_free(DiffusionCoefficient_t* dc)
1188 {
1189 if (dc != NULL)
1190 {
1191 delete dc;
1192 }
1193 }
1194
1195
1196 /*
1197 * Returns the value of the "variable" attribute of this
1198 * DiffusionCoefficient_t.
1199 */
1200 LIBSBML_EXTERN
1201 char *
DiffusionCoefficient_getVariable(const DiffusionCoefficient_t * dc)1202 DiffusionCoefficient_getVariable(const DiffusionCoefficient_t * dc)
1203 {
1204 if (dc == NULL)
1205 {
1206 return NULL;
1207 }
1208
1209 return dc->getVariable().empty() ? NULL :
1210 safe_strdup(dc->getVariable().c_str());
1211 }
1212
1213
1214 /*
1215 * Returns the value of the "type" attribute of this DiffusionCoefficient_t.
1216 */
1217 LIBSBML_EXTERN
1218 DiffusionKind_t
DiffusionCoefficient_getType(const DiffusionCoefficient_t * dc)1219 DiffusionCoefficient_getType(const DiffusionCoefficient_t * dc)
1220 {
1221 if (dc == NULL)
1222 {
1223 return SPATIAL_DIFFUSIONKIND_INVALID;
1224 }
1225
1226 return dc->getType();
1227 }
1228
1229
1230 /*
1231 * Returns the value of the "type" attribute of this DiffusionCoefficient_t.
1232 */
1233 LIBSBML_EXTERN
1234 char *
DiffusionCoefficient_getTypeAsString(const DiffusionCoefficient_t * dc)1235 DiffusionCoefficient_getTypeAsString(const DiffusionCoefficient_t * dc)
1236 {
1237 return (char*)(DiffusionKind_toString(dc->getType()));
1238 }
1239
1240
1241 /*
1242 * Returns the value of the "coordinateReference1" attribute of this
1243 * DiffusionCoefficient_t.
1244 */
1245 LIBSBML_EXTERN
1246 CoordinateKind_t
DiffusionCoefficient_getCoordinateReference1(const DiffusionCoefficient_t * dc)1247 DiffusionCoefficient_getCoordinateReference1(const DiffusionCoefficient_t * dc)
1248 {
1249 if (dc == NULL)
1250 {
1251 return SPATIAL_COORDINATEKIND_INVALID;
1252 }
1253
1254 return dc->getCoordinateReference1();
1255 }
1256
1257
1258 /*
1259 * Returns the value of the "coordinateReference1" attribute of this
1260 * DiffusionCoefficient_t.
1261 */
1262 LIBSBML_EXTERN
1263 char *
DiffusionCoefficient_getCoordinateReference1AsString(const DiffusionCoefficient_t * dc)1264 DiffusionCoefficient_getCoordinateReference1AsString(const
1265 DiffusionCoefficient_t * dc)
1266 {
1267 return (char*)(CoordinateKind_toString(dc->getCoordinateReference1()));
1268 }
1269
1270
1271 /*
1272 * Returns the value of the "coordinateReference2" attribute of this
1273 * DiffusionCoefficient_t.
1274 */
1275 LIBSBML_EXTERN
1276 CoordinateKind_t
DiffusionCoefficient_getCoordinateReference2(const DiffusionCoefficient_t * dc)1277 DiffusionCoefficient_getCoordinateReference2(const DiffusionCoefficient_t * dc)
1278 {
1279 if (dc == NULL)
1280 {
1281 return SPATIAL_COORDINATEKIND_INVALID;
1282 }
1283
1284 return dc->getCoordinateReference2();
1285 }
1286
1287
1288 /*
1289 * Returns the value of the "coordinateReference2" attribute of this
1290 * DiffusionCoefficient_t.
1291 */
1292 LIBSBML_EXTERN
1293 char *
DiffusionCoefficient_getCoordinateReference2AsString(const DiffusionCoefficient_t * dc)1294 DiffusionCoefficient_getCoordinateReference2AsString(const
1295 DiffusionCoefficient_t * dc)
1296 {
1297 return (char*)(CoordinateKind_toString(dc->getCoordinateReference2()));
1298 }
1299
1300
1301 /*
1302 * Predicate returning @c 1 (true) if this DiffusionCoefficient_t's "variable"
1303 * attribute is set.
1304 */
1305 LIBSBML_EXTERN
1306 int
DiffusionCoefficient_isSetVariable(const DiffusionCoefficient_t * dc)1307 DiffusionCoefficient_isSetVariable(const DiffusionCoefficient_t * dc)
1308 {
1309 return (dc != NULL) ? static_cast<int>(dc->isSetVariable()) : 0;
1310 }
1311
1312
1313 /*
1314 * Predicate returning @c 1 (true) if this DiffusionCoefficient_t's "type"
1315 * attribute is set.
1316 */
1317 LIBSBML_EXTERN
1318 int
DiffusionCoefficient_isSetType(const DiffusionCoefficient_t * dc)1319 DiffusionCoefficient_isSetType(const DiffusionCoefficient_t * dc)
1320 {
1321 return (dc != NULL) ? static_cast<int>(dc->isSetType()) : 0;
1322 }
1323
1324
1325 /*
1326 * Predicate returning @c 1 (true) if this DiffusionCoefficient_t's
1327 * "coordinateReference1" attribute is set.
1328 */
1329 LIBSBML_EXTERN
1330 int
DiffusionCoefficient_isSetCoordinateReference1(const DiffusionCoefficient_t * dc)1331 DiffusionCoefficient_isSetCoordinateReference1(const DiffusionCoefficient_t *
1332 dc)
1333 {
1334 return (dc != NULL) ? static_cast<int>(dc->isSetCoordinateReference1()) : 0;
1335 }
1336
1337
1338 /*
1339 * Predicate returning @c 1 (true) if this DiffusionCoefficient_t's
1340 * "coordinateReference2" attribute is set.
1341 */
1342 LIBSBML_EXTERN
1343 int
DiffusionCoefficient_isSetCoordinateReference2(const DiffusionCoefficient_t * dc)1344 DiffusionCoefficient_isSetCoordinateReference2(const DiffusionCoefficient_t *
1345 dc)
1346 {
1347 return (dc != NULL) ? static_cast<int>(dc->isSetCoordinateReference2()) : 0;
1348 }
1349
1350
1351 /*
1352 * Sets the value of the "variable" attribute of this DiffusionCoefficient_t.
1353 */
1354 LIBSBML_EXTERN
1355 int
DiffusionCoefficient_setVariable(DiffusionCoefficient_t * dc,const char * variable)1356 DiffusionCoefficient_setVariable(DiffusionCoefficient_t * dc,
1357 const char * variable)
1358 {
1359 return (dc != NULL) ? dc->setVariable(variable) : LIBSBML_INVALID_OBJECT;
1360 }
1361
1362
1363 /*
1364 * Sets the value of the "type" attribute of this DiffusionCoefficient_t.
1365 */
1366 LIBSBML_EXTERN
1367 int
DiffusionCoefficient_setType(DiffusionCoefficient_t * dc,DiffusionKind_t type)1368 DiffusionCoefficient_setType(DiffusionCoefficient_t * dc,
1369 DiffusionKind_t type)
1370 {
1371 return (dc != NULL) ? dc->setType(type) : LIBSBML_INVALID_OBJECT;
1372 }
1373
1374
1375 /*
1376 * Sets the value of the "type" attribute of this DiffusionCoefficient_t.
1377 */
1378 LIBSBML_EXTERN
1379 int
DiffusionCoefficient_setTypeAsString(DiffusionCoefficient_t * dc,const char * type)1380 DiffusionCoefficient_setTypeAsString(DiffusionCoefficient_t * dc,
1381 const char * type)
1382 {
1383 return (dc != NULL) ? dc->setType(type): LIBSBML_INVALID_OBJECT;
1384 }
1385
1386
1387 /*
1388 * Sets the value of the "coordinateReference1" attribute of this
1389 * DiffusionCoefficient_t.
1390 */
1391 LIBSBML_EXTERN
1392 int
DiffusionCoefficient_setCoordinateReference1(DiffusionCoefficient_t * dc,CoordinateKind_t coordinateReference1)1393 DiffusionCoefficient_setCoordinateReference1(DiffusionCoefficient_t * dc,
1394 CoordinateKind_t
1395 coordinateReference1)
1396 {
1397 return (dc != NULL) ? dc->setCoordinateReference1(coordinateReference1) :
1398 LIBSBML_INVALID_OBJECT;
1399 }
1400
1401
1402 /*
1403 * Sets the value of the "coordinateReference1" attribute of this
1404 * DiffusionCoefficient_t.
1405 */
1406 LIBSBML_EXTERN
1407 int
DiffusionCoefficient_setCoordinateReference1AsString(DiffusionCoefficient_t * dc,const char * coordinateReference1)1408 DiffusionCoefficient_setCoordinateReference1AsString(
1409 DiffusionCoefficient_t *
1410 dc,
1411 const char *
1412 coordinateReference1)
1413 {
1414 return (dc != NULL) ? dc->setCoordinateReference1(coordinateReference1):
1415 LIBSBML_INVALID_OBJECT;
1416 }
1417
1418
1419 /*
1420 * Sets the value of the "coordinateReference2" attribute of this
1421 * DiffusionCoefficient_t.
1422 */
1423 LIBSBML_EXTERN
1424 int
DiffusionCoefficient_setCoordinateReference2(DiffusionCoefficient_t * dc,CoordinateKind_t coordinateReference2)1425 DiffusionCoefficient_setCoordinateReference2(DiffusionCoefficient_t * dc,
1426 CoordinateKind_t
1427 coordinateReference2)
1428 {
1429 return (dc != NULL) ? dc->setCoordinateReference2(coordinateReference2) :
1430 LIBSBML_INVALID_OBJECT;
1431 }
1432
1433
1434 /*
1435 * Sets the value of the "coordinateReference2" attribute of this
1436 * DiffusionCoefficient_t.
1437 */
1438 LIBSBML_EXTERN
1439 int
DiffusionCoefficient_setCoordinateReference2AsString(DiffusionCoefficient_t * dc,const char * coordinateReference2)1440 DiffusionCoefficient_setCoordinateReference2AsString(
1441 DiffusionCoefficient_t *
1442 dc,
1443 const char *
1444 coordinateReference2)
1445 {
1446 return (dc != NULL) ? dc->setCoordinateReference2(coordinateReference2):
1447 LIBSBML_INVALID_OBJECT;
1448 }
1449
1450
1451 /*
1452 * Unsets the value of the "variable" attribute of this DiffusionCoefficient_t.
1453 */
1454 LIBSBML_EXTERN
1455 int
DiffusionCoefficient_unsetVariable(DiffusionCoefficient_t * dc)1456 DiffusionCoefficient_unsetVariable(DiffusionCoefficient_t * dc)
1457 {
1458 return (dc != NULL) ? dc->unsetVariable() : LIBSBML_INVALID_OBJECT;
1459 }
1460
1461
1462 /*
1463 * Unsets the value of the "type" attribute of this DiffusionCoefficient_t.
1464 */
1465 LIBSBML_EXTERN
1466 int
DiffusionCoefficient_unsetType(DiffusionCoefficient_t * dc)1467 DiffusionCoefficient_unsetType(DiffusionCoefficient_t * dc)
1468 {
1469 return (dc != NULL) ? dc->unsetType() : LIBSBML_INVALID_OBJECT;
1470 }
1471
1472
1473 /*
1474 * Unsets the value of the "coordinateReference1" attribute of this
1475 * DiffusionCoefficient_t.
1476 */
1477 LIBSBML_EXTERN
1478 int
DiffusionCoefficient_unsetCoordinateReference1(DiffusionCoefficient_t * dc)1479 DiffusionCoefficient_unsetCoordinateReference1(DiffusionCoefficient_t * dc)
1480 {
1481 return (dc != NULL) ? dc->unsetCoordinateReference1() :
1482 LIBSBML_INVALID_OBJECT;
1483 }
1484
1485
1486 /*
1487 * Unsets the value of the "coordinateReference2" attribute of this
1488 * DiffusionCoefficient_t.
1489 */
1490 LIBSBML_EXTERN
1491 int
DiffusionCoefficient_unsetCoordinateReference2(DiffusionCoefficient_t * dc)1492 DiffusionCoefficient_unsetCoordinateReference2(DiffusionCoefficient_t * dc)
1493 {
1494 return (dc != NULL) ? dc->unsetCoordinateReference2() :
1495 LIBSBML_INVALID_OBJECT;
1496 }
1497
1498
1499 /*
1500 * Predicate returning @c 1 (true) if all the required attributes for this
1501 * DiffusionCoefficient_t object have been set.
1502 */
1503 LIBSBML_EXTERN
1504 int
DiffusionCoefficient_hasRequiredAttributes(const DiffusionCoefficient_t * dc)1505 DiffusionCoefficient_hasRequiredAttributes(const DiffusionCoefficient_t * dc)
1506 {
1507 return (dc != NULL) ? static_cast<int>(dc->hasRequiredAttributes()) : 0;
1508 }
1509
1510
1511
1512
1513 LIBSBML_CPP_NAMESPACE_END
1514
1515
1516