1 /**
2  * @file    SpeciesReference.cpp
3  * @brief   Implementation of SpeciesReference and ListOfSpeciesReferences.
4  * @author  Ben Bornstein
5  *
6  *
7  * <!--------------------------------------------------------------------------
8  * This file is part of libSBML.  Please visit http://sbml.org for more
9  * information about SBML, and the latest version of libSBML.
10  *
11  * Copyright (C) 2020 jointly by the following organizations:
12  *     1. California Institute of Technology, Pasadena, CA, USA
13  *     2. University of Heidelberg, Heidelberg, Germany
14  *     3. University College London, London, UK
15  *
16  * Copyright (C) 2019 jointly by the following organizations:
17  *     1. California Institute of Technology, Pasadena, CA, USA
18  *     2. University of Heidelberg, Heidelberg, Germany
19  *
20  * Copyright (C) 2013-2018 jointly by the following organizations:
21  *     1. California Institute of Technology, Pasadena, CA, USA
22  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
23  *     3. University of Heidelberg, Heidelberg, Germany
24  *
25  * Copyright (C) 2009-2013 jointly by the following organizations:
26  *     1. California Institute of Technology, Pasadena, CA, USA
27  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
28  *
29  * Copyright (C) 2006-2008 by the California Institute of Technology,
30  *     Pasadena, CA, USA
31  *
32  * Copyright (C) 2002-2005 jointly by the following organizations:
33  *     1. California Institute of Technology, Pasadena, CA, USA
34  *     2. Japan Science and Technology Agency, Japan
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the GNU Lesser General Public License as published by
38  * the Free Software Foundation.  A copy of the license agreement is provided
39  * in the file named "LICENSE.txt" included with this software distribution
40  * and also available online as http://sbml.org/software/libsbml/license.html
41  * ---------------------------------------------------------------------- -->*/
42 
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/annotation/RDFAnnotation.h>
50 #include <sbml/math/FormulaParser.h>
51 #include <sbml/math/MathML.h>
52 #include <sbml/math/ASTNode.h>
53 
54 #include <sbml/SBO.h>
55 #include <sbml/SBMLVisitor.h>
56 #include <sbml/SBMLError.h>
57 #include <sbml/SBMLDocument.h>
58 #include <sbml/Model.h>
59 #include <sbml/SpeciesReference.h>
60 #include <sbml/SimpleSpeciesReference.h>
61 #include <sbml/ModifierSpeciesReference.h>
62 #include <sbml/extension/SBasePlugin.h>
63 
64 /** @cond doxygenIgnored */
65 using namespace std;
66 /** @endcond */
67 
68 LIBSBML_CPP_NAMESPACE_BEGIN
69 #ifdef __cplusplus
70 
71 
SpeciesReference(unsigned int level,unsigned int version)72 SpeciesReference::SpeciesReference (unsigned int level, unsigned int version) :
73    SimpleSpeciesReference( level, version)
74  , mStoichiometry        ( 1.0 )
75  , mDenominator          ( 1   )
76  , mStoichiometryMath    ( NULL   )
77  , mConstant             (false)
78  , mIsSetConstant        (false)
79  , mIsSetStoichiometry   (false)
80  , mExplicitlySetStoichiometry (false)
81  , mExplicitlySetDenominator   (false)
82 {
83 
84   if (!hasValidLevelVersionNamespaceCombination())
85     throw SBMLConstructorException();
86 
87   // if level 3 values have no defaults
88   if (level == 3)
89   {
90     mStoichiometry = numeric_limits<double>::quiet_NaN();
91   }
92 }
93 
SpeciesReference(SBMLNamespaces * sbmlns)94 SpeciesReference::SpeciesReference (SBMLNamespaces *sbmlns) :
95    SimpleSpeciesReference( sbmlns )
96  , mStoichiometry        ( 1.0 )
97  , mDenominator          ( 1   )
98  , mStoichiometryMath    ( NULL             )
99  , mConstant             (false)
100  , mIsSetConstant        (false)
101  , mIsSetStoichiometry   (false)
102  , mExplicitlySetStoichiometry (false)
103  , mExplicitlySetDenominator   (false)
104 {
105   if (!hasValidLevelVersionNamespaceCombination())
106   {
107     throw SBMLConstructorException(getElementName(), sbmlns);
108   }
109 
110   loadPlugins(sbmlns);
111 
112   // if level 3 values have no defaults
113   if (sbmlns->getLevel() == 3)
114   {
115     mStoichiometry = numeric_limits<double>::quiet_NaN();
116   }
117 }
118 
119 
120 /*
121  * Destroys this SpeciesReference.
122  */
~SpeciesReference()123 SpeciesReference::~SpeciesReference ()
124 {
125   delete mStoichiometryMath;
126 }
127 
128 
129 /*
130  * Copy constructor. Creates a copy of this SpeciesReference.
131  */
SpeciesReference(const SpeciesReference & orig)132 SpeciesReference::SpeciesReference (const SpeciesReference& orig)
133  : SimpleSpeciesReference( orig                )
134  , mStoichiometry        ( orig.mStoichiometry )
135  , mDenominator          ( orig.mDenominator   )
136  , mStoichiometryMath    ( NULL                )
137  , mConstant             ( orig.mConstant)
138  , mIsSetConstant        ( orig.mIsSetConstant)
139  , mIsSetStoichiometry   ( orig.mIsSetStoichiometry)
140  , mExplicitlySetStoichiometry ( orig.mExplicitlySetStoichiometry)
141  , mExplicitlySetDenominator   ( orig.mExplicitlySetDenominator)
142 {
143   if (orig.mStoichiometryMath != NULL)
144   {
145     mStoichiometryMath = new StoichiometryMath(*orig.getStoichiometryMath());
146     mStoichiometryMath->connectToParent(this);
147   }
148 }
149 
150 
151 /*
152  * Assignment operator
153  */
operator =(const SpeciesReference & rhs)154 SpeciesReference& SpeciesReference::operator=(const SpeciesReference& rhs)
155 {
156   if(&rhs!=this)
157   {
158     this->SBase::operator =(rhs);
159     this->SimpleSpeciesReference::operator = ( rhs );
160     mStoichiometry = rhs.mStoichiometry ;
161     mDenominator = rhs.mDenominator   ;
162     mConstant = rhs.mConstant;
163     mIsSetConstant = rhs.mIsSetConstant;
164     mIsSetStoichiometry = rhs.mIsSetStoichiometry;
165     mExplicitlySetStoichiometry = rhs.mExplicitlySetStoichiometry;
166     mExplicitlySetDenominator = rhs.mExplicitlySetDenominator;
167 
168     delete mStoichiometryMath;
169     if (rhs.mStoichiometryMath != NULL)
170     {
171       mStoichiometryMath = new StoichiometryMath(*rhs.getStoichiometryMath());
172       mStoichiometryMath->connectToParent(this);
173     }
174     else
175     {
176       mStoichiometryMath = NULL;
177     }
178   }
179 
180   return *this;
181 }
182 
183 
184 /** @cond doxygenLibsbmlInternal */
185 bool
accept(SBMLVisitor & v) const186 SpeciesReference::accept (SBMLVisitor& v) const
187 {
188   bool result = v.visit(*this);
189 
190   if (mStoichiometryMath != NULL) mStoichiometryMath->accept(v);
191 
192   return result;
193 }
194 /** @endcond */
195 
196 
197 /*
198  * @return a (deep) copy of this SpeciesReference.
199  */
200 SpeciesReference*
clone() const201 SpeciesReference::clone () const
202 {
203   return new SpeciesReference(*this);
204 }
205 
206 
207 /*
208  * Initializes the fields of this SpeciesReference to their defaults:
209  *
210  *   - stoichiometry = 1
211  *   - denominator   = 1
212  */
213 void
initDefaults()214 SpeciesReference::initDefaults ()
215 {
216   setStoichiometry(1.0);
217   setDenominator(1);
218 
219   // mark as not explicitly set
220   mExplicitlySetStoichiometry = false;
221   mExplicitlySetDenominator   = false;
222 }
223 
224 
225 /*
226  * @return the stoichiometry of this SpeciesReference.
227  */
228 double
getStoichiometry() const229 SpeciesReference::getStoichiometry () const
230 {
231   return mStoichiometry;
232 }
233 
234 
235 /*
236  * @return the stoichiometryMath of this SpeciesReference.
237  */
238 const StoichiometryMath*
getStoichiometryMath() const239 SpeciesReference::getStoichiometryMath () const
240 {
241   return mStoichiometryMath;
242 }
243 
244 
245 /*
246  * @return the stoichiometryMath of this SpeciesReference.
247  */
248 StoichiometryMath*
getStoichiometryMath()249 SpeciesReference::getStoichiometryMath ()
250 {
251   return mStoichiometryMath;
252 }
253 
254 
255 /*
256  * @return the denominator of this SpeciesReference.
257  */
258 int
getDenominator() const259 SpeciesReference::getDenominator () const
260 {
261   return mDenominator;
262 }
263 
264 
265 /*
266  * Get the value of the "constant" attribute.
267  */
268 bool
getConstant() const269 SpeciesReference::getConstant () const
270 {
271   return mConstant;
272 }
273 
274 
275 /*
276  * @return @c true if the stoichiometryMath of this SpeciesReference is
277  * set, false otherwise.
278  */
279 bool
isSetStoichiometryMath() const280 SpeciesReference::isSetStoichiometryMath () const
281 {
282   return (mStoichiometryMath != NULL);
283 }
284 
285 
286 /*
287  * @return @c true if the constant of this SpeciesReference is
288  * set, false otherwise.
289  */
290 bool
isSetConstant() const291 SpeciesReference::isSetConstant () const
292 {
293   return mIsSetConstant;
294 }
295 
296 
297 /*
298  * @return @c true if the stoichiometry of this SpeciesReference is
299  * set, false otherwise.
300  */
301 bool
isSetStoichiometry() const302 SpeciesReference::isSetStoichiometry () const
303 {
304   return mIsSetStoichiometry;
305 }
306 
307 
308 /*
309  * Sets the stoichiometry of this SpeciesReference to value.
310  */
311 int
setStoichiometry(double value)312 SpeciesReference::setStoichiometry (double value)
313 {
314    unsetStoichiometryMath();
315 
316    mStoichiometry = value;
317    mIsSetStoichiometry = true;
318    mExplicitlySetStoichiometry = true;
319   return LIBSBML_OPERATION_SUCCESS;
320 }
321 
322 
323 /*
324  * Sets the stoichiometryMath of this SpeciesReference to a copy of the
325  * given ASTNode.
326  */
327 int
setStoichiometryMath(const StoichiometryMath * math)328 SpeciesReference::setStoichiometryMath (const StoichiometryMath* math)
329 {
330   if ( getLevel() != 2 )
331   {
332     return LIBSBML_UNEXPECTED_ATTRIBUTE;
333   }
334 
335   int returnValue = checkCompatibility(static_cast<const SBase *>(math));
336 
337   if (returnValue == LIBSBML_OPERATION_FAILED && math == NULL)
338   {
339     return unsetStoichiometryMath();
340   }
341   else if (returnValue != LIBSBML_OPERATION_SUCCESS)
342   {
343     return returnValue;
344   }
345 
346   if (mStoichiometryMath == math)
347   {
348     mIsSetStoichiometry = false;
349     mExplicitlySetStoichiometry = false;
350     mStoichiometry = 1.0;
351     mDenominator = 1;
352     return LIBSBML_OPERATION_SUCCESS;
353   }
354   else
355   {
356     mIsSetStoichiometry = false;
357     mExplicitlySetStoichiometry = false;
358     mStoichiometry      = 1.0;
359     mDenominator        = 1;
360 
361     delete mStoichiometryMath;
362     mStoichiometryMath = static_cast<StoichiometryMath*>(math->clone());
363     if (mStoichiometryMath != NULL) mStoichiometryMath->connectToParent(this);
364 
365     return LIBSBML_OPERATION_SUCCESS;
366   }
367 }
368 
369 
370 /*
371  * Sets the denominator of this SpeciesReference to value.
372  */
373 int
setDenominator(int value)374 SpeciesReference::setDenominator (int value)
375 {
376   // this attribute was removed in l2 but we were able to capture it
377   // by creating a stoichiometryMath element for the speciesReference
378   // however stoichiometryMath was removed in l3 and so would require
379   // an initialAssignment which would only work if the SpeciesReference
380   // was already placed within a model
381   // so we return unexpected attribute in L3
382   if (getLevel() < 3)
383   {
384     mDenominator = value;
385     mExplicitlySetDenominator = true;
386     return LIBSBML_OPERATION_SUCCESS;
387   }
388   else
389   {
390     mDenominator = value;
391     return LIBSBML_UNEXPECTED_ATTRIBUTE;
392   }
393 }
394 
395 
396 /*
397  * Sets the constant field of this SpeciesReference to value.
398  */
399 int
setConstant(bool flag)400 SpeciesReference::setConstant (bool flag)
401 {
402   if ( getLevel() < 3 )
403   {
404     mConstant = flag;
405     return LIBSBML_UNEXPECTED_ATTRIBUTE;
406   }
407   else
408   {
409     mConstant = flag;
410     mIsSetConstant = true;
411     return LIBSBML_OPERATION_SUCCESS;
412   }
413 }
414 
415 
416 /*
417  * Unsets the "stoichiometryMath" subelement of this SpeciesReference.
418  */
419 int
unsetStoichiometryMath()420 SpeciesReference::unsetStoichiometryMath ()
421 {
422   delete mStoichiometryMath;
423   mStoichiometryMath = NULL;
424 
425   if ( getLevel() != 2 )
426   {
427     return LIBSBML_UNEXPECTED_ATTRIBUTE;
428   }
429   else if (!mIsSetStoichiometry)
430   {
431     //
432     // In SBML Level2, "stoichiometry" attribute is set to 1 (default value)
433     // if neither the "stoichiometry" attribute and the "stoichiometryMath"
434     // element are present.
435     //
436     mIsSetStoichiometry = true;
437     mStoichiometry = 1.0;
438     mDenominator = 1;
439   }
440 
441   if (mStoichiometryMath == NULL)
442   {
443     return LIBSBML_OPERATION_SUCCESS;
444   }
445   else
446   {
447     return LIBSBML_OPERATION_FAILED;
448   }
449 }
450 
451 /* unset the stoichiometry */
452 int
unsetStoichiometry()453 SpeciesReference::unsetStoichiometry ()
454 {
455   const unsigned int level = getLevel();
456 
457   if ( level > 2 )
458   {
459     mStoichiometry      = numeric_limits<double>::quiet_NaN();
460     mDenominator = 1;
461     mIsSetStoichiometry = false;
462     mExplicitlySetStoichiometry = false;
463     if (!isSetStoichiometry())
464     {
465       return LIBSBML_OPERATION_SUCCESS;
466     }
467     else
468     {
469       return LIBSBML_OPERATION_FAILED;
470     }
471   }
472   else
473   {
474     mStoichiometry      = 1.0;
475     mDenominator = 1;
476 
477     if ( level == 2 )
478     {
479       //
480       // In SBML Level2, "stoichiometry" attribute is set to 1 (default value)
481       // if neither the "stoichiometry" attribute and the "stoichiometryMath"
482       // element are present.
483       //
484       if (!isSetStoichiometryMath())
485       {
486         mIsSetStoichiometry = true;
487       }
488       else
489       {
490         mIsSetStoichiometry = false;
491         mExplicitlySetStoichiometry = false;
492       }
493     }
494     else
495     {
496       //
497       // In SBML Level 1, "stoichiometry" is always set (default is 1.0).
498       //
499       mIsSetStoichiometry = true;
500     }
501   }
502 
503   return LIBSBML_OPERATION_SUCCESS;
504 }
505 
506 
507 /*
508  * Sets the constant field of this SpeciesReference to value.
509  */
510 int
unsetConstant()511 SpeciesReference::unsetConstant ()
512 {
513   if ( getLevel() < 3 )
514   {
515     mConstant = false;
516     mIsSetConstant = false;
517     return LIBSBML_UNEXPECTED_ATTRIBUTE;
518   }
519   else
520   {
521     // no default
522     mIsSetConstant = false;
523     return LIBSBML_OPERATION_SUCCESS;
524   }
525 }
526 
527 
528 /*
529  * Creates a new StoichiometryMath, adds it to this SpeciesReference
530  * and returns it.
531  */
532 StoichiometryMath*
createStoichiometryMath()533 SpeciesReference::createStoichiometryMath ()
534 {
535   delete mStoichiometryMath;
536   mStoichiometryMath = NULL;
537 
538   try
539   {
540     mStoichiometryMath = new StoichiometryMath(getSBMLNamespaces());
541   }
542   catch (...)
543   {
544     /* here we do not create a default object as the level/version must
545      * match the parent object
546      *
547      * so do nothing
548      */
549   }
550 
551   if (mStoichiometryMath != NULL)
552   {
553     mStoichiometryMath->connectToParent(this);
554     /* this should unset the stoichiometry */
555     mStoichiometry = 1.0;
556     mDenominator = 1;
557     mIsSetStoichiometry = false;
558     mExplicitlySetStoichiometry = false;
559   }
560 
561   return mStoichiometryMath;
562 }
563 
564 
565 /*
566  * @return the typecode (int) of this SBML object or SBML_UNKNOWN
567  * (default).
568  *
569  * @see getElementName()
570  */
571 int
getTypeCode() const572 SpeciesReference::getTypeCode () const
573 {
574   return SBML_SPECIES_REFERENCE;
575 }
576 
577 
578 bool
hasRequiredAttributes() const579 SpeciesReference::hasRequiredAttributes() const
580 {
581   bool allPresent = SimpleSpeciesReference::hasRequiredAttributes();
582 
583   if (getLevel() > 2 && !isSetConstant())
584     allPresent = false;
585 
586   return allPresent;
587 }
588 
589 
590 
591 
592 
593 
594 
595 /** @cond doxygenLibsbmlInternal */
596 
597 /*
598  * Returns the value of the "attributeName" attribute of this SpeciesReference.
599  */
600 int
getAttribute(const std::string & attributeName,bool & value) const601 SpeciesReference::getAttribute(const std::string& attributeName,
602                                bool& value) const
603 {
604   int return_value = SimpleSpeciesReference::getAttribute(attributeName,
605     value);
606 
607   if (return_value == LIBSBML_OPERATION_SUCCESS)
608   {
609     return return_value;
610   }
611 
612   if (attributeName == "constant")
613   {
614     value = getConstant();
615     return_value = LIBSBML_OPERATION_SUCCESS;
616   }
617 
618   return return_value;
619 }
620 
621 /** @endcond */
622 
623 
624 
625 /** @cond doxygenLibsbmlInternal */
626 
627 /*
628  * Returns the value of the "attributeName" attribute of this SpeciesReference.
629  */
630 int
getAttribute(const std::string & attributeName,int & value) const631 SpeciesReference::getAttribute(const std::string& attributeName,
632                                int& value) const
633 {
634   int return_value = SimpleSpeciesReference::getAttribute(attributeName,
635     value);
636 
637   if (attributeName == "stoichiometry")
638   {
639     value = (int)(getStoichiometry());
640     return_value = LIBSBML_OPERATION_SUCCESS;
641   }
642   else if (attributeName == "denominator")
643   {
644     value = getDenominator();
645     return_value = LIBSBML_OPERATION_SUCCESS;
646   }
647 
648   return return_value;
649 }
650 
651 /** @endcond */
652 
653 
654 
655 /** @cond doxygenLibsbmlInternal */
656 
657 /*
658  * Returns the value of the "attributeName" attribute of this SpeciesReference.
659  */
660 int
getAttribute(const std::string & attributeName,double & value) const661 SpeciesReference::getAttribute(const std::string& attributeName,
662                                double& value) const
663 {
664   int return_value = SimpleSpeciesReference::getAttribute(attributeName,
665     value);
666 
667   if (return_value == LIBSBML_OPERATION_SUCCESS)
668   {
669     return return_value;
670   }
671 
672   if (attributeName == "stoichiometry")
673   {
674     value = getStoichiometry();
675     return_value = LIBSBML_OPERATION_SUCCESS;
676   }
677 
678   return return_value;
679 }
680 
681 /** @endcond */
682 
683 
684 
685 /** @cond doxygenLibsbmlInternal */
686 
687 /*
688  * Returns the value of the "attributeName" attribute of this SpeciesReference.
689  */
690 int
getAttribute(const std::string & attributeName,unsigned int & value) const691 SpeciesReference::getAttribute(const std::string& attributeName,
692                                unsigned int& value) const
693 {
694   int return_value = SimpleSpeciesReference::getAttribute(attributeName,
695     value);
696 
697   if (return_value == LIBSBML_OPERATION_SUCCESS)
698   {
699     return return_value;
700   }
701 
702   return return_value;
703 }
704 
705 /** @endcond */
706 
707 
708 
709 /** @cond doxygenLibsbmlInternal */
710 
711 /*
712  * Returns the value of the "attributeName" attribute of this SpeciesReference.
713  */
714 int
getAttribute(const std::string & attributeName,std::string & value) const715 SpeciesReference::getAttribute(const std::string& attributeName,
716                                std::string& value) const
717 {
718   int return_value = SimpleSpeciesReference::getAttribute(attributeName,
719     value);
720 
721   return return_value;
722 }
723 
724 /** @endcond */
725 
726 
727 
728 /** @cond doxygenLibsbmlInternal */
729 
730 /*
731  * Returns the value of the "attributeName" attribute of this SpeciesReference.
732  */
733 //int
734 //SpeciesReference::getAttribute(const std::string& attributeName,
735 //                               const char* value) const
736 //{
737 //  int return_value = SimpleSpeciesReference::getAttribute(attributeName,
738 //    value);
739 //
740 //  return return_value;
741 //}
742 
743 /** @endcond */
744 
745 
746 
747 /** @cond doxygenLibsbmlInternal */
748 
749 /*
750  * Predicate returning @c true if this SpeciesReference's attribute
751  * "attributeName" is set.
752  */
753 bool
isSetAttribute(const std::string & attributeName) const754 SpeciesReference::isSetAttribute(const std::string& attributeName) const
755 {
756   bool value = SimpleSpeciesReference::isSetAttribute(attributeName);
757 
758   if (attributeName == "stoichiometry")
759   {
760     value = isSetStoichiometry();
761   }
762   else if (attributeName == "constant")
763   {
764     value = isSetConstant();
765   }
766   else if (attributeName == "denominator")
767   {
768     value = true;
769   }
770 
771   return value;
772 }
773 
774 /** @endcond */
775 
776 
777 
778 /** @cond doxygenLibsbmlInternal */
779 
780 /*
781  * Sets the value of the "attributeName" attribute of this SpeciesReference.
782  */
783 int
setAttribute(const std::string & attributeName,bool value)784 SpeciesReference::setAttribute(const std::string& attributeName, bool value)
785 {
786   int return_value = SimpleSpeciesReference::setAttribute(attributeName,
787     value);
788 
789   if (attributeName == "constant")
790   {
791     return_value = setConstant(value);
792   }
793 
794   return return_value;
795 }
796 
797 /** @endcond */
798 
799 
800 
801 /** @cond doxygenLibsbmlInternal */
802 
803 /*
804  * Sets the value of the "attributeName" attribute of this SpeciesReference.
805  */
806 int
setAttribute(const std::string & attributeName,int value)807 SpeciesReference::setAttribute(const std::string& attributeName, int value)
808 {
809   int return_value = SimpleSpeciesReference::setAttribute(attributeName,
810     value);
811 
812   if (attributeName == "stoichiometry")
813   {
814     return_value = setStoichiometry(value);
815   }
816   else if (attributeName == "denominator")
817   {
818     return_value = setDenominator(value);
819   }
820   return return_value;
821 }
822 
823 /** @endcond */
824 
825 
826 
827 /** @cond doxygenLibsbmlInternal */
828 
829 /*
830  * Sets the value of the "attributeName" attribute of this SpeciesReference.
831  */
832 int
setAttribute(const std::string & attributeName,double value)833 SpeciesReference::setAttribute(const std::string& attributeName, double value)
834 {
835   int return_value = SimpleSpeciesReference::setAttribute(attributeName,
836     value);
837 
838   if (attributeName == "stoichiometry")
839   {
840     return_value = setStoichiometry(value);
841   }
842 
843   return return_value;
844 }
845 
846 /** @endcond */
847 
848 
849 
850 /** @cond doxygenLibsbmlInternal */
851 
852 /*
853  * Sets the value of the "attributeName" attribute of this SpeciesReference.
854  */
855 int
setAttribute(const std::string & attributeName,unsigned int value)856 SpeciesReference::setAttribute(const std::string& attributeName,
857                                unsigned int value)
858 {
859   int return_value = SimpleSpeciesReference::setAttribute(attributeName,
860     value);
861 
862   return return_value;
863 }
864 
865 /** @endcond */
866 
867 
868 
869 /** @cond doxygenLibsbmlInternal */
870 
871 /*
872  * Sets the value of the "attributeName" attribute of this SpeciesReference.
873  */
874 int
setAttribute(const std::string & attributeName,const std::string & value)875 SpeciesReference::setAttribute(const std::string& attributeName,
876                                const std::string& value)
877 {
878   int return_value = SimpleSpeciesReference::setAttribute(attributeName,
879     value);
880 
881   return return_value;
882 }
883 
884 /** @endcond */
885 
886 
887 
888 /** @cond doxygenLibsbmlInternal */
889 
890 /*
891  * Sets the value of the "attributeName" attribute of this SpeciesReference.
892  */
893 //int
894 //SpeciesReference::setAttribute(const std::string& attributeName,
895 //                               const char* value)
896 //{
897 //  int return_value = SimpleSpeciesReference::setAttribute(attributeName,
898 //    value);
899 //
900 //  return return_value;
901 //}
902 
903 /** @endcond */
904 
905 
906 
907 /** @cond doxygenLibsbmlInternal */
908 
909 /*
910  * Unsets the value of the "attributeName" attribute of this SpeciesReference.
911  */
912 int
unsetAttribute(const std::string & attributeName)913 SpeciesReference::unsetAttribute(const std::string& attributeName)
914 {
915   int value = SimpleSpeciesReference::unsetAttribute(attributeName);
916 
917   if (attributeName == "stoichiometry")
918   {
919     value = unsetStoichiometry();
920   }
921   else if (attributeName == "constant")
922   {
923     value = unsetConstant();
924   }
925   else if (attributeName == "denominator")
926   {
927     mDenominator = 1;
928     value = LIBSBML_OPERATION_SUCCESS;
929   }
930 
931   return value;
932 }
933 
934 /** @endcond */
935 
936 /** @cond doxygenLibsbmlInternal */
937 
938 /*
939  * Creates and returns an new "elementName" object in this SpeciesReference.
940  */
941 SBase*
createChildObject(const std::string & elementName)942 SpeciesReference::createChildObject(const std::string& elementName)
943 {
944   SBase* obj = NULL;
945 
946   if (elementName == "stoichiometryMath")
947   {
948     return createStoichiometryMath();
949   }
950 
951   return obj;
952 }
953 
954 /** @endcond */
955 
956 /** @cond doxygenLibsbmlInternal */
957 /*
958  * Adds an new "elementName" object in this SpeciesReference.
959  */
960 int
addChildObject(const std::string & elementName,const SBase * element)961 SpeciesReference::addChildObject(const std::string& elementName, const SBase* element)
962 {
963   if (elementName == "stoichiometryMath" && element->getTypeCode() == SBML_STOICHIOMETRY_MATH)
964   {
965     return setStoichiometryMath((const StoichiometryMath*)(element));
966   }
967 
968   return LIBSBML_OPERATION_FAILED;
969 }
970 
971 /** @endcond */
972 
973 
974 /** @cond doxygenLibsbmlInternal */
975 
976 /*
977  * Adds an new "elementName" object in this SpeciesReference.
978  */
979 SBase*
removeChildObject(const std::string & elementName,const std::string & id)980 SpeciesReference::removeChildObject(const std::string& elementName, const std::string& id)
981 {
982 
983   if (elementName == "stoichiometryMath")
984   {
985     unsetStoichiometryMath();
986   }
987   return NULL;
988 }
989 
990 /** @endcond */
991 
992 
993 /** @cond doxygenLibsbmlInternal */
994 
995 /*
996  * Returns the number of "elementName" in this SpeciesReference.
997  */
998 unsigned int
getNumObjects(const std::string & elementName)999 SpeciesReference::getNumObjects(const std::string& elementName)
1000 {
1001   unsigned int n = 0;
1002 
1003   if (elementName == "stoichiometryMath")
1004   {
1005     if (isSetStoichiometryMath())
1006     {
1007       return 1;
1008     }
1009   }
1010 
1011   return n;
1012 }
1013 
1014 /** @endcond */
1015 
1016 
1017 
1018 /** @cond doxygenLibsbmlInternal */
1019 
1020 /*
1021  * Returns the nth object of "objectName" in this SpeciesReference.
1022  */
1023 SBase*
getObject(const std::string & elementName,unsigned int index)1024 SpeciesReference::getObject(const std::string& elementName, unsigned int index)
1025 {
1026   SBase* obj = NULL;
1027 
1028   if (elementName == "stoichiometryMath")
1029   {
1030     return getStoichiometryMath();
1031   }
1032 
1033   return obj;
1034 }
1035 
1036 /** @endcond */
1037 
1038 
1039 
1040 
1041 /*
1042  * Sets the annotation of this SBML object to a copy of annotation.
1043  */
1044 int
setAnnotation(const XMLNode * annotation)1045 SpeciesReference::setAnnotation (const XMLNode* annotation)
1046 {
1047   int success = SBase::setAnnotation(annotation);
1048 
1049   if (success == 0)
1050   {
1051   }
1052 
1053   return success;
1054 }
1055 
1056 
1057 /*
1058  * Sets the annotation (by string) of this SBML object to a copy of annotation.
1059  */
1060 int
setAnnotation(const std::string & annotation)1061 SpeciesReference::setAnnotation (const std::string& annotation)
1062 {
1063   int success = LIBSBML_OPERATION_FAILED;
1064 
1065   if(annotation.empty())
1066   {
1067     unsetAnnotation();
1068     return LIBSBML_OPERATION_SUCCESS;
1069   }
1070 
1071   XMLNode* annt_xmln;
1072   if (getSBMLDocument() != NULL)
1073   {
1074     XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces();
1075     annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns);
1076   }
1077   else
1078   {
1079     annt_xmln = XMLNode::convertStringToXMLNode(annotation);
1080   }
1081 
1082   if(annt_xmln != NULL)
1083   {
1084     success = setAnnotation(annt_xmln);
1085     delete annt_xmln;
1086   }
1087   return success;
1088 }
1089 
1090 
1091 /*
1092  * Appends annotation to the existing annotations.
1093  * This allows other annotations to be preserved whilst
1094  * adding additional information.
1095  */
1096 int
appendAnnotation(const XMLNode * annotation)1097 SpeciesReference::appendAnnotation (const XMLNode* annotation)
1098 {
1099   int success = LIBSBML_OPERATION_FAILED;
1100   if(!annotation) return LIBSBML_OPERATION_SUCCESS;
1101 
1102   XMLNode* new_annotation = annotation->clone();
1103 
1104   success = SBase::appendAnnotation(new_annotation);
1105 
1106   delete new_annotation;
1107 
1108   return success;
1109 }
1110 
1111 /*
1112  * Appends annotation (by string) to the existing annotations.
1113  * This allows other annotations to be preserved whilst
1114  * adding additional information.
1115  */
1116 int
appendAnnotation(const std::string & annotation)1117 SpeciesReference::appendAnnotation (const std::string& annotation)
1118 {
1119   int success = LIBSBML_OPERATION_FAILED;
1120   XMLNode* annt_xmln;
1121   if (getSBMLDocument() != NULL)
1122   {
1123     XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces();
1124     annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns);
1125   }
1126   else
1127   {
1128     annt_xmln = XMLNode::convertStringToXMLNode(annotation);
1129   }
1130 
1131   if(annt_xmln != NULL)
1132   {
1133     success = appendAnnotation(annt_xmln);
1134     delete annt_xmln;
1135   }
1136 
1137   return success;
1138 }
1139 
1140 
1141 /*
1142  * @return the name of this element ie "speciesReference".
1143 
1144  */
1145 const string&
getElementName() const1146 SpeciesReference::getElementName () const
1147 {
1148   static const string specie  = "specieReference";
1149   static const string species = "speciesReference";
1150 
1151   return (getLevel() == 1 && getVersion() == 1) ? specie : species;
1152 }
1153 
1154 
1155 /** @cond doxygenLibsbmlInternal */
1156 void
sortMath()1157 SpeciesReference::sortMath()
1158 {
1159   if (mStoichiometryMath != NULL &&
1160     mStoichiometryMath->isSetMath() &&
1161     mStoichiometryMath->getMath()->isRational())
1162   {
1163     mStoichiometry = mStoichiometryMath->getMath()->getNumerator();
1164     mDenominator   = (int)mStoichiometryMath->getMath()->getDenominator();
1165 
1166     delete mStoichiometryMath;
1167     mStoichiometryMath = NULL;
1168   }
1169 }
1170 /** @endcond */
1171 
1172 
1173 /** @cond doxygenLibsbmlInternal */
1174 /*
1175  * @return the SBML object corresponding to next XMLToken in the
1176  * XMLInputStream or @c NULL if the token was not recognized.
1177  */
1178 SBase*
createObject(XMLInputStream & stream)1179 SpeciesReference::createObject (XMLInputStream& stream)
1180 {
1181   SBase *object = NULL;
1182   const string& name = stream.peek().getName();
1183 
1184   if (name == "stoichiometryMath")
1185   {
1186     if (getLevel() != 2)
1187     {
1188       return NULL;
1189     }
1190     delete mStoichiometryMath;
1191 
1192     try
1193     {
1194       mStoichiometryMath = new StoichiometryMath(getSBMLNamespaces());
1195     }
1196     catch (SBMLConstructorException*)
1197     {
1198       mStoichiometryMath = new StoichiometryMath(
1199                                            SBMLDocument::getDefaultLevel(),
1200                                            SBMLDocument::getDefaultVersion());
1201     }
1202     catch ( ... )
1203     {
1204       mStoichiometryMath = new StoichiometryMath(
1205                                            SBMLDocument::getDefaultLevel(),
1206                                            SBMLDocument::getDefaultVersion());
1207     }
1208     return mStoichiometryMath;
1209   }
1210 
1211   return object;
1212 }
1213 /** @endcond */
1214 
1215 
1216 /** @cond doxygenLibsbmlInternal */
1217 /*
1218  * Subclasses should override this method to read (and store) XHTML,
1219  * MathML, etc. directly from the XMLInputStream.
1220  *
1221  * @return @c true if the subclass read from the stream, false otherwise.
1222  */
1223 bool
readOtherXML(XMLInputStream & stream)1224 SpeciesReference::readOtherXML (XMLInputStream& stream)
1225 {
1226   bool          read = false;
1227   const string& name = stream.peek().getName();
1228 
1229  // if (name == "stoichiometryMath")
1230  // {
1231  //   const XMLToken wrapperElement = stream.next();
1232  //   stream.skipText();
1233  //   const XMLToken element = stream.peek();
1234 
1235  //   bool found = false;
1236 
1237  //   /* The first element must always be 'math'. */
1238 
1239  //   if (element.getName() != "math")
1240  //   {
1241  //     found = true;
1242  //   }
1243 
1244  //   /* Check this declares the MathML namespace.  This may be explicitly
1245  //    * declared here or implicitly declared on the whole document
1246  //    */
1247 
1248  //   if (!found && element.getNamespaces().getLength() != 0)
1249  //   {
1250  //     for (int n = 0; n < element.getNamespaces().getLength(); n++)
1251  //     {
1252  //       if (!strcmp(element.getNamespaces().getURI(n).c_str(),
1253   //	    "http://www.w3.org/1998/Math/MathML"))
1254  //       {
1255   //  found = true;
1256  //         break;
1257  //       }
1258  //     }
1259  //   }
1260  //   if (!found && mSBML->getNamespaces() != 0)
1261  //   {
1262  //     /* check for implicit declaration */
1263  //     for (int n = 0; n < mSBML->getNamespaces()->getLength(); n++)
1264  //     {
1265   //if (!strcmp(mSBML->getNamespaces()->getURI(n).c_str(),
1266   //	    "http://www.w3.org/1998/Math/MathML"))
1267   //{
1268   //  found = true;
1269   //  break;
1270   //}
1271  //     }
1272  //   }
1273 
1274  //   if (! found)
1275  //   {
1276  //     static_cast <SBMLErrorLog*> (stream.getErrorLog())->logError(10201);
1277  //   }
1278 
1279  //   delete mStoichiometryMath;
1280  //   mStoichiometryMath = readMathML(stream);
1281  //   read               = true;
1282 
1283  //   stream.skipPastEnd(wrapperElement);
1284 
1285  //   if (mStoichiometryMath && mStoichiometryMath->isRational())
1286  //   {
1287  //     mStoichiometry = mStoichiometryMath->getNumerator();
1288  //     mDenominator   = mStoichiometryMath->getDenominator();
1289 
1290  //     delete mStoichiometryMath;
1291  //     mStoichiometryMath = 0;
1292  //   }
1293  // }
1294   //else
1295 
1296   // This has to do additional work for reading annotations, so the code
1297   // here is copied and expanded from SBase::readNotes().
1298 
1299   if (name == "annotation")
1300   {
1301 //    XMLNode* new_annotation = NULL;
1302     /* if annotation already exists then it is an error
1303      */
1304     if (mAnnotation != NULL)
1305     {
1306       if (getLevel() < 3)
1307       {
1308         logError(NotSchemaConformant, getLevel(), getVersion(),
1309           "Only one <annotation> element is permitted inside a "
1310           "particular containing element.");
1311       }
1312       else
1313       {
1314         string msg = "An SBML <speciesReference> element ";
1315         if (isSetId()) {
1316           msg += "with the id '" + getId() + "' ";
1317         }
1318         msg += "has multiple <annotation> children.";
1319         logError(MultipleAnnotations, getLevel(), getVersion(), msg);
1320       }
1321     }
1322     delete mAnnotation;
1323     mAnnotation = new XMLNode(stream);
1324     checkAnnotation();
1325     if (mCVTerms != NULL)
1326     {
1327       unsigned int size = mCVTerms->getSize();
1328       while (size--) delete static_cast<CVTerm*>( mCVTerms->remove(0) );
1329       delete mCVTerms;
1330     }
1331     mCVTerms = new List();
1332     delete mHistory;
1333     if (RDFAnnotationParser::hasHistoryRDFAnnotation(mAnnotation))
1334     {
1335       mHistory = RDFAnnotationParser::parseRDFAnnotation(mAnnotation,
1336                                             getMetaId().c_str(), &(stream));
1337 
1338       if (mHistory != NULL && mHistory->hasRequiredAttributes() == false)
1339       {
1340         logError(RDFNotCompleteModelHistory, getLevel(), getVersion(),
1341           "An invalid ModelHistory element has been stored.");
1342       }
1343       setModelHistory(mHistory);
1344     }
1345     else
1346       mHistory = NULL;
1347     if (RDFAnnotationParser::hasCVTermRDFAnnotation(mAnnotation))
1348       RDFAnnotationParser::parseRDFAnnotation(mAnnotation, mCVTerms,
1349                                                getMetaId().c_str(), &(stream));
1350 //    new_annotation = RDFAnnotationParser::deleteRDFAnnotation(mAnnotation);
1351 //    delete mAnnotation;
1352 //    mAnnotation = new_annotation;
1353 
1354     read = true;
1355   }
1356 
1357   /* ------------------------------
1358    *
1359    *   (EXTENSION)
1360    *
1361    * ------------------------------ */
1362   if ( SBase::readOtherXML(stream) )
1363     read = true;
1364 
1365   return read;
1366 }
1367 /** @endcond */
1368 
1369 
1370 /** @cond doxygenLibsbmlInternal */
1371 /**
1372  * Subclasses should override this method to get the list of
1373  * expected attributes.
1374  * This function is invoked from corresponding readAttributes()
1375  * function.
1376  */
1377 void
addExpectedAttributes(ExpectedAttributes & attributes)1378 SpeciesReference::addExpectedAttributes(ExpectedAttributes& attributes)
1379 {
1380   SimpleSpeciesReference::addExpectedAttributes(attributes);
1381 
1382   const unsigned int level   = getLevel  ();
1383 
1384   attributes.add("stoichiometry");
1385   if (level == 1)
1386   {
1387     attributes.add("denominator");
1388   }
1389   if (level > 2)
1390   {
1391     attributes.add("constant");
1392   }
1393 }
1394 
1395 
1396 /*
1397  * Subclasses should override this method to read values from the given
1398  * XMLAttributes set into their specific fields.  Be sure to call your
1399  * parent's implementation of this method as well.
1400  */
1401 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)1402 SpeciesReference::readAttributes (const XMLAttributes& attributes,
1403                                   const ExpectedAttributes& expectedAttributes)
1404 {
1405   SimpleSpeciesReference::readAttributes(attributes,expectedAttributes);
1406 
1407   const unsigned int level   = getLevel  ();
1408   switch (level)
1409   {
1410   case 1:
1411     readL1Attributes(attributes);
1412     break;
1413   case 2:
1414     readL2Attributes(attributes);
1415     break;
1416   case 3:
1417   default:
1418     readL3Attributes(attributes);
1419     break;
1420   }
1421 }
1422 /** @endcond */
1423 
1424 
1425 /** @cond doxygenLibsbmlInternal */
1426 /*
1427  * Subclasses should override this method to read values from the given
1428  * XMLAttributes set into their specific fields.  Be sure to call your
1429  * parent's implementation of this method as well.
1430  */
1431 void
readL1Attributes(const XMLAttributes & attributes)1432 SpeciesReference::readL1Attributes (const XMLAttributes& attributes)
1433 {
1434   //
1435   // stoichiometry: integer  { use="optional" default="1" }  (L1v1, L1v2)
1436   // stoichiometry: double   { use="optional" default="1" }  (L2v1->)
1437   //
1438   mIsSetStoichiometry = attributes.readInto("stoichiometry", mStoichiometry, getErrorLog(), false, getLine(), getColumn());
1439   if (!mIsSetStoichiometry)
1440   {
1441     //
1442     // setting default value
1443     //
1444     mStoichiometry = 1;
1445     mIsSetStoichiometry = true;
1446   }
1447   else
1448   {
1449     mExplicitlySetStoichiometry = true;
1450   }
1451 
1452   //
1453   // denominator: integer  { use="optional" default="1" }  (L1v1, L1v2)
1454   //
1455   mExplicitlySetDenominator = attributes.readInto("denominator", mDenominator,getErrorLog(), false, getLine(), getColumn());
1456 
1457 }
1458 /** @endcond */
1459 
1460 
1461 /** @cond doxygenLibsbmlInternal */
1462 /*
1463  * Subclasses should override this method to read values from the given
1464  * XMLAttributes set into their specific fields.  Be sure to call your
1465  * parent's implementation of this method as well.
1466  */
1467 void
readL2Attributes(const XMLAttributes & attributes)1468 SpeciesReference::readL2Attributes (const XMLAttributes& attributes)
1469 {
1470   // stoichiometry: double   { use="optional" default="1" }  (L2v1->)
1471   //
1472   mIsSetStoichiometry = attributes.readInto("stoichiometry", mStoichiometry, getErrorLog(), false, getLine(), getColumn());
1473   mExplicitlySetStoichiometry = mIsSetStoichiometry;
1474 }
1475 /** @endcond */
1476 
1477 
1478 /** @cond doxygenLibsbmlInternal */
1479 /*
1480  * Subclasses should override this method to read values from the given
1481  * XMLAttributes set into their specific fields.  Be sure to call your
1482  * parent's implementation of this method as well.
1483  */
1484 void
readL3Attributes(const XMLAttributes & attributes)1485 SpeciesReference::readL3Attributes (const XMLAttributes& attributes)
1486 {
1487   const unsigned int level = 3;
1488   const unsigned int version = getVersion();
1489   //
1490   // stoichiometry: double   { use="optional" default="1" }  (L2v1->)
1491   //
1492   mIsSetStoichiometry = attributes.readInto("stoichiometry", mStoichiometry, getErrorLog(), false, getLine(), getColumn());
1493 
1494   string elplusid = "<" + getElementName() + ">";
1495   if (!mId.empty()) {
1496     elplusid += " with the id '" + mId + "'";
1497   }
1498   SBase* rxn = getAncestorOfType(SBML_REACTION);
1499   if (rxn && rxn->isSetId())
1500   {
1501     elplusid += " from the <reaction> with the id '" + rxn->getId() + "'";
1502   }
1503   //
1504   // constant: bool { use="required" } (L3v1 -> )
1505   //
1506   mIsSetConstant = attributes.readInto("constant", mConstant, getErrorLog(), false, getLine(), getColumn());
1507   if (!mIsSetConstant && !isModifier())
1508   {
1509     logError(AllowedAttributesOnSpeciesReference, level, version,
1510              "The required attribute 'constant' is missing from the "
1511              + elplusid + ".");
1512   }
1513 
1514 }
1515 /** @endcond */
1516 
1517 
1518 /** @cond doxygenLibsbmlInternal */
1519 /*
1520  * Subclasses should override this method to write their XML attributes
1521  * to the XMLOutputStream.  Be sure to call your parent's implementation
1522  * of this method as well.
1523  */
1524 void
writeAttributes(XMLOutputStream & stream) const1525 SpeciesReference::writeAttributes (XMLOutputStream& stream) const
1526 {
1527   SimpleSpeciesReference::writeAttributes(stream);
1528 
1529   if (getLevel() == 1)
1530   {
1531     //
1532     // stoichiometry: integer  { use="optional" default="1" }  (L1v1, L1v2)
1533     //
1534     int s = static_cast<int>( mStoichiometry );
1535     if (isExplicitlySetStoichiometry() || s != 1) stream.writeAttribute("stoichiometry", s);
1536 
1537     //
1538     // denominator  { use="optional" default="1" }  (L1v1, L1v2)
1539     //
1540     if (isExplicitlySetDenominator() || mDenominator != 1) stream.writeAttribute("denominator", mDenominator);
1541   }
1542   else if (getLevel() == 2)
1543   {
1544     //
1545     // stoichiometry: double   { use="optional" default="1" }  (L2v1, L2v2)
1546     //
1547     if ((mDenominator == 1) &&
1548       (mStoichiometry != 1 || isExplicitlySetStoichiometry()))
1549     {
1550       stream.writeAttribute("stoichiometry", mStoichiometry);
1551     }
1552   }
1553   else
1554   {
1555     if (isSetStoichiometry())
1556       stream.writeAttribute("stoichiometry", mStoichiometry);
1557   }
1558   //
1559   // constant: bool { use="required" } (L3v1 -> )
1560   //
1561   if (getLevel() > 2)
1562   {
1563     // in L3 only write it out if it has been set
1564     if (isSetConstant())
1565       stream.writeAttribute("constant", mConstant);
1566   }
1567 }
1568 /** @endcond */
1569 
1570 
1571 /** @cond doxygenLibsbmlInternal */
1572 /*
1573  * Subclasses should override this method to write out their contained
1574  * SBML objects as XML elements.  Be sure to call your parent's
1575  * implementation of this method as well.
1576  */
1577 void
writeElements(XMLOutputStream & stream) const1578 SpeciesReference::writeElements (XMLOutputStream& stream) const
1579 {
1580   if (mNotes != NULL)
1581   {
1582     mNotes->writeToStream(stream);
1583   }
1584   SpeciesReference * sr = const_cast <SpeciesReference *> (this);
1585   sr->syncAnnotation();
1586   if ( mAnnotation != NULL ) stream << *mAnnotation;
1587 
1588   if (getLevel() == 2)
1589   {
1590     if (mStoichiometryMath || mDenominator != 1)
1591     {
1592       if (mStoichiometryMath != NULL)
1593       {
1594         mStoichiometryMath->write(stream);
1595       }
1596       else
1597       {
1598         ASTNode node;
1599         node.setValue(static_cast<long>(mStoichiometry), mDenominator);
1600 
1601         stream.startElement("stoichiometryMath");
1602         writeMathML(&node, stream);
1603         stream.endElement("stoichiometryMath");
1604       }
1605     }
1606   }
1607 
1608   //
1609   // (EXTENSION)
1610   //
1611   SBase::writeExtensionElements(stream);
1612 
1613 }
1614 /** @endcond */
1615 
1616 
1617 /** @cond doxygenLibsbmlInternal */
1618 /*
1619  * Synchronizes the annotation of this SBML object.
1620  */
1621 void
syncAnnotation()1622 SpeciesReference::syncAnnotation ()
1623 {
1624   SBase::syncAnnotation();
1625 }
1626 /** @endcond */
1627 
1628 
1629 /** @cond doxygenLibsbmlInternal */
1630 bool
isExplicitlySetStoichiometry() const1631 SpeciesReference::isExplicitlySetStoichiometry() const
1632 {
1633   return mExplicitlySetStoichiometry;
1634 }
1635 /** @endcond */
1636 
1637 
1638 /** @cond doxygenLibsbmlInternal */
1639 bool
isExplicitlySetDenominator() const1640 SpeciesReference::isExplicitlySetDenominator() const
1641 {
1642   return mExplicitlySetDenominator;
1643 }
1644 /** @endcond */
1645 
1646 
1647 /*
1648  * Creates a new ListOfSpeciesReferences items.
1649  */
ListOfSpeciesReferences(unsigned int level,unsigned int version)1650 ListOfSpeciesReferences::ListOfSpeciesReferences (unsigned int level, unsigned int version)
1651   : ListOf(level,version)
1652  , mType(Unknown)
1653 {
1654 }
1655 
1656 
1657 /*
1658  * Creates a new ListOfSpeciesReferences items.
1659  */
ListOfSpeciesReferences(SBMLNamespaces * sbmlns)1660 ListOfSpeciesReferences::ListOfSpeciesReferences (SBMLNamespaces* sbmlns)
1661   : ListOf(sbmlns)
1662  , mType(Unknown)
1663 {
1664   loadPlugins(sbmlns);
1665 }
1666 
1667 
1668 /*
1669  * @return a (deep) copy of this ListOfSpeciesReferences.
1670  */
1671 ListOfSpeciesReferences*
clone() const1672 ListOfSpeciesReferences::clone () const
1673 {
1674   return new ListOfSpeciesReferences(*this);
1675 }
1676 
1677 
1678 /*
1679  * @return the typecode (int) of SBML objects contained in this ListOf or
1680  * SBML_UNKNOWN (default).
1681  */
1682 int
getItemTypeCode() const1683 ListOfSpeciesReferences::getItemTypeCode () const
1684 {
1685   switch(mType)
1686   {
1687   case Reactant:
1688   case Product:
1689     return SBML_SPECIES_REFERENCE;
1690   case Modifier:
1691     return SBML_MODIFIER_SPECIES_REFERENCE;
1692   case Unknown:
1693     return SBML_UNKNOWN;
1694   }
1695   //Shouldn't reach:  all enum values accounted for above
1696   return SBML_UNKNOWN;
1697 }
1698 
1699 
1700 /*
1701  * @return the name of this element ie "listOfReactants" or "listOfProducts" etc.
1702  */
1703 const string&
getElementName() const1704 ListOfSpeciesReferences::getElementName () const
1705 {
1706   static const string unknown   = "listOfUnknowns";
1707   static const string reactants = "listOfReactants";
1708   static const string products  = "listOfProducts";
1709   static const string modifiers = "listOfModifiers";
1710 
1711        if (mType == Reactant) return reactants;
1712   else if (mType == Product ) return products;
1713   else if (mType == Modifier) return modifiers;
1714   else return unknown;
1715 }
1716 
1717 
1718 /**
1719  * Used by ListOfSpeciesReferences::get() to lookup an SBase based by its id.
1720  */
1721 struct IdEqSSR : public unary_function<SBase*, bool>
1722 {
1723   const string& mId;
1724 
IdEqSSRIdEqSSR1725   IdEqSSR (const string& id) : mId(id) { }
operator ()IdEqSSR1726   bool operator() (SBase* sb)
1727        { return (static_cast <SimpleSpeciesReference *> (sb)->getId()  == mId)
1728          || (static_cast <SimpleSpeciesReference *> (sb)->getSpecies() == mId); }
1729 };
1730 
1731 
1732 /* return nth item in list */
1733 SimpleSpeciesReference *
get(unsigned int n)1734 ListOfSpeciesReferences::get(unsigned int n)
1735 {
1736   return static_cast<SimpleSpeciesReference*>(ListOf::get(n));
1737 }
1738 
1739 
1740 /* return nth item in list */
1741 const SimpleSpeciesReference *
get(unsigned int n) const1742 ListOfSpeciesReferences::get(unsigned int n) const
1743 {
1744   return static_cast<const SimpleSpeciesReference*>(ListOf::get(n));
1745 }
1746 
1747 
1748 /* return item by id */
1749 SimpleSpeciesReference*
get(const std::string & sid)1750 ListOfSpeciesReferences::get (const std::string& sid)
1751 {
1752   return const_cast<SimpleSpeciesReference*>(
1753     static_cast<const ListOfSpeciesReferences&>(*this).get(sid) );
1754 }
1755 
1756 
1757 /* return item by id */
1758 const SimpleSpeciesReference*
get(const std::string & sid) const1759 ListOfSpeciesReferences::get (const std::string& sid) const
1760 {
1761   vector<SBase*>::const_iterator result;
1762 
1763   result = find_if( mItems.begin(), mItems.end(), IdEqSSR(sid) );
1764   return (result == mItems.end()) ? NULL :
1765                            static_cast <SimpleSpeciesReference*> (*result);
1766 }
1767 
1768 
1769 /* Removes the nth item from this list */
1770 SimpleSpeciesReference*
remove(unsigned int n)1771 ListOfSpeciesReferences::remove (unsigned int n)
1772 {
1773    return static_cast<SimpleSpeciesReference*>(ListOf::remove(n));
1774 }
1775 
1776 
1777 /* Removes item in this list by id */
1778 SimpleSpeciesReference*
remove(const std::string & sid)1779 ListOfSpeciesReferences::remove (const std::string& sid)
1780 {
1781   SBase* item = NULL;
1782   vector<SBase*>::iterator result;
1783 
1784   result = find_if( mItems.begin(), mItems.end(), IdEqSSR(sid) );
1785 
1786   if (result != mItems.end())
1787   {
1788     item = *result;
1789     mItems.erase(result);
1790   }
1791 
1792   return static_cast <SimpleSpeciesReference*> (item);
1793 }
1794 
1795 
1796 /** @cond doxygenLibsbmlInternal */
1797 /*
1798  * @return the ordinal position of the element with respect to its siblings
1799  * or -1 (default) to indicate the position is not significant.
1800  */
1801 int
getElementPosition() const1802 ListOfSpeciesReferences::getElementPosition () const
1803 {
1804   int position;
1805 
1806   switch (mType)
1807   {
1808     case Reactant: position =  1; break;
1809     case Product:  position =  2; break;
1810     case Modifier: position =  3; break;
1811     default:       position = -1; break;
1812   }
1813 
1814   return position;
1815 }
1816 /** @endcond */
1817 
1818 
1819 /** @cond doxygenLibsbmlInternal */
1820 /*
1821  * Sets type of this ListOfSpeciesReferences.
1822  */
1823 void
setType(SpeciesType type)1824 ListOfSpeciesReferences::setType (SpeciesType type)
1825 {
1826   mType = type;
1827 }
1828 /** @endcond */
1829 
1830 /** @cond doxygenLibsbmlInternal */
1831 /*
1832  * gets type of this ListOfSpeciesReferences.
1833  */
1834 unsigned int
getType() const1835 ListOfSpeciesReferences::getType() const
1836 {
1837   switch (mType)
1838   {
1839   case Unknown:
1840     return 0;
1841 
1842   case Reactant:
1843     return 1;
1844 
1845   case Product:
1846     return 2;
1847 
1848   case Modifier:
1849     return 3;
1850 
1851   default:
1852     return 0;
1853 
1854   }
1855 }
1856 /** @endcond */
1857 
1858 /** @cond doxygenLibsbmlInternal */
1859 /*
1860  * @return the SBML object corresponding to next XMLToken in the
1861  * XMLInputStream or @c NULL if the token was not recognized.
1862  */
1863 SBase*
createObject(XMLInputStream & stream)1864 ListOfSpeciesReferences::createObject (XMLInputStream& stream)
1865 {
1866   const string& name   = stream.peek().getName();
1867   SBase*        object = NULL;
1868 
1869 
1870   if (mType == Reactant || mType == Product)
1871   {
1872     if (name == "speciesReference" || name == "specieReference")
1873     {
1874       try
1875       {
1876         object = new SpeciesReference(getSBMLNamespaces());
1877       }
1878       catch (SBMLConstructorException*)
1879       {
1880         object = new SpeciesReference(SBMLDocument::getDefaultLevel(),
1881         SBMLDocument::getDefaultVersion());
1882       }
1883       catch ( ... )
1884       {
1885         object = new SpeciesReference(SBMLDocument::getDefaultLevel(),
1886         SBMLDocument::getDefaultVersion());
1887       }
1888     }
1889     else if (name == "annotation" || name == "notes")
1890     {
1891       // do nothing
1892     }
1893     else
1894     {
1895       /* create the object anyway - or will also get unrecognized element message
1896        * which is confusion if user has merely reversed modifierSpeciesReference
1897        * and speciesReference */
1898       try
1899       {
1900         object = new SpeciesReference(getSBMLNamespaces());
1901       }
1902       catch (SBMLConstructorException*)
1903       {
1904         object = new SpeciesReference(SBMLDocument::getDefaultLevel(),
1905         SBMLDocument::getDefaultVersion());
1906       }
1907       catch ( ... )
1908       {
1909         object = new SpeciesReference(SBMLDocument::getDefaultLevel(),
1910         SBMLDocument::getDefaultVersion());
1911       }
1912       logError(InvalidReactantsProductsList);
1913     }
1914   }
1915   else if (mType == Modifier)
1916   {
1917     if (name == "modifierSpeciesReference")
1918     {
1919       try
1920       {
1921         object = new ModifierSpeciesReference(getSBMLNamespaces());
1922       }
1923       catch (SBMLConstructorException*)
1924       {
1925         object = new ModifierSpeciesReference(SBMLDocument::getDefaultLevel(),
1926         SBMLDocument::getDefaultVersion());
1927       }
1928       catch ( ... )
1929       {
1930         object = new ModifierSpeciesReference(SBMLDocument::getDefaultLevel(),
1931         SBMLDocument::getDefaultVersion());
1932       }
1933     }
1934     else if (name == "annotation" || name == "notes")
1935     {
1936       // do nothing
1937     }
1938     else
1939     {
1940       try
1941       {
1942         object = new ModifierSpeciesReference(getSBMLNamespaces());
1943       }
1944       catch (SBMLConstructorException*)
1945       {
1946         object = new ModifierSpeciesReference(SBMLDocument::getDefaultLevel(),
1947         SBMLDocument::getDefaultVersion());
1948       }
1949       catch ( ... )
1950       {
1951         object = new ModifierSpeciesReference(SBMLDocument::getDefaultLevel(),
1952         SBMLDocument::getDefaultVersion());
1953       }
1954       logError(InvalidModifiersList);
1955     }
1956   }
1957 
1958   if (object != NULL) mItems.push_back(object);
1959 
1960   return object;
1961 }
1962 /** @endcond */
1963 
1964 
1965 #endif /* __cplusplus */
1966 /** @cond doxygenIgnored */
1967 LIBSBML_EXTERN
1968 SpeciesReference_t *
SpeciesReference_create(unsigned int level,unsigned int version)1969 SpeciesReference_create (unsigned int level, unsigned int version)
1970 {
1971   try
1972   {
1973     SpeciesReference* obj = new SpeciesReference(level,version);
1974     return obj;
1975   }
1976   catch (SBMLConstructorException)
1977   {
1978     return NULL;
1979   }
1980 }
1981 
1982 
1983 LIBSBML_EXTERN
1984 SpeciesReference_t *
SpeciesReference_createWithNS(SBMLNamespaces_t * sbmlns)1985 SpeciesReference_createWithNS (SBMLNamespaces_t* sbmlns)
1986 {
1987   try
1988   {
1989     SpeciesReference* obj = new SpeciesReference(sbmlns);
1990     return obj;
1991   }
1992   catch (SBMLConstructorException)
1993   {
1994     return NULL;
1995   }
1996 }
1997 
1998 
1999 LIBSBML_EXTERN
2000 SpeciesReference_t *
SpeciesReference_createModifier(unsigned int level,unsigned int version)2001 SpeciesReference_createModifier (unsigned int level, unsigned int version)
2002 {
2003   try
2004   {
2005     ModifierSpeciesReference* obj = new ModifierSpeciesReference(level,version);
2006     return obj;
2007   }
2008   catch (SBMLConstructorException)
2009   {
2010     return NULL;
2011   }
2012 }
2013 
2014 
2015 LIBSBML_EXTERN
2016 SpeciesReference_t *
SpeciesReference_createModifierWithNS(SBMLNamespaces_t * sbmlns)2017 SpeciesReference_createModifierWithNS (SBMLNamespaces_t* sbmlns)
2018 {
2019   try
2020   {
2021     ModifierSpeciesReference* obj = new ModifierSpeciesReference(sbmlns);
2022     return obj;
2023   }
2024   catch (SBMLConstructorException)
2025   {
2026     return NULL;
2027   }
2028 }
2029 
2030 
2031 LIBSBML_EXTERN
2032 void
SpeciesReference_free(SpeciesReference_t * sr)2033 SpeciesReference_free (SpeciesReference_t *sr)
2034 {
2035   if (sr != NULL)
2036   delete sr;
2037 }
2038 
2039 
2040 LIBSBML_EXTERN
2041 SpeciesReference_t *
SpeciesReference_clone(const SpeciesReference_t * sr)2042 SpeciesReference_clone (const SpeciesReference_t *sr)
2043 {
2044   return (sr != NULL) ? static_cast<SpeciesReference_t*>( sr->clone() ) : NULL;
2045 }
2046 
2047 
2048 LIBSBML_EXTERN
2049 void
SpeciesReference_initDefaults(SpeciesReference_t * sr)2050 SpeciesReference_initDefaults (SpeciesReference_t *sr)
2051 {
2052   if (sr != NULL)
2053   {
2054     if (sr->isModifier()) return;
2055     static_cast<SpeciesReference*>(sr)->initDefaults();
2056   }
2057 }
2058 
2059 
2060 LIBSBML_EXTERN
2061 const XMLNamespaces_t *
SpeciesReference_getNamespaces(SpeciesReference_t * sr)2062 SpeciesReference_getNamespaces(SpeciesReference_t *sr)
2063 {
2064   return (sr != NULL) ? sr->getNamespaces() : NULL;
2065 }
2066 
2067 LIBSBML_EXTERN
2068 int
SpeciesReference_isModifier(const SpeciesReference_t * sr)2069 SpeciesReference_isModifier (const SpeciesReference_t *sr)
2070 {
2071   return (sr != NULL) ? static_cast<int>( sr->isModifier() ) : 0;
2072 }
2073 
2074 
2075 LIBSBML_EXTERN
2076 const char *
SpeciesReference_getId(const SpeciesReference_t * sr)2077 SpeciesReference_getId (const SpeciesReference_t *sr)
2078 {
2079   return (sr != NULL && sr->isSetId()) ? sr->getId().c_str() : NULL;
2080 }
2081 
2082 
2083 LIBSBML_EXTERN
2084 const char *
SpeciesReference_getName(const SpeciesReference_t * sr)2085 SpeciesReference_getName (const SpeciesReference_t *sr)
2086 {
2087   return (sr != NULL && sr->isSetName()) ? sr->getName().c_str() : NULL;
2088 }
2089 
2090 
2091 LIBSBML_EXTERN
2092 const char *
SpeciesReference_getSpecies(const SpeciesReference_t * sr)2093 SpeciesReference_getSpecies (const SpeciesReference_t *sr)
2094 {
2095   return (sr != NULL && sr->isSetSpecies()) ? sr->getSpecies().c_str() : NULL;
2096 }
2097 
2098 
2099 LIBSBML_EXTERN
2100 double
SpeciesReference_getStoichiometry(const SpeciesReference_t * sr)2101 SpeciesReference_getStoichiometry (const SpeciesReference_t *sr)
2102 {
2103   if (sr != NULL)
2104   {
2105     if (sr->isModifier()) return 0.0;
2106     return static_cast<const SpeciesReference*>(sr)->getStoichiometry();
2107   }
2108   else
2109     return numeric_limits<double>::quiet_NaN();
2110 }
2111 
2112 
2113 LIBSBML_EXTERN
2114 StoichiometryMath_t *
SpeciesReference_getStoichiometryMath(SpeciesReference_t * sr)2115 SpeciesReference_getStoichiometryMath (SpeciesReference_t *sr)
2116 {
2117   if (sr != NULL)
2118   {
2119     if (sr->isModifier()) return NULL;
2120     return static_cast<SpeciesReference*>(sr)->getStoichiometryMath();
2121   }
2122   else
2123     return NULL;
2124 }
2125 
2126 
2127 LIBSBML_EXTERN
2128 int
SpeciesReference_getDenominator(const SpeciesReference_t * sr)2129 SpeciesReference_getDenominator (const SpeciesReference_t *sr)
2130 {
2131   if (sr != NULL)
2132   {
2133     if (sr->isModifier()) return 0;
2134     return static_cast<const SpeciesReference*>(sr)->getDenominator();
2135   }
2136   else
2137     return SBML_INT_MAX;
2138 }
2139 
2140 
2141 LIBSBML_EXTERN
2142 int
SpeciesReference_getConstant(const SpeciesReference_t * sr)2143 SpeciesReference_getConstant (const SpeciesReference_t *sr)
2144 {
2145   if (sr != NULL)
2146   {
2147     if (sr->isModifier()) return 0;
2148     return static_cast<const SpeciesReference*>(sr)->getConstant();
2149   }
2150   else
2151     return 0;
2152 }
2153 
2154 
2155 LIBSBML_EXTERN
2156 int
SpeciesReference_isSetId(const SpeciesReference_t * sr)2157 SpeciesReference_isSetId (const SpeciesReference_t *sr)
2158 {
2159   return (sr != NULL) ? static_cast<int>( sr->isSetId() ) : 0;
2160 }
2161 
2162 
2163 LIBSBML_EXTERN
2164 int
SpeciesReference_isSetName(const SpeciesReference_t * sr)2165 SpeciesReference_isSetName (const SpeciesReference_t *sr)
2166 {
2167   return (sr != NULL) ? static_cast<int>( sr->isSetName() ) : 0;
2168 }
2169 
2170 
2171 LIBSBML_EXTERN
2172 int
SpeciesReference_isSetSpecies(const SpeciesReference_t * sr)2173 SpeciesReference_isSetSpecies (const SpeciesReference_t *sr)
2174 {
2175   return (sr != NULL) ? static_cast<int>( sr->isSetSpecies() ) : 0;
2176 }
2177 
2178 
2179 LIBSBML_EXTERN
2180 int
SpeciesReference_isSetStoichiometryMath(const SpeciesReference_t * sr)2181 SpeciesReference_isSetStoichiometryMath (const SpeciesReference_t *sr)
2182 {
2183   if (sr != NULL)
2184   {
2185     if (sr->isModifier()) return 0;
2186 
2187     return static_cast<int>
2188     (
2189       static_cast<const SpeciesReference*>(sr)->isSetStoichiometryMath()
2190     );
2191   }
2192   else
2193     return 0;
2194 }
2195 
2196 
2197 LIBSBML_EXTERN
2198 int
SpeciesReference_isSetStoichiometry(const SpeciesReference_t * sr)2199 SpeciesReference_isSetStoichiometry (const SpeciesReference_t *sr)
2200 {
2201   if (sr != NULL)
2202   {
2203     if (sr->isModifier()) return 0;
2204 
2205     return static_cast<int>(
2206       static_cast<const SpeciesReference*>(sr)->isSetStoichiometry() );
2207   }
2208   else
2209     return 0;
2210 }
2211 
2212 
2213 LIBSBML_EXTERN
2214 int
SpeciesReference_isSetConstant(const SpeciesReference_t * sr)2215 SpeciesReference_isSetConstant (const SpeciesReference_t *sr)
2216 {
2217   if (sr != NULL)
2218   {
2219     if (sr->isModifier()) return 0;
2220 
2221     return static_cast<int>
2222       (static_cast<const SpeciesReference*>(sr)->isSetConstant() );
2223   }
2224   else
2225     return 0;
2226 }
2227 
2228 
2229 LIBSBML_EXTERN
2230 int
SpeciesReference_setId(SpeciesReference_t * sr,const char * sid)2231 SpeciesReference_setId (SpeciesReference_t *sr, const char *sid)
2232 {
2233   if (sr != NULL)
2234     return (sid == NULL) ? sr->unsetId() : sr->setId(sid);
2235   else
2236     return LIBSBML_INVALID_OBJECT;
2237 }
2238 
2239 
2240 LIBSBML_EXTERN
2241 int
SpeciesReference_setName(SpeciesReference_t * sr,const char * name)2242 SpeciesReference_setName (SpeciesReference_t *sr, const char *name)
2243 {
2244   if (sr != NULL)
2245     return (name == NULL) ? sr->unsetName() : sr->setName(name);
2246   else
2247     return LIBSBML_INVALID_OBJECT;
2248 }
2249 
2250 
2251 LIBSBML_EXTERN
2252 int
SpeciesReference_setSpecies(SpeciesReference_t * sr,const char * sid)2253 SpeciesReference_setSpecies (SpeciesReference_t *sr, const char *sid)
2254 {
2255   if (sr != NULL)
2256     return sr->setSpecies(sid != NULL ? sid : "");
2257   else
2258     return LIBSBML_INVALID_OBJECT;
2259 }
2260 
2261 
2262 LIBSBML_EXTERN
2263 int
SpeciesReference_setStoichiometry(SpeciesReference_t * sr,double value)2264 SpeciesReference_setStoichiometry (SpeciesReference_t *sr, double value)
2265 {
2266   if (sr != NULL)
2267   {
2268     if (sr->isModifier()) return LIBSBML_UNEXPECTED_ATTRIBUTE;
2269     return static_cast<SpeciesReference*>(sr)->setStoichiometry(value);
2270   }
2271   else
2272     return LIBSBML_INVALID_OBJECT;
2273 }
2274 
2275 
2276 LIBSBML_EXTERN
2277 StoichiometryMath_t *
SpeciesReference_createStoichiometryMath(SpeciesReference_t * sr)2278 SpeciesReference_createStoichiometryMath (SpeciesReference_t *sr)
2279 {
2280   return (sr != NULL) ?
2281     static_cast<SpeciesReference*> (sr)->createStoichiometryMath() : NULL;
2282 }
2283 
2284 LIBSBML_EXTERN
2285 int
SpeciesReference_setStoichiometryMath(SpeciesReference_t * sr,const StoichiometryMath_t * math)2286 SpeciesReference_setStoichiometryMath (  SpeciesReference_t *sr
2287                                        , const StoichiometryMath_t    *math )
2288 {
2289   if (sr != NULL)
2290   {
2291     if (sr->isModifier()) return LIBSBML_UNEXPECTED_ATTRIBUTE;
2292     return static_cast<SpeciesReference*>(sr)->setStoichiometryMath(math);
2293   }
2294   else
2295     return LIBSBML_INVALID_OBJECT;
2296 }
2297 
2298 
2299 LIBSBML_EXTERN
2300 int
SpeciesReference_setDenominator(SpeciesReference_t * sr,int value)2301 SpeciesReference_setDenominator (SpeciesReference_t *sr, int value)
2302 {
2303   if (sr != NULL)
2304   {
2305     if (sr->isModifier()) return LIBSBML_UNEXPECTED_ATTRIBUTE;
2306     return static_cast<SpeciesReference*>(sr)->setDenominator(value);
2307   }
2308   else
2309     return LIBSBML_INVALID_OBJECT;
2310 }
2311 
2312 
2313 LIBSBML_EXTERN
2314 int
SpeciesReference_setConstant(SpeciesReference_t * sr,int value)2315 SpeciesReference_setConstant (SpeciesReference_t *sr, int value)
2316 {
2317   if (sr != NULL)
2318   {
2319     if (sr->isModifier()) return LIBSBML_UNEXPECTED_ATTRIBUTE;
2320     return static_cast<SpeciesReference*>(sr)->setConstant(value);
2321   }
2322   else
2323     return LIBSBML_INVALID_OBJECT;
2324 }
2325 
2326 
2327 LIBSBML_EXTERN
2328 int
SpeciesReference_unsetId(SpeciesReference_t * sr)2329 SpeciesReference_unsetId (SpeciesReference_t *sr)
2330 {
2331   return (sr != NULL) ? sr->unsetId() : LIBSBML_INVALID_OBJECT;
2332 }
2333 
2334 
2335 LIBSBML_EXTERN
2336 int
SpeciesReference_unsetName(SpeciesReference_t * sr)2337 SpeciesReference_unsetName (SpeciesReference_t *sr)
2338 {
2339   return (sr != NULL) ? sr->unsetName() : LIBSBML_INVALID_OBJECT;
2340 }
2341 
2342 
2343 LIBSBML_EXTERN
2344 int
SpeciesReference_unsetSpecies(SpeciesReference_t * sr)2345 SpeciesReference_unsetSpecies (SpeciesReference_t *sr)
2346 {
2347   return (sr != NULL) ? sr->unsetSpecies() : LIBSBML_INVALID_OBJECT;
2348 }
2349 
2350 
2351 LIBSBML_EXTERN
2352 int
SpeciesReference_unsetConstant(SpeciesReference_t * sr)2353 SpeciesReference_unsetConstant (SpeciesReference_t *sr)
2354 {
2355   return (sr != NULL) ? static_cast<SpeciesReference*>(sr)->unsetConstant()
2356                       : LIBSBML_INVALID_OBJECT;
2357 }
2358 
2359 
2360 LIBSBML_EXTERN
2361 int
SpeciesReference_unsetStoichiometryMath(SpeciesReference_t * sr)2362 SpeciesReference_unsetStoichiometryMath (SpeciesReference_t *sr)
2363 {
2364   if (sr != NULL)
2365   {
2366     if (sr->isModifier()) return LIBSBML_UNEXPECTED_ATTRIBUTE;
2367     return static_cast<SpeciesReference*>(sr)->unsetStoichiometryMath();
2368   }
2369   else
2370     return LIBSBML_INVALID_OBJECT;
2371 }
2372 
2373 
2374 LIBSBML_EXTERN
2375 int
SpeciesReference_unsetStoichiometry(SpeciesReference_t * sr)2376 SpeciesReference_unsetStoichiometry (SpeciesReference_t *sr)
2377 {
2378   if (sr != NULL)
2379   {
2380     if (sr->isModifier()) return LIBSBML_UNEXPECTED_ATTRIBUTE;
2381     return static_cast<SpeciesReference*>(sr)->unsetStoichiometry();
2382   }
2383   else
2384     return LIBSBML_INVALID_OBJECT;
2385 }
2386 
2387 
2388 LIBSBML_EXTERN
2389 int
SpeciesReference_hasRequiredAttributes(SpeciesReference_t * sr)2390 SpeciesReference_hasRequiredAttributes(SpeciesReference_t *sr)
2391 {
2392   return (sr != NULL) ? static_cast<int>(
2393     static_cast<SpeciesReference*>(sr)->hasRequiredAttributes()) : 0;
2394 }
2395 
2396 
2397 LIBSBML_EXTERN
2398 SpeciesReference_t *
ListOfSpeciesReferences_getById(ListOf_t * lo,const char * sid)2399 ListOfSpeciesReferences_getById (ListOf_t *lo, const char *sid)
2400 {
2401   if (lo != NULL)
2402     return (sid != NULL) ?
2403       static_cast <ListOfSpeciesReferences *> (lo)->get(sid) : NULL;
2404   else
2405     return NULL;
2406 }
2407 
2408 
2409 LIBSBML_EXTERN
2410 SpeciesReference_t *
ListOfSpeciesReferences_removeById(ListOf_t * lo,const char * sid)2411 ListOfSpeciesReferences_removeById (ListOf_t *lo, const char *sid)
2412 {
2413   if (lo != NULL)
2414     return (sid != NULL) ?
2415       static_cast <ListOfSpeciesReferences *> (lo)->remove(sid) : NULL;
2416   else
2417     return NULL;
2418 }
2419 /** @endcond */
2420 
2421 LIBSBML_CPP_NAMESPACE_END
2422 
2423