1 /**
2 * @file Species.cpp
3 * @brief Implementations of Species and ListOfSpecies.
4 * @author Ben Bornstein
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
37 * the Free Software Foundation. A copy of the license agreement is provided
38 * in the file named "LICENSE.txt" included with this software distribution
39 * and also available online as http://sbml.org/software/libsbml/license.html
40 * ---------------------------------------------------------------------- -->*/
41
42 #include <limits>
43
44 #include <sbml/xml/XMLNode.h>
45 #include <sbml/xml/XMLAttributes.h>
46 #include <sbml/xml/XMLInputStream.h>
47 #include <sbml/xml/XMLOutputStream.h>
48
49 #include <sbml/SBMLVisitor.h>
50 #include <sbml/SBMLError.h>
51 #include <sbml/SBMLDocument.h>
52 #include <sbml/Model.h>
53 #include <sbml/Species.h>
54
55 /** @cond doxygenIgnored */
56 using namespace std;
57 /** @endcond */
58
59 LIBSBML_CPP_NAMESPACE_BEGIN
60 #ifdef __cplusplus
61
Species(unsigned int level,unsigned int version)62 Species::Species (unsigned int level, unsigned int version) :
63 SBase ( level, version )
64 , mSpeciesType ( "" )
65 , mCompartment ( "" )
66 , mInitialAmount ( 0.0 )
67 , mInitialConcentration ( 0.0 )
68 , mSubstanceUnits ( "" )
69 , mSpatialSizeUnits ( "" )
70 , mHasOnlySubstanceUnits ( false )
71 , mBoundaryCondition ( false )
72 , mCharge ( 0 )
73 , mConstant ( false )
74 , mIsSetInitialAmount ( false )
75 , mIsSetInitialConcentration( false )
76 , mIsSetCharge ( false )
77 , mConversionFactor ( "" )
78 , mIsSetBoundaryCondition ( false )
79 , mIsSetHasOnlySubstanceUnits (false )
80 , mIsSetConstant ( false )
81 , mExplicitlySetBoundaryCondition ( false )
82 , mExplicitlySetConstant ( false )
83 , mExplicitlySetHasOnlySubsUnits ( false )
84 {
85 if (!hasValidLevelVersionNamespaceCombination())
86 throw SBMLConstructorException();
87
88 // if level 3 values have no defaults
89 if (level == 3)
90 {
91 mInitialAmount = numeric_limits<double>::quiet_NaN();
92 mInitialConcentration = numeric_limits<double>::quiet_NaN();
93 }
94 // before level 3 bc hOSU and constant were set by default
95 if (level < 3)
96 {
97 mIsSetBoundaryCondition = true;
98 }
99 if (level == 2)
100 {
101 mIsSetHasOnlySubstanceUnits = true;
102 mIsSetConstant = true;
103 }
104 }
105
106
Species(SBMLNamespaces * sbmlns)107 Species::Species (SBMLNamespaces *sbmlns) :
108 SBase ( sbmlns )
109 , mSpeciesType ( "" )
110 , mCompartment ( "" )
111 , mInitialAmount ( 0.0 )
112 , mInitialConcentration ( 0.0 )
113 , mSubstanceUnits ( "" )
114 , mSpatialSizeUnits ( "" )
115 , mHasOnlySubstanceUnits ( false )
116 , mBoundaryCondition ( false )
117 , mCharge ( 0 )
118 , mConstant ( false )
119 , mIsSetInitialAmount ( false )
120 , mIsSetInitialConcentration( false )
121 , mIsSetCharge ( false )
122 , mConversionFactor ( "" )
123 , mIsSetBoundaryCondition ( false )
124 , mIsSetHasOnlySubstanceUnits (false )
125 , mIsSetConstant ( false )
126 , mExplicitlySetBoundaryCondition ( false )
127 , mExplicitlySetConstant ( false )
128 , mExplicitlySetHasOnlySubsUnits ( false )
129 {
130 if (!hasValidLevelVersionNamespaceCombination())
131 {
132 throw SBMLConstructorException(getElementName(), sbmlns);
133 }
134
135 // if level 3 values have no defaults
136 if (sbmlns->getLevel() == 3)
137 {
138 mInitialAmount = numeric_limits<double>::quiet_NaN();
139 mInitialConcentration = numeric_limits<double>::quiet_NaN();
140 }
141 // before level 3 bc hOSU and constant were set by default
142 if (sbmlns->getLevel() < 3)
143 {
144 mIsSetBoundaryCondition = true;
145 }
146 if (sbmlns->getLevel() == 2)
147 {
148 mIsSetHasOnlySubstanceUnits = true;
149 mIsSetConstant = true;
150 }
151
152 loadPlugins(sbmlns);
153 }
154
155
156 /*
157 * Destroys this Species.
158 */
~Species()159 Species::~Species ()
160 {
161 }
162
163
164 /*
165 * Copy constructor. Creates a copy of this Species.
166 */
Species(const Species & orig)167 Species::Species(const Species& orig)
168 : SBase ( orig )
169 , mSpeciesType ( orig.mSpeciesType)
170 , mCompartment ( orig.mCompartment)
171 , mInitialAmount ( orig.mInitialAmount)
172 , mInitialConcentration ( orig.mInitialConcentration)
173 , mSubstanceUnits ( orig.mSubstanceUnits)
174 , mSpatialSizeUnits ( orig.mSpatialSizeUnits)
175 , mHasOnlySubstanceUnits ( orig.mHasOnlySubstanceUnits)
176 , mBoundaryCondition ( orig.mBoundaryCondition)
177 , mCharge ( orig.mCharge)
178 , mConstant ( orig.mConstant)
179 , mIsSetInitialAmount ( orig.mIsSetInitialAmount)
180 , mIsSetInitialConcentration ( orig.mIsSetInitialConcentration)
181 , mIsSetCharge ( orig.mIsSetCharge)
182 , mConversionFactor ( orig.mConversionFactor)
183 , mIsSetBoundaryCondition ( orig.mIsSetBoundaryCondition)
184 , mIsSetHasOnlySubstanceUnits ( orig.mIsSetHasOnlySubstanceUnits)
185 , mIsSetConstant ( orig.mIsSetConstant)
186 , mExplicitlySetBoundaryCondition ( orig.mExplicitlySetBoundaryCondition)
187 , mExplicitlySetConstant ( orig.mExplicitlySetConstant)
188 , mExplicitlySetHasOnlySubsUnits ( orig.mExplicitlySetHasOnlySubsUnits)
189 {
190 }
191
192
193 /*
194 * Assignment operator.
195 */
operator =(const Species & rhs)196 Species& Species::operator=(const Species& rhs)
197 {
198 if(&rhs!=this)
199 {
200 this->SBase::operator =(rhs);
201 this->mSpeciesType = rhs.mSpeciesType;
202 this->mCompartment = rhs.mCompartment;
203
204 this->mInitialAmount = rhs.mInitialAmount;
205 this->mInitialConcentration = rhs.mInitialConcentration;
206
207 this->mSubstanceUnits = rhs.mSubstanceUnits;
208 this->mSpatialSizeUnits = rhs.mSpatialSizeUnits;
209
210 this->mHasOnlySubstanceUnits = rhs.mHasOnlySubstanceUnits;
211 this->mBoundaryCondition = rhs.mBoundaryCondition;
212 this->mCharge = rhs.mCharge;
213 this->mConstant = rhs.mConstant;
214
215 this->mIsSetInitialAmount = rhs.mIsSetInitialAmount;
216 this->mIsSetInitialConcentration = rhs.mIsSetInitialConcentration;
217 this->mIsSetCharge = rhs.mIsSetCharge;
218 this->mConversionFactor = rhs.mConversionFactor;
219 this->mIsSetBoundaryCondition = rhs.mIsSetBoundaryCondition;
220 this->mIsSetHasOnlySubstanceUnits = rhs.mIsSetHasOnlySubstanceUnits;
221 this->mIsSetConstant = rhs.mIsSetConstant;
222 this->mExplicitlySetBoundaryCondition = rhs.mExplicitlySetBoundaryCondition;
223 this->mExplicitlySetConstant = rhs.mExplicitlySetConstant;
224 this->mExplicitlySetHasOnlySubsUnits = rhs.mExplicitlySetHasOnlySubsUnits;
225 }
226
227 return *this;
228 }
229
230
231 /** @cond doxygenLibsbmlInternal */
232 bool
accept(SBMLVisitor & v) const233 Species::accept (SBMLVisitor& v) const
234 {
235 return v.visit(*this);
236 }
237 /** @endcond */
238
239
240 /*
241 * @return a (deep) copy of this Species.
242 */
243 Species*
clone() const244 Species::clone () const
245 {
246 return new Species(*this);
247 }
248
249
250 /*
251 * Initializes the fields of this Species to their defaults:
252 *
253 * - boundaryCondition = false
254 * - constant = false (L2 only)
255 * - hasOnlySubstanceUnits = false (L2 only)
256 */
257 void
initDefaults()258 Species::initDefaults ()
259 {
260 setBoundaryCondition (false);
261 setConstant (false);
262 setHasOnlySubstanceUnits (false);
263
264 mExplicitlySetBoundaryCondition = false;
265 mExplicitlySetConstant = false;
266 mExplicitlySetHasOnlySubsUnits = false;
267 if (getLevel() > 2)
268 {
269 setSubstanceUnits("mole");
270 }
271 }
272
273
274 /*
275 * @return the id of this SBML object.
276 */
277 const string&
getId() const278 Species::getId () const
279 {
280 return mId;
281 }
282
283
284 /*
285 * @return the name of this SBML object.
286 */
287 const string&
getName() const288 Species::getName () const
289 {
290 return (getLevel() == 1) ? mId : mName;
291 }
292
293
294 /*
295 * @return the speciesType of this Species.
296 */
297 const string&
getSpeciesType() const298 Species::getSpeciesType () const
299 {
300 return mSpeciesType;
301 }
302
303
304 /*
305 * @return the compartment of this Species.
306 */
307 const string&
getCompartment() const308 Species::getCompartment () const
309 {
310 return mCompartment;
311 }
312
313
314 /*
315 * @return the initialAmount of this Species.
316 */
317 double
getInitialAmount() const318 Species::getInitialAmount () const
319 {
320 double initialAmount = mInitialAmount;
321
322 // need to cover case where user has changed level
323 // and expects an initial amount where there was none
324 if ( getLevel() == 1 && isSetInitialConcentration() )
325 {
326 const Compartment *c = getModel()->getCompartment(getCompartment());
327 if (c != NULL)
328 {
329 initialAmount = mInitialConcentration * c->getSize();
330 }
331 }
332
333 return initialAmount;
334 }
335
336
337 /*
338 * @return the initialConcentration of this Species.
339 */
340 double
getInitialConcentration() const341 Species::getInitialConcentration () const
342 {
343 return mInitialConcentration;
344 }
345
346
347 /*
348 * @return the substanceUnits of this Species.
349 */
350 const string&
getSubstanceUnits() const351 Species::getSubstanceUnits () const
352 {
353 return mSubstanceUnits;
354 }
355
356
357 /*
358 * @return the spatialSizeUnits of this Species.
359 */
360 const string&
getSpatialSizeUnits() const361 Species::getSpatialSizeUnits () const
362 {
363 return mSpatialSizeUnits;
364 }
365
366
367 /*
368 * @return the units of this Species (L1 only).
369 */
370 const string&
getUnits() const371 Species::getUnits () const
372 {
373 return mSubstanceUnits;
374 }
375
376
377 /*
378 * @return @c true if this Species hasOnlySubstanceUnits, false otherwise.
379 */
380 bool
getHasOnlySubstanceUnits() const381 Species::getHasOnlySubstanceUnits () const
382 {
383 return mHasOnlySubstanceUnits;
384 }
385
386
387 /*
388 * @return @c true if this Species has boundaryCondition
389 * true, false otherwise.
390 */
391 bool
getBoundaryCondition() const392 Species::getBoundaryCondition () const
393 {
394 return mBoundaryCondition;
395 }
396
397
398 /*
399 * @return the charge of this Species.
400 */
401 int
getCharge() const402 Species::getCharge () const
403 {
404 return mCharge;
405 }
406
407
408 /*
409 * @return @c true if this Species is constant, false otherwise.
410 */
411 bool
getConstant() const412 Species::getConstant () const
413 {
414 return mConstant;
415 }
416
417
418 /*
419 * @return the conversionFactor of this Species, as a string.
420 */
421 const std::string&
getConversionFactor() const422 Species::getConversionFactor () const
423 {
424 return mConversionFactor;
425 }
426
427
428 /*
429 * @return @c true if the id of this SBML object has been set, false
430 * otherwise.
431 */
432 bool
isSetId() const433 Species::isSetId () const
434 {
435 return (mId.empty() == false);
436 }
437
438
439 /*
440 * @return @c true if the name of this SBML object is set, false
441 * otherwise.
442 */
443 bool
isSetName() const444 Species::isSetName () const
445 {
446 return (getLevel() == 1) ? (mId.empty() == false) :
447 (mName.empty() == false);
448 }
449
450
451 /*
452 * @return @c true if the speciesType of this Species is set, false
453 * otherwise.
454 */
455 bool
isSetSpeciesType() const456 Species::isSetSpeciesType () const
457 {
458 return (mSpeciesType.empty() == false);
459 }
460
461
462 /*
463 * @return @c true if the compartment of this Species is set, false
464 * otherwise.
465 */
466 bool
isSetCompartment() const467 Species::isSetCompartment () const
468 {
469 return (mCompartment.empty() == false);
470 }
471
472
473 /*
474 * @return @c true if the initialAmount of this Species is set, false
475 * otherwise.
476 *
477 * In SBML L1, a Species initialAmount is required and therefore <b>should
478 * always be set</b>. In L2, initialAmount is optional and as such may or
479 * may not be set.
480 */
481 bool
isSetInitialAmount() const482 Species::isSetInitialAmount () const
483 {
484 return mIsSetInitialAmount;
485 }
486
487
488 /*
489 * @return @c true if the initialConcentration of this Species is set,
490 * false otherwise.
491 */
492 bool
isSetInitialConcentration() const493 Species::isSetInitialConcentration () const
494 {
495 return mIsSetInitialConcentration;
496 }
497
498
499 /*
500 * @return @c true if the substanceUnits of this Species is set, false
501 * otherwise.
502 */
503 bool
isSetSubstanceUnits() const504 Species::isSetSubstanceUnits () const
505 {
506 return (mSubstanceUnits.empty() == false);
507 }
508
509
510 /*
511 * @return @c true if the spatialSizeUnits of this Species is set, false
512 * otherwise.
513 */
514 bool
isSetSpatialSizeUnits() const515 Species::isSetSpatialSizeUnits () const
516 {
517 return (mSpatialSizeUnits.empty() == false);
518 }
519
520
521 /*
522 * @return @c true if the units of this Species is set, false otherwise
523 * (L1 only).
524 */
525 bool
isSetUnits() const526 Species::isSetUnits () const
527 {
528 return isSetSubstanceUnits();
529 }
530
531
532 /*
533 * @return @c true if the charge of this Species is set, false
534 * otherwise.
535 */
536 bool
isSetCharge() const537 Species::isSetCharge () const
538 {
539 return mIsSetCharge;
540 }
541
542
543 /*
544 * @return @c true if the conversionFactor of this Species is set, false
545 * otherwise.
546 */
547 bool
isSetConversionFactor() const548 Species::isSetConversionFactor () const
549 {
550 return (mConversionFactor.empty() == false);
551 }
552
553
554 /*
555 * Predicate returning @c true if this
556 * Species's "boundaryCondition" attribute is set.
557 */
558 bool
isSetBoundaryCondition() const559 Species::isSetBoundaryCondition () const
560 {
561 return mIsSetBoundaryCondition;
562 }
563
564
565 /*
566 * Predicate returning @c true if this
567 * Species's "hasOnlySubstanceUnits" attribute is set.
568 */
569 bool
isSetHasOnlySubstanceUnits() const570 Species::isSetHasOnlySubstanceUnits () const
571 {
572 return mIsSetHasOnlySubstanceUnits;
573 }
574
575
576 /*
577 * Predicate returning @c true if this
578 * Species's "constant" attribute is set.
579 */
580 bool
isSetConstant() const581 Species::isSetConstant () const
582 {
583 return mIsSetConstant;
584 }
585
586
587 /*
588 * Sets the id of this SBML object to a copy of @p sid.
589 */
590 int
setId(const std::string & sid)591 Species::setId (const std::string& sid)
592 {
593 /* since the setId function has been used as an
594 * alias for setName we cant require it to only
595 * be used on a L2 model
596 */
597 /* if (getLevel() == 1)
598 {
599 return LIBSBML_UNEXPECTED_ATTRIBUTE;
600 }
601 */
602 if (!(SyntaxChecker::isValidInternalSId(sid)))
603 {
604 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
605 }
606 else
607 {
608 mId = sid;
609 return LIBSBML_OPERATION_SUCCESS;
610 }
611 }
612
613
614 /*
615 * Sets the name of this SBML object to a copy of name.
616 */
617 int
setName(const std::string & name)618 Species::setName (const std::string& name)
619 {
620 /* if this is setting an L2 name the type is string
621 * whereas if it is setting an L1 name its type is SId
622 */
623 if (getLevel() == 1)
624 {
625 if (!(SyntaxChecker::isValidInternalSId(name)))
626 {
627 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
628 }
629 else
630 {
631 mId = name;
632 return LIBSBML_OPERATION_SUCCESS;
633 }
634 }
635 else
636 {
637 mName = name;
638 return LIBSBML_OPERATION_SUCCESS;
639 }
640 }
641
642
643 /*
644 * Sets the speciesType field of this Species to a copy of @p sid.
645 */
646 int
setSpeciesType(const std::string & sid)647 Species::setSpeciesType (const std::string& sid)
648 {
649 if ( (getLevel() < 2)
650 || (getLevel() == 2 && getVersion() == 1))
651 {
652 return LIBSBML_UNEXPECTED_ATTRIBUTE;
653 }
654 else if (!(SyntaxChecker::isValidInternalSId(sid)))
655 {
656 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
657 }
658 else
659 {
660 mSpeciesType = sid;
661 return LIBSBML_OPERATION_SUCCESS;
662 }
663 }
664
665
666 /*
667 * Sets the compartment of this Species to a copy of @p sid.
668 */
669 int
setCompartment(const std::string & sid)670 Species::setCompartment (const std::string& sid)
671 {
672 if (!(SyntaxChecker::isValidInternalSId(sid)))
673 {
674 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
675 }
676 else
677 {
678 mCompartment = sid;
679 return LIBSBML_OPERATION_SUCCESS;
680 }
681 }
682
683
684 /*
685 * Sets the initialAmount of this Species to value and marks the field as
686 * set. This method also unsets the initialConcentration field.
687 */
688 int
setInitialAmount(double value)689 Species::setInitialAmount (double value)
690 {
691 mInitialAmount = value;
692 mIsSetInitialAmount = true;
693
694 unsetInitialConcentration();
695 return LIBSBML_OPERATION_SUCCESS;
696 }
697
698
699 /*
700 * Sets the initialConcentration of this Species to value and marks the
701 * field as set. This method also unsets the initialAmount field.
702 */
703 int
setInitialConcentration(double value)704 Species::setInitialConcentration (double value)
705 {
706 if ( getLevel() < 2)
707 {
708 return LIBSBML_UNEXPECTED_ATTRIBUTE;
709 }
710 else
711 {
712 mInitialConcentration = value;
713 mIsSetInitialConcentration = true;
714
715 unsetInitialAmount();
716 return LIBSBML_OPERATION_SUCCESS;
717 }
718 }
719
720
721 /*
722 * Sets the substanceUnits of this Species to a copy of @p sid.
723 */
724 int
setSubstanceUnits(const std::string & sid)725 Species::setSubstanceUnits (const std::string& sid)
726 {
727 if (!(SyntaxChecker::isValidInternalSId(sid)))
728 {
729 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
730 }
731 else
732 {
733 mSubstanceUnits = sid;
734 return LIBSBML_OPERATION_SUCCESS;
735 }
736 }
737
738
739 /*
740 * Sets the spatialSizeUnits of this Species to a copy of @p sid.
741 */
742 int
setSpatialSizeUnits(const std::string & sid)743 Species::setSpatialSizeUnits (const std::string& sid)
744 {
745 if ( (getLevel() != 2)
746 || (getLevel() == 2 && getVersion() > 2))
747 {
748 return LIBSBML_UNEXPECTED_ATTRIBUTE;
749 }
750 else if (!(SyntaxChecker::isValidInternalSId(sid)))
751 {
752 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
753 }
754 else
755 {
756 mSpatialSizeUnits = sid;
757 return LIBSBML_OPERATION_SUCCESS;
758 }
759 }
760
761
762 /*
763 * Sets the units of this Species to a copy of sname (L1 only).
764 */
765 int
setUnits(const std::string & sname)766 Species::setUnits (const std::string& sname)
767 {
768 return setSubstanceUnits(sname);
769 }
770
771
772 /*
773 * Sets the hasOnlySubstanceUnits field of this Species to value.
774 */
775 int
setHasOnlySubstanceUnits(bool value)776 Species::setHasOnlySubstanceUnits (bool value)
777 {
778 if (getLevel() < 2)
779 {
780 return LIBSBML_UNEXPECTED_ATTRIBUTE;
781 }
782 else
783 {
784 mHasOnlySubstanceUnits = value;
785 mIsSetHasOnlySubstanceUnits = true;
786 mExplicitlySetHasOnlySubsUnits = true;
787 return LIBSBML_OPERATION_SUCCESS;
788 }
789 }
790
791
792 /*
793 * Sets the boundaryCondition of this Species to value.
794 */
795 int
setBoundaryCondition(bool value)796 Species::setBoundaryCondition (bool value)
797 {
798 mBoundaryCondition = value;
799 mIsSetBoundaryCondition = true;
800 mExplicitlySetBoundaryCondition = true;
801 return LIBSBML_OPERATION_SUCCESS;
802 }
803
804
805 /*
806 * Sets the charge of this Species to value and marks the field as set.
807 */
808 int
setCharge(int value)809 Species::setCharge (int value)
810 {
811 if ( !((getLevel() == 1)
812 || (getLevel() == 2 && getVersion() == 1)))
813 {
814 return LIBSBML_UNEXPECTED_ATTRIBUTE;
815 }
816 else
817 {
818 mCharge = value;
819 mIsSetCharge = true;
820 return LIBSBML_OPERATION_SUCCESS;
821 }
822 }
823
824
825 /*
826 * Sets the constant field of this Species to value.
827 */
828 int
setConstant(bool value)829 Species::setConstant (bool value)
830 {
831 if ( getLevel() < 2 )
832 {
833 mConstant = value;
834 return LIBSBML_UNEXPECTED_ATTRIBUTE;
835 }
836 else
837 {
838 mConstant = value;
839 mIsSetConstant = true;
840 mExplicitlySetConstant = true;
841 return LIBSBML_OPERATION_SUCCESS;
842 }
843 }
844
845
846 /*
847 * Sets the conversionFactor field of this Species to a copy of @p sid.
848 */
849 int
setConversionFactor(const std::string & sid)850 Species::setConversionFactor (const std::string& sid)
851 {
852 if (getLevel() < 3)
853 {
854 return LIBSBML_UNEXPECTED_ATTRIBUTE;
855 }
856 else if (!(SyntaxChecker::isValidInternalSId(sid)))
857 {
858 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
859 }
860 else
861 {
862 mConversionFactor = sid;
863 return LIBSBML_OPERATION_SUCCESS;
864 }
865 }
866
867
868 /*
869 * Unsets the name of this SBML object.
870 */
871 int
unsetName()872 Species::unsetName ()
873 {
874 if (getLevel() == 1)
875 {
876 mId.erase();
877 }
878 else
879 {
880 mName.erase();
881 }
882
883 if (getLevel() == 1 && mId.empty())
884 {
885 return LIBSBML_OPERATION_SUCCESS;
886 }
887 else if (mName.empty())
888 {
889 return LIBSBML_OPERATION_SUCCESS;
890 }
891 else
892 {
893 return LIBSBML_OPERATION_FAILED;
894 }
895 }
896
897
898 int
unsetConstant()899 Species::unsetConstant ()
900 {
901 if ( getLevel() < 2 )
902 {
903 mConstant = false;
904 return LIBSBML_UNEXPECTED_ATTRIBUTE;
905 }
906 else if (getLevel() == 2)
907 {
908 // reset default
909 mConstant = false;
910 mIsSetConstant = true;
911 mExplicitlySetConstant = false;
912 return LIBSBML_UNEXPECTED_ATTRIBUTE;
913 }
914 else
915 {
916 mIsSetConstant = false;
917 mExplicitlySetConstant = false;
918 return LIBSBML_OPERATION_SUCCESS;
919 }
920 }
921
922
923 /*
924 * Unsets the speciesType of this Species.
925 */
926 int
unsetSpeciesType()927 Species::unsetSpeciesType ()
928 {
929 mSpeciesType.erase();
930
931 if (mSpeciesType.empty())
932 {
933 return LIBSBML_OPERATION_SUCCESS;
934 }
935 else
936 {
937 return LIBSBML_OPERATION_FAILED;
938 }
939 }
940
941
942 /*
943 * Unsets the initialAmount of this Species.
944 */
945 int
unsetInitialAmount()946 Species::unsetInitialAmount ()
947 {
948 mInitialAmount = numeric_limits<double>::quiet_NaN();
949 mIsSetInitialAmount = false;
950
951 if (!isSetInitialAmount())
952 {
953 return LIBSBML_OPERATION_SUCCESS;
954 }
955 else
956 {
957 return LIBSBML_OPERATION_FAILED;
958 }
959 }
960
961
962 /*
963 * Unsets the initialConcentration of this Species.
964 */
965 int
unsetInitialConcentration()966 Species::unsetInitialConcentration ()
967 {
968 mInitialConcentration = numeric_limits<double>::quiet_NaN();
969 mIsSetInitialConcentration = false;
970
971 if (!isSetInitialConcentration())
972 {
973 return LIBSBML_OPERATION_SUCCESS;
974 }
975 else
976 {
977 return LIBSBML_OPERATION_FAILED;
978 }
979 }
980
981
982 /*
983 * Unsets the substanceUnits of this Species.
984 */
985 int
unsetSubstanceUnits()986 Species::unsetSubstanceUnits ()
987 {
988 mSubstanceUnits.erase();
989
990 if (mSubstanceUnits.empty())
991 {
992 return LIBSBML_OPERATION_SUCCESS;
993 }
994 else
995 {
996 return LIBSBML_OPERATION_FAILED;
997 }
998 }
999
1000
1001 /*
1002 * Unsets the spatialSizeUnits of this Species.
1003 */
1004 int
unsetSpatialSizeUnits()1005 Species::unsetSpatialSizeUnits ()
1006 {
1007 mSpatialSizeUnits.erase();
1008
1009 if (mSpatialSizeUnits.empty())
1010 {
1011 return LIBSBML_OPERATION_SUCCESS;
1012 }
1013 else
1014 {
1015 return LIBSBML_OPERATION_FAILED;
1016 }
1017 }
1018
1019
1020 /*
1021 * Unsets the units of this Species (L1 only).
1022 */
1023 int
unsetUnits()1024 Species::unsetUnits ()
1025 {
1026 return unsetSubstanceUnits();
1027 }
1028
1029
1030 /*
1031 * Unsets the charge of this Species.
1032 */
1033 int
unsetCharge()1034 Species::unsetCharge ()
1035 {
1036 if ( !((getLevel() == 1)
1037 || (getLevel() == 2 && getVersion() == 1)))
1038 {
1039 return LIBSBML_UNEXPECTED_ATTRIBUTE;
1040 }
1041
1042 mCharge = 0;
1043 mIsSetCharge = false;
1044
1045 if (!isSetCharge())
1046 {
1047 return LIBSBML_OPERATION_SUCCESS;
1048 }
1049 else
1050 {
1051 return LIBSBML_OPERATION_FAILED;
1052 }
1053 }
1054
1055
1056 /*
1057 * Unsets the conversionFactor of this Species.
1058 */
1059 int
unsetConversionFactor()1060 Species::unsetConversionFactor ()
1061 {
1062 /* only in L3 */
1063 if (getLevel() < 3)
1064 {
1065 return LIBSBML_UNEXPECTED_ATTRIBUTE;
1066 }
1067
1068 mConversionFactor.erase();
1069
1070 if (mConversionFactor.empty())
1071 {
1072 return LIBSBML_OPERATION_SUCCESS;
1073 }
1074 else
1075 {
1076 return LIBSBML_OPERATION_FAILED;
1077 }
1078 }
1079
1080
1081 /*
1082 * Unsets the hasOnlySubstanceUnits field of this Species to value.
1083 */
1084 int
unsetHasOnlySubstanceUnits()1085 Species::unsetHasOnlySubstanceUnits ()
1086 {
1087 if (getLevel() < 2)
1088 {
1089 return LIBSBML_UNEXPECTED_ATTRIBUTE;
1090 }
1091 else if (getLevel() == 2)
1092 {
1093 // reset defaults
1094 mHasOnlySubstanceUnits = false;
1095 mIsSetHasOnlySubstanceUnits = true;
1096 mExplicitlySetHasOnlySubsUnits = false;
1097 return LIBSBML_UNEXPECTED_ATTRIBUTE;
1098 }
1099 else
1100 {
1101 mIsSetHasOnlySubstanceUnits = false;
1102 mExplicitlySetHasOnlySubsUnits = false;
1103 return LIBSBML_OPERATION_SUCCESS;
1104 }
1105 }
1106
1107
1108 int
unsetBoundaryCondition()1109 Species::unsetBoundaryCondition ()
1110 {
1111 if (getLevel() < 3)
1112 {
1113 // reset default
1114 mBoundaryCondition = false;
1115 mIsSetBoundaryCondition = true;
1116 mExplicitlySetBoundaryCondition = false;
1117 return LIBSBML_UNEXPECTED_ATTRIBUTE;
1118 }
1119
1120 mIsSetBoundaryCondition = false;
1121 mExplicitlySetBoundaryCondition = false;
1122 return LIBSBML_OPERATION_SUCCESS;
1123 }
1124
1125
1126 int
unsetCompartment()1127 Species::unsetCompartment ()
1128 {
1129 mCompartment.erase();
1130
1131 if (mCompartment.empty())
1132 {
1133 return LIBSBML_OPERATION_SUCCESS;
1134 }
1135 else
1136 {
1137 return LIBSBML_OPERATION_FAILED;
1138 }
1139 }
1140
1141
1142 /*
1143 * Constructs and returns a UnitDefinition that expresses the units of this
1144 * Species.
1145 */
1146 UnitDefinition *
getDerivedUnitDefinition()1147 Species::getDerivedUnitDefinition()
1148 {
1149 /* if we have the whole model but it is not in a document
1150 * it is still possible to determine the units
1151 */
1152
1153 /* VERY NASTY HACK THAT WILL WORK IF WE DONT KNOW ABOUT COMP
1154 * but will identify if the parent model is a ModelDefinition
1155 */
1156 Model * m = NULL;
1157
1158 if (this->isPackageEnabled("comp"))
1159 {
1160 m = static_cast <Model *> (getAncestorOfType(251, "comp"));
1161 }
1162
1163 if (m == NULL)
1164 {
1165 m = static_cast <Model *> (getAncestorOfType(SBML_MODEL));
1166 }
1167
1168 /* we should have a model by this point
1169 * OR the object is not yet a child of a model
1170 */
1171
1172 if (m != NULL)
1173 {
1174 if (!m->isPopulatedListFormulaUnitsData())
1175 {
1176 m->populateListFormulaUnitsData();
1177 }
1178
1179 FormulaUnitsData *fud = m->getFormulaUnitsData(getId(), getTypeCode());
1180 if (fud != NULL)
1181 {
1182 return fud->getUnitDefinition();
1183 }
1184 else
1185 {
1186 return NULL;
1187 }
1188 }
1189 else
1190 {
1191 return NULL;
1192 }
1193 }
1194
1195
1196 /*
1197 * Constructs and returns a UnitDefinition that expresses the units of this
1198 * Compartment.
1199 */
1200 const UnitDefinition *
getDerivedUnitDefinition() const1201 Species::getDerivedUnitDefinition() const
1202 {
1203 return const_cast <Species *> (this)->getDerivedUnitDefinition();
1204 }
1205
1206
1207 /*
1208 * @return the typecode (int) of this SBML object or SBML_UNKNOWN
1209 * (default).
1210 *
1211 * @see getElementName()
1212 */
1213 int
getTypeCode() const1214 Species::getTypeCode () const
1215 {
1216 return SBML_SPECIES;
1217 }
1218
1219
1220 /*
1221 * @return the name of this element ie "specie" (L1) or "species" (L2).
1222 */
1223 const string&
getElementName() const1224 Species::getElementName () const
1225 {
1226 static const string specie = "specie";
1227 static const string species = "species";
1228
1229 return (getLevel() == 1 && getVersion() == 1) ? specie : species;
1230 }
1231
1232
1233 bool
hasRequiredAttributes() const1234 Species::hasRequiredAttributes() const
1235 {
1236 bool allPresent = true;
1237
1238 /* required attributes for species:
1239 * @li id (name L1)
1240 * @li compartment
1241 * @li initialAmount (L1 only)
1242 * @li hasOnlySubstanceUnits (L3 on)
1243 * @li boundaryCondition (L3 on)
1244 * @li constant (L3 on)
1245 */
1246
1247 if (!isSetId())
1248 allPresent = false;
1249
1250 if (!isSetCompartment())
1251 allPresent = false;
1252
1253 if (getLevel() == 1 && !isSetInitialAmount())
1254 allPresent = false;
1255
1256 if (getLevel() > 2 && !isSetHasOnlySubstanceUnits())
1257 allPresent = false;
1258
1259 if (getLevel() > 2 && !isSetBoundaryCondition())
1260 allPresent = false;
1261
1262 if (getLevel() > 2 && !isSetConstant())
1263 allPresent = false;
1264
1265 return allPresent;
1266 }
1267
1268
1269
1270
1271
1272
1273
1274 /** @cond doxygenLibsbmlInternal */
1275
1276 /*
1277 * Returns the value of the "attributeName" attribute of this Species.
1278 */
1279 int
getAttribute(const std::string & attributeName,bool & value) const1280 Species::getAttribute(const std::string& attributeName, bool& value) const
1281 {
1282 int return_value = SBase::getAttribute(attributeName, value);
1283
1284 if (return_value == LIBSBML_OPERATION_SUCCESS)
1285 {
1286 return return_value;
1287 }
1288
1289 if (attributeName == "hasOnlySubstanceUnits")
1290 {
1291 value = getHasOnlySubstanceUnits();
1292 return_value = LIBSBML_OPERATION_SUCCESS;
1293 }
1294 else if (attributeName == "boundaryCondition")
1295 {
1296 value = getBoundaryCondition();
1297 return_value = LIBSBML_OPERATION_SUCCESS;
1298 }
1299 else if (attributeName == "constant")
1300 {
1301 value = getConstant();
1302 return_value = LIBSBML_OPERATION_SUCCESS;
1303 }
1304
1305 return return_value;
1306 }
1307
1308 /** @endcond */
1309
1310
1311
1312 /** @cond doxygenLibsbmlInternal */
1313
1314 /*
1315 * Returns the value of the "attributeName" attribute of this Species.
1316 */
1317 int
getAttribute(const std::string & attributeName,int & value) const1318 Species::getAttribute(const std::string& attributeName, int& value) const
1319 {
1320 int return_value = SBase::getAttribute(attributeName, value);
1321
1322 if (return_value == LIBSBML_OPERATION_SUCCESS)
1323 {
1324 return return_value;
1325 }
1326
1327 if (attributeName == "charge")
1328 {
1329 value = getCharge();
1330 return_value = LIBSBML_OPERATION_SUCCESS;
1331 }
1332
1333 return return_value;
1334 }
1335
1336 /** @endcond */
1337
1338
1339
1340 /** @cond doxygenLibsbmlInternal */
1341
1342 /*
1343 * Returns the value of the "attributeName" attribute of this Species.
1344 */
1345 int
getAttribute(const std::string & attributeName,double & value) const1346 Species::getAttribute(const std::string& attributeName, double& value) const
1347 {
1348 int return_value = SBase::getAttribute(attributeName, value);
1349
1350 if (return_value == LIBSBML_OPERATION_SUCCESS)
1351 {
1352 return return_value;
1353 }
1354
1355 if (attributeName == "initialAmount")
1356 {
1357 value = getInitialAmount();
1358 return_value = LIBSBML_OPERATION_SUCCESS;
1359 }
1360 else if (attributeName == "initialConcentration")
1361 {
1362 value = getInitialConcentration();
1363 return_value = LIBSBML_OPERATION_SUCCESS;
1364 }
1365
1366 return return_value;
1367 }
1368
1369 /** @endcond */
1370
1371
1372
1373 /** @cond doxygenLibsbmlInternal */
1374
1375 /*
1376 * Returns the value of the "attributeName" attribute of this Species.
1377 */
1378 int
getAttribute(const std::string & attributeName,unsigned int & value) const1379 Species::getAttribute(const std::string& attributeName,
1380 unsigned int& value) const
1381 {
1382 int return_value = SBase::getAttribute(attributeName, value);
1383
1384 return return_value;
1385 }
1386
1387 /** @endcond */
1388
1389
1390
1391 /** @cond doxygenLibsbmlInternal */
1392
1393 /*
1394 * Returns the value of the "attributeName" attribute of this Species.
1395 */
1396 int
getAttribute(const std::string & attributeName,std::string & value) const1397 Species::getAttribute(const std::string& attributeName,
1398 std::string& value) const
1399 {
1400 int return_value = SBase::getAttribute(attributeName, value);
1401
1402 if (return_value == LIBSBML_OPERATION_SUCCESS)
1403 {
1404 return return_value;
1405 }
1406
1407 if (attributeName == "compartment")
1408 {
1409 value = getCompartment();
1410 return_value = LIBSBML_OPERATION_SUCCESS;
1411 }
1412 else if (attributeName == "substanceUnits")
1413 {
1414 value = getSubstanceUnits();
1415 return_value = LIBSBML_OPERATION_SUCCESS;
1416 }
1417 else if (attributeName == "conversionFactor")
1418 {
1419 value = getConversionFactor();
1420 return_value = LIBSBML_OPERATION_SUCCESS;
1421 }
1422 else if (attributeName == "speciesType")
1423 {
1424 value = getSpeciesType();
1425 return_value = LIBSBML_OPERATION_SUCCESS;
1426 }
1427 else if (attributeName == "spatialSizeUnits")
1428 {
1429 value = getSpatialSizeUnits();
1430 return_value = LIBSBML_OPERATION_SUCCESS;
1431 }
1432 else if (attributeName == "units")
1433 {
1434 value = getUnits();
1435 return_value = LIBSBML_OPERATION_SUCCESS;
1436 }
1437
1438 return return_value;
1439 }
1440
1441 /** @endcond */
1442
1443
1444
1445 /** @cond doxygenLibsbmlInternal */
1446
1447 /*
1448 * Returns the value of the "attributeName" attribute of this Species.
1449 */
1450 //int
1451 //Species::getAttribute(const std::string& attributeName,
1452 // const char* value) const
1453 //{
1454 // int return_value = SBase::getAttribute(attributeName, value);
1455 //
1456 // if (return_value == LIBSBML_OPERATION_SUCCESS)
1457 // {
1458 // return return_value;
1459 // }
1460 //
1461 // if (attributeName == "compartment")
1462 // {
1463 // value = getCompartment().c_str();
1464 // return_value = LIBSBML_OPERATION_SUCCESS;
1465 // }
1466 // else if (attributeName == "substanceUnits")
1467 // {
1468 // value = getSubstanceUnits().c_str();
1469 // return_value = LIBSBML_OPERATION_SUCCESS;
1470 // }
1471 // else if (attributeName == "conversionFactor")
1472 // {
1473 // value = getConversionFactor().c_str();
1474 // return_value = LIBSBML_OPERATION_SUCCESS;
1475 // }
1476 // else if (attributeName == "speciesType")
1477 // {
1478 // value = getSpeciesType().c_str();
1479 // return_value = LIBSBML_OPERATION_SUCCESS;
1480 // }
1481 // else if (attributeName == "spatialSizeUnits")
1482 // {
1483 // value = getSpatialSizeUnits().c_str();
1484 // return_value = LIBSBML_OPERATION_SUCCESS;
1485 // }
1486 // else if (attributeName == "units")
1487 // {
1488 // value = getUnits().c_str();
1489 // return_value = LIBSBML_OPERATION_SUCCESS;
1490 // }
1491 //
1492 // return return_value;
1493 //}
1494 //
1495 /** @endcond */
1496
1497
1498
1499 /** @cond doxygenLibsbmlInternal */
1500
1501 /*
1502 * Predicate returning @c true if this Species's attribute "attributeName" is
1503 * set.
1504 */
1505 bool
isSetAttribute(const std::string & attributeName) const1506 Species::isSetAttribute(const std::string& attributeName) const
1507 {
1508 bool value = SBase::isSetAttribute(attributeName);
1509
1510 if (attributeName == "compartment")
1511 {
1512 value = isSetCompartment();
1513 }
1514 else if (attributeName == "initialAmount")
1515 {
1516 value = isSetInitialAmount();
1517 }
1518 else if (attributeName == "initialConcentration")
1519 {
1520 value = isSetInitialConcentration();
1521 }
1522 else if (attributeName == "substanceUnits")
1523 {
1524 value = isSetSubstanceUnits();
1525 }
1526 else if (attributeName == "hasOnlySubstanceUnits")
1527 {
1528 value = isSetHasOnlySubstanceUnits();
1529 }
1530 else if (attributeName == "boundaryCondition")
1531 {
1532 value = isSetBoundaryCondition();
1533 }
1534 else if (attributeName == "constant")
1535 {
1536 value = isSetConstant();
1537 }
1538 else if (attributeName == "conversionFactor")
1539 {
1540 value = isSetConversionFactor();
1541 }
1542 else if (attributeName == "charge")
1543 {
1544 value = isSetCharge();
1545 }
1546 else if (attributeName == "speciesType")
1547 {
1548 value = isSetSpeciesType();
1549 }
1550 else if (attributeName == "spatialSizeUnits")
1551 {
1552 value = isSetSpatialSizeUnits();
1553 }
1554 else if (attributeName == "units")
1555 {
1556 value = isSetUnits();
1557 }
1558
1559 return value;
1560 }
1561
1562 /** @endcond */
1563
1564
1565
1566 /** @cond doxygenLibsbmlInternal */
1567
1568 /*
1569 * Sets the value of the "attributeName" attribute of this Species.
1570 */
1571 int
setAttribute(const std::string & attributeName,bool value)1572 Species::setAttribute(const std::string& attributeName, bool value)
1573 {
1574 int return_value = SBase::setAttribute(attributeName, value);
1575
1576 if (attributeName == "hasOnlySubstanceUnits")
1577 {
1578 return_value = setHasOnlySubstanceUnits(value);
1579 }
1580 else if (attributeName == "boundaryCondition")
1581 {
1582 return_value = setBoundaryCondition(value);
1583 }
1584 else if (attributeName == "constant")
1585 {
1586 return_value = setConstant(value);
1587 }
1588
1589 return return_value;
1590 }
1591
1592 /** @endcond */
1593
1594
1595
1596 /** @cond doxygenLibsbmlInternal */
1597
1598 /*
1599 * Sets the value of the "attributeName" attribute of this Species.
1600 */
1601 int
setAttribute(const std::string & attributeName,int value)1602 Species::setAttribute(const std::string& attributeName, int value)
1603 {
1604 int return_value = SBase::setAttribute(attributeName, value);
1605
1606 if (attributeName == "charge")
1607 {
1608 return_value = setCharge(value);
1609 }
1610
1611 return return_value;
1612 }
1613
1614 /** @endcond */
1615
1616
1617
1618 /** @cond doxygenLibsbmlInternal */
1619
1620 /*
1621 * Sets the value of the "attributeName" attribute of this Species.
1622 */
1623 int
setAttribute(const std::string & attributeName,double value)1624 Species::setAttribute(const std::string& attributeName, double value)
1625 {
1626 int return_value = SBase::setAttribute(attributeName, value);
1627
1628 if (attributeName == "initialAmount")
1629 {
1630 return_value = setInitialAmount(value);
1631 }
1632 else if (attributeName == "initialConcentration")
1633 {
1634 return_value = setInitialConcentration(value);
1635 }
1636
1637 return return_value;
1638 }
1639
1640 /** @endcond */
1641
1642
1643
1644 /** @cond doxygenLibsbmlInternal */
1645
1646 /*
1647 * Sets the value of the "attributeName" attribute of this Species.
1648 */
1649 int
setAttribute(const std::string & attributeName,unsigned int value)1650 Species::setAttribute(const std::string& attributeName, unsigned int value)
1651 {
1652 int return_value = SBase::setAttribute(attributeName, value);
1653
1654 return return_value;
1655 }
1656
1657 /** @endcond */
1658
1659
1660
1661 /** @cond doxygenLibsbmlInternal */
1662
1663 /*
1664 * Sets the value of the "attributeName" attribute of this Species.
1665 */
1666 int
setAttribute(const std::string & attributeName,const std::string & value)1667 Species::setAttribute(const std::string& attributeName,
1668 const std::string& value)
1669 {
1670 int return_value = SBase::setAttribute(attributeName, value);
1671
1672 if (attributeName == "compartment")
1673 {
1674 return_value = setCompartment(value);
1675 }
1676 else if (attributeName == "substanceUnits")
1677 {
1678 return_value = setSubstanceUnits(value);
1679 }
1680 else if (attributeName == "conversionFactor")
1681 {
1682 return_value = setConversionFactor(value);
1683 }
1684 else if (attributeName == "speciesType")
1685 {
1686 return_value = setSpeciesType(value);
1687 }
1688 else if (attributeName == "spatialSizeUnits")
1689 {
1690 return_value = setSpatialSizeUnits(value);
1691 }
1692 else if (attributeName == "units")
1693 {
1694 return_value = setUnits(value);
1695 }
1696
1697 return return_value;
1698 }
1699
1700 /** @endcond */
1701
1702
1703
1704 /** @cond doxygenLibsbmlInternal */
1705
1706 /*
1707 * Sets the value of the "attributeName" attribute of this Species.
1708 */
1709 //int
1710 //Species::setAttribute(const std::string& attributeName, const char* value)
1711 //{
1712 // int return_value = SBase::setAttribute(attributeName, value);
1713 //
1714 // if (attributeName == "compartment")
1715 // {
1716 // return_value = setCompartment(value);
1717 // }
1718 // else if (attributeName == "substanceUnits")
1719 // {
1720 // return_value = setSubstanceUnits(value);
1721 // }
1722 // else if (attributeName == "conversionFactor")
1723 // {
1724 // return_value = setConversionFactor(value);
1725 // }
1726 // else if (attributeName == "speciesType")
1727 // {
1728 // return_value = setSpeciesType(value);
1729 // }
1730 // else if (attributeName == "spatialSizeUnits")
1731 // {
1732 // return_value = setSpatialSizeUnits(value);
1733 // }
1734 // else if (attributeName == "units")
1735 // {
1736 // return_value = setUnits(value);
1737 // }
1738 //
1739 // return return_value;
1740 //}
1741 //
1742 /** @endcond */
1743
1744
1745
1746 /** @cond doxygenLibsbmlInternal */
1747
1748 /*
1749 * Unsets the value of the "attributeName" attribute of this Species.
1750 */
1751 int
unsetAttribute(const std::string & attributeName)1752 Species::unsetAttribute(const std::string& attributeName)
1753 {
1754 int value = SBase::unsetAttribute(attributeName);
1755
1756 if (attributeName == "compartment")
1757 {
1758 value = unsetCompartment();
1759 }
1760 else if (attributeName == "initialAmount")
1761 {
1762 value = unsetInitialAmount();
1763 }
1764 else if (attributeName == "initialConcentration")
1765 {
1766 value = unsetInitialConcentration();
1767 }
1768 else if (attributeName == "substanceUnits")
1769 {
1770 value = unsetSubstanceUnits();
1771 }
1772 else if (attributeName == "hasOnlySubstanceUnits")
1773 {
1774 value = unsetHasOnlySubstanceUnits();
1775 }
1776 else if (attributeName == "boundaryCondition")
1777 {
1778 value = unsetBoundaryCondition();
1779 }
1780 else if (attributeName == "constant")
1781 {
1782 value = unsetConstant();
1783 }
1784 else if (attributeName == "conversionFactor")
1785 {
1786 value = unsetConversionFactor();
1787 }
1788 else if (attributeName == "charge")
1789 {
1790 value = unsetCharge();
1791 }
1792 else if (attributeName == "speciesType")
1793 {
1794 value = unsetSpeciesType();
1795 }
1796 else if (attributeName == "spatialSizeUnits")
1797 {
1798 value = unsetSpatialSizeUnits();
1799 }
1800 else if (attributeName == "units")
1801 {
1802 value = unsetUnits();
1803 }
1804
1805 return value;
1806 }
1807
isExplicitlySetBoundaryCondition() const1808 bool Species::isExplicitlySetBoundaryCondition() const
1809 {
1810 return mExplicitlySetBoundaryCondition;
1811 }
1812
isExplicitlySetConstant() const1813 bool Species::isExplicitlySetConstant() const
1814 {
1815 return mExplicitlySetConstant;
1816 }
1817
isExplicitlySetHasOnlySubsUnits() const1818 bool Species::isExplicitlySetHasOnlySubsUnits() const
1819 {
1820 return mExplicitlySetHasOnlySubsUnits;
1821 }
1822 /** @endcond */
1823
1824
1825
1826
1827 void
renameSIdRefs(const std::string & oldid,const std::string & newid)1828 Species::renameSIdRefs(const std::string& oldid, const std::string& newid)
1829 {
1830 SBase::renameSIdRefs(oldid, newid);
1831 if (isSetSpeciesType()) {
1832 if (mSpeciesType==oldid) setSpeciesType(newid);
1833 }
1834 if (isSetCompartment()) {
1835 if (mCompartment==oldid) setCompartment(newid);
1836 }
1837 if (isSetConversionFactor()) {
1838 if (mConversionFactor==oldid) setConversionFactor(newid);
1839 }
1840 }
1841
1842 void
renameUnitSIdRefs(const std::string & oldid,const std::string & newid)1843 Species::renameUnitSIdRefs(const std::string& oldid, const std::string& newid)
1844 {
1845 SBase::renameUnitSIdRefs(oldid, newid);
1846 if (isSetSubstanceUnits()) {
1847 if (mSubstanceUnits==oldid) setSubstanceUnits(newid);
1848 }
1849 if (isSetSpatialSizeUnits()) {
1850 if (mSpatialSizeUnits==oldid) setSpatialSizeUnits(newid);
1851 }
1852 }
1853
1854 /** @cond doxygenLibsbmlInternal */
1855 /**
1856 * Subclasses should override this method to get the list of
1857 * expected attributes.
1858 * This function is invoked from corresponding readAttributes()
1859 * function.
1860 */
1861 void
addExpectedAttributes(ExpectedAttributes & attributes)1862 Species::addExpectedAttributes(ExpectedAttributes& attributes)
1863 {
1864 SBase::addExpectedAttributes(attributes);
1865
1866 const unsigned int level = getLevel ();
1867 const unsigned int version = getVersion();
1868
1869 switch (level)
1870 {
1871 case 1:
1872 attributes.add("name");
1873 attributes.add("compartment");
1874 attributes.add("initialAmount");
1875 attributes.add("boundaryCondition");
1876 attributes.add("charge");
1877 attributes.add("units");
1878 break;
1879 case 2:
1880 attributes.add("name");
1881 attributes.add("compartment");
1882 attributes.add("initialAmount");
1883 attributes.add("boundaryCondition");
1884 attributes.add("charge");
1885 attributes.add("id");
1886 attributes.add("initialConcentration");
1887 attributes.add("substanceUnits");
1888 attributes.add("hasOnlySubstanceUnits");
1889 attributes.add("constant");
1890 if (version > 1)
1891 {
1892 attributes.add("speciesType");
1893 }
1894 if (version < 3)
1895 {
1896 attributes.add("spatialSizeUnits");
1897 }
1898 break;
1899 case 3:
1900 default:
1901 attributes.add("name");
1902 attributes.add("compartment");
1903 attributes.add("initialAmount");
1904 attributes.add("boundaryCondition");
1905 attributes.add("charge");
1906 attributes.add("id");
1907 attributes.add("initialConcentration");
1908 attributes.add("substanceUnits");
1909 attributes.add("hasOnlySubstanceUnits");
1910 attributes.add("constant");
1911 attributes.add("conversionFactor");
1912 break;
1913 }
1914 }
1915
1916
1917 /*
1918 * Subclasses should override this method to read values from the given
1919 * XMLAttributes set into their specific fields. Be sure to call your
1920 * parent's implementation of this method as well.
1921 */
1922 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)1923 Species::readAttributes (const XMLAttributes& attributes,
1924 const ExpectedAttributes& expectedAttributes)
1925 {
1926 const unsigned int level = getLevel ();
1927
1928 SBase::readAttributes(attributes, expectedAttributes);
1929
1930 switch (level)
1931 {
1932 case 1:
1933 readL1Attributes(attributes);
1934 break;
1935 case 2:
1936 readL2Attributes(attributes);
1937 break;
1938 case 3:
1939 default:
1940 readL3Attributes(attributes);
1941 break;
1942 }
1943 }
1944 /** @endcond */
1945
1946
1947 /** @cond doxygenLibsbmlInternal */
1948 /*
1949 * Subclasses should override this method to read values from the given
1950 * XMLAttributes set into their specific fields. Be sure to call your
1951 * parent's implementation of this method as well.
1952 */
1953 void
readL1Attributes(const XMLAttributes & attributes)1954 Species::readL1Attributes (const XMLAttributes& attributes)
1955 {
1956 const unsigned int level = getLevel ();
1957 const unsigned int version = getVersion();
1958
1959 //
1960 // name: SName { use="required" } (L1v1, L1v2)
1961 //
1962 bool assigned = attributes.readInto("name", mId, getErrorLog(), true, getLine(), getColumn());
1963 if (assigned && mId.size() == 0)
1964 {
1965 logEmptyString("name", level, version, "<species>");
1966 }
1967 if (!SyntaxChecker::isValidInternalSId(mId))
1968 logError(InvalidIdSyntax, level, version, "The id '" + mId + "' does not conform to the syntax.");
1969
1970 //
1971 // compartment: SName { use="required" } (L1v1, L2v1)
1972 //
1973 attributes.readInto("compartment", mCompartment, getErrorLog(), true, getLine(), getColumn());
1974
1975 //
1976 // initialAmount: double { use="required" } (L1v1, L1v2)
1977 //
1978 mIsSetInitialAmount = attributes.readInto("initialAmount", mInitialAmount,
1979 getErrorLog(), true, getLine(), getColumn());
1980
1981 //
1982 // units: SName { use="optional" } (L1v1, L1v2)
1983 //
1984 assigned = attributes.readInto("units", mSubstanceUnits, getErrorLog(), false, getLine(), getColumn());
1985 if (assigned && mSubstanceUnits.size() == 0)
1986 {
1987 logEmptyString("units", level, version, "<species>");
1988 }
1989 if (!SyntaxChecker::isValidInternalUnitSId(mSubstanceUnits))
1990 {
1991 logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The units attribute '" + mSubstanceUnits + "' does not conform to the syntax.");
1992 }
1993
1994 //
1995 // boundaryCondition: boolean
1996 // { use="optional" default="false" } (L1v1, L1v2, L2v1->)
1997 //
1998 mExplicitlySetBoundaryCondition =
1999 attributes.readInto("boundaryCondition", mBoundaryCondition, getErrorLog(), false, getLine(), getColumn());
2000
2001 //
2002 // charge: integer { use="optional" } (L1v1, L1v2, L2v1)
2003 //
2004 mIsSetCharge = attributes.readInto("charge", mCharge, getErrorLog(), false, getLine(), getColumn());
2005 }
2006 /** @endcond */
2007
2008
2009 /** @cond doxygenLibsbmlInternal */
2010 /*
2011 * Subclasses should override this method to read values from the given
2012 * XMLAttributes set into their specific fields. Be sure to call your
2013 * parent's implementation of this method as well.
2014 */
2015 void
readL2Attributes(const XMLAttributes & attributes)2016 Species::readL2Attributes (const XMLAttributes& attributes)
2017 {
2018 const unsigned int level = getLevel ();
2019 const unsigned int version = getVersion();
2020 //
2021 // id: SId { use="required" } (L2v1->)
2022 //
2023 bool assigned = attributes.readInto("id", mId, getErrorLog(), true, getLine(), getColumn());
2024 if (assigned && mId.size() == 0)
2025 {
2026 logEmptyString("id", level, version, "<species>");
2027 }
2028 if (!SyntaxChecker::isValidInternalSId(mId))
2029 logError(InvalidIdSyntax, level, version, "The id '" + mId + "' does not conform to the syntax.");
2030
2031 //
2032 // compartment: SId { use="required" } (L2v1->)
2033 //
2034 attributes.readInto("compartment", mCompartment, getErrorLog(), true, getLine(), getColumn());
2035
2036 //
2037 // initialAmount: double { use="optional" } (L2v1->)
2038 //
2039 mIsSetInitialAmount = attributes.readInto("initialAmount", mInitialAmount, getErrorLog(), false, getLine(), getColumn());
2040
2041 //
2042 // substanceUntis: SId { use="optional" } (L2v1->)
2043 //
2044 assigned = attributes.readInto("substanceUnits", mSubstanceUnits, getErrorLog(), false, getLine(), getColumn());
2045 if (assigned && mSubstanceUnits.size() == 0)
2046 {
2047 logEmptyString("substanceUnits", level, version, "<species>");
2048 }
2049 if (!SyntaxChecker::isValidInternalUnitSId(mSubstanceUnits))
2050 {
2051 logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The substanceUnits attribute '" + mSubstanceUnits + "' does not conform to the syntax.");
2052 }
2053
2054 //
2055 // boundaryCondition: boolean
2056 // { use="optional" default="false" } (L1v1, L1v2, L2v1->)
2057 //
2058 mExplicitlySetBoundaryCondition =
2059 attributes.readInto("boundaryCondition", mBoundaryCondition, getErrorLog(), false, getLine(), getColumn());
2060
2061 //
2062 // charge: integer { use="optional" } (L1v1, L1v2, L2v1)
2063 // charge: integer { use="optional" } deprecated (L2v2)
2064 //
2065 mIsSetCharge = attributes.readInto("charge", mCharge, getErrorLog(), false, getLine(), getColumn());
2066
2067 //
2068 // name: string { use="optional" } (L2v1->)
2069 //
2070 attributes.readInto("name", mName, getErrorLog(), false, getLine(), getColumn());
2071
2072 //
2073 // speciesType: SId { use="optional" } (L2v2-> L2v4)
2074 //
2075 if (version > 1)
2076 {
2077 attributes.readInto("speciesType", mSpeciesType, getErrorLog(), false, getLine(), getColumn());
2078 }
2079
2080 //
2081 // initialConcentration: double { use="optional" } (L2v1->)
2082 //
2083 mIsSetInitialConcentration =
2084 attributes.readInto("initialConcentration", mInitialConcentration, getErrorLog(),false, getLine(), getColumn());
2085
2086 //
2087 // spatialSizeUnits: SId { use="optional" } (L2v1, L2v2) removed in l2v3
2088 //
2089 if (version < 3)
2090 {
2091 assigned = attributes.readInto("spatialSizeUnits", mSpatialSizeUnits, getErrorLog(), false, getLine(), getColumn());
2092 if (assigned && mSpatialSizeUnits.size() == 0)
2093 {
2094 logEmptyString("spatialSizeUnits", level, version, "<species>");
2095 }
2096 if (!SyntaxChecker::isValidInternalUnitSId(mSpatialSizeUnits))
2097 {
2098 logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The spatialSizeUnits attribute '" + mSpatialSizeUnits + "' does not conform to the syntax.");
2099 }
2100 }
2101
2102 //
2103 // hasOnlySubstanceUnits: boolean
2104 // { use="optional" default="false" } (L2v1->)
2105 //
2106 mExplicitlySetHasOnlySubsUnits =
2107 attributes.readInto("hasOnlySubstanceUnits", mHasOnlySubstanceUnits, getErrorLog(), false, getLine(), getColumn());
2108
2109 //
2110 // constant: boolean { use="optional" default="false" } (L2v1->)
2111 //
2112 mExplicitlySetConstant = attributes.readInto("constant", mConstant, getErrorLog(), false, getLine(), getColumn());
2113 }
2114 /** @endcond */
2115
2116
2117 /** @cond doxygenLibsbmlInternal */
2118 /*
2119 * Subclasses should override this method to read values from the given
2120 * XMLAttributes set into their specific fields. Be sure to call your
2121 * parent's implementation of this method as well.
2122 */
2123 void
readL3Attributes(const XMLAttributes & attributes)2124 Species::readL3Attributes (const XMLAttributes& attributes)
2125 {
2126 const unsigned int level = getLevel ();
2127 const unsigned int version = getVersion();
2128
2129 //
2130 // id: SId { use="required" } (L2v1->)
2131 //
2132 bool assigned;
2133 // for l3v2 sbase will read this as generically optional
2134 // we want to log errors relating to the specific object
2135 if (version == 1)
2136 {
2137 assigned = attributes.readInto("id", mId, getErrorLog(), false,
2138 getLine(), getColumn());
2139 if (!assigned)
2140 {
2141 logError(AllowedAttributesOnSpecies, level, version,
2142 "The required attribute 'id' is missing.");
2143 }
2144 if (assigned && mId.size() == 0)
2145 {
2146 logEmptyString("id", level, version, "<species>");
2147 }
2148 if (!SyntaxChecker::isValidInternalSId(mId))
2149 logError(InvalidIdSyntax, level, version, "The id '" + mId + "' does not conform to the syntax.");
2150 }
2151 else
2152 {
2153 // need to check that id was present
2154 // it has already been read and checked for syntax/emptyness
2155 if (attributes.hasAttribute("id") == false)
2156 {
2157 logError(AllowedAttributesOnSpecies, level, version,
2158 "The required attribute 'id' is missing.");
2159 }
2160 }
2161
2162 string spplusid = "<species>";
2163 if (!mId.empty()) {
2164 spplusid += " with the id '" + mId + "'";
2165 }
2166 //
2167 // compartment: SId { use="required" } (L2v1->)
2168 //
2169 assigned = attributes.readInto("compartment", mCompartment, getErrorLog(),
2170 false, getLine(), getColumn());
2171 if (!assigned)
2172 {
2173 logError(MissingSpeciesCompartment, level, version,
2174 "The " + spplusid + " is missing the 'compartment' attribute.");
2175 }
2176
2177 //
2178 // initialAmount: double { use="optional" } (L2v1->)
2179 //
2180 mIsSetInitialAmount = attributes.readInto("initialAmount",
2181 mInitialAmount, getErrorLog(), false, getLine(), getColumn());
2182
2183 //
2184 // substanceUntis: SId { use="optional" } (L2v1->)
2185 //
2186 const string units = (level == 1) ? "units" : "substanceUnits";
2187 assigned = attributes.readInto(units, mSubstanceUnits, getErrorLog(),
2188 false, getLine(), getColumn());
2189 if (assigned && mSubstanceUnits.size() == 0)
2190 {
2191 logEmptyString("substanceUnits", level, version, "<species>");
2192 }
2193 if (!SyntaxChecker::isValidInternalUnitSId(mSubstanceUnits))
2194 {
2195 logError(InvalidUnitIdSyntax, level, version, "The " + spplusid +
2196 " has a substanceUnits with a value of '" + mSubstanceUnits
2197 + "' which does not conform .");
2198 }
2199
2200 //
2201 // boundaryCondition: boolean
2202 // { use="required" } (L3v1->)
2203 //
2204 mIsSetBoundaryCondition = attributes.readInto("boundaryCondition",
2205 mBoundaryCondition, getErrorLog(), false,
2206 getLine(), getColumn());
2207 mExplicitlySetBoundaryCondition = mIsSetBoundaryCondition;
2208 if (!mIsSetBoundaryCondition)
2209 {
2210 logError(AllowedAttributesOnSpecies, level, version,
2211 "The required attribute 'boundaryCondition' is missing from the "
2212 + spplusid + ".");
2213 }
2214
2215 //
2216 // name: string { use="optional" } (L2v1->)
2217 //
2218 // for l3v2 sbase will read this
2219 if (version == 1)
2220 {
2221 attributes.readInto("name", mName, getErrorLog(), false,
2222 getLine(), getColumn());
2223 }
2224
2225 //
2226 // initialConcentration: double { use="optional" } (L2v1->)
2227 //
2228 mIsSetInitialConcentration =
2229 attributes.readInto("initialConcentration", mInitialConcentration,
2230 getErrorLog(), false, getLine(), getColumn());
2231
2232 //
2233 // hasOnlySubstanceUnits: boolean
2234 // { use="required" } (L3v1 -> )
2235 mIsSetHasOnlySubstanceUnits = attributes.readInto(
2236 "hasOnlySubstanceUnits", mHasOnlySubstanceUnits,
2237 getErrorLog(), false, getLine(), getColumn());
2238 mExplicitlySetHasOnlySubsUnits = mIsSetHasOnlySubstanceUnits;
2239 if (!mIsSetHasOnlySubstanceUnits)
2240 {
2241 logError(AllowedAttributesOnSpecies, level, version,
2242 "The required attribute 'hasOnlySubstanceUnits' is missing from the "
2243 + spplusid + ".");
2244 }
2245
2246 //
2247 // constant: boolean { use="required" } (L3v1->)
2248 //
2249 mIsSetConstant = attributes.readInto("constant", mConstant, getErrorLog(),
2250 false, getLine(), getColumn());
2251 mExplicitlySetConstant = mIsSetConstant;
2252 if (!mIsSetConstant)
2253 {
2254 logError(AllowedAttributesOnSpecies, level, version,
2255 "The required attribute 'constant' is missing from the "
2256 + spplusid + ".");
2257 }
2258
2259 //
2260 // conversionFactor: SIdRef {use="optional" } (L3v1 ->)
2261 //
2262 assigned = attributes.readInto("conversionFactor", mConversionFactor,
2263 getErrorLog(), false, getLine(), getColumn());
2264 if (assigned && mConversionFactor.size() == 0)
2265 {
2266 logEmptyString("conversionFactor", level, version, "<species>");
2267 }
2268 if (!SyntaxChecker::isValidInternalSId(mConversionFactor))
2269 {
2270 logError(InvalidIdSyntax, getLevel(), getVersion(),
2271 "The " + spplusid + " has a conversionFactor with a value of '" + mConversionFactor
2272 + "' which does not conform .");
2273 }
2274 }
2275 /** @endcond */
2276
2277
2278 /** @cond doxygenLibsbmlInternal */
2279 /*
2280 * Subclasses should override this method to write out their contained
2281 * SBML objects as XML elements. Be sure to call your parent's
2282 * implementation of this method as well.
2283 */
2284 void
writeElements(XMLOutputStream & stream) const2285 Species::writeElements (XMLOutputStream& stream) const
2286 {
2287 SBase::writeElements(stream);
2288 //
2289 // (EXTENSION)
2290 //
2291 SBase::writeExtensionElements(stream);
2292 }
2293 /** @endcond */
2294
2295
2296 /** @cond doxygenLibsbmlInternal */
2297 /*
2298 * Subclasses should override this method to write their XML attributes
2299 * to the XMLOutputStream. Be sure to call your parent's implementation
2300 * of this method as well.
2301 */
2302 void
writeAttributes(XMLOutputStream & stream) const2303 Species::writeAttributes (XMLOutputStream& stream) const
2304 {
2305 SBase::writeAttributes(stream);
2306
2307 const unsigned int level = getLevel ();
2308 const unsigned int version = getVersion();
2309
2310 // for L3V2 and above SBase will write this out
2311 if (level < 3 || (level == 3 && version == 1))
2312 {
2313 //
2314 // name: SName { use="required" } (L1v1, L1v2)
2315 // id: SId { use="required" } (L2v1, L2v2)
2316 //
2317 const string id = (level == 1) ? "name" : "id";
2318 stream.writeAttribute(id, mId);
2319 }
2320 if (level > 1)
2321 {
2322 // for L3V2 and above SBase will write this out
2323 if (level < 3 || (level == 3 && version == 1))
2324 {
2325 //
2326 // name: string { use="optional" } (L2v1->)
2327 //
2328 stream.writeAttribute("name", mName);
2329 }
2330
2331 //
2332 // speciesType: SId { use="optional" } (L2v2->)
2333 //
2334 if (level == 2 && version > 1)
2335 {
2336 stream.writeAttribute("speciesType", mSpeciesType);
2337 }
2338 }
2339
2340 //
2341 // compartment: SName { use="required" } (L1v1, L2v1)
2342 // compartment: SId { use="required" } (L2v1->)
2343 //
2344 stream.writeAttribute("compartment", mCompartment);
2345
2346 //
2347 // initialAmount: double { use="required" } (L1v1, L1v2)
2348 // initialAmount: double { use="optional" } (L2v1->)
2349 //
2350 if ( isSetInitialAmount() )
2351 {
2352 stream.writeAttribute("initialAmount", mInitialAmount);
2353 }
2354
2355 //
2356 // initialConcentration: double { use="optional" } (L2v1-> )
2357 //
2358 else if ( level > 1 && isSetInitialConcentration() )
2359 {
2360 stream.writeAttribute("initialConcentration", mInitialConcentration);
2361 }
2362
2363 //
2364 // If user is converting a model from L2 to L1, two possiblities exist
2365 // that have not been covered:
2366 //
2367 // 1. InitialConcentration has been used, so it must be converted to
2368 // initialAmount
2369 //
2370 // 2. No initialAmount/initialAmount has been set, but initialAmount
2371 // is required in L1
2372 //
2373 else if (level == 1)
2374 {
2375 if ( isSetInitialConcentration() )
2376 {
2377 const Model* m = getModel();
2378 const Compartment* c = m ? m->getCompartment( getCompartment() ) : NULL;
2379
2380 if (c != NULL)
2381 {
2382 double amount = mInitialConcentration * c->getSize();
2383 stream.writeAttribute("initialAmount", amount);
2384 }
2385 else
2386 {
2387 stream.writeAttribute("initialAmount", mInitialConcentration);
2388 }
2389 }
2390 else
2391 {
2392 stream.writeAttribute("initialAmount", mInitialAmount);
2393 }
2394 }
2395
2396 //
2397 // units: SName { use="optional" } (L1v1, L1v2)
2398 // substanceUntis: SId { use="optional" } (L2v1->)
2399 //
2400 const string units = (level == 1) ? "units" : "substanceUnits";
2401 stream.writeAttribute( units, getUnits() );
2402
2403 if (level > 1)
2404 {
2405 if (level == 2 && version < 3)
2406 {
2407 //
2408 // spatialSizeUnits: SId { use="optional" } (L2v1, L2v2)
2409 //
2410 stream.writeAttribute("spatialSizeUnits", mSpatialSizeUnits);
2411 }
2412
2413 //
2414 // hasOnlySubstanceUnits: boolean
2415 // { use="optional" default="false" } (L2v1->)
2416 // { use="required" } (L3v1->)
2417 //
2418 if (level == 2 &&
2419 (mHasOnlySubstanceUnits || isExplicitlySetHasOnlySubsUnits()))
2420 {
2421 stream.writeAttribute( "hasOnlySubstanceUnits",
2422 mHasOnlySubstanceUnits );
2423 }
2424 else if (level > 2)
2425 {
2426 // in L3 only write it out if it has been set
2427 if (isSetHasOnlySubstanceUnits())
2428 stream.writeAttribute( "hasOnlySubstanceUnits",
2429 mHasOnlySubstanceUnits );
2430 }
2431 }
2432
2433 //
2434 // boundaryCondition: boolean
2435 // { use="optional" default="false" } (L1v1, L1v2, L2v1->)
2436 // { use="required" } (L3v1->)
2437 //
2438 if (level < 3)
2439 {
2440 if (mBoundaryCondition || isExplicitlySetBoundaryCondition())
2441 stream.writeAttribute("boundaryCondition", mBoundaryCondition);
2442 }
2443 else
2444 {
2445 // in L3 only write it out if it has been set
2446 if (isSetBoundaryCondition())
2447 stream.writeAttribute("boundaryCondition", mBoundaryCondition);
2448 }
2449
2450
2451 //
2452 // charge: integer { use="optional" } (L1v1, L1v2, L2v1)
2453 // charge: integer { use="optional" } deprecated (L2v2)
2454 //
2455 if ( level < 3 && !(level == 2 && version > 2) && isSetCharge() )
2456 {
2457 stream.writeAttribute("charge", mCharge);
2458 }
2459
2460 if (level > 1)
2461 {
2462 //
2463 // constant: boolean { use="optional" default="false" } (L2v1->)
2464 // constant: boolean { use="required" } (L3v1->)
2465 //
2466 if (level == 2 &&
2467 (mConstant != false || isExplicitlySetConstant()))
2468 {
2469 stream.writeAttribute("constant", mConstant);
2470 }
2471 else if (level > 2)
2472 {
2473 // in L3 only write it out if it has been set
2474 if (isSetConstant())
2475 stream.writeAttribute("constant", mConstant);
2476 }
2477
2478 //
2479 // sboTerm: SBOTerm { use="optional" } (L2v3->)
2480 // is written in SBase::writeAttributes()
2481 //
2482 }
2483
2484 if (level > 2)
2485 {
2486 stream.writeAttribute("conversionFactor", mConversionFactor);
2487 }
2488
2489 //
2490 // (EXTENSION)
2491 //
2492 SBase::writeExtensionAttributes(stream);
2493 }
2494 /** @endcond */
2495
2496
2497 /*
2498 * Creates a new ListOfSpecies items.
2499 */
ListOfSpecies(unsigned int level,unsigned int version)2500 ListOfSpecies::ListOfSpecies (unsigned int level, unsigned int version)
2501 : ListOf(level,version)
2502 {
2503 }
2504
2505
2506 /*
2507 * Creates a new ListOfSpecies items.
2508 */
ListOfSpecies(SBMLNamespaces * sbmlns)2509 ListOfSpecies::ListOfSpecies (SBMLNamespaces* sbmlns)
2510 : ListOf(sbmlns)
2511 {
2512 loadPlugins(sbmlns);
2513 }
2514
2515
2516 /*
2517 * @return a (deep) copy of this ListOfSpecies.
2518 */
2519 ListOfSpecies*
clone() const2520 ListOfSpecies::clone () const
2521 {
2522 return new ListOfSpecies(*this);
2523 }
2524
2525
2526 /*
2527 * @return the typecode (int) of SBML objects contained in this ListOf or
2528 * SBML_UNKNOWN (default).
2529 */
2530 int
getItemTypeCode() const2531 ListOfSpecies::getItemTypeCode () const
2532 {
2533 return SBML_SPECIES;
2534 }
2535
2536
2537 /*
2538 * @return the name of this element ie "listOfSpecies".
2539 */
2540 const string&
getElementName() const2541 ListOfSpecies::getElementName () const
2542 {
2543 static const string name = "listOfSpecies";
2544 return name;
2545 }
2546
2547
2548 /* return nth item in list */
2549 Species *
get(unsigned int n)2550 ListOfSpecies::get(unsigned int n)
2551 {
2552 return static_cast<Species*>(ListOf::get(n));
2553 }
2554
2555
2556 /* return nth item in list */
2557 const Species *
get(unsigned int n) const2558 ListOfSpecies::get(unsigned int n) const
2559 {
2560 return static_cast<const Species*>(ListOf::get(n));
2561 }
2562
2563
2564 /**
2565 * Used by ListOf::get() to lookup an SBase based by its id.
2566 */
2567 struct IdEqS : public unary_function<SBase*, bool>
2568 {
2569 const string& mId;
2570
IdEqSIdEqS2571 IdEqS (const string& id) : mId(id) { }
operator ()IdEqS2572 bool operator() (SBase* sb)
2573 { return static_cast <Species *> (sb)->getId() == mId; }
2574 };
2575 /* return item by id */
2576 Species*
get(const std::string & sid)2577 ListOfSpecies::get (const std::string& sid)
2578 {
2579 return const_cast<Species*>(
2580 static_cast<const ListOfSpecies&>(*this).get(sid) );
2581 }
2582
2583
2584 /* return item by id */
2585 const Species*
get(const std::string & sid) const2586 ListOfSpecies::get (const std::string& sid) const
2587 {
2588 vector<SBase*>::const_iterator result;
2589
2590 result = find_if( mItems.begin(), mItems.end(), IdEqS(sid) );
2591 return (result == mItems.end()) ? NULL : static_cast <Species*> (*result);
2592 }
2593
2594
2595 /* Removes the nth item from this list */
2596 Species*
remove(unsigned int n)2597 ListOfSpecies::remove (unsigned int n)
2598 {
2599 return static_cast<Species*>(ListOf::remove(n));
2600 }
2601
2602
2603 /* Removes item in this list by id */
2604 Species*
remove(const std::string & sid)2605 ListOfSpecies::remove (const std::string& sid)
2606 {
2607 SBase* item = NULL;
2608 vector<SBase*>::iterator result;
2609
2610 result = find_if( mItems.begin(), mItems.end(), IdEqS(sid) );
2611
2612 if (result != mItems.end())
2613 {
2614 item = *result;
2615 mItems.erase(result);
2616 }
2617
2618 return static_cast <Species*> (item);
2619 }
2620
2621
2622 /** @cond doxygenLibsbmlInternal */
2623 /*
2624 * @return the ordinal position of the element with respect to its siblings
2625 * or -1 (default) to indicate the position is not significant.
2626 */
2627 int
getElementPosition() const2628 ListOfSpecies::getElementPosition () const
2629 {
2630 return 6;
2631 }
2632 /** @endcond */
2633
2634
2635 /** @cond doxygenLibsbmlInternal */
2636 /*
2637 * @return the SBML object corresponding to next XMLToken in the
2638 * XMLInputStream or @c NULL if the token was not recognized.
2639 */
2640 SBase*
createObject(XMLInputStream & stream)2641 ListOfSpecies::createObject (XMLInputStream& stream)
2642 {
2643 const string& name = stream.peek().getName();
2644 SBase* object = NULL;
2645
2646
2647 if (name == "species" || name == "specie")
2648 {
2649 try
2650 {
2651 object = new Species(getSBMLNamespaces());
2652 }
2653 catch (SBMLConstructorException*)
2654 {
2655 object = new Species(SBMLDocument::getDefaultLevel(),
2656 SBMLDocument::getDefaultVersion());
2657 }
2658 catch ( ... )
2659 {
2660 object = new Species(SBMLDocument::getDefaultLevel(),
2661 SBMLDocument::getDefaultVersion());
2662 }
2663
2664 if (object != NULL) mItems.push_back(object);
2665 }
2666
2667 return object;
2668 }
2669 /** @endcond */
2670
2671
2672 #endif /* __cplusplus */
2673 /** @cond doxygenIgnored */
2674 LIBSBML_EXTERN
2675 Species_t *
Species_create(unsigned int level,unsigned int version)2676 Species_create (unsigned int level, unsigned int version)
2677 {
2678 try
2679 {
2680 Species* obj = new Species(level,version);
2681 return obj;
2682 }
2683 catch (SBMLConstructorException)
2684 {
2685 return NULL;
2686 }
2687 }
2688
2689
2690 LIBSBML_EXTERN
2691 Species_t *
Species_createWithNS(SBMLNamespaces_t * sbmlns)2692 Species_createWithNS (SBMLNamespaces_t* sbmlns)
2693 {
2694 try
2695 {
2696 Species* obj = new Species(sbmlns);
2697 return obj;
2698 }
2699 catch (SBMLConstructorException)
2700 {
2701 return NULL;
2702 }
2703 }
2704
2705
2706 LIBSBML_EXTERN
2707 void
Species_free(Species_t * s)2708 Species_free (Species_t *s)
2709 {
2710 if (s != NULL)
2711 delete s;
2712 }
2713
2714
2715 LIBSBML_EXTERN
2716 Species_t *
Species_clone(const Species_t * s)2717 Species_clone (const Species_t *s)
2718 {
2719 return (s != NULL) ? static_cast<Species*>( s->clone() ) : NULL;
2720 }
2721
2722
2723 LIBSBML_EXTERN
2724 void
Species_initDefaults(Species_t * s)2725 Species_initDefaults (Species_t *s)
2726 {
2727 if (s != NULL)
2728 s->initDefaults();
2729 }
2730
2731
2732 LIBSBML_EXTERN
2733 const XMLNamespaces_t *
Species_getNamespaces(Species_t * s)2734 Species_getNamespaces(Species_t *s)
2735 {
2736 return (s != NULL) ? s->getNamespaces() : NULL;
2737 }
2738
2739 LIBSBML_EXTERN
2740 const char *
Species_getId(const Species_t * s)2741 Species_getId (const Species_t *s)
2742 {
2743 return (s != NULL && s->isSetId()) ? s->getId().c_str() : NULL;
2744 }
2745
2746
2747 LIBSBML_EXTERN
2748 const char *
Species_getName(const Species_t * s)2749 Species_getName (const Species_t *s)
2750 {
2751 return (s != NULL && s->isSetName()) ? s->getName().c_str() : NULL;
2752 }
2753
2754
2755 LIBSBML_EXTERN
2756 const char *
Species_getSpeciesType(const Species_t * s)2757 Species_getSpeciesType (const Species_t *s)
2758 {
2759 return (s != NULL && s->isSetSpeciesType()) ?
2760 s->getSpeciesType().c_str() : NULL;
2761 }
2762
2763
2764 LIBSBML_EXTERN
2765 const char *
Species_getCompartment(const Species_t * s)2766 Species_getCompartment (const Species_t *s)
2767 {
2768 return (s != NULL && s->isSetCompartment()) ?
2769 s->getCompartment().c_str() : NULL;
2770 }
2771
2772
2773 LIBSBML_EXTERN
2774 double
Species_getInitialAmount(const Species_t * s)2775 Species_getInitialAmount (const Species_t *s)
2776 {
2777 return (s != NULL) ? s->getInitialAmount() :
2778 numeric_limits<double>::quiet_NaN();
2779 }
2780
2781
2782 LIBSBML_EXTERN
2783 double
Species_getInitialConcentration(const Species_t * s)2784 Species_getInitialConcentration (const Species_t *s)
2785 {
2786 return (s != NULL) ? s->getInitialConcentration() :
2787 numeric_limits<double>::quiet_NaN();
2788 }
2789
2790
2791 LIBSBML_EXTERN
2792 const char *
Species_getSubstanceUnits(const Species_t * s)2793 Species_getSubstanceUnits (const Species_t *s)
2794 {
2795 return (s != NULL && s->isSetSubstanceUnits()) ?
2796 s->getSubstanceUnits().c_str() : NULL;
2797 }
2798
2799
2800 LIBSBML_EXTERN
2801 const char *
Species_getSpatialSizeUnits(const Species_t * s)2802 Species_getSpatialSizeUnits (const Species_t *s)
2803 {
2804 return (s != NULL && s->isSetSpatialSizeUnits()) ?
2805 s->getSpatialSizeUnits().c_str() : NULL;
2806 }
2807
2808
2809 LIBSBML_EXTERN
2810 const char *
Species_getUnits(const Species_t * s)2811 Species_getUnits (const Species_t *s)
2812 {
2813 return (s != NULL && s->isSetUnits()) ? s->getUnits().c_str() : NULL;
2814 }
2815
2816
2817 LIBSBML_EXTERN
2818 int
Species_getHasOnlySubstanceUnits(const Species_t * s)2819 Species_getHasOnlySubstanceUnits (const Species_t *s)
2820 {
2821 return (s != NULL) ? static_cast<int>( s->getHasOnlySubstanceUnits() ) : 0;
2822 }
2823
2824
2825 LIBSBML_EXTERN
2826 int
Species_getBoundaryCondition(const Species_t * s)2827 Species_getBoundaryCondition (const Species_t *s)
2828 {
2829 return (s != NULL) ? static_cast<int>( s->getBoundaryCondition() ) : 0;
2830 }
2831
2832
2833 LIBSBML_EXTERN
2834 int
Species_getCharge(const Species_t * s)2835 Species_getCharge (const Species_t *s)
2836 {
2837 return (s != NULL) ? s->getCharge() : SBML_INT_MAX;
2838 }
2839
2840
2841 LIBSBML_EXTERN
2842 int
Species_getConstant(const Species_t * s)2843 Species_getConstant (const Species_t *s)
2844 {
2845 return (s != NULL) ? static_cast<int>( s->getConstant() ) : 0;
2846 }
2847
2848
2849 LIBSBML_EXTERN
2850 const char *
Species_getConversionFactor(const Species_t * s)2851 Species_getConversionFactor (const Species_t *s)
2852 {
2853 return (s != NULL && s->isSetConversionFactor()) ?
2854 s->getConversionFactor().c_str() : NULL;
2855 }
2856
2857
2858 LIBSBML_EXTERN
2859 int
Species_isSetId(const Species_t * s)2860 Species_isSetId (const Species_t *s)
2861 {
2862 return (s != NULL) ? static_cast<int>( s->isSetId() ) : 0;
2863 }
2864
2865
2866 LIBSBML_EXTERN
2867 int
Species_isSetName(const Species_t * s)2868 Species_isSetName (const Species_t *s)
2869 {
2870 return (s != NULL) ? static_cast<int>( s->isSetName() ) : 0;
2871 }
2872
2873
2874 LIBSBML_EXTERN
2875 int
Species_isSetSpeciesType(const Species_t * s)2876 Species_isSetSpeciesType (const Species_t *s)
2877 {
2878 return (s != NULL) ? static_cast<int>( s->isSetSpeciesType() ) : 0;
2879 }
2880
2881
2882 LIBSBML_EXTERN
2883 int
Species_isSetCompartment(const Species_t * s)2884 Species_isSetCompartment (const Species_t *s)
2885 {
2886 return (s != NULL) ? static_cast<int>( s->isSetCompartment() ) : 0;
2887 }
2888
2889
2890 LIBSBML_EXTERN
2891 int
Species_isSetInitialAmount(const Species_t * s)2892 Species_isSetInitialAmount (const Species_t *s)
2893 {
2894 return (s != NULL) ? static_cast<int>( s->isSetInitialAmount() ) : 0;
2895 }
2896
2897
2898 LIBSBML_EXTERN
2899 int
Species_isSetInitialConcentration(const Species_t * s)2900 Species_isSetInitialConcentration (const Species_t *s)
2901 {
2902 return (s != NULL) ? static_cast<int>( s->isSetInitialConcentration() ) : 0;
2903 }
2904
2905
2906 LIBSBML_EXTERN
2907 int
Species_isSetSubstanceUnits(const Species_t * s)2908 Species_isSetSubstanceUnits (const Species_t *s)
2909 {
2910 return (s != NULL) ? static_cast<int>( s->isSetSubstanceUnits() ) : 0;
2911 }
2912
2913
2914 LIBSBML_EXTERN
2915 int
Species_isSetSpatialSizeUnits(const Species_t * s)2916 Species_isSetSpatialSizeUnits (const Species_t *s)
2917 {
2918 return (s != NULL) ? static_cast<int>( s->isSetSpatialSizeUnits() ) : 0;
2919 }
2920
2921
2922 LIBSBML_EXTERN
2923 int
Species_isSetUnits(const Species_t * s)2924 Species_isSetUnits (const Species_t *s)
2925 {
2926 return (s != NULL) ? static_cast<int>( s->isSetUnits() ) : 0;
2927 }
2928
2929
2930 LIBSBML_EXTERN
2931 int
Species_isSetCharge(const Species_t * s)2932 Species_isSetCharge (const Species_t *s)
2933 {
2934 return (s != NULL) ? static_cast<int>( s->isSetCharge() ) : 0;
2935 }
2936
2937
2938 LIBSBML_EXTERN
2939 int
Species_isSetConversionFactor(const Species_t * s)2940 Species_isSetConversionFactor (const Species_t *s)
2941 {
2942 return (s != NULL) ? static_cast<int>( s->isSetConversionFactor() ) : 0;
2943 }
2944
2945
2946 LIBSBML_EXTERN
2947 int
Species_isSetConstant(const Species_t * s)2948 Species_isSetConstant (const Species_t *s)
2949 {
2950 return (s != NULL) ? static_cast<int>( s->isSetConstant() ) : 0;
2951 }
2952
2953
2954 LIBSBML_EXTERN
2955 int
Species_isSetBoundaryCondition(const Species_t * s)2956 Species_isSetBoundaryCondition (const Species_t *s)
2957 {
2958 return (s != NULL) ? static_cast<int>( s->isSetBoundaryCondition() ) : 0;
2959 }
2960
2961
2962 LIBSBML_EXTERN
2963 int
Species_isSetHasOnlySubstanceUnits(const Species_t * s)2964 Species_isSetHasOnlySubstanceUnits (const Species_t *s)
2965 {
2966 return (s != NULL) ? static_cast<int>( s->isSetHasOnlySubstanceUnits() ) : 0;
2967 }
2968
2969
2970 LIBSBML_EXTERN
2971 int
Species_setId(Species_t * s,const char * sid)2972 Species_setId (Species_t *s, const char *sid)
2973 {
2974 if (s != NULL)
2975 return (sid == NULL) ? s->setId("") : s->setId(sid);
2976 else
2977 return LIBSBML_INVALID_OBJECT;
2978 }
2979
2980
2981 LIBSBML_EXTERN
2982 int
Species_setName(Species_t * s,const char * name)2983 Species_setName (Species_t *s, const char *name)
2984 {
2985 if (s != NULL)
2986 return (name == NULL) ? s->unsetName() : s->setName(name);
2987 else
2988 return LIBSBML_INVALID_OBJECT;
2989 }
2990
2991
2992 LIBSBML_EXTERN
2993 int
Species_setSpeciesType(Species_t * s,const char * sid)2994 Species_setSpeciesType (Species_t *s, const char *sid)
2995 {
2996 if (s != NULL)
2997 return (sid == NULL) ? s->unsetSpeciesType() : s->setSpeciesType(sid);
2998 else
2999 return LIBSBML_INVALID_OBJECT;
3000 }
3001
3002
3003 LIBSBML_EXTERN
3004 int
Species_setCompartment(Species_t * s,const char * sid)3005 Species_setCompartment (Species_t *s, const char *sid)
3006 {
3007 if (s != NULL)
3008 return (sid == NULL) ? s->setCompartment("") : s->setCompartment(sid);
3009 else
3010 return LIBSBML_INVALID_OBJECT;
3011 }
3012
3013
3014 LIBSBML_EXTERN
3015 int
Species_setInitialAmount(Species_t * s,double value)3016 Species_setInitialAmount (Species_t *s, double value)
3017 {
3018 if (s != NULL)
3019 return s->setInitialAmount(value);
3020 else
3021 return LIBSBML_INVALID_OBJECT;
3022 }
3023
3024
3025 LIBSBML_EXTERN
3026 int
Species_setInitialConcentration(Species_t * s,double value)3027 Species_setInitialConcentration (Species_t *s, double value)
3028 {
3029 if (s != NULL)
3030 return s->setInitialConcentration(value);
3031 else
3032 return LIBSBML_INVALID_OBJECT;
3033 }
3034
3035
3036 LIBSBML_EXTERN
3037 int
Species_setSubstanceUnits(Species_t * s,const char * sid)3038 Species_setSubstanceUnits (Species_t *s, const char *sid)
3039 {
3040 if (s != NULL)
3041 return (sid == NULL) ? s->unsetSubstanceUnits() : s->setSubstanceUnits(sid);
3042 else
3043 return LIBSBML_INVALID_OBJECT;
3044 }
3045
3046
3047 LIBSBML_EXTERN
3048 int
Species_setSpatialSizeUnits(Species_t * s,const char * sid)3049 Species_setSpatialSizeUnits (Species_t *s, const char *sid)
3050 {
3051 if (s != NULL)
3052 return (sid == NULL) ? s->unsetSpatialSizeUnits() :
3053 s->setSpatialSizeUnits(sid);
3054 else
3055 return LIBSBML_INVALID_OBJECT;
3056 }
3057
3058
3059 LIBSBML_EXTERN
3060 int
Species_setUnits(Species_t * s,const char * sname)3061 Species_setUnits (Species_t *s, const char *sname)
3062 {
3063 if (s != NULL)
3064 return (sname == NULL) ? s->unsetUnits() : s->setUnits(sname);
3065 else
3066 return LIBSBML_INVALID_OBJECT;
3067 }
3068
3069
3070 LIBSBML_EXTERN
3071 int
Species_setHasOnlySubstanceUnits(Species_t * s,int value)3072 Species_setHasOnlySubstanceUnits (Species_t *s, int value)
3073 {
3074 if (s != NULL)
3075 return s->setHasOnlySubstanceUnits( static_cast<bool>(value) );
3076 else
3077 return LIBSBML_INVALID_OBJECT;
3078 }
3079
3080
3081 LIBSBML_EXTERN
3082 int
Species_setBoundaryCondition(Species_t * s,int value)3083 Species_setBoundaryCondition (Species_t *s, int value)
3084 {
3085 if (s != NULL)
3086 return s->setBoundaryCondition( static_cast<bool>(value) );
3087 else
3088 return LIBSBML_INVALID_OBJECT;
3089 }
3090
3091
3092 LIBSBML_EXTERN
3093 int
Species_setCharge(Species_t * s,int value)3094 Species_setCharge (Species_t *s, int value)
3095 {
3096 if (s != NULL)
3097 return s->setCharge(value);
3098 else
3099 return LIBSBML_INVALID_OBJECT;
3100 }
3101
3102
3103 LIBSBML_EXTERN
3104 int
Species_setConstant(Species_t * s,int value)3105 Species_setConstant (Species_t *s, int value)
3106 {
3107 if (s != NULL)
3108 return s->setConstant( static_cast<bool>(value) );
3109 else
3110 return LIBSBML_INVALID_OBJECT;
3111 }
3112
3113
3114 LIBSBML_EXTERN
3115 int
Species_setConversionFactor(Species_t * s,const char * sid)3116 Species_setConversionFactor (Species_t *s, const char *sid)
3117 {
3118 if (s != NULL)
3119 return (sid == NULL) ? s->unsetConversionFactor() :
3120 s->setConversionFactor(sid);
3121 else
3122 return LIBSBML_INVALID_OBJECT;
3123 }
3124
3125
3126 LIBSBML_EXTERN
3127 int
Species_unsetId(Species_t * s)3128 Species_unsetId (Species_t *s)
3129 {
3130 if (s != NULL)
3131 return s->unsetId();
3132 else
3133 return LIBSBML_INVALID_OBJECT;
3134 }
3135
3136
3137 LIBSBML_EXTERN
3138 int
Species_unsetName(Species_t * s)3139 Species_unsetName(Species_t *s)
3140 {
3141 if (s != NULL)
3142 return s->unsetName();
3143 else
3144 return LIBSBML_INVALID_OBJECT;
3145 }
3146
3147
3148
3149 LIBSBML_EXTERN
3150 int
Species_unsetConstant(Species_t * c)3151 Species_unsetConstant (Species_t *c)
3152 {
3153 if (c != NULL)
3154 return c->unsetConstant();
3155 else
3156 return LIBSBML_INVALID_OBJECT;
3157 }
3158
3159 LIBSBML_EXTERN
3160 int
Species_unsetSpeciesType(Species_t * s)3161 Species_unsetSpeciesType (Species_t *s)
3162 {
3163 if (s != NULL)
3164 return s->unsetSpeciesType();
3165 else
3166 return LIBSBML_INVALID_OBJECT;
3167 }
3168
3169
3170 LIBSBML_EXTERN
3171 int
Species_unsetInitialAmount(Species_t * s)3172 Species_unsetInitialAmount (Species_t *s)
3173 {
3174 if (s != NULL)
3175 return s->unsetInitialAmount();
3176 else
3177 return LIBSBML_INVALID_OBJECT;
3178 }
3179
3180
3181 LIBSBML_EXTERN
3182 int
Species_unsetInitialConcentration(Species_t * s)3183 Species_unsetInitialConcentration (Species_t *s)
3184 {
3185 if (s != NULL)
3186 return s->unsetInitialConcentration();
3187 else
3188 return LIBSBML_INVALID_OBJECT;
3189 }
3190
3191
3192 LIBSBML_EXTERN
3193 int
Species_unsetSubstanceUnits(Species_t * s)3194 Species_unsetSubstanceUnits (Species_t *s)
3195 {
3196 if (s != NULL)
3197 return s->unsetSubstanceUnits();
3198 else
3199 return LIBSBML_INVALID_OBJECT;
3200 }
3201
3202
3203 LIBSBML_EXTERN
3204 int
Species_unsetSpatialSizeUnits(Species_t * s)3205 Species_unsetSpatialSizeUnits (Species_t *s)
3206 {
3207 if (s != NULL)
3208 return s->unsetSpatialSizeUnits();
3209 else
3210 return LIBSBML_INVALID_OBJECT;
3211 }
3212
3213
3214 LIBSBML_EXTERN
3215 int
Species_unsetUnits(Species_t * s)3216 Species_unsetUnits (Species_t *s)
3217 {
3218 if (s != NULL)
3219 return s->unsetUnits();
3220 else
3221 return LIBSBML_INVALID_OBJECT;
3222 }
3223
3224
3225 LIBSBML_EXTERN
3226 int
Species_unsetCharge(Species_t * s)3227 Species_unsetCharge (Species_t *s)
3228 {
3229 if (s != NULL)
3230 return s->unsetCharge();
3231 else
3232 return LIBSBML_INVALID_OBJECT;
3233 }
3234
3235
3236 LIBSBML_EXTERN
3237 int
Species_unsetConversionFactor(Species_t * s)3238 Species_unsetConversionFactor (Species_t *s)
3239 {
3240 if (s != NULL)
3241 return s->unsetConversionFactor();
3242 else
3243 return LIBSBML_INVALID_OBJECT;
3244 }
3245
3246
3247 LIBSBML_EXTERN
3248 int
Species_unsetCompartment(Species_t * s)3249 Species_unsetCompartment (Species_t *s)
3250 {
3251 if (s != NULL)
3252 return s->unsetCompartment();
3253 else
3254 return LIBSBML_INVALID_OBJECT;
3255 }
3256
3257
3258 LIBSBML_EXTERN
3259 int
Species_unsetHasOnlySubstanceUnits(Species_t * s)3260 Species_unsetHasOnlySubstanceUnits (Species_t *s)
3261 {
3262 if (s != NULL)
3263 return s->unsetHasOnlySubstanceUnits();
3264 else
3265 return LIBSBML_INVALID_OBJECT;
3266 }
3267
3268
3269 LIBSBML_EXTERN
3270 int
Species_unsetBoundaryCondition(Species_t * s)3271 Species_unsetBoundaryCondition (Species_t *s)
3272 {
3273 if (s != NULL)
3274 return s->unsetBoundaryCondition();
3275 else
3276 return LIBSBML_INVALID_OBJECT;
3277 }
3278
3279
3280 LIBSBML_EXTERN
3281 UnitDefinition_t *
Species_getDerivedUnitDefinition(Species_t * s)3282 Species_getDerivedUnitDefinition(Species_t *s)
3283 {
3284 return (s != NULL) ? s->getDerivedUnitDefinition() : NULL;
3285 }
3286
3287
3288 LIBSBML_EXTERN
3289 int
Species_hasRequiredAttributes(Species_t * s)3290 Species_hasRequiredAttributes(Species_t *s)
3291 {
3292 return (s != NULL) ? static_cast<int>(s->hasRequiredAttributes()) : 0;
3293 }
3294
3295
3296 LIBSBML_EXTERN
3297 Species_t *
ListOfSpecies_getById(ListOf_t * lo,const char * sid)3298 ListOfSpecies_getById (ListOf_t *lo, const char *sid)
3299 {
3300 if (lo != NULL)
3301 return (sid != NULL) ?
3302 static_cast <ListOfSpecies *> (lo)->get(sid) : NULL;
3303 else
3304 return NULL;
3305 }
3306
3307
3308 LIBSBML_EXTERN
3309 Species_t *
ListOfSpecies_removeById(ListOf_t * lo,const char * sid)3310 ListOfSpecies_removeById (ListOf_t *lo, const char *sid)
3311 {
3312 if (lo != NULL)
3313 return (sid != NULL) ?
3314 static_cast <ListOfSpecies *> (lo)->remove(sid) : NULL;
3315 else
3316 return NULL;
3317 }
3318 /** @endcond */
3319
3320 LIBSBML_CPP_NAMESPACE_END
3321