1 /**
2  * @file    Model.cpp
3  * @brief   Implementation of Model.
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 <sbml/xml/XMLNode.h>
43 #include <sbml/xml/XMLAttributes.h>
44 #include <sbml/xml/XMLInputStream.h>
45 #include <sbml/xml/XMLOutputStream.h>
46 
47 #include <sbml/annotation/RDFAnnotation.h>
48 #include <sbml/math/ASTNode.h>
49 
50 #include <sbml/SBMLDocument.h>
51 #include <sbml/SBO.h>
52 #include <sbml/SBMLVisitor.h>
53 #include <sbml/SBMLError.h>
54 #include <sbml/KineticLaw.h>
55 
56 #include <sbml/Model.h>
57 
58 #include <sbml/ModifierSpeciesReference.h>
59 #include <sbml/SimpleSpeciesReference.h>
60 
61 #include <sbml/AlgebraicRule.h>
62 #include <sbml/AssignmentRule.h>
63 #include <sbml/RateRule.h>
64 
65 #include <sbml/util/IdentifierTransformer.h>
66 #include <sbml/util/ElementFilter.h>
67 #include <sbml/util/IdFilter.h>
68 #include <sbml/util/MetaIdFilter.h>
69 
70 #include <sbml/extension/SBMLExtensionRegistry.h>
71 #include <sbml/extension/SBasePlugin.h>
72 
73 
74 
75 /** @cond doxygenIgnored */
76 using namespace std;
77 /** @endcond */
78 
79 LIBSBML_CPP_NAMESPACE_BEGIN
80 #ifdef __cplusplus
81 
Model(unsigned int level,unsigned int version)82 Model::Model (unsigned int level, unsigned int version) :
83    SBase ( level, version )
84  , mSubstanceUnits   ( "" )
85  , mTimeUnits        ( "" )
86  , mVolumeUnits      ( "" )
87  , mAreaUnits        ( "" )
88  , mLengthUnits      ( "" )
89  , mExtentUnits      ( "" )
90  , mConversionFactor ( "" )
91  , mFunctionDefinitions (level,version)
92  , mUnitDefinitions     (level,version)
93  , mCompartmentTypes    (level,version)
94  , mSpeciesTypes        (level,version)
95  , mCompartments        (level,version)
96  , mSpecies             (level,version)
97  , mParameters          (level,version)
98  , mInitialAssignments  (level,version)
99  , mRules               (level,version)
100  , mConstraints         (level,version)
101  , mReactions           (level,version)
102  , mEvents              (level,version)
103  , mFormulaUnitsData ( NULL  )
104  , mIdList (  )
105  , mMetaidList ( )
106  , mUnitsDataMap ()
107 {
108   if (!hasValidLevelVersionNamespaceCombination())
109     throw SBMLConstructorException();
110 
111   connectToChild();
112 }
113 
114 
Model(SBMLNamespaces * sbmlns)115 Model::Model (SBMLNamespaces * sbmlns) :
116    SBase             ( sbmlns )
117  , mSubstanceUnits   ( "" )
118  , mTimeUnits        ( "" )
119  , mVolumeUnits      ( "" )
120  , mAreaUnits        ( "" )
121  , mLengthUnits      ( "" )
122  , mExtentUnits      ( "" )
123  , mConversionFactor ( "" )
124  , mFunctionDefinitions (sbmlns)
125  , mUnitDefinitions     (sbmlns)
126  , mCompartmentTypes    (sbmlns)
127  , mSpeciesTypes        (sbmlns)
128  , mCompartments        (sbmlns)
129  , mSpecies             (sbmlns)
130  , mParameters          (sbmlns)
131  , mInitialAssignments  (sbmlns)
132  , mRules               (sbmlns)
133  , mConstraints         (sbmlns)
134  , mReactions           (sbmlns)
135  , mEvents              (sbmlns)
136  , mFormulaUnitsData ( NULL  )
137  , mIdList (  )
138  , mMetaidList ( )
139  , mUnitsDataMap ()
140 {
141   if (!hasValidLevelVersionNamespaceCombination())
142   {
143     throw SBMLConstructorException(getElementName(), sbmlns);
144   }
145 
146   connectToChild();
147   loadPlugins(sbmlns);
148 
149 }
150 
151 
152 /*
153  * Destroys this Model.
154  */
~Model()155 Model::~Model ()
156 {
157   if (mFormulaUnitsData != NULL)
158   {
159     unsigned int size = mFormulaUnitsData->getSize();
160     while (size > 0)
161     {
162       delete static_cast<FormulaUnitsData*>( mFormulaUnitsData->remove(0) );
163       size--;
164     }
165     delete mFormulaUnitsData;
166   }
167   mEvents.clear();
168   mUnitsDataMap.clear();
169 }
170 
171 
172 /*
173  * Copy constructor.
174  */
Model(const Model & orig)175 Model::Model(const Model& orig)
176   : SBase                (orig)
177   , mSubstanceUnits      (orig.mSubstanceUnits)
178   , mTimeUnits           (orig.mTimeUnits)
179   , mVolumeUnits         (orig.mVolumeUnits)
180   , mAreaUnits           (orig.mAreaUnits)
181   , mLengthUnits         (orig.mLengthUnits)
182   , mExtentUnits         (orig.mExtentUnits)
183   , mConversionFactor    (orig.mConversionFactor)
184   , mFunctionDefinitions (orig.mFunctionDefinitions)
185   , mUnitDefinitions     (orig.mUnitDefinitions)
186   , mCompartmentTypes    (orig.mCompartmentTypes)
187   , mSpeciesTypes        (orig.mSpeciesTypes)
188   , mCompartments        (orig.mCompartments)
189   , mSpecies             (orig.mSpecies)
190   , mParameters          (orig.mParameters)
191   , mInitialAssignments  (orig.mInitialAssignments)
192   , mRules               (orig.mRules)
193   , mConstraints         (orig.mConstraints)
194   , mReactions           (orig.mReactions)
195   , mEvents              (orig.mEvents)
196   , mFormulaUnitsData    (NULL)
197   , mIdList              (orig.mIdList)
198   , mMetaidList          (orig.mMetaidList)
199   , mUnitsDataMap        ()
200 {
201 
202   if (orig.mFormulaUnitsData != NULL)
203   {
204     this->mFormulaUnitsData = new List();
205     unsigned int i, iMax = orig.mFormulaUnitsData->getSize();
206     for (i = 0; i < iMax; ++i)
207     {
208       FormulaUnitsData *newFud = static_cast<FormulaUnitsData*>
209         (orig.mFormulaUnitsData->get(i))->clone();
210       this->mFormulaUnitsData->add((void *)newFud);
211       std::string id = newFud->getUnitReferenceId();
212       int typecode = newFud->getComponentTypecode();
213 
214       KeyValue key(id, typecode);
215       mUnitsDataMap.insert(make_pair(key, newFud));
216     }
217   }
218   connectToChild();
219 
220 }
221 
222 
223 /*
224  * Assignment operator
225  */
operator =(const Model & rhs)226 Model& Model::operator=(const Model& rhs)
227 {
228   if(&rhs!=this)
229   {
230     this->SBase::operator = (rhs);
231     mSubstanceUnits       = rhs.mSubstanceUnits ;
232     mTimeUnits            = rhs.mTimeUnits ;
233     mVolumeUnits          = rhs.mVolumeUnits ;
234     mAreaUnits            = rhs.mAreaUnits ;
235     mLengthUnits          = rhs.mLengthUnits ;
236     mExtentUnits          = rhs.mExtentUnits ;
237     mConversionFactor     = rhs.mConversionFactor ;
238     mFunctionDefinitions  = rhs.mFunctionDefinitions;
239     mUnitDefinitions      = rhs.mUnitDefinitions;
240     mCompartmentTypes     = rhs.mCompartmentTypes;
241     mSpeciesTypes         = rhs.mSpeciesTypes;
242     mCompartments         = rhs.mCompartments;
243     mSpecies              = rhs.mSpecies;
244     mParameters           = rhs.mParameters;
245     mInitialAssignments   = rhs.mInitialAssignments;
246     mRules                = rhs.mRules;
247     mConstraints          = rhs.mConstraints;
248     mReactions            = rhs.mReactions;
249     mEvents               = rhs.mEvents;
250 
251 
252     if (this->mFormulaUnitsData  != NULL)
253     {
254       unsigned int size = this->mFormulaUnitsData->getSize();
255       while (size--)
256         delete static_cast<FormulaUnitsData*>(
257                           this->mFormulaUnitsData->remove(0) );
258       delete this->mFormulaUnitsData;
259       mUnitsDataMap.clear();
260     }
261 
262     if(rhs.mFormulaUnitsData != NULL)
263     {
264       this->mFormulaUnitsData  = new List();
265       unsigned int i,iMax = rhs.mFormulaUnitsData->getSize();
266       for(i = 0; i < iMax; ++i)
267       {
268         FormulaUnitsData *newFud = static_cast<FormulaUnitsData*>
269           (rhs.mFormulaUnitsData->get(i))->clone();
270         this->mFormulaUnitsData->add((void *)newFud);
271         std::string id = newFud->getUnitReferenceId();
272         int typecode = newFud->getComponentTypecode();
273 
274         KeyValue key(id, typecode);
275         mUnitsDataMap.insert(make_pair(key, newFud));
276       }
277     }
278     else
279     {
280       this->mFormulaUnitsData = NULL;
281       mUnitsDataMap.clear();
282     }
283   }
284 
285   mIdList     = rhs.mIdList;
286   mMetaidList = rhs.mMetaidList;
287 
288   connectToChild();
289 
290   return *this;
291 }
292 
293 
294 /** @cond doxygenLibsbmlInternal */
295 bool
accept(SBMLVisitor & v) const296 Model::accept (SBMLVisitor& v) const
297 {
298   v.visit(*this);
299 
300   mFunctionDefinitions.accept(v);
301   mUnitDefinitions    .accept(v);
302   mCompartmentTypes   .accept(v);
303   mSpeciesTypes       .accept(v);
304   mCompartments       .accept(v);
305   mSpecies            .accept(v);
306   mParameters         .accept(v);
307   mInitialAssignments .accept(v);
308   mRules              .accept(v);
309   mConstraints        .accept(v);
310   mReactions          .accept(v);
311   mEvents             .accept(v);
312 
313   v.leave(*this);
314 
315   return true;
316 }
317 /** @endcond */
318 
319 
320 /*
321  * @return a (deep) copy of this Model.
322  */
323 Model*
clone() const324 Model::clone () const
325 {
326   return new Model(*this);
327 }
328 
329 SBase*
getElementBySId(const std::string & id)330 Model::getElementBySId(const std::string& id)
331 {
332   if (id.empty()) return NULL;
333   SBase* obj = mFunctionDefinitions.getElementBySId(id);
334   if (obj != NULL) return obj;
335   obj = mUnitDefinitions.getElementBySId(id);
336   if (obj != NULL) return obj;
337   obj = mCompartmentTypes.getElementBySId(id);
338   if (obj != NULL) return obj;
339   obj = mSpeciesTypes.getElementBySId(id);
340   if (obj != NULL) return obj;
341   obj = mCompartments.getElementBySId(id);
342   if (obj != NULL) return obj;
343   obj = mSpecies.getElementBySId(id);
344   if (obj != NULL) return obj;
345   obj = mParameters.getElementBySId(id);
346   if (obj != NULL) return obj;
347   obj = mReactions.getElementBySId(id);
348   if (obj != NULL) return obj;
349   obj = mInitialAssignments.getElementBySId(id);
350   if (obj != NULL) return obj;
351   obj = mRules.getElementBySId(id);
352   if (obj != NULL) return obj;
353   obj = mConstraints.getElementBySId(id);
354   if (obj != NULL) return obj;
355   obj = mEvents.getElementBySId(id);
356   if (obj != NULL) return obj;
357 
358   return getElementFromPluginsBySId(id);
359 }
360 
361 
362 SBase*
getElementByMetaId(const std::string & metaid)363 Model::getElementByMetaId(const std::string& metaid)
364 {
365   if (metaid.empty()) return NULL;
366   if (mFunctionDefinitions.getMetaId()==metaid) return &mFunctionDefinitions;
367   if (mUnitDefinitions.getMetaId()==metaid) return &mUnitDefinitions;
368   if (mCompartmentTypes.getMetaId()==metaid) return &mCompartmentTypes;
369   if (mSpeciesTypes.getMetaId()==metaid) return &mSpeciesTypes;
370   if (mCompartments.getMetaId()==metaid) return &mCompartments;
371   if (mSpecies.getMetaId()==metaid) return &mSpecies;
372   if (mParameters.getMetaId()==metaid) return &mParameters;
373   if (mInitialAssignments.getMetaId()==metaid) return &mInitialAssignments;
374   if (mRules.getMetaId()==metaid) return &mRules;
375   if (mConstraints.getMetaId()==metaid) return &mConstraints;
376   if (mReactions.getMetaId()==metaid) return &mReactions;
377   if (mEvents.getMetaId()==metaid) return &mEvents;
378 
379   SBase* obj = mFunctionDefinitions.getElementByMetaId(metaid);
380   if (obj != NULL) return obj;
381   obj = mUnitDefinitions.getElementByMetaId(metaid);
382   if (obj != NULL) return obj;
383   obj = mCompartmentTypes.getElementByMetaId(metaid);
384   if (obj != NULL) return obj;
385   obj = mSpeciesTypes.getElementByMetaId(metaid);
386   if (obj != NULL) return obj;
387   obj = mCompartments.getElementByMetaId(metaid);
388   if (obj != NULL) return obj;
389   obj = mSpecies.getElementByMetaId(metaid);
390   if (obj != NULL) return obj;
391   obj = mParameters.getElementByMetaId(metaid);
392   if (obj != NULL) return obj;
393   obj = mInitialAssignments.getElementByMetaId(metaid);
394   if (obj != NULL) return obj;
395   obj = mRules.getElementByMetaId(metaid);
396   if (obj != NULL) return obj;
397   obj = mConstraints.getElementByMetaId(metaid);
398   if (obj != NULL) return obj;
399   obj = mReactions.getElementByMetaId(metaid);
400   if (obj != NULL) return obj;
401   obj = mEvents.getElementByMetaId(metaid);
402   if (obj != NULL) return obj;
403 
404   return getElementFromPluginsByMetaId(metaid);
405 }
406 
407 
408 List*
getAllElements(ElementFilter * filter)409 Model::getAllElements(ElementFilter *filter)
410 {
411   List* ret = new List();
412   List* sublist = NULL;
413 
414   ADD_FILTERED_LIST(ret, sublist, mFunctionDefinitions, filter);
415   ADD_FILTERED_LIST(ret, sublist, mUnitDefinitions, filter);
416   ADD_FILTERED_LIST(ret, sublist, mCompartmentTypes, filter);
417   ADD_FILTERED_LIST(ret, sublist, mSpeciesTypes, filter);
418   ADD_FILTERED_LIST(ret, sublist, mCompartments, filter);
419   ADD_FILTERED_LIST(ret, sublist, mSpecies, filter);
420   ADD_FILTERED_LIST(ret, sublist, mParameters, filter);
421   ADD_FILTERED_LIST(ret, sublist, mInitialAssignments, filter);
422   ADD_FILTERED_LIST(ret, sublist, mRules, filter);
423   ADD_FILTERED_LIST(ret, sublist, mConstraints, filter);
424   ADD_FILTERED_LIST(ret, sublist, mReactions, filter);
425   ADD_FILTERED_LIST(ret, sublist, mEvents, filter);
426 
427   ADD_FILTERED_FROM_PLUGIN(ret, sublist, filter);
428 
429   return ret;
430 }
431 
432 
433 /** @cond doxygenLibsbmlInternal */
434 int
renameAllIds(IdentifierTransformer * idTransformer,ElementFilter * filter)435 Model::renameAllIds(IdentifierTransformer* idTransformer, ElementFilter* filter)
436 {
437   if (idTransformer == NULL)
438   return LIBSBML_OPERATION_SUCCESS;
439 
440   //get all elements
441   List* allElements = getAllElements(filter);
442 
443   //Rename the SIds, UnitSIds, and MetaIDs
444   renameIDs(allElements, idTransformer);
445 
446   delete allElements;
447 
448   return LIBSBML_OPERATION_SUCCESS;
449 }
450 /** @endcond */
451 
452 
453 /** @cond doxygenLibsbmlInternal */
454 void
renameIDs(List * elements,IdentifierTransformer * idTransformer)455 Model::renameIDs(List* elements, IdentifierTransformer* idTransformer)
456 {
457   if (elements == NULL || elements->getSize() == 0 || idTransformer == NULL)
458     return;
459 
460   vector<pair<string, string> > renamedSIds;
461   vector<pair<string, string> > renamedUnitSIds;
462   vector<pair<string, string> > renamedMetaIds;
463   vector<pair<string, string> >::iterator it;
464 
465   for (unsigned long el=0; el < elements->getSize(); ++el)
466   {
467     SBase* element = static_cast<SBase*>(elements->get((unsigned int)el));
468     string id = element->getId();
469     string metaid = element->getMetaId();
470     element->transformIdentifiers(idTransformer);
471 
472     if (element->getTypeCode() == SBML_LOCAL_PARAMETER)
473   {
474       element->setId(id); //Change it back.  This would perhaps be better served by overriding 'prependStringToAllIdentifiers' but hey.
475     }
476     string newid = element->getId();
477     string newmetaid = element->getMetaId();
478     if (id != newid)
479   {
480       int type = element->getTypeCode();
481       if (type==SBML_UNIT_DEFINITION)
482     {
483         renamedUnitSIds.push_back(make_pair(id, newid));
484       }
485       //else if (type==SBML_COMP_PORT)
486     //{
487       //  //Do nothing--these can only be referenced from outside the Model, so they need to be handled specially.
488       //  // (In the default case, we throw them away).
489       //}
490       else
491     {
492         //This is a little dangerous, but hey!  What's a little danger between friends!
493         //(What we are assuming is that any attribute you can get with 'getId' is of the type 'SId')
494         renamedSIds.push_back(make_pair(id, newid));
495       }
496     }
497     if (metaid != newmetaid)
498   {
499       renamedMetaIds.push_back(make_pair(metaid, newmetaid));
500     }
501   }
502 
503   for (unsigned long el = 0; el< elements->getSize(); ++el)
504   {
505     SBase* element = static_cast<SBase*>(elements->get((unsigned int)el));
506 
507     for (it = renamedSIds.begin(); it != renamedSIds.end(); ++it)
508   {
509       element->renameSIdRefs((*it).first, (*it).second);
510     }
511 
512     for (it = renamedUnitSIds.begin(); it != renamedUnitSIds.end(); ++it)
513   {
514       element->renameUnitSIdRefs((*it).first, (*it).second);
515     }
516 
517     for (it = renamedMetaIds.begin(); it != renamedMetaIds.end(); ++it)
518   {
519       element->renameMetaIdRefs((*it).first, (*it).second);
520     }
521   }
522 }
523 /** @endcond */
524 
525 
526 /** @cond doxygenLibsbmlInternal */
527 /*
528  * @return the id of this SBML object.
529  */
530 const string&
getId() const531 Model::getId () const
532 {
533   return mId;
534 }
535 /** @endcond */
536 
537 
538 /*
539  * @return the name of this SBML object.
540  */
541 const string&
getName() const542 Model::getName () const
543 {
544   return (getLevel() == 1) ? mId : mName;
545 }
546 
547 
548 /*
549  * Returns the value of the "substanceUnits" attribute of this Model.
550  */
551 const std::string&
getSubstanceUnits() const552 Model::getSubstanceUnits () const
553 {
554   return mSubstanceUnits;
555 }
556 
557 
558 /*
559  * Returns the value of the "timeUnits" attribute of this Model.
560  */
561 const std::string&
getTimeUnits() const562 Model::getTimeUnits () const
563 {
564   return mTimeUnits;
565 }
566 
567 /*
568  * Returns the value of the "volumeUnits" attribute of this Model.
569  */
570 const std::string&
getVolumeUnits() const571 Model::getVolumeUnits () const
572 {
573   return mVolumeUnits;
574 }
575 
576 
577 /*
578  * Returns the value of the "areaUnits" attribute of this Model.
579  */
580 const std::string&
getAreaUnits() const581 Model::getAreaUnits () const
582 {
583   return mAreaUnits;
584 }
585 
586 
587 /*
588  * Returns the value of the "lengthUnits" attribute of this Model.
589  */
590 const std::string&
getLengthUnits() const591 Model::getLengthUnits () const
592 {
593   return mLengthUnits;
594 }
595 
596 
597 /*
598  * Returns the value of the "extentUnits" attribute of this Model.
599  */
600 const std::string&
getExtentUnits() const601 Model::getExtentUnits () const
602 {
603   return mExtentUnits;
604 }
605 
606 
607 /*
608  * Returns the value of the "conversionFactor" attribute of this Model.
609  */
610 const std::string&
getConversionFactor() const611 Model::getConversionFactor () const
612 {
613   return mConversionFactor;
614 }
615 
616 
617 
618 /*
619  * @return @c true if the id of this SBML object has been set, false
620  * otherwise.
621  */
622 bool
isSetId() const623 Model::isSetId () const
624 {
625   return (mId.empty() == false);
626 }
627 
628 
629 /*
630  * @return @c true if the name of this SBML object is set, false
631  * otherwise.
632  */
633 bool
isSetName() const634 Model::isSetName () const
635 {
636   return (getLevel() == 1) ? (mId.empty() == false) :
637                             (mName.empty() == false);
638 }
639 
640 
641 /*
642  * Predicate returning @c true if this
643  * Model's "substanceUnits" attribute is set.
644  */
645 bool
isSetSubstanceUnits() const646 Model::isSetSubstanceUnits () const
647 {
648   return (mSubstanceUnits.empty() == false);
649 }
650 
651 
652 /*
653  * Predicate returning @c true if this
654  * Model's "timeUnits" attribute is set.
655  */
656 bool
isSetTimeUnits() const657 Model::isSetTimeUnits () const
658 {
659   return (mTimeUnits.empty() == false);
660 }
661 
662 
663 /*
664  * Predicate returning @c true if this
665  * Model's "volumeUnits" attribute is set.
666  */
667 bool
isSetVolumeUnits() const668 Model::isSetVolumeUnits () const
669 {
670   return (mVolumeUnits.empty() == false);
671 }
672 
673 
674 /*
675  * Predicate returning @c true if this
676  * Model's "areaUnits" attribute is set.
677  */
678 bool
isSetAreaUnits() const679 Model::isSetAreaUnits () const
680 {
681   return (mAreaUnits.empty() == false);
682 }
683 
684 
685 /*
686  * Predicate returning @c true if this
687  * Model's "lengthUnits" attribute is set.
688  */
689 bool
isSetLengthUnits() const690 Model::isSetLengthUnits () const
691 {
692   return (mLengthUnits.empty() == false);
693 }
694 
695 
696 /*
697  * Predicate returning @c true if this
698  * Model's "extentUnits" attribute is set.
699  */
700 bool
isSetExtentUnits() const701 Model::isSetExtentUnits () const
702 {
703   return (mExtentUnits.empty() == false);
704 }
705 
706 
707 /*
708  * Predicate returning @c true if this
709  * Model's "conversionFactor" attribute is set.
710  */
711 bool
isSetConversionFactor() const712 Model::isSetConversionFactor () const
713 {
714   return (mConversionFactor.empty() == false);
715 }
716 
717 
718 /*
719  * Sets the id of this SBML object to a copy of @p sid.
720  */
721 int
setId(const std::string & sid)722 Model::setId (const std::string& sid)
723 {
724   /* since the setId function has been used as an
725    * alias for setName we cant require it to only
726    * be used on a L2 model
727    */
728 /*  if (getLevel() == 1)
729   {
730     return LIBSBML_UNEXPECTED_ATTRIBUTE;
731   }
732 */
733   if (!(SyntaxChecker::isValidInternalSId(sid)))
734   {
735     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
736   }
737   else
738   {
739     mId = sid;
740     return LIBSBML_OPERATION_SUCCESS;
741   }
742 }
743 
744 
745 /*
746  * Sets the name of this SBML object to a copy of name.
747  */
748 int
setName(const std::string & name)749 Model::setName (const std::string& name)
750 {
751   /* if this is setting an L2 name the type is string
752    * whereas if it is setting an L1 name its type is SId
753    */
754   if (getLevel() == 1)
755   {
756     if (!(SyntaxChecker::isValidInternalSId(name)))
757     {
758       return LIBSBML_INVALID_ATTRIBUTE_VALUE;
759     }
760     else
761     {
762       mId = name;
763       return LIBSBML_OPERATION_SUCCESS;
764     }
765   }
766   else
767   {
768     mName = name;
769     return LIBSBML_OPERATION_SUCCESS;
770   }
771 }
772 
773 
774 /*
775  * Sets the substanceUnits of this SBML object.
776  */
777 int
setSubstanceUnits(const std::string & units)778 Model::setSubstanceUnits (const std::string& units)
779 {
780   if (getLevel() < 3)
781   {
782     return LIBSBML_UNEXPECTED_ATTRIBUTE;
783   }
784   else if (!(SyntaxChecker::isValidInternalUnitSId(units)))
785   {
786     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
787   }
788   else
789   {
790     mSubstanceUnits = units;
791     return LIBSBML_OPERATION_SUCCESS;
792   }
793 }
794 
795 
796 /*
797  * Sets the substanceUnits of this SBML object.
798  */
799 int
setTimeUnits(const std::string & units)800 Model::setTimeUnits (const std::string& units)
801 {
802   if (getLevel() < 3)
803   {
804     return LIBSBML_UNEXPECTED_ATTRIBUTE;
805   }
806   else if (!(SyntaxChecker::isValidInternalUnitSId(units)))
807   {
808     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
809   }
810   else
811   {
812     mTimeUnits = units;
813     return LIBSBML_OPERATION_SUCCESS;
814   }
815 }
816 
817 
818 /*
819  * Sets the substanceUnits of this SBML object.
820  */
821 int
setVolumeUnits(const std::string & units)822 Model::setVolumeUnits (const std::string& units)
823 {
824   if (getLevel() < 3)
825   {
826     return LIBSBML_UNEXPECTED_ATTRIBUTE;
827   }
828   else if (!(SyntaxChecker::isValidInternalUnitSId(units)))
829   {
830     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
831   }
832   else
833   {
834     mVolumeUnits = units;
835     return LIBSBML_OPERATION_SUCCESS;
836   }
837 }
838 
839 
840 /*
841  * Sets the substanceUnits of this SBML object.
842  */
843 int
setAreaUnits(const std::string & units)844 Model::setAreaUnits (const std::string& units)
845 {
846   if (getLevel() < 3)
847   {
848     return LIBSBML_UNEXPECTED_ATTRIBUTE;
849   }
850   else if (!(SyntaxChecker::isValidInternalUnitSId(units)))
851   {
852     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
853   }
854   else
855   {
856     mAreaUnits = units;
857     return LIBSBML_OPERATION_SUCCESS;
858   }
859 }
860 
861 
862 /*
863  * Sets the substanceUnits of this SBML object.
864  */
865 int
setLengthUnits(const std::string & units)866 Model::setLengthUnits (const std::string& units)
867 {
868   if (getLevel() < 3)
869   {
870     return LIBSBML_UNEXPECTED_ATTRIBUTE;
871   }
872   else if (!(SyntaxChecker::isValidInternalUnitSId(units)))
873   {
874     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
875   }
876   else
877   {
878     mLengthUnits = units;
879     return LIBSBML_OPERATION_SUCCESS;
880   }
881 }
882 
883 
884 /*
885  * Sets the substanceUnits of this SBML object.
886  */
887 int
setExtentUnits(const std::string & units)888 Model::setExtentUnits (const std::string& units)
889 {
890   if (getLevel() < 3)
891   {
892     return LIBSBML_UNEXPECTED_ATTRIBUTE;
893   }
894   else if (!(SyntaxChecker::isValidInternalUnitSId(units)))
895   {
896     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
897   }
898   else
899   {
900     mExtentUnits = units;
901     return LIBSBML_OPERATION_SUCCESS;
902   }
903 }
904 
905 
906 /*
907  * Sets the substanceUnits of this SBML object.
908  */
909 int
setConversionFactor(const std::string & id)910 Model::setConversionFactor (const std::string& id)
911 {
912   if (getLevel() < 3)
913   {
914     return LIBSBML_UNEXPECTED_ATTRIBUTE;
915   }
916   else if (!(SyntaxChecker::isValidInternalSId(id)))
917   {
918     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
919   }
920   else
921   {
922     mConversionFactor = id;
923     return LIBSBML_OPERATION_SUCCESS;
924   }
925 }
926 
927 
928 /*
929  * Unsets the id of this SBML object.
930  */
931 int
unsetId()932 Model::unsetId ()
933 {
934   mId.erase();
935 
936   if (mId.empty())
937   {
938     return LIBSBML_OPERATION_SUCCESS;
939   }
940   else
941   {
942     return LIBSBML_OPERATION_FAILED;
943   }
944 }
945 
946 
947 /*
948  * Unsets the name of this SBML object.
949  */
950 int
unsetName()951 Model::unsetName ()
952 {
953   if (getLevel() == 1)
954   {
955     mId.erase();
956   }
957   else
958   {
959     mName.erase();
960   }
961 
962   if (getLevel() == 1 && mId.empty())
963   {
964     return LIBSBML_OPERATION_SUCCESS;
965   }
966   else if (mName.empty())
967   {
968     return LIBSBML_OPERATION_SUCCESS;
969   }
970   else
971   {
972     return LIBSBML_OPERATION_FAILED;
973   }
974 }
975 
976 
977 
978 /*
979  * Unsets the SubstanceUnits of this SBML object.
980  */
981 int
unsetSubstanceUnits()982 Model::unsetSubstanceUnits ()
983 {
984   /* only in L3 */
985   if (getLevel() < 3)
986   {
987     mSubstanceUnits.erase();
988     return LIBSBML_UNEXPECTED_ATTRIBUTE;
989   }
990 
991   mSubstanceUnits.erase();
992 
993   if (mSubstanceUnits.empty())
994   {
995     return LIBSBML_OPERATION_SUCCESS;
996   }
997   else
998   {
999     return LIBSBML_OPERATION_FAILED;
1000   }
1001 }
1002 
1003 
1004 /*
1005  * Unsets the TimeUnits of this SBML object.
1006  */
1007 int
unsetTimeUnits()1008 Model::unsetTimeUnits ()
1009 {
1010   /* only in L3 */
1011   if (getLevel() < 3)
1012   {
1013     mTimeUnits.erase();
1014     return LIBSBML_UNEXPECTED_ATTRIBUTE;
1015   }
1016 
1017   mTimeUnits.erase();
1018 
1019   if (mTimeUnits.empty())
1020   {
1021     return LIBSBML_OPERATION_SUCCESS;
1022   }
1023   else
1024   {
1025     return LIBSBML_OPERATION_FAILED;
1026   }
1027 }
1028 
1029 
1030 /*
1031  * Unsets the VolumeUnits of this SBML object.
1032  */
1033 int
unsetVolumeUnits()1034 Model::unsetVolumeUnits ()
1035 {
1036   /* only in L3 */
1037   if (getLevel() < 3)
1038   {
1039     mVolumeUnits.erase();
1040     return LIBSBML_UNEXPECTED_ATTRIBUTE;
1041   }
1042 
1043   mVolumeUnits.erase();
1044 
1045   if (mVolumeUnits.empty())
1046   {
1047     return LIBSBML_OPERATION_SUCCESS;
1048   }
1049   else
1050   {
1051     return LIBSBML_OPERATION_FAILED;
1052   }
1053 }
1054 
1055 
1056 /*
1057  * Unsets the AreaUnits of this SBML object.
1058  */
1059 int
unsetAreaUnits()1060 Model::unsetAreaUnits ()
1061 {
1062   /* only in L3 */
1063   if (getLevel() < 3)
1064   {
1065     mAreaUnits.erase();
1066     return LIBSBML_UNEXPECTED_ATTRIBUTE;
1067   }
1068 
1069   mAreaUnits.erase();
1070 
1071   if (mAreaUnits.empty())
1072   {
1073     return LIBSBML_OPERATION_SUCCESS;
1074   }
1075   else
1076   {
1077     return LIBSBML_OPERATION_FAILED;
1078   }
1079 }
1080 
1081 
1082 /*
1083  * Unsets the LengthUnits of this SBML object.
1084  */
1085 int
unsetLengthUnits()1086 Model::unsetLengthUnits ()
1087 {
1088   /* only in L3 */
1089   if (getLevel() < 3)
1090   {
1091     mLengthUnits.erase();
1092     return LIBSBML_UNEXPECTED_ATTRIBUTE;
1093   }
1094 
1095   mLengthUnits.erase();
1096 
1097   if (mLengthUnits.empty())
1098   {
1099     return LIBSBML_OPERATION_SUCCESS;
1100   }
1101   else
1102   {
1103     return LIBSBML_OPERATION_FAILED;
1104   }
1105 }
1106 
1107 
1108 /*
1109  * Unsets the LengthUnits of this SBML object.
1110  */
1111 int
unsetExtentUnits()1112 Model::unsetExtentUnits ()
1113 {
1114   /* only in L3 */
1115   if (getLevel() < 3)
1116   {
1117     mExtentUnits.erase();
1118     return LIBSBML_UNEXPECTED_ATTRIBUTE;
1119   }
1120 
1121   mExtentUnits.erase();
1122 
1123   if (mExtentUnits.empty())
1124   {
1125     return LIBSBML_OPERATION_SUCCESS;
1126   }
1127   else
1128   {
1129     return LIBSBML_OPERATION_FAILED;
1130   }
1131 }
1132 
1133 
1134 /*
1135  * Unsets the ConversionFactor of this SBML object.
1136  */
1137 int
unsetConversionFactor()1138 Model::unsetConversionFactor ()
1139 {
1140   /* only in L3 */
1141   if (getLevel() < 3)
1142   {
1143     mConversionFactor.erase();
1144     return LIBSBML_UNEXPECTED_ATTRIBUTE;
1145   }
1146 
1147   mConversionFactor.erase();
1148 
1149   if (mConversionFactor.empty())
1150   {
1151     return LIBSBML_OPERATION_SUCCESS;
1152   }
1153   else
1154   {
1155     return LIBSBML_OPERATION_FAILED;
1156   }
1157 }
1158 
1159 
1160 /*
1161  * Adds a copy of the given FunctionDefinition to this Model.
1162  */
1163 int
addFunctionDefinition(const FunctionDefinition * fd)1164 Model::addFunctionDefinition (const FunctionDefinition* fd)
1165 {
1166   int returnValue = checkCompatibility(static_cast<const SBase *>(fd));
1167   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1168   {
1169     return returnValue;
1170   }
1171   else if (getFunctionDefinition(fd->getId()) != NULL)
1172   {
1173     // an object with this id already exists
1174     return LIBSBML_DUPLICATE_OBJECT_ID;
1175   }
1176   else
1177   {
1178     return mFunctionDefinitions.append(fd);
1179   }
1180 }
1181 
1182 
1183 /*
1184  * Adds a copy of the given UnitDefinition to this Model.
1185  */
1186 int
addUnitDefinition(const UnitDefinition * ud)1187 Model::addUnitDefinition (const UnitDefinition* ud)
1188 {
1189   int returnValue = checkCompatibility(static_cast<const SBase *>(ud));
1190   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1191   {
1192     return returnValue;
1193   }
1194   else if (getUnitDefinition(ud->getId()) != NULL)
1195   {
1196     // an object with this id already exists
1197     return LIBSBML_DUPLICATE_OBJECT_ID;
1198   }
1199   else
1200   {
1201     return mUnitDefinitions.append(ud);
1202   }
1203 }
1204 
1205 
1206 /*
1207  * Adds a copy of the given CompartmentType to this Model.
1208  */
1209 int
addCompartmentType(const CompartmentType * ct)1210 Model::addCompartmentType (const CompartmentType* ct)
1211 {
1212   int returnValue = checkCompatibility(static_cast<const SBase *>(ct));
1213   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1214   {
1215     return returnValue;
1216   }
1217   else if (getCompartmentType(ct->getId()) != NULL)
1218   {
1219     // an object with this id already exists
1220     return LIBSBML_DUPLICATE_OBJECT_ID;
1221   }
1222   else
1223   {
1224     return mCompartmentTypes.append(ct);
1225   }
1226 }
1227 
1228 
1229 /*
1230  * Adds a copy of the given SpeciesType to this Model.
1231  */
1232 int
addSpeciesType(const SpeciesType * st)1233 Model::addSpeciesType (const SpeciesType* st)
1234 {
1235   int returnValue = checkCompatibility(static_cast<const SBase *>(st));
1236   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1237   {
1238     return returnValue;
1239   }
1240   else if (getSpeciesType(st->getId()) != NULL)
1241   {
1242     // an object with this id already exists
1243     return LIBSBML_DUPLICATE_OBJECT_ID;
1244   }
1245   else
1246   {
1247     return mSpeciesTypes.append(st);
1248   }
1249 }
1250 
1251 
1252 /*
1253  * Adds a copy of the given Compartment to this Model.
1254  */
1255 int
addCompartment(const Compartment * c)1256 Model::addCompartment (const Compartment* c)
1257 {
1258   int returnValue = checkCompatibility(static_cast<const SBase *>(c));
1259   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1260   {
1261     return returnValue;
1262   }
1263   else if (getCompartment(c->getId()) != NULL)
1264   {
1265     // an object with this id already exists
1266     return LIBSBML_DUPLICATE_OBJECT_ID;
1267   }
1268   else
1269   {
1270     return mCompartments.append(c);
1271   }
1272 }
1273 
1274 
1275 /*
1276  * Adds a copy of the given Species to this Model.
1277  */
1278 int
addSpecies(const Species * s)1279 Model::addSpecies (const Species* s)
1280 {
1281   int returnValue = checkCompatibility(static_cast<const SBase *>(s));
1282   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1283   {
1284     return returnValue;
1285   }
1286   else if (getSpecies(s->getId()) != NULL)
1287   {
1288     // an object with this id already exists
1289     return LIBSBML_DUPLICATE_OBJECT_ID;
1290   }
1291   else
1292   {
1293     return mSpecies.append(s);
1294   }
1295 }
1296 
1297 
1298 /*
1299  * Adds a copy of the given Parameter to this Model.
1300  */
1301 int
addParameter(const Parameter * p)1302 Model::addParameter (const Parameter* p)
1303 {
1304   int returnValue = checkCompatibility(static_cast<const SBase *>(p));
1305   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1306   {
1307     return returnValue;
1308   }
1309   else if (getParameter(p->getId()) != NULL)
1310   {
1311     // an object with this id already exists
1312     return LIBSBML_DUPLICATE_OBJECT_ID;
1313   }
1314   else
1315   {
1316     /* hack so that this will accept a local parameter !! */
1317     if (p->getTypeCode() == SBML_LOCAL_PARAMETER)
1318     {
1319       Parameter p1(*p);
1320       return mParameters.append(&p1);
1321     }
1322     else
1323     {
1324       return mParameters.append(p);
1325     }
1326   }
1327 }
1328 
1329 
1330 /*
1331  * Adds a copy of the given InitialAssignment to this Model.
1332  */
1333 int
addInitialAssignment(const InitialAssignment * ia)1334 Model::addInitialAssignment (const InitialAssignment* ia)
1335 {
1336   int returnValue = checkCompatibility(static_cast<const SBase *>(ia));
1337   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1338   {
1339     return returnValue;
1340   }
1341   else if (getInitialAssignment(ia->getSymbol()) != NULL)
1342   {
1343     // an object with this id already exists
1344     return LIBSBML_DUPLICATE_OBJECT_ID;
1345   }
1346   else
1347   {
1348     return mInitialAssignments.append(ia);
1349   }
1350 }
1351 
1352 
1353 /*
1354  * Adds a copy of the given Rule to this Model.
1355  */
1356 int
addRule(const Rule * r)1357 Model::addRule (const Rule* r)
1358 {
1359   int returnValue = checkCompatibility(static_cast<const SBase *>(r));
1360   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1361   {
1362     return returnValue;
1363   }
1364   else if (!r->isAlgebraic()
1365          && getRule(r->getVariable()) != NULL)
1366   {
1367     // an object with this id already exists
1368     return LIBSBML_DUPLICATE_OBJECT_ID;
1369   }
1370   else
1371   {
1372     return mRules.append(r);
1373   }
1374 }
1375 
1376 
1377 /*
1378  * Adds a copy of the given Constraint to this Model.
1379  */
1380 int
addConstraint(const Constraint * c)1381 Model::addConstraint (const Constraint* c)
1382 {
1383   int returnValue = checkCompatibility(static_cast<const SBase *>(c));
1384   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1385   {
1386     return returnValue;
1387   }
1388   else
1389   {
1390     return mConstraints.append(c);
1391   }
1392 }
1393 
1394 
1395 /*
1396  * Adds a copy of the given Reaction to this Model.
1397  */
1398 int
addReaction(const Reaction * r)1399 Model::addReaction (const Reaction* r)
1400 {
1401   int returnValue = checkCompatibility(static_cast<const SBase *>(r));
1402   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1403   {
1404     return returnValue;
1405   }
1406   else if (getReaction(r->getId()) != NULL)
1407   {
1408     // an object with this id already exists
1409     return LIBSBML_DUPLICATE_OBJECT_ID;
1410   }
1411   else
1412   {
1413     return mReactions.append(r);
1414   }
1415 }
1416 
1417 
1418 /*
1419  * Adds a copy of the given Event to this Model.
1420  */
1421 int
addEvent(const Event * e)1422 Model::addEvent (const Event* e)
1423 {
1424   int returnValue = checkCompatibility(static_cast<const SBase *>(e));
1425   if (returnValue != LIBSBML_OPERATION_SUCCESS)
1426   {
1427     return returnValue;
1428   }
1429   else if (e->isSetId() && getEvent(e->getId()) != NULL)
1430   {
1431     // an object with this id already exists
1432     return LIBSBML_DUPLICATE_OBJECT_ID;
1433   }
1434   else
1435   {
1436     return mEvents.append(e);
1437   }
1438 }
1439 
1440 
1441 /*
1442  * Creates a new FunctionDefinition inside this Model and returns it.
1443  */
1444 FunctionDefinition*
createFunctionDefinition()1445 Model::createFunctionDefinition ()
1446 {
1447   FunctionDefinition* fd = NULL;
1448 
1449   try
1450   {
1451     fd = new FunctionDefinition(getSBMLNamespaces());
1452   }
1453   catch (...)
1454   {
1455     /* here we do not create a default object as the level/version must
1456      * match the parent object
1457      *
1458      * so do nothing
1459      */
1460     return NULL;
1461   }
1462 
1463   if (fd != NULL) mFunctionDefinitions.appendAndOwn(fd);
1464 
1465   return fd;
1466 }
1467 
1468 
1469 /*
1470  * Creates a new UnitDefinition inside this Model and returns it.
1471  */
1472 UnitDefinition*
createUnitDefinition()1473 Model::createUnitDefinition ()
1474 {
1475   UnitDefinition* ud = NULL;
1476 
1477   try
1478   {
1479     ud = new UnitDefinition(getSBMLNamespaces());
1480   }
1481   catch (...)
1482   {
1483     /* here we do not create a default object as the level/version must
1484      * match the parent object
1485      *
1486      * so do nothing
1487      */
1488     return NULL;
1489   }
1490 
1491   if (ud != NULL) mUnitDefinitions.appendAndOwn(ud);
1492 
1493   return ud;
1494 }
1495 
1496 
1497 /*
1498  * Creates a new Unit inside this Model and returns a pointer to it.  The
1499  * Unit is added to the last UnitDefinition created.
1500  *
1501  * If a UnitDefinitions does not exist for this model, a new Unit is not
1502  * created and @c NULL is returned.
1503  */
1504 Unit*
createUnit()1505 Model::createUnit ()
1506 {
1507   unsigned int size = getNumUnitDefinitions();
1508   return (size > 0) ? getUnitDefinition(size - 1)->createUnit() : NULL;
1509 }
1510 
1511 
1512 /*
1513  * Creates a new CompartmentType inside this Model and returns it.
1514  */
1515 CompartmentType*
createCompartmentType()1516 Model::createCompartmentType ()
1517 {
1518   CompartmentType* ct = NULL;
1519 
1520   try
1521   {
1522     ct = new CompartmentType(getSBMLNamespaces());
1523   }
1524   catch (...)
1525   {
1526     /* here we do not create a default object as the level/version must
1527      * match the parent object
1528      *
1529      * so do nothing
1530      */
1531     return NULL;
1532   }
1533 
1534   if (ct != NULL) mCompartmentTypes.appendAndOwn(ct);
1535 
1536   return ct;
1537 }
1538 
1539 
1540 /*
1541  * Creates a new SpeciesType inside this Model and returns it.
1542  */
1543 SpeciesType*
createSpeciesType()1544 Model::createSpeciesType ()
1545 {
1546   SpeciesType* st = NULL;
1547 
1548   try
1549   {
1550     st = new SpeciesType(getSBMLNamespaces());
1551   }
1552   catch (...)
1553   {
1554     /* here we do not create a default object as the level/version must
1555      * match the parent object
1556      *
1557      * so do nothing
1558      */
1559     return NULL;
1560   }
1561 
1562   if (st != NULL) mSpeciesTypes.appendAndOwn(st);
1563 
1564   return st;
1565 }
1566 
1567 
1568 /*
1569  * Creates a new Compartment inside this Model and returns it.
1570  */
1571 Compartment*
createCompartment()1572 Model::createCompartment ()
1573 {
1574   Compartment* c = NULL;
1575 
1576   try
1577   {
1578     c = new Compartment(getSBMLNamespaces());
1579   }
1580   catch (...)
1581   {
1582     /* here we do not create a default object as the level/version must
1583      * match the parent object
1584      *
1585      * so do nothing
1586      */
1587     return NULL;
1588   }
1589 
1590   if (c != NULL) mCompartments.appendAndOwn(c);
1591 
1592   return c;
1593 }
1594 
1595 
1596 /*
1597  * Creates a new Species inside this Model and returns it.
1598  */
1599 Species*
createSpecies()1600 Model::createSpecies ()
1601 {
1602   Species* s = NULL;
1603 
1604   try
1605   {
1606     s = new Species(getSBMLNamespaces());
1607   }
1608   catch (...)
1609   {
1610     /* here we do not create a default object as the level/version must
1611      * match the parent object
1612      *
1613      * so do nothing
1614      */
1615     return NULL;
1616   }
1617 
1618   if (s != NULL) mSpecies.appendAndOwn(s);
1619 
1620   return s;
1621 }
1622 
1623 
1624 /*
1625  * Creates a new Parameter inside this Model and returns.
1626  */
1627 Parameter*
createParameter()1628 Model::createParameter ()
1629 {
1630   Parameter* p = NULL;
1631 
1632   try
1633   {
1634     p = new Parameter(getSBMLNamespaces());
1635   }
1636   catch (...)
1637   {
1638     /* here we do not create a default object as the level/version must
1639      * match the parent object
1640      *
1641      * so do nothing
1642      */
1643     return NULL;
1644   }
1645 
1646   if (p != NULL) mParameters.appendAndOwn(p);
1647 
1648   return p;
1649 }
1650 
1651 
1652 /*
1653  * Creates a new InitialAssignment inside this Model and returns it.
1654  */
1655 InitialAssignment*
createInitialAssignment()1656 Model::createInitialAssignment ()
1657 {
1658   InitialAssignment* ia = NULL;
1659 
1660   try
1661   {
1662     ia = new InitialAssignment(getSBMLNamespaces());
1663   }
1664   catch (...)
1665   {
1666     /* here we do not create a default object as the level/version must
1667      * match the parent object
1668      *
1669      * so do nothing
1670      */
1671     return NULL;
1672   }
1673 
1674   if (ia != NULL) mInitialAssignments.appendAndOwn(ia);
1675 
1676   return ia;
1677 }
1678 
1679 
1680 /*
1681  * Creates a new AlgebraicRule inside this Model and returns it.
1682  */
1683 AlgebraicRule*
createAlgebraicRule()1684 Model::createAlgebraicRule ()
1685 {
1686   AlgebraicRule* ar = NULL;
1687 
1688   try
1689   {
1690     ar = new AlgebraicRule(getSBMLNamespaces());
1691   }
1692   catch (...)
1693   {
1694     /* here we do not create a default object as the level/version must
1695      * match the parent object
1696      *
1697      * so do nothing
1698      */
1699     return NULL;
1700   }
1701 
1702   if (ar != NULL) mRules.appendAndOwn(ar);
1703 
1704   return ar;
1705 }
1706 
1707 
1708 /*
1709  * Creates a new AssignmentRule inside this Model and returns it.
1710  */
1711 AssignmentRule*
createAssignmentRule()1712 Model::createAssignmentRule ()
1713 {
1714   AssignmentRule* ar = NULL;
1715 
1716   try
1717   {
1718     ar = new AssignmentRule(getSBMLNamespaces());
1719   }
1720   catch (...)
1721   {
1722     /* here we do not create a default object as the level/version must
1723      * match the parent object
1724      *
1725      * so do nothing
1726      */
1727     return NULL;
1728   }
1729 
1730   if (ar != NULL) mRules.appendAndOwn(ar);
1731 
1732   return ar;
1733 }
1734 
1735 
1736 /*
1737  * Creates a new RateRule inside this Model and returns it.
1738  */
1739 RateRule*
createRateRule()1740 Model::createRateRule ()
1741 {
1742   RateRule* rr = NULL;
1743 
1744   try
1745   {
1746     rr = new RateRule(getSBMLNamespaces());
1747   }
1748   catch (...)
1749   {
1750     /* here we do not create a default object as the level/version must
1751      * match the parent object
1752      *
1753      * so do nothing
1754      */
1755     return NULL;
1756   }
1757 
1758   if (rr != NULL) mRules.appendAndOwn(rr);
1759 
1760   return rr;
1761 }
1762 
1763 
1764 /*
1765  * Creates a new Constraint inside this Model and returns it.
1766  */
1767 Constraint*
createConstraint()1768 Model::createConstraint ()
1769 {
1770   Constraint* c = NULL;
1771 
1772   try
1773   {
1774     c = new Constraint(getSBMLNamespaces());
1775   }
1776   catch (...)
1777   {
1778     /* here we do not create a default object as the level/version must
1779      * match the parent object
1780      *
1781      * so do nothing
1782      */
1783     return NULL;
1784   }
1785 
1786   if (c != NULL) mConstraints.appendAndOwn(c);
1787 
1788   return c;
1789 }
1790 
1791 
1792 /*
1793  * Creates a new Reaction inside this Model and returns it.
1794  */
1795 Reaction*
createReaction()1796 Model::createReaction ()
1797 {
1798   Reaction* r = NULL;
1799 
1800   try
1801   {
1802     r = new Reaction(getSBMLNamespaces());
1803   }
1804   catch (...)
1805   {
1806     /* here we do not create a default object as the level/version must
1807      * match the parent object
1808      *
1809      * so do nothing
1810      */
1811     return NULL;
1812   }
1813 
1814   if (r != NULL) mReactions.appendAndOwn(r);
1815 
1816   return r;
1817 }
1818 
1819 
1820 /*
1821  * Creates a new Reactant (ie SpeciesReference) inside this Model and
1822  * returns a pointer to it.  The SpeciesReference is added to the reactants
1823  * of the last Reaction created.
1824  *
1825  * If a Reaction does not exist for this model, a new SpeciesReference is
1826  * not created and @c NULL is returned.
1827  */
1828 SpeciesReference*
createReactant()1829 Model::createReactant ()
1830 {
1831   unsigned int size = getNumReactions();
1832   return (size > 0) ? getReaction(size - 1)->createReactant() : NULL;
1833 }
1834 
1835 
1836 /*
1837  * Creates a new Product (ie SpeciesReference) inside this Model and
1838  * returns a pointer to it.  The SpeciesReference is added to the products
1839  * of the last Reaction created.
1840  *
1841  * If a Reaction does not exist for this model, a new SpeciesReference is
1842  * not created and @c NULL is returned.
1843  */
1844 SpeciesReference*
createProduct()1845 Model::createProduct ()
1846 {
1847   unsigned int size = getNumReactions();
1848   return (size > 0) ? getReaction(size - 1)->createProduct() : NULL;
1849 }
1850 
1851 
1852 /*
1853  * Creates a new Modifer (ie ModifierSpeciesReference) inside this Model
1854  * and returns a pointer to it.  The ModifierSpeciesReference is added to
1855  * the modifiers of the last Reaction created.
1856  *
1857  * If a Reaction does not exist for this model, a new
1858  * ModifierSpeciesReference is not created and @c NULL is returned.
1859  */
1860 ModifierSpeciesReference*
createModifier()1861 Model::createModifier ()
1862 {
1863   unsigned int size = getNumReactions();
1864   return (size > 0) ? getReaction(size - 1)->createModifier() : NULL;
1865 }
1866 
1867 
1868 /*
1869  * Creates a new KineticLaw inside this Model and returns a pointer to it.
1870  * The KineticLaw is associated with the last Reaction created.
1871  *
1872  * If a Reaction does not exist for this model, or a Reaction does exist,
1873  * but already has a KineticLaw, a new KineticLaw is not created and NULL
1874  * is returned.
1875  */
1876 KineticLaw*
createKineticLaw()1877 Model::createKineticLaw ()
1878 {
1879   unsigned int size = getNumReactions();
1880   return (size > 0) ? getReaction(size - 1)->createKineticLaw() : NULL;
1881 }
1882 
1883 
1884 /*
1885  * Creates a new Parameter (of a KineticLaw) inside this Model and returns
1886  * a pointer to it.  The Parameter is associated with the KineticLaw of the
1887  * last Reaction created.
1888  *
1889  * If a Reaction does not exist for this model, or a KineticLaw for the
1890  * Reaction, a new Parameter is not created and @c NULL is returned.
1891  */
1892 Parameter*
createKineticLawParameter()1893 Model::createKineticLawParameter ()
1894 {
1895   unsigned int size = getNumReactions();
1896 
1897   if (size > 0)
1898   {
1899     KineticLaw* kl = getReaction(size - 1)->getKineticLaw();
1900     if (kl != NULL) return kl->createParameter();
1901   }
1902 
1903   return NULL;
1904 }
1905 
1906 
1907 /*
1908  * Creates a new Parameter (of a KineticLaw) inside this Model and returns
1909  * a pointer to it.  The Parameter is associated with the KineticLaw of the
1910  * last Reaction created.
1911  *
1912  * If a Reaction does not exist for this model, or a KineticLaw for the
1913  * Reaction, a new Parameter is not created and @c NULL is returned.
1914  */
1915 LocalParameter*
createKineticLawLocalParameter()1916 Model::createKineticLawLocalParameter ()
1917 {
1918   unsigned int size = getNumReactions();
1919 
1920   if (size > 0)
1921   {
1922     KineticLaw* kl = getReaction(size - 1)->getKineticLaw();
1923     if (kl != NULL) return kl->createLocalParameter();
1924   }
1925 
1926   return NULL;
1927 }
1928 
1929 
1930 /*
1931  * Creates a new Event inside this Model and returns it.
1932  */
1933 Event*
createEvent()1934 Model::createEvent ()
1935 {
1936   Event* e = NULL;
1937 
1938   try
1939   {
1940     e = new Event(getSBMLNamespaces());
1941   }
1942   catch (...)
1943   {
1944     /* here we do not create a default object as the level/version must
1945      * match the parent object
1946      *
1947      * so do nothing
1948      */
1949     return NULL;
1950   }
1951 
1952   if (e != NULL) mEvents.appendAndOwn(e);
1953 
1954   return e;
1955 }
1956 
1957 
1958 /*
1959  * Creates a new EventAssignment inside this Model and returns a pointer to
1960  * it.  The EventAssignment is added to the the last Event created.
1961  *
1962  * If an Event does not exist for this model, a new EventAssignment is not
1963  * created and @c NULL is returned.
1964  */
1965 EventAssignment*
createEventAssignment()1966 Model::createEventAssignment ()
1967 {
1968   unsigned int size = getNumEvents();
1969   return (size > 0) ? getEvent(size - 1)->createEventAssignment() : NULL;
1970 }
1971 
1972 
1973 /*
1974  * Creates a new Trigger inside this Model and returns a pointer to
1975  * it.  The Trigger is added to the the last Event created.
1976  *
1977  * If an Event does not exist for this model, a new Trigger is not
1978  * created and @c NULL is returned.
1979  */
1980 Trigger*
createTrigger()1981 Model::createTrigger ()
1982 {
1983   unsigned int size = getNumEvents();
1984   return (size > 0) ? getEvent(size - 1)->createTrigger() : NULL;
1985 }
1986 
1987 
1988 /*
1989  * Creates a new Delay inside this Model and returns a pointer to
1990  * it.  The Delay is added to the the last Event created.
1991  *
1992  * If an Event does not exist for this model, a new Delay is not
1993  * created and @c NULL is returned.
1994  */
1995 Delay*
createDelay()1996 Model::createDelay ()
1997 {
1998   unsigned int size = getNumEvents();
1999   return (size > 0) ? getEvent(size - 1)->createDelay() : NULL;
2000 }
2001 
2002 
2003 /*
2004  * Sets the annotation of this SBML object to a copy of annotation.
2005  */
2006 int
setAnnotation(const XMLNode * annotation)2007 Model::setAnnotation (const XMLNode* annotation)
2008 {
2009   int success = SBase::setAnnotation(annotation);
2010 
2011   if (success == 0)
2012   {
2013     //
2014     // delete existing mHistory
2015     //
2016     // existing mHistory (if any) needs to be deleted at any rate, otherwise
2017     // unsetAnnotation() ( setAnnotation(NULL) ) doesn't work as expected.
2018     // (These functions must clear all elements in an annotation.)
2019     //
2020     delete mHistory;
2021     mHistory = NULL;
2022 
2023     if(mAnnotation != NULL
2024        && RDFAnnotationParser::hasHistoryRDFAnnotation(mAnnotation))
2025     {
2026       // parse mAnnotation (if any) and set mHistory
2027       mHistory = RDFAnnotationParser::parseRDFAnnotation(mAnnotation);
2028       mHistoryChanged = true;
2029 
2030     }
2031   }
2032 
2033   return success;
2034 }
2035 
2036 
2037 /*
2038  * Sets the annotation (by string) of this SBML object to a copy of annotation.
2039  */
2040 int
setAnnotation(const std::string & annotation)2041 Model::setAnnotation (const std::string& annotation)
2042 {
2043   int success = LIBSBML_OPERATION_FAILED;
2044   if(annotation.empty())
2045   {
2046     unsetAnnotation();
2047     return LIBSBML_OPERATION_SUCCESS;
2048   }
2049 
2050   XMLNode* annt_xmln;
2051   if (getSBMLDocument())
2052   {
2053     XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces();
2054     annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns);
2055   }
2056   else
2057   {
2058     annt_xmln = XMLNode::convertStringToXMLNode(annotation);
2059   }
2060 
2061   if(annt_xmln != NULL)
2062   {
2063     success = setAnnotation(annt_xmln);
2064     delete annt_xmln;
2065   }
2066   return success;
2067 }
2068 
2069 
2070 /*
2071  * Appends annotation to the existing annotations.
2072  * This allows other annotations to be preserved whilst
2073  * adding additional information.
2074  */
2075 int
appendAnnotation(const XMLNode * annotation)2076 Model::appendAnnotation (const XMLNode* annotation)
2077 {
2078   // take out any attempt to merge RDF
2079 
2080   return SBase::appendAnnotation(annotation);
2081 
2082 //  int success = LIBSBML_OPERATION_FAILED;
2083 //  if(annotation == NULL) return LIBSBML_OPERATION_SUCCESS;
2084 //
2085 //  XMLNode* new_annotation = NULL;
2086 //  const string&  name = annotation->getName();
2087 //
2088 //  // check for annotation tags and add if necessary
2089 //  if (name != "annotation")
2090 //  {
2091 //    XMLToken ann_t = XMLToken(XMLTriple("annotation", "", ""), XMLAttributes());
2092 //    new_annotation = new XMLNode(ann_t);
2093 //    new_annotation->addChild(*annotation);
2094 //  }
2095 //  else
2096 //  {
2097 //    new_annotation = annotation->clone();
2098 //  }
2099 //
2100 //  // parse new_annotation and reset mHistory
2101 //  if (RDFAnnotationParser::hasHistoryRDFAnnotation(new_annotation))
2102 //  {
2103 //    ModelHistory* new_mhistory = RDFAnnotationParser::parseRDFAnnotation(new_annotation);
2104 //    if(new_mhistory != NULL)
2105 //    {
2106 //      delete mHistory;
2107 //      mHistory = new_mhistory;
2108 ////      mHistoryChanged = true;
2109 //    }
2110 //  }
2111 //
2112 //  success = SBase::appendAnnotation(new_annotation);
2113 //
2114 //  delete new_annotation;
2115 //
2116 //  return success;
2117 }
2118 
2119 
2120 /*
2121  * Appends annotation (by string) to the existing annotations.
2122  * This allows other annotations to be preserved whilst
2123  * adding additional information.
2124  */
2125 int
appendAnnotation(const std::string & annotation)2126 Model::appendAnnotation (const std::string& annotation)
2127 {
2128   int success = LIBSBML_OPERATION_FAILED;
2129   XMLNode* annt_xmln;
2130   if (getSBMLDocument() != NULL)
2131   {
2132     XMLNamespaces* xmlns = getSBMLDocument()->getNamespaces();
2133     annt_xmln = XMLNode::convertStringToXMLNode(annotation,xmlns);
2134   }
2135   else
2136   {
2137     annt_xmln = XMLNode::convertStringToXMLNode(annotation);
2138   }
2139 
2140   if(annt_xmln != NULL)
2141   {
2142     success = appendAnnotation(annt_xmln);
2143     delete annt_xmln;
2144   }
2145 
2146   return success;
2147 }
2148 
2149 
2150 /** @cond doxygenLibsbmlInternal */
2151 /*
2152  * Synchronizes the annotation of this SBML object.
2153  */
2154 void
syncAnnotation()2155 Model::syncAnnotation ()
2156 {
2157   SBase::syncAnnotation();
2158 
2159   //if (mAnnotationChanged == false)
2160   //  return;
2161 
2162   //if (mHistoryChanged == false && mCVTermsChanged == false)
2163   //  return;
2164   //else
2165   //  reconstructRDFAnnotation();
2166 
2167   //bool hasRDF = false;
2168   //bool hasAdditionalRDF = false;
2169   //// determine status of existing annotation before doing anything
2170   //if (mAnnotation != NULL)
2171   //{
2172   //  hasRDF = RDFAnnotationParser::hasRDFAnnotation(mAnnotation);
2173   //  hasAdditionalRDF =
2174   //    RDFAnnotationParser::hasAdditionalRDFAnnotation(mAnnotation);
2175   //}
2176 
2177   //XMLNode * history = RDFAnnotationParser::parseModelHistory(this);
2178 
2179   //if(mAnnotation != NULL && hasRDF && mHistoryChanged == true)
2180   //{
2181   //  XMLNode* new_annotation = RDFAnnotationParser::deleteRDFAnnotation(mAnnotation);
2182   //  if(new_annotation == NULL)
2183   //  {
2184   //    XMLToken ann_token = XMLToken(XMLTriple("annotation", "", ""), XMLAttributes());
2185   //    new_annotation = new XMLNode(ann_token);
2186   //    new_annotation->addChild(*mAnnotation);
2187   //  }
2188   //  *mAnnotation = *new_annotation;
2189   //  delete new_annotation;
2190   //}
2191 
2192   //if (history != NULL)
2193   //{
2194   //  if (mHistoryChanged == true)
2195   //  {
2196   //    if (mAnnotation == NULL)
2197   //    {
2198   //      mAnnotation = history;
2199   //    }
2200   //    else
2201   //    {
2202   //      if (mAnnotation->isEnd())
2203   //      {
2204   //        mAnnotation->unsetEnd();
2205   //      }
2206   //      if (hasAdditionalRDF)
2207   //      {
2208   //        //need to insert the history into existing RDF
2209   //        unsigned int n = 0;
2210   //        while (n < mAnnotation->getNumChildren())
2211   //        {
2212   //          if (mAnnotation->getChild(n).getName() == "RDF")
2213   //          {
2214   //            mAnnotation->getChild(n).insertChild(0,
2215   //              history->getChild(0).getChild(0));
2216   //            break;
2217   //          }
2218   //          n++;
2219   //        }
2220   //      }
2221   //      else
2222   //      {
2223   //        mAnnotation->addChild(history->getChild(0));
2224   //      }
2225   //      delete history;
2226   //    }
2227   //  }
2228   //}
2229   //else
2230   //{
2231   //  // Annotations for CVTerm are added by the above RDFAnnotationParser::parseModelHistory(this)
2232   //  // if and only if mHistory is not NULL.
2233   //  // Thus, annotations for CVTerm (if any) needs to be added here if history (mHistory) is NULL.
2234   //  SBase::syncAnnotation();
2235   //}
2236 
2237 }
2238 /** @endcond */
2239 
2240 
2241 /*
2242  * @return the list of FunctionDefinitions for this Model.
2243  */
2244 const ListOfFunctionDefinitions*
getListOfFunctionDefinitions() const2245 Model::getListOfFunctionDefinitions () const
2246 {
2247   return &mFunctionDefinitions;
2248 }
2249 
2250 
2251 /*
2252  * @return the list of FunctionDefinitions for this Model.
2253  */
2254 ListOfFunctionDefinitions*
getListOfFunctionDefinitions()2255 Model::getListOfFunctionDefinitions ()
2256 {
2257   return &mFunctionDefinitions;
2258 }
2259 
2260 
2261 /*
2262  * @return the list of UnitDefinitions for this Model.
2263  */
2264 const ListOfUnitDefinitions*
getListOfUnitDefinitions() const2265 Model::getListOfUnitDefinitions () const
2266 {
2267   return &mUnitDefinitions;
2268 }
2269 
2270 
2271 /*
2272  * @return the list of UnitDefinitions for this Model.
2273  */
2274 ListOfUnitDefinitions*
getListOfUnitDefinitions()2275 Model::getListOfUnitDefinitions ()
2276 {
2277   return &mUnitDefinitions;
2278 }
2279 
2280 
2281 /*
2282  * @return the list of CompartmentTypes for this Model.
2283  */
2284 const ListOfCompartmentTypes*
getListOfCompartmentTypes() const2285 Model::getListOfCompartmentTypes () const
2286 {
2287   return &mCompartmentTypes;
2288 }
2289 
2290 
2291 /*
2292  * @return the list of CompartmentTypes for this Model.
2293  */
2294 ListOfCompartmentTypes*
getListOfCompartmentTypes()2295 Model::getListOfCompartmentTypes ()
2296 {
2297   return &mCompartmentTypes;
2298 }
2299 
2300 
2301 /*
2302  * @return the list of SpeciesTypes for this Model.
2303  */
2304 const ListOfSpeciesTypes*
getListOfSpeciesTypes() const2305 Model::getListOfSpeciesTypes () const
2306 {
2307   return &mSpeciesTypes;
2308 }
2309 
2310 
2311 /*
2312  * @return the list of SpeciesTypes for this Model.
2313  */
2314 ListOfSpeciesTypes*
getListOfSpeciesTypes()2315 Model::getListOfSpeciesTypes ()
2316 {
2317   return &mSpeciesTypes;
2318 }
2319 
2320 
2321 /*
2322  * @return the list of Compartments for this Model.
2323  */
2324 const ListOfCompartments*
getListOfCompartments() const2325 Model::getListOfCompartments () const
2326 {
2327   return &mCompartments;
2328 }
2329 
2330 
2331 /*
2332  * @return the list of Compartments for this Model.
2333  */
2334 ListOfCompartments*
getListOfCompartments()2335 Model::getListOfCompartments ()
2336 {
2337   return &mCompartments;
2338 }
2339 
2340 
2341 /*
2342  * @return the list of Species for this Model.
2343  */
2344 const ListOfSpecies*
getListOfSpecies() const2345 Model::getListOfSpecies () const
2346 {
2347   return &mSpecies;
2348 }
2349 
2350 
2351 /*
2352  * @return the list of Species for this Model.
2353  */
2354 ListOfSpecies*
getListOfSpecies()2355 Model::getListOfSpecies ()
2356 {
2357   return &mSpecies;
2358 }
2359 
2360 
2361 /*
2362  * @return the list of Parameters for this Model.
2363  */
2364 const ListOfParameters*
getListOfParameters() const2365 Model::getListOfParameters () const
2366 {
2367   return &mParameters;
2368 }
2369 
2370 
2371 /*
2372  * @return the list of Parameters for this Model.
2373  */
2374 ListOfParameters*
getListOfParameters()2375 Model::getListOfParameters ()
2376 {
2377   return &mParameters;
2378 }
2379 
2380 
2381 /*
2382  * @return the list of InitialAssignments for this Model.
2383  */
2384 const ListOfInitialAssignments*
getListOfInitialAssignments() const2385 Model::getListOfInitialAssignments () const
2386 {
2387   return &mInitialAssignments;
2388 }
2389 
2390 
2391 /*
2392  * @return the list of InitialAssignment for this Model.
2393  */
2394 ListOfInitialAssignments*
getListOfInitialAssignments()2395 Model::getListOfInitialAssignments ()
2396 {
2397   return &mInitialAssignments;
2398 }
2399 
2400 
2401 /*
2402  * @return the list of Rules for this Model.
2403  */
2404 const ListOfRules*
getListOfRules() const2405 Model::getListOfRules () const
2406 {
2407   return &mRules;
2408 }
2409 
2410 
2411 /*
2412  * @return the list of Rules for this Model.
2413  */
2414 ListOfRules*
getListOfRules()2415 Model::getListOfRules ()
2416 {
2417   return &mRules;
2418 }
2419 
2420 
2421 /*
2422  * @return the list of Constraints for this Model.
2423  */
2424 const ListOfConstraints*
getListOfConstraints() const2425 Model::getListOfConstraints () const
2426 {
2427   return &mConstraints;
2428 }
2429 
2430 
2431 /*
2432  * @return the list of Constraints for this Model.
2433  */
2434 ListOfConstraints*
getListOfConstraints()2435 Model::getListOfConstraints ()
2436 {
2437   return &mConstraints;
2438 }
2439 
2440 
2441 /*
2442  * @return the list of Reactions for this Model.
2443  */
2444 const ListOfReactions*
getListOfReactions() const2445 Model::getListOfReactions () const
2446 {
2447   return &mReactions;
2448 }
2449 
2450 
2451 /*
2452  * @return the list of Reactions for this Model.
2453  */
2454 ListOfReactions*
getListOfReactions()2455 Model::getListOfReactions ()
2456 {
2457   return &mReactions;
2458 }
2459 
2460 
2461 /*
2462  * @return the list of Events for this Model.
2463  */
2464 const ListOfEvents*
getListOfEvents() const2465 Model::getListOfEvents () const
2466 {
2467   return &mEvents;
2468 }
2469 
2470 
2471 /*
2472  * @return the list of Events for this Model.
2473  */
2474 ListOfEvents*
getListOfEvents()2475 Model::getListOfEvents ()
2476 {
2477   return &mEvents;
2478 }
2479 
2480 
2481 /*
2482  * @return the nth FunctionDefinition of this Model.
2483  */
2484 const FunctionDefinition*
getFunctionDefinition(unsigned int n) const2485 Model::getFunctionDefinition (unsigned int n) const
2486 {
2487   return static_cast<const FunctionDefinition*>( mFunctionDefinitions.get(n) );
2488 }
2489 
2490 
2491 /*
2492  * @return the nth FunctionDefinition of this Model.
2493  */
2494 FunctionDefinition*
getFunctionDefinition(unsigned int n)2495 Model::getFunctionDefinition (unsigned int n)
2496 {
2497   return static_cast<FunctionDefinition*>( mFunctionDefinitions.get(n) );
2498 }
2499 
2500 
2501 /*
2502  * @return the FunctionDefinition in this Model with the given @p id or @c NULL
2503  * if no such FunctionDefinition exists.
2504  */
2505 const FunctionDefinition*
getFunctionDefinition(const std::string & sid) const2506 Model::getFunctionDefinition (const std::string& sid) const
2507 {
2508   return static_cast<const FunctionDefinition*>(mFunctionDefinitions.get(sid));
2509 }
2510 
2511 
2512 /*
2513  * @return the FunctionDefinition in this Model with the given @p id or @c NULL
2514  * if no such FunctionDefinition exists.
2515  */
2516 FunctionDefinition*
getFunctionDefinition(const std::string & sid)2517 Model::getFunctionDefinition (const std::string& sid)
2518 {
2519   return static_cast<FunctionDefinition*>( mFunctionDefinitions.get(sid) );
2520 }
2521 
2522 
2523 /*
2524  * @return the nth UnitDefinition of this Model.
2525  */
2526 const UnitDefinition*
getUnitDefinition(unsigned int n) const2527 Model::getUnitDefinition (unsigned int n) const
2528 {
2529   return static_cast<const UnitDefinition*>( mUnitDefinitions.get(n) );
2530 }
2531 
2532 
2533 /*
2534  * @return the nth UnitDefinition of this Model.
2535  */
2536 UnitDefinition*
getUnitDefinition(unsigned int n)2537 Model::getUnitDefinition (unsigned int n)
2538 {
2539   return static_cast<UnitDefinition*>( mUnitDefinitions.get(n) );
2540 }
2541 
2542 
2543 /*
2544  * @return the UnitDefinition in this Model with the given @p id or @c NULL if no
2545  * such UnitDefinition exists.
2546  */
2547 const UnitDefinition*
getUnitDefinition(const std::string & sid) const2548 Model::getUnitDefinition (const std::string& sid) const
2549 {
2550   return static_cast<const UnitDefinition*>( mUnitDefinitions.get(sid) );
2551 }
2552 
2553 
2554 /*
2555  * @return the UnitDefinition in this Model with the given @p id or @c NULL if no
2556  * such UnitDefinition exists.
2557  */
2558 UnitDefinition*
getUnitDefinition(const std::string & sid)2559 Model::getUnitDefinition (const std::string& sid)
2560 {
2561   return static_cast<UnitDefinition*>( mUnitDefinitions.get(sid) );
2562 }
2563 
2564 
2565 /*
2566  * @return the nth CompartmentType of this Model.
2567  */
2568 const CompartmentType*
getCompartmentType(unsigned int n) const2569 Model::getCompartmentType (unsigned int n) const
2570 {
2571   return static_cast<const CompartmentType*>( mCompartmentTypes.get(n) );
2572 }
2573 
2574 
2575 /*
2576  * @return the nth CompartmentType of this Model.
2577  */
2578 CompartmentType*
getCompartmentType(unsigned int n)2579 Model::getCompartmentType (unsigned int n)
2580 {
2581   return static_cast<CompartmentType*>( mCompartmentTypes.get(n) );
2582 }
2583 
2584 
2585 /*
2586  * @return the CompartmentType in this Model with the given @p id or @c NULL if
2587  * no such CompartmentType exists.
2588  */
2589 const CompartmentType*
getCompartmentType(const std::string & sid) const2590 Model::getCompartmentType (const std::string& sid) const
2591 {
2592   return static_cast<const CompartmentType*>( mCompartmentTypes.get(sid) );
2593 }
2594 
2595 
2596 /*
2597  * @return the CompartmentType in this Model with the given @p id or @c NULL if
2598  * no such CompartmentType exists.
2599  */
2600 CompartmentType*
getCompartmentType(const std::string & sid)2601 Model::getCompartmentType (const std::string& sid)
2602 {
2603   return static_cast<CompartmentType*>( mCompartmentTypes.get(sid) );
2604 }
2605 
2606 
2607 /*
2608  * @return the nth SpeciesType of this Model.
2609  */
2610 const SpeciesType*
getSpeciesType(unsigned int n) const2611 Model::getSpeciesType (unsigned int n) const
2612 {
2613   return static_cast<const SpeciesType*>( mSpeciesTypes.get(n) );
2614 }
2615 
2616 
2617 /*
2618  * @return the nth SpeciesType of this Model.
2619  */
2620 SpeciesType*
getSpeciesType(unsigned int n)2621 Model::getSpeciesType (unsigned int n)
2622 {
2623   return static_cast<SpeciesType*>( mSpeciesTypes.get(n) );
2624 }
2625 
2626 
2627 /*
2628  * @return the SpeciesType in this Model with the given @p id or @c NULL if
2629  * no such SpeciesType exists.
2630  */
2631 const SpeciesType*
getSpeciesType(const std::string & sid) const2632 Model::getSpeciesType (const std::string& sid) const
2633 {
2634   return static_cast<const SpeciesType*>( mSpeciesTypes.get(sid) );
2635 }
2636 
2637 
2638 /*
2639  * @return the SpeciesType in this Model with the given @p id or @c NULL if
2640  * no such SpeciesType exists.
2641  */
2642 SpeciesType*
getSpeciesType(const std::string & sid)2643 Model::getSpeciesType (const std::string& sid)
2644 {
2645   return static_cast<SpeciesType*>( mSpeciesTypes.get(sid) );
2646 }
2647 
2648 
2649 /*
2650  * @return the nth Compartment of this Model.
2651  */
2652 const Compartment*
getCompartment(unsigned int n) const2653 Model::getCompartment (unsigned int n) const
2654 {
2655   return static_cast<const Compartment*>( mCompartments.get(n) );
2656 }
2657 
2658 
2659 /*
2660  * @return the nth Compartment of this Model.
2661  */
2662 Compartment*
getCompartment(unsigned int n)2663 Model::getCompartment (unsigned int n)
2664 {
2665   return static_cast<Compartment*>( mCompartments.get(n) );
2666 }
2667 
2668 
2669 /*
2670  * @return the Compartment in this Model with the given @p id or @c NULL if no
2671  * such Compartment exists.
2672  */
2673 const Compartment*
getCompartment(const std::string & sid) const2674 Model::getCompartment (const std::string& sid) const
2675 {
2676   return static_cast<const Compartment*>( mCompartments.get(sid) );
2677 }
2678 
2679 
2680 /*
2681  * @return the Compartment in this Model with the given @p id or @c NULL if no
2682  * such Compartment exists.
2683  */
2684 Compartment*
getCompartment(const std::string & sid)2685 Model::getCompartment (const std::string& sid)
2686 {
2687   return static_cast<Compartment*>( mCompartments.get(sid) );
2688 }
2689 
2690 
2691 /*
2692  * @return the nth Species of this Model.
2693  */
2694 const Species*
getSpecies(unsigned int n) const2695 Model::getSpecies (unsigned int n) const
2696 {
2697   return static_cast<const Species*>( mSpecies.get(n) );
2698 }
2699 
2700 
2701 /*
2702  * @return the nth Species of this Model.
2703  */
2704 Species*
getSpecies(unsigned int n)2705 Model::getSpecies (unsigned int n)
2706 {
2707   return static_cast<Species*>( mSpecies.get(n) );
2708 }
2709 
2710 
2711 /*
2712  * @return the Species in this Model with the given @p id or @c NULL if no such
2713  * Species exists.
2714  */
2715 const Species*
getSpecies(const std::string & sid) const2716 Model::getSpecies (const std::string& sid) const
2717 {
2718   return static_cast<const Species*>( mSpecies.get(sid) );
2719 }
2720 
2721 
2722 /*
2723  * @return the Species in this Model with the given @p id or @c NULL if no such
2724  * Species exists.
2725  */
2726 Species*
getSpecies(const std::string & sid)2727 Model::getSpecies (const std::string& sid)
2728 {
2729   return static_cast<Species*>( mSpecies.get(sid) );
2730 }
2731 
2732 
2733 /*
2734  * @return the nth Parameter of this Model.
2735  */
2736 const Parameter*
getParameter(unsigned int n) const2737 Model::getParameter (unsigned int n) const
2738 {
2739   return static_cast<const Parameter*>( mParameters.get(n) );
2740 }
2741 
2742 
2743 /*
2744  * @return the nth Parameter of this Model.
2745  */
2746 Parameter*
getParameter(unsigned int n)2747 Model::getParameter (unsigned int n)
2748 {
2749   return static_cast<Parameter*>( mParameters.get(n) );
2750 }
2751 
2752 
2753 /*
2754  * @return the Parameter in this Model with the given @p id or @c NULL if no such
2755  * Parameter exists.
2756  */
2757 const Parameter*
getParameter(const std::string & sid) const2758 Model::getParameter (const std::string& sid) const
2759 {
2760   return static_cast<const Parameter*>( mParameters.get(sid) );
2761 }
2762 
2763 
2764 /*
2765  * @return the Parameter in this Model with the given @p id or @c NULL if no such
2766  * Parameter exists.
2767  */
2768 Parameter*
getParameter(const std::string & sid)2769 Model::getParameter (const std::string& sid)
2770 {
2771   return static_cast<Parameter*>( mParameters.get(sid) );
2772 }
2773 
2774 
2775 /*
2776  * @return the nth InitialAssignment of this Model.
2777  */
2778 const InitialAssignment*
getInitialAssignment(unsigned int n) const2779 Model::getInitialAssignment (unsigned int n) const
2780 {
2781   return static_cast<const InitialAssignment*>( mInitialAssignments.get(n) );
2782 }
2783 
2784 
2785 /*
2786  * @return the nth InitialAssignment of this Model.
2787  */
2788 InitialAssignment*
getInitialAssignment(unsigned int n)2789 Model::getInitialAssignment (unsigned int n)
2790 {
2791   return static_cast<InitialAssignment*>( mInitialAssignments.get(n) );
2792 }
2793 
2794 
2795 /*
2796  * @return the InitialAssignment in this Model with the given symbol or
2797  * @c NULL if no such InitialAssignment exists.
2798  */
2799 const InitialAssignment*
getInitialAssignment(const std::string & symbol) const2800 Model::getInitialAssignment (const std::string& symbol) const
2801 {
2802   return static_cast<const InitialAssignment*>
2803   (
2804     mInitialAssignments.get(symbol)
2805   );
2806 }
2807 
2808 /*
2809  * @return the InitialAssignment in this Model with the given symbol or
2810  * @c NULL if no such InitialAssignment exists.
2811  */
2812 const InitialAssignment*
getInitialAssignmentBySymbol(const std::string & symbol) const2813 Model::getInitialAssignmentBySymbol(const std::string& symbol) const
2814 {
2815   return getInitialAssignment(symbol);
2816 }
2817 
2818 
2819 /*
2820  * @return the InitialAssignment in this Model with the given symbol or
2821  * @c NULL if no such InitialAssignment exists.
2822  */
2823 InitialAssignment*
getInitialAssignment(const std::string & symbol)2824 Model::getInitialAssignment (const std::string& symbol)
2825 {
2826   return static_cast<InitialAssignment*>( mInitialAssignments.get(symbol) );
2827 }
2828 
2829 
2830 /*
2831  * @return the InitialAssignment in this Model with the given symbol or
2832  * @c NULL if no such InitialAssignment exists.
2833  */
2834 InitialAssignment*
getInitialAssignmentBySymbol(const std::string & symbol)2835 Model::getInitialAssignmentBySymbol(const std::string& symbol)
2836 {
2837   return getInitialAssignment(symbol);
2838 }
2839 
2840 
2841 /*
2842  * @return the nth Rule of this Model.
2843  */
2844 const Rule*
getRule(unsigned int n) const2845 Model::getRule (unsigned int n) const
2846 {
2847   return static_cast<const Rule*>( mRules.get(n) );
2848 }
2849 
2850 
2851 /*
2852  * @return the nth Rule of this Model.
2853  */
2854 Rule*
getRule(unsigned int n)2855 Model::getRule (unsigned int n)
2856 {
2857   return static_cast<Rule*>( mRules.get(n) );
2858 }
2859 
2860 
2861 /*
2862  * @return the Rule in this Model with the given variable or @c NULL if no
2863  * such Rule exists.
2864  */
2865 const Rule*
getRule(const std::string & variable) const2866 Model::getRule (const std::string& variable) const
2867 {
2868   return static_cast<const Rule*>( mRules.get(variable) );
2869 }
2870 
2871 
2872 /*
2873  * @return the Rule in this Model with the given symbol or @c NULL if no
2874  * such Rule exists.
2875  */
2876 Rule*
getRule(const std::string & variable)2877 Model::getRule (const std::string& variable)
2878 {
2879   return static_cast<Rule*>( mRules.get(variable) );
2880 }
2881 
2882 
2883 /*
2884  * @return the Rule in this Model with the given variable or @c NULL if no
2885  * such Rule exists.
2886  */
2887 const Rule*
getRuleByVariable(const std::string & variable) const2888 Model::getRuleByVariable(const std::string& variable) const
2889 {
2890   return getRule(variable);
2891 }
2892 
2893 
2894 /*
2895  * @return the Rule in this Model with the given symbol or @c NULL if no
2896  * such Rule exists.
2897  */
2898 Rule*
getRuleByVariable(const std::string & variable)2899 Model::getRuleByVariable(const std::string& variable)
2900 {
2901   return getRule(variable);
2902 }
2903 
2904 
2905 
2906 /*
2907  * @return the Rule in this Model with the given variable or @c NULL if no
2908  * such Rule exists.
2909  */
2910 const AssignmentRule*
getAssignmentRule(const std::string & variable) const2911 Model::getAssignmentRule (const std::string& variable) const
2912 {
2913   const Rule * rule = static_cast<const Rule*>( mRules.get(variable) );
2914 
2915   if (rule != NULL && rule->getTypeCode() == SBML_ASSIGNMENT_RULE)
2916   {
2917     return static_cast<const AssignmentRule*>(rule);
2918   }
2919   else
2920   {
2921     return NULL;
2922   }
2923 }
2924 
2925 
2926 /*
2927  * @return the Rule in this Model with the given symbol or @c NULL if no
2928  * such Rule exists.
2929  */
2930 AssignmentRule*
getAssignmentRule(const std::string & variable)2931 Model::getAssignmentRule (const std::string& variable)
2932 {
2933   Rule * rule = static_cast<Rule*>( mRules.get(variable) );
2934 
2935   if (rule != NULL && rule->getTypeCode() == SBML_ASSIGNMENT_RULE)
2936   {
2937     return static_cast<AssignmentRule*>(rule);
2938   }
2939   else
2940   {
2941     return NULL;
2942   }
2943 }
2944 
2945 
2946 
2947 /*
2948  * @return the Rule in this Model with the given variable or @c NULL if no
2949  * such Rule exists.
2950  */
2951 const RateRule*
getRateRule(const std::string & variable) const2952 Model::getRateRule (const std::string& variable) const
2953 {
2954   const Rule * rule = static_cast<const Rule*>( mRules.get(variable) );
2955 
2956   if (rule != NULL && rule->getTypeCode() == SBML_RATE_RULE)
2957   {
2958     return static_cast<const RateRule*>(rule);
2959   }
2960   else
2961   {
2962     return NULL;
2963   }
2964 }
2965 
2966 
2967 /*
2968  * @return the Rule in this Model with the given symbol or @c NULL if no
2969  * such Rule exists.
2970  */
2971 RateRule*
getRateRule(const std::string & variable)2972 Model::getRateRule (const std::string& variable)
2973 {
2974   Rule * rule = static_cast<Rule*>( mRules.get(variable) );
2975 
2976   if (rule != NULL && rule->getTypeCode() == SBML_RATE_RULE)
2977   {
2978     return static_cast<RateRule*>(rule);
2979   }
2980   else
2981   {
2982     return NULL;
2983   }
2984 }
2985 
2986 
2987 /*
2988  * @return the Rule in this Model with the given variable or @c NULL if no
2989  * such Rule exists.
2990  */
2991 const AssignmentRule*
getAssignmentRuleByVariable(const std::string & variable) const2992 Model::getAssignmentRuleByVariable(const std::string& variable) const
2993 {
2994   return getAssignmentRule(variable);
2995 }
2996 
2997 
2998 /*
2999  * @return the Rule in this Model with the given symbol or @c NULL if no
3000  * such Rule exists.
3001  */
3002 AssignmentRule*
getAssignmentRuleByVariable(const std::string & variable)3003 Model::getAssignmentRuleByVariable(const std::string& variable)
3004 {
3005   return getAssignmentRule(variable);
3006 }
3007 
3008 
3009 
3010 /*
3011  * @return the Rule in this Model with the given variable or @c NULL if no
3012  * such Rule exists.
3013  */
3014 const RateRule*
getRateRuleByVariable(const std::string & variable) const3015 Model::getRateRuleByVariable(const std::string& variable) const
3016 {
3017   return getRateRule(variable);
3018 }
3019 
3020 
3021 /*
3022  * @return the Rule in this Model with the given symbol or @c NULL if no
3023  * such Rule exists.
3024  */
3025 RateRule*
getRateRuleByVariable(const std::string & variable)3026 Model::getRateRuleByVariable(const std::string& variable)
3027 {
3028   return getRateRule(variable);
3029 }
3030 
3031 
3032 /*
3033  * @return the nth Constraint of this Model.
3034  */
3035 const Constraint*
getConstraint(unsigned int n) const3036 Model::getConstraint (unsigned int n) const
3037 {
3038   return static_cast<const Constraint*>( mConstraints.get(n) );
3039 }
3040 
3041 
3042 /*
3043  * @return the nth Constraint of this Model.
3044  */
3045 Constraint*
getConstraint(unsigned int n)3046 Model::getConstraint (unsigned int n)
3047 {
3048   return static_cast<Constraint*>( mConstraints.get(n) );
3049 }
3050 
3051 
3052 /*
3053  * @return the nth Reaction of this Model.
3054  */
3055 const Reaction*
getReaction(unsigned int n) const3056 Model::getReaction (unsigned int n) const
3057 {
3058   return static_cast<const Reaction*>( mReactions.get(n) );
3059 }
3060 
3061 
3062 /*
3063  * @return the nth Reaction of this Model.
3064  */
3065 Reaction*
getReaction(unsigned int n)3066 Model::getReaction (unsigned int n)
3067 {
3068   return static_cast<Reaction*>( mReactions.get(n) );
3069 }
3070 
3071 
3072 /*
3073  * @return the Reaction in this Model with the given @p id or @c NULL if no such
3074  * Reaction exists.
3075  */
3076 const Reaction*
getReaction(const std::string & sid) const3077 Model::getReaction (const std::string& sid) const
3078 {
3079   return static_cast<const Reaction*>( mReactions.get(sid) );
3080 }
3081 
3082 
3083 /*
3084  * @return the Reaction in this Model with the given @p id or @c NULL if no such
3085  * Reaction exists.
3086  */
3087 Reaction*
getReaction(const std::string & sid)3088 Model::getReaction (const std::string& sid)
3089 {
3090   return static_cast<Reaction*>( mReactions.get(sid) );
3091 }
3092 
3093 
3094 /**
3095  * Get a SpeciesReference object based on its identifier.
3096  */
3097 SpeciesReference*
getSpeciesReference(const std::string & sid)3098 Model::getSpeciesReference (const std::string& sid)
3099 {
3100   SpeciesReference* sr = NULL;
3101   for (unsigned int i = 0; i < getNumReactions(); i++)
3102   {
3103     sr = getReaction(i)->getReactant(sid);
3104     if (sr != NULL) break;
3105 
3106     sr = getReaction(i)->getProduct(sid);
3107     if (sr != NULL) break;
3108   }
3109 
3110   return sr;
3111 }
3112 
3113 const SpeciesReference*
getSpeciesReference(const std::string & sid) const3114 Model::getSpeciesReference (const std::string& sid) const
3115 {
3116   const SpeciesReference* sr = NULL;
3117   for (unsigned int i = 0; i < getNumReactions(); i++)
3118   {
3119     sr = getReaction(i)->getReactant(sid);
3120     if (sr != NULL) break;
3121 
3122     sr = getReaction(i)->getProduct(sid);
3123     if (sr != NULL) break;
3124   }
3125 
3126   return sr;
3127 }
3128 
3129 
3130 const ModifierSpeciesReference*
getModifierSpeciesReference(const std::string & sid) const3131 Model::getModifierSpeciesReference (const std::string& sid) const
3132 {
3133   const ModifierSpeciesReference* sr = NULL;
3134   for (unsigned int i = 0; i < getNumReactions(); i++)
3135   {
3136     sr = getReaction(i)->getModifier(sid);
3137     if (sr != NULL) break;
3138   }
3139 
3140   return sr;
3141 }
3142 
3143 
3144 ModifierSpeciesReference*
getModifierSpeciesReference(const std::string & sid)3145 Model::getModifierSpeciesReference (const std::string& sid)
3146 {
3147   ModifierSpeciesReference* sr = NULL;
3148   for (unsigned int i = 0; i < getNumReactions(); i++)
3149   {
3150     sr = getReaction(i)->getModifier(sid);
3151     if (sr != NULL) break;
3152   }
3153 
3154   return sr;
3155 }
3156 
3157 
3158 /*
3159  * @return the nth Event of this Model.
3160  */
3161 const Event*
getEvent(unsigned int n) const3162 Model::getEvent (unsigned int n) const
3163 {
3164   return static_cast<const Event*>( mEvents.get(n) );
3165 }
3166 
3167 
3168 /*
3169  * @return the nth Event of this Model.
3170  */
3171 Event*
getEvent(unsigned int n)3172 Model::getEvent (unsigned int n)
3173 {
3174   return static_cast<Event*>( mEvents.get(n) );
3175 }
3176 
3177 
3178 /*
3179  * @return the Event in this Model with the given @p id or @c NULL if no such
3180  * Event exists.
3181  */
3182 const Event*
getEvent(const std::string & sid) const3183 Model::getEvent (const std::string& sid) const
3184 {
3185   return static_cast<const Event*>( mEvents.get(sid) );
3186 }
3187 
3188 
3189 /*
3190  * @return the Event in this Model with the given @p id or @c NULL if no such
3191  * Event exists.
3192  */
3193 Event*
getEvent(const std::string & sid)3194 Model::getEvent (const std::string& sid)
3195 {
3196   return static_cast<Event*>( mEvents.get(sid) );
3197 }
3198 
3199 
3200 /*
3201  * @return the number of FunctionDefinitions in this Model.
3202  */
3203 unsigned int
getNumFunctionDefinitions() const3204 Model::getNumFunctionDefinitions () const
3205 {
3206   return mFunctionDefinitions.size();
3207 }
3208 
3209 
3210 /*
3211  * @return the number of UnitDefinitions in this Model.
3212  */
3213 unsigned int
getNumUnitDefinitions() const3214 Model::getNumUnitDefinitions () const
3215 {
3216   return mUnitDefinitions.size();
3217 }
3218 
3219 
3220 /*
3221  * @return the number of CompartmentTypes in this Model.
3222  */
3223 unsigned int
getNumCompartmentTypes() const3224 Model::getNumCompartmentTypes () const
3225 {
3226   return mCompartmentTypes.size();
3227 }
3228 
3229 
3230 /*
3231  * @return the number of SpeciesTypes in this Model.
3232  */
3233 unsigned int
getNumSpeciesTypes() const3234 Model::getNumSpeciesTypes () const
3235 {
3236   return mSpeciesTypes.size();
3237 }
3238 
3239 
3240 /*
3241  * @return the number of Compartments in this Model.
3242  */
3243 unsigned int
getNumCompartments() const3244 Model::getNumCompartments () const
3245 {
3246   return mCompartments.size();
3247 }
3248 
3249 
3250 /*
3251  * @return the number of Species in this Model.
3252  */
3253 unsigned int
getNumSpecies() const3254 Model::getNumSpecies () const
3255 {
3256   return mSpecies.size();
3257 }
3258 
3259 
3260 /*
3261  * @return the number of Species in this Model with boundaryCondition set
3262  * to true.
3263  */
3264 unsigned int
getNumSpeciesWithBoundaryCondition() const3265 Model::getNumSpeciesWithBoundaryCondition () const
3266 {
3267   unsigned int count = 0;
3268 
3269   for(unsigned int i = 0; i < mSpecies.size(); i++)
3270   {
3271     if (getSpecies(i)->getBoundaryCondition())
3272       count++;
3273   }
3274   return count;
3275 }
3276 
3277 
3278 /*
3279  * @return the number of Parameters in this Model.  Parameters defined in
3280  * KineticLaws are not included.
3281  */
3282 unsigned int
getNumParameters() const3283 Model::getNumParameters () const
3284 {
3285   return mParameters.size();
3286 }
3287 
3288 
3289 /*
3290  * @return the number of InitialAssignments in this Model.
3291  */
3292 unsigned int
getNumInitialAssignments() const3293 Model::getNumInitialAssignments () const
3294 {
3295   return mInitialAssignments.size();
3296 }
3297 
3298 
3299 /*
3300  * @return the number of Rules in this Model.
3301  */
3302 unsigned int
getNumRules() const3303 Model::getNumRules () const
3304 {
3305   return mRules.size();
3306 }
3307 
3308 
3309 /*
3310  * @return the number of Constraints in this Model.
3311  */
3312 unsigned int
getNumConstraints() const3313 Model::getNumConstraints () const
3314 {
3315   return mConstraints.size();
3316 }
3317 
3318 
3319 /*
3320  * @return the number of Reactions in this Model.
3321  */
3322 unsigned int
getNumReactions() const3323 Model::getNumReactions () const
3324 {
3325   return mReactions.size();
3326 }
3327 
3328 
3329 /*
3330  * @return the number of Events in this Model.
3331  */
3332 unsigned int
getNumEvents() const3333 Model::getNumEvents () const
3334 {
3335   return mEvents.size();
3336 }
3337 
removeFromParentAndDelete()3338 int Model::removeFromParentAndDelete()
3339 {
3340   SBase* parent = getParentSBMLObject();
3341   if (parent==NULL) return LIBSBML_OPERATION_FAILED;
3342   SBMLDocument* parentDoc= static_cast<SBMLDocument*>(parent);
3343   if (parentDoc== NULL) return LIBSBML_OPERATION_FAILED;
3344   return parentDoc->setModel(NULL);
3345 }
3346 
3347 
3348 /** @cond doxygenLibsbmlInternal */
3349 /*
3350  * @return @c true if the given ASTNode is a boolean.  Often times, this
3351  * question can be answered with the ASTNode's own isBoolean() method,
3352  * but if the AST is an expression that calls a function defined in the
3353  * Model's ListOf FunctionDefinitions, the model is needed for lookup
3354  * context.
3355  */
3356 LIBSBML_EXTERN
3357 bool
isBoolean(const ASTNode * node) const3358 Model::isBoolean (const ASTNode* node) const
3359 {
3360   if (node == NULL)
3361   {
3362     return false;
3363   }
3364 
3365   else if ( node->isBoolean() )
3366   {
3367     return true;
3368   }
3369 
3370   else if (node->getType() == AST_FUNCTION)
3371   {
3372     const FunctionDefinition* fd = getFunctionDefinition( node->getName() );
3373 
3374     if (fd != NULL && fd->isSetMath())
3375     {
3376       return isBoolean( fd->getBody() );
3377     }
3378     else
3379     {
3380       return false;
3381     }
3382   }
3383 
3384   else if (node->getType() == AST_FUNCTION_PIECEWISE)
3385   {
3386     for (unsigned int c = 0; c < node->getNumChildren(); c += 2)
3387     {
3388       if ( !isBoolean( node->getChild(c) ) ) return false;
3389     }
3390 
3391     return true;
3392   }
3393 
3394   return false;
3395 }
3396 /** @endcond */
3397 
3398 /** @cond doxygenLibsbmlInternal */
3399 /*
3400  * Sets the parent SBMLDocument of this SBML object.
3401  */
3402 void
setSBMLDocument(SBMLDocument * d)3403 Model::setSBMLDocument (SBMLDocument* d)
3404 {
3405   SBase::setSBMLDocument(d);
3406 
3407   mFunctionDefinitions.setSBMLDocument(d);
3408   mUnitDefinitions    .setSBMLDocument(d);
3409   mCompartmentTypes   .setSBMLDocument(d);
3410   mSpeciesTypes       .setSBMLDocument(d);
3411   mCompartments       .setSBMLDocument(d);
3412   mSpecies            .setSBMLDocument(d);
3413   mParameters         .setSBMLDocument(d);
3414   mInitialAssignments .setSBMLDocument(d);
3415   mRules              .setSBMLDocument(d);
3416   mConstraints        .setSBMLDocument(d);
3417   mReactions          .setSBMLDocument(d);
3418   mEvents             .setSBMLDocument(d);
3419 
3420 }
3421 
3422 /*
3423  * Sets this SBML object to child SBML objects (if any).
3424  * (Creates a child-parent relationship by the parent)
3425   */
3426 void
connectToChild()3427 Model::connectToChild()
3428 {
3429       SBase::connectToChild();
3430     mFunctionDefinitions.connectToParent(this);
3431     mUnitDefinitions    .connectToParent(this);
3432     mCompartmentTypes   .connectToParent(this);
3433     mSpeciesTypes       .connectToParent(this);
3434     mCompartments       .connectToParent(this);
3435     mSpecies            .connectToParent(this);
3436     mParameters         .connectToParent(this);
3437     mInitialAssignments .connectToParent(this);
3438     mRules              .connectToParent(this);
3439     mConstraints        .connectToParent(this);
3440     mReactions          .connectToParent(this);
3441     mEvents             .connectToParent(this);
3442 }
3443 
3444 
3445 /**
3446  * Enables/Disables the given package with this element and child
3447  * elements (if any).
3448  * (This is an internal implementation for enablePackage function)
3449  */
3450 void
enablePackageInternal(const std::string & pkgURI,const std::string & pkgPrefix,bool flag)3451 Model::enablePackageInternal(const std::string& pkgURI,
3452                              const std::string& pkgPrefix, bool flag)
3453 {
3454   SBase::enablePackageInternal(pkgURI,pkgPrefix,flag);
3455 
3456   mFunctionDefinitions.enablePackageInternal(pkgURI,pkgPrefix,flag);
3457   mUnitDefinitions    .enablePackageInternal(pkgURI,pkgPrefix,flag);
3458   mCompartmentTypes   .enablePackageInternal(pkgURI,pkgPrefix,flag);
3459   mSpeciesTypes       .enablePackageInternal(pkgURI,pkgPrefix,flag);
3460   mCompartments       .enablePackageInternal(pkgURI,pkgPrefix,flag);
3461   mSpecies            .enablePackageInternal(pkgURI,pkgPrefix,flag);
3462   mParameters         .enablePackageInternal(pkgURI,pkgPrefix,flag);
3463   mInitialAssignments .enablePackageInternal(pkgURI,pkgPrefix,flag);
3464   mRules              .enablePackageInternal(pkgURI,pkgPrefix,flag);
3465   mConstraints        .enablePackageInternal(pkgURI,pkgPrefix,flag);
3466   mReactions          .enablePackageInternal(pkgURI,pkgPrefix,flag);
3467   mEvents             .enablePackageInternal(pkgURI,pkgPrefix,flag);
3468 }
3469 
3470 
3471 void
updateSBMLNamespace(const std::string & pkg,unsigned int level,unsigned int version)3472 Model::updateSBMLNamespace(const std::string& pkg, unsigned int level,
3473   unsigned int version)
3474 {
3475   SBase::updateSBMLNamespace(pkg, level, version);
3476 
3477   mFunctionDefinitions.updateSBMLNamespace(pkg, level, version);
3478   mUnitDefinitions.updateSBMLNamespace(pkg, level, version);
3479   mCompartmentTypes.updateSBMLNamespace(pkg, level, version);
3480   mSpeciesTypes.updateSBMLNamespace(pkg, level, version);
3481   mCompartments.updateSBMLNamespace(pkg, level, version);
3482   mSpecies.updateSBMLNamespace(pkg, level, version);
3483   mParameters.updateSBMLNamespace(pkg, level, version);
3484   mInitialAssignments.updateSBMLNamespace(pkg, level, version);
3485   mRules.updateSBMLNamespace(pkg, level, version);
3486   mConstraints.updateSBMLNamespace(pkg, level, version);
3487   mReactions.updateSBMLNamespace(pkg, level, version);
3488   mEvents.updateSBMLNamespace(pkg, level, version);
3489 
3490 }
3491 /** @endcond */
3492 
3493 
3494 /*
3495  * @return the typecode (int) of this SBML object or SBML_UNKNOWN
3496  * (default).
3497  *
3498  * @see getElementName()
3499  */
3500 int
getTypeCode() const3501 Model::getTypeCode () const
3502 {
3503   return SBML_MODEL;
3504 }
3505 
3506 
3507 /*
3508  * @return the name of this element ie "model".
3509 
3510  */
3511 const string&
getElementName() const3512 Model::getElementName () const
3513 {
3514   static const string name = "model";
3515   return name;
3516 }
3517 
3518 
3519 bool
hasRequiredElements() const3520 Model::hasRequiredElements() const
3521 {
3522   bool allPresent = true;
3523 
3524   /* required attributes for model: compart(L1); species (L1V1)
3525    * reaction (L1V1)
3526    */
3527 
3528   if (getLevel() == 1)
3529   {
3530     if (getNumCompartments() == 0)
3531       allPresent = false;
3532 
3533     if (getVersion() == 1)
3534     {
3535       if (getNumSpecies() == 0)
3536         allPresent = false;
3537       if (getNumReactions() == 0)
3538         allPresent = false;
3539     }
3540   }
3541   return allPresent;
3542 }
3543 
3544 
3545 /**
3546  * Removes the nth FunctionDefinition object from this Model object and
3547  * returns a pointer to it.
3548  */
3549 FunctionDefinition*
removeFunctionDefinition(unsigned int n)3550 Model::removeFunctionDefinition (unsigned int n)
3551 {
3552   return mFunctionDefinitions.remove(n);
3553 }
3554 
3555 
3556 /**
3557  * Removes the FunctionDefinition object with the given identifier from this Model
3558  * object and returns a pointer to it.
3559  */
3560 FunctionDefinition*
removeFunctionDefinition(const std::string & sid)3561 Model::removeFunctionDefinition (const std::string& sid)
3562 {
3563   return mFunctionDefinitions.remove(sid);
3564 }
3565 
3566 
3567 /**
3568  * Removes the nth UnitDefinition object from this Model object and
3569  * returns a pointer to it.
3570  */
3571 UnitDefinition*
removeUnitDefinition(unsigned int n)3572 Model::removeUnitDefinition (unsigned int n)
3573 {
3574   return mUnitDefinitions.remove(n);
3575 }
3576 
3577 
3578 /**
3579  * Removes the UnitDefinition object with the given identifier from this Model
3580  * object and returns a pointer to it.
3581  */
3582 UnitDefinition*
removeUnitDefinition(const std::string & sid)3583 Model::removeUnitDefinition (const std::string& sid)
3584 {
3585   return mUnitDefinitions.remove(sid);
3586 }
3587 
3588 
3589 /**
3590  * Removes the nth CompartmentType object from this Model object and
3591  * returns a pointer to it.
3592  */
3593 CompartmentType*
removeCompartmentType(unsigned int n)3594 Model::removeCompartmentType (unsigned int n)
3595 {
3596   return mCompartmentTypes.remove(n);
3597 }
3598 
3599 
3600 /**
3601  * Removes the CompartmentType object with the given identifier from this Model
3602  * object and returns a pointer to it.
3603  */
3604 CompartmentType*
removeCompartmentType(const std::string & sid)3605 Model::removeCompartmentType (const std::string& sid)
3606 {
3607   return mCompartmentTypes.remove(sid);
3608 }
3609 
3610 
3611 /**
3612  * Removes the nth SpeciesType object from this Model object and
3613  * returns a pointer to it.
3614  */
3615 SpeciesType*
removeSpeciesType(unsigned int n)3616 Model::removeSpeciesType (unsigned int n)
3617 {
3618   return mSpeciesTypes.remove(n);
3619 }
3620 
3621 
3622 /**
3623  * Removes the SpeciesType object with the given identifier from this Model
3624  * object and returns a pointer to it.
3625  */
3626 SpeciesType*
removeSpeciesType(const std::string & sid)3627 Model::removeSpeciesType (const std::string& sid)
3628 {
3629   return mSpeciesTypes.remove(sid);
3630 }
3631 
3632 
3633 /**
3634  * Removes the nth Compartment object from this Model object and
3635  * returns a pointer to it.
3636  */
3637 Compartment*
removeCompartment(unsigned int n)3638 Model::removeCompartment (unsigned int n)
3639 {
3640   return mCompartments.remove(n);
3641 }
3642 
3643 
3644 /**
3645  * Removes the Compartment object with the given identifier from this Model
3646  * object and returns a pointer to it.
3647  */
3648 Compartment*
removeCompartment(const std::string & sid)3649 Model::removeCompartment (const std::string& sid)
3650 {
3651   return mCompartments.remove(sid);
3652 }
3653 
3654 
3655 /**
3656  * Removes the nth Species object from this Model object and
3657  * returns a pointer to it.
3658  */
3659 Species*
removeSpecies(unsigned int n)3660 Model::removeSpecies (unsigned int n)
3661 {
3662   return mSpecies.remove(n);
3663 }
3664 
3665 
3666 /**
3667  * Removes the Species object with the given identifier from this Model
3668  * object and returns a pointer to it.
3669  */
3670 Species*
removeSpecies(const std::string & sid)3671 Model::removeSpecies (const std::string& sid)
3672 {
3673   return mSpecies.remove(sid);
3674 }
3675 
3676 
3677 /**
3678  * Removes the nth Parameter object from this Model object and
3679  * returns a pointer to it.
3680  */
3681 Parameter*
removeParameter(unsigned int n)3682 Model::removeParameter (unsigned int n)
3683 {
3684   return mParameters.remove(n);
3685 }
3686 
3687 
3688 /**
3689  * Removes the Parameter object with the given identifier from this Model
3690  * object and returns a pointer to it.
3691  */
3692 Parameter*
removeParameter(const std::string & sid)3693 Model::removeParameter (const std::string& sid)
3694 {
3695   return mParameters.remove(sid);
3696 }
3697 
3698 
3699 /**
3700  * Removes the nth InitialAssignment object from this Model object and
3701  * returns a pointer to it.
3702  */
3703 InitialAssignment*
removeInitialAssignment(unsigned int n)3704 Model::removeInitialAssignment (unsigned int n)
3705 {
3706   return mInitialAssignments.remove(n);
3707 }
3708 
3709 
3710 /**
3711  * Removes the InitialAssignment object with the given identifier from this Model
3712  * object and returns a pointer to it.
3713  */
3714 InitialAssignment*
removeInitialAssignment(const std::string & sid)3715 Model::removeInitialAssignment (const std::string& sid)
3716 {
3717   return mInitialAssignments.remove(sid);
3718 }
3719 
3720 
3721 /**
3722  * Removes the nth Rule object from this Model object and
3723  * returns a pointer to it.
3724  */
3725 Rule*
removeRule(unsigned int n)3726 Model::removeRule (unsigned int n)
3727 {
3728   return mRules.remove(n);
3729 }
3730 
3731 
3732 /**
3733  * Removes the Rule object with the given identifier from this Model
3734  * object and returns a pointer to it.
3735  */
3736 Rule*
removeRule(const std::string & sid)3737 Model::removeRule (const std::string& sid)
3738 {
3739   return mRules.remove(sid);
3740 }
3741 
3742 /**
3743  * Removes the Rule object with the given variable from this Model
3744  * object and returns a pointer to it.
3745  */
3746 Rule*
removeRuleByVariable(const std::string & variable)3747 Model::removeRuleByVariable (const std::string& variable)
3748 {
3749   return mRules.remove(variable);
3750 }
3751 
3752 
3753 /**
3754  * Removes the nth Constraint object from this Model object and
3755  * returns a pointer to it.
3756  */
3757 Constraint*
removeConstraint(unsigned int n)3758 Model::removeConstraint (unsigned int n)
3759 {
3760   return mConstraints.remove(n);
3761 }
3762 
3763 
3764 /**
3765  * Removes the nth Reaction object from this Model object and
3766  * returns a pointer to it.
3767  */
3768 Reaction*
removeReaction(unsigned int n)3769 Model::removeReaction (unsigned int n)
3770 {
3771   return mReactions.remove(n);
3772 }
3773 
3774 
3775 /**
3776  * Removes the Reaction object with the given identifier from this Model
3777  * object and returns a pointer to it.
3778  */
3779 Reaction*
removeReaction(const std::string & sid)3780 Model::removeReaction (const std::string& sid)
3781 {
3782   return mReactions.remove(sid);
3783 }
3784 
3785 
3786 /**
3787  * Removes the nth Event object from this Model object and
3788  * returns a pointer to it.
3789  */
3790 Event*
removeEvent(unsigned int n)3791 Model::removeEvent (unsigned int n)
3792 {
3793   return mEvents.remove(n);
3794 }
3795 
3796 
3797 /**
3798  * Removes the Event object with the given identifier from this Model
3799  * object and returns a pointer to it.
3800  */
3801 Event*
removeEvent(const std::string & sid)3802 Model::removeEvent (const std::string& sid)
3803 {
3804   return mEvents.remove(sid);
3805 }
3806 
3807 
3808 
3809 
3810 
3811 
3812 /** @cond doxygenLibsbmlInternal */
3813 
3814 /*
3815  * Returns the value of the "attributeName" attribute of this Model.
3816  */
3817 int
getAttribute(const std::string & attributeName,bool & value) const3818 Model::getAttribute(const std::string& attributeName, bool& value) const
3819 {
3820   int return_value = SBase::getAttribute(attributeName, value);
3821 
3822   return return_value;
3823 }
3824 
3825 /** @endcond */
3826 
3827 
3828 
3829 /** @cond doxygenLibsbmlInternal */
3830 
3831 /*
3832  * Returns the value of the "attributeName" attribute of this Model.
3833  */
3834 int
getAttribute(const std::string & attributeName,int & value) const3835 Model::getAttribute(const std::string& attributeName, int& value) const
3836 {
3837   int return_value = SBase::getAttribute(attributeName, value);
3838 
3839   return return_value;
3840 }
3841 
3842 /** @endcond */
3843 
3844 
3845 
3846 /** @cond doxygenLibsbmlInternal */
3847 
3848 /*
3849  * Returns the value of the "attributeName" attribute of this Model.
3850  */
3851 int
getAttribute(const std::string & attributeName,double & value) const3852 Model::getAttribute(const std::string& attributeName, double& value) const
3853 {
3854   int return_value = SBase::getAttribute(attributeName, value);
3855 
3856   return return_value;
3857 }
3858 
3859 /** @endcond */
3860 
3861 
3862 
3863 /** @cond doxygenLibsbmlInternal */
3864 
3865 /*
3866  * Returns the value of the "attributeName" attribute of this Model.
3867  */
3868 int
getAttribute(const std::string & attributeName,unsigned int & value) const3869 Model::getAttribute(const std::string& attributeName,
3870                     unsigned int& value) const
3871 {
3872   int return_value = SBase::getAttribute(attributeName, value);
3873 
3874   return return_value;
3875 }
3876 
3877 /** @endcond */
3878 
3879 
3880 
3881 /** @cond doxygenLibsbmlInternal */
3882 
3883 /*
3884  * Returns the value of the "attributeName" attribute of this Model.
3885  */
3886 int
getAttribute(const std::string & attributeName,std::string & value) const3887 Model::getAttribute(const std::string& attributeName,
3888                     std::string& value) const
3889 {
3890   int return_value = SBase::getAttribute(attributeName, value);
3891 
3892   if (return_value == LIBSBML_OPERATION_SUCCESS)
3893   {
3894     return return_value;
3895   }
3896 
3897   if (attributeName == "substanceUnits")
3898   {
3899     value = getSubstanceUnits();
3900     return_value = LIBSBML_OPERATION_SUCCESS;
3901   }
3902   else if (attributeName == "timeUnits")
3903   {
3904     value = getTimeUnits();
3905     return_value = LIBSBML_OPERATION_SUCCESS;
3906   }
3907   else if (attributeName == "volumeUnits")
3908   {
3909     value = getVolumeUnits();
3910     return_value = LIBSBML_OPERATION_SUCCESS;
3911   }
3912   else if (attributeName == "lengthUnits")
3913   {
3914     value = getLengthUnits();
3915     return_value = LIBSBML_OPERATION_SUCCESS;
3916   }
3917   else if (attributeName == "areaUnits")
3918   {
3919     value = getAreaUnits();
3920     return_value = LIBSBML_OPERATION_SUCCESS;
3921   }
3922   else if (attributeName == "extentUnits")
3923   {
3924     value = getExtentUnits();
3925     return_value = LIBSBML_OPERATION_SUCCESS;
3926   }
3927   else if (attributeName == "conversionFactor")
3928   {
3929     value = getConversionFactor();
3930     return_value = LIBSBML_OPERATION_SUCCESS;
3931   }
3932 
3933   return return_value;
3934 }
3935 
3936 /** @endcond */
3937 
3938 
3939 
3940 /** @cond doxygenLibsbmlInternal */
3941 
3942 /*
3943  * Returns the value of the "attributeName" attribute of this Model.
3944  */
3945 //int
3946 //Model::getAttribute(const std::string& attributeName, const char* value) const
3947 //{
3948 //  int return_value = SBase::getAttribute(attributeName, value);
3949 //
3950 //  if (return_value == LIBSBML_OPERATION_SUCCESS)
3951 //  {
3952 //    return return_value;
3953 //  }
3954 //
3955 //  if (attributeName == "substanceUnits")
3956 //  {
3957 //    value = getSubstanceUnits().c_str();
3958 //    return_value = LIBSBML_OPERATION_SUCCESS;
3959 //  }
3960 //  else if (attributeName == "timeUnits")
3961 //  {
3962 //    value = getTimeUnits().c_str();
3963 //    return_value = LIBSBML_OPERATION_SUCCESS;
3964 //  }
3965 //  else if (attributeName == "volumeUnits")
3966 //  {
3967 //    value = getVolumeUnits().c_str();
3968 //    return_value = LIBSBML_OPERATION_SUCCESS;
3969 //  }
3970 //  else if (attributeName == "lengthUnits")
3971 //  {
3972 //    value = getLengthUnits().c_str();
3973 //    return_value = LIBSBML_OPERATION_SUCCESS;
3974 //  }
3975 //  else if (attributeName == "areaUnits")
3976 //  {
3977 //    value = getAreaUnits().c_str();
3978 //    return_value = LIBSBML_OPERATION_SUCCESS;
3979 //  }
3980 //  else if (attributeName == "extentUnits")
3981 //  {
3982 //    value = getExtentUnits().c_str();
3983 //    return_value = LIBSBML_OPERATION_SUCCESS;
3984 //  }
3985 //  else if (attributeName == "conversionFactor")
3986 //  {
3987 //    value = getConversionFactor().c_str();
3988 //    return_value = LIBSBML_OPERATION_SUCCESS;
3989 //  }
3990 //
3991 //  return return_value;
3992 //}
3993 
3994 /** @endcond */
3995 
3996 
3997 
3998 /** @cond doxygenLibsbmlInternal */
3999 
4000 /*
4001  * Predicate returning @c true if this Model's attribute "attributeName" is
4002  * set.
4003  */
4004 bool
isSetAttribute(const std::string & attributeName) const4005 Model::isSetAttribute(const std::string& attributeName) const
4006 {
4007   bool value = SBase::isSetAttribute(attributeName);
4008 
4009   if (attributeName == "substanceUnits")
4010   {
4011     value = isSetSubstanceUnits();
4012   }
4013   else if (attributeName == "timeUnits")
4014   {
4015     value = isSetTimeUnits();
4016   }
4017   else if (attributeName == "volumeUnits")
4018   {
4019     value = isSetVolumeUnits();
4020   }
4021   else if (attributeName == "lengthUnits")
4022   {
4023     value = isSetLengthUnits();
4024   }
4025   else if (attributeName == "areaUnits")
4026   {
4027     value = isSetAreaUnits();
4028   }
4029   else if (attributeName == "extentUnits")
4030   {
4031     value = isSetExtentUnits();
4032   }
4033   else if (attributeName == "conversionFactor")
4034   {
4035     value = isSetConversionFactor();
4036   }
4037 
4038   return value;
4039 }
4040 
4041 /** @endcond */
4042 
4043 
4044 
4045 /** @cond doxygenLibsbmlInternal */
4046 
4047 /*
4048  * Sets the value of the "attributeName" attribute of this Model.
4049  */
4050 int
setAttribute(const std::string & attributeName,bool value)4051 Model::setAttribute(const std::string& attributeName, bool value)
4052 {
4053   int return_value = SBase::setAttribute(attributeName, value);
4054 
4055   return return_value;
4056 }
4057 
4058 /** @endcond */
4059 
4060 
4061 
4062 /** @cond doxygenLibsbmlInternal */
4063 
4064 /*
4065  * Sets the value of the "attributeName" attribute of this Model.
4066  */
4067 int
setAttribute(const std::string & attributeName,int value)4068 Model::setAttribute(const std::string& attributeName, int value)
4069 {
4070   int return_value = SBase::setAttribute(attributeName, value);
4071 
4072   return return_value;
4073 }
4074 
4075 /** @endcond */
4076 
4077 
4078 
4079 /** @cond doxygenLibsbmlInternal */
4080 
4081 /*
4082  * Sets the value of the "attributeName" attribute of this Model.
4083  */
4084 int
setAttribute(const std::string & attributeName,double value)4085 Model::setAttribute(const std::string& attributeName, double value)
4086 {
4087   int return_value = SBase::setAttribute(attributeName, value);
4088 
4089   return return_value;
4090 }
4091 
4092 /** @endcond */
4093 
4094 
4095 
4096 /** @cond doxygenLibsbmlInternal */
4097 
4098 /*
4099  * Sets the value of the "attributeName" attribute of this Model.
4100  */
4101 int
setAttribute(const std::string & attributeName,unsigned int value)4102 Model::setAttribute(const std::string& attributeName, unsigned int value)
4103 {
4104   int return_value = SBase::setAttribute(attributeName, value);
4105 
4106   return return_value;
4107 }
4108 
4109 /** @endcond */
4110 
4111 
4112 
4113 /** @cond doxygenLibsbmlInternal */
4114 
4115 /*
4116  * Sets the value of the "attributeName" attribute of this Model.
4117  */
4118 int
setAttribute(const std::string & attributeName,const std::string & value)4119 Model::setAttribute(const std::string& attributeName,
4120                     const std::string& value)
4121 {
4122   int return_value = SBase::setAttribute(attributeName, value);
4123 
4124   if (attributeName == "substanceUnits")
4125   {
4126     return_value = setSubstanceUnits(value);
4127   }
4128   else if (attributeName == "timeUnits")
4129   {
4130     return_value = setTimeUnits(value);
4131   }
4132   else if (attributeName == "volumeUnits")
4133   {
4134     return_value = setVolumeUnits(value);
4135   }
4136   else if (attributeName == "lengthUnits")
4137   {
4138     return_value = setLengthUnits(value);
4139   }
4140   else if (attributeName == "areaUnits")
4141   {
4142     return_value = setAreaUnits(value);
4143   }
4144   else if (attributeName == "extentUnits")
4145   {
4146     return_value = setExtentUnits(value);
4147   }
4148   else if (attributeName == "conversionFactor")
4149   {
4150     return_value = setConversionFactor(value);
4151   }
4152 
4153   return return_value;
4154 }
4155 
4156 /** @endcond */
4157 
4158 
4159 
4160 /** @cond doxygenLibsbmlInternal */
4161 
4162 /*
4163  * Sets the value of the "attributeName" attribute of this Model.
4164  */
4165 //int
4166 //Model::setAttribute(const std::string& attributeName, const char* value)
4167 //{
4168 //  int return_value = SBase::setAttribute(attributeName, value);
4169 //
4170 //  if (attributeName == "substanceUnits")
4171 //  {
4172 //    return_value = setSubstanceUnits(value);
4173 //  }
4174 //  else if (attributeName == "timeUnits")
4175 //  {
4176 //    return_value = setTimeUnits(value);
4177 //  }
4178 //  else if (attributeName == "volumeUnits")
4179 //  {
4180 //    return_value = setVolumeUnits(value);
4181 //  }
4182 //  else if (attributeName == "lengthUnits")
4183 //  {
4184 //    return_value = setLengthUnits(value);
4185 //  }
4186 //  else if (attributeName == "areaUnits")
4187 //  {
4188 //    return_value = setAreaUnits(value);
4189 //  }
4190 //  else if (attributeName == "extentUnits")
4191 //  {
4192 //    return_value = setExtentUnits(value);
4193 //  }
4194 //  else if (attributeName == "conversionFactor")
4195 //  {
4196 //    return_value = setConversionFactor(value);
4197 //  }
4198 //
4199 //  return return_value;
4200 //}
4201 //
4202 /** @endcond */
4203 
4204 
4205 
4206 /** @cond doxygenLibsbmlInternal */
4207 
4208 /*
4209  * Unsets the value of the "attributeName" attribute of this Model.
4210  */
4211 int
unsetAttribute(const std::string & attributeName)4212 Model::unsetAttribute(const std::string& attributeName)
4213 {
4214   int value = SBase::unsetAttribute(attributeName);
4215 
4216   if (attributeName == "substanceUnits")
4217   {
4218     value = unsetSubstanceUnits();
4219   }
4220   else if (attributeName == "timeUnits")
4221   {
4222     value = unsetTimeUnits();
4223   }
4224   else if (attributeName == "volumeUnits")
4225   {
4226     value = unsetVolumeUnits();
4227   }
4228   else if (attributeName == "lengthUnits")
4229   {
4230     value = unsetLengthUnits();
4231   }
4232   else if (attributeName == "areaUnits")
4233   {
4234     value = unsetAreaUnits();
4235   }
4236   else if (attributeName == "extentUnits")
4237   {
4238     value = unsetExtentUnits();
4239   }
4240   else if (attributeName == "conversionFactor")
4241   {
4242     value = unsetConversionFactor();
4243   }
4244 
4245   return value;
4246 }
4247 
4248 /** @endcond */
4249 
4250 
4251 
4252 /** @cond doxygenLibsbmlInternal */
4253 
4254 /*
4255  * Creates and returns an new "elementName" object in this Model.
4256  */
4257 SBase*
createChildObject(const std::string & elementName)4258 Model::createChildObject(const std::string& elementName)
4259 {
4260   SBase* obj = NULL;
4261 
4262   if (elementName == "functionDefinition")
4263   {
4264     return createFunctionDefinition();
4265   }
4266   else if (elementName == "unitDefinition")
4267   {
4268     return createUnitDefinition();
4269   }
4270   else if (elementName == "compartment")
4271   {
4272     return createCompartment();
4273   }
4274   else if (elementName == "species")
4275   {
4276     return createSpecies();
4277   }
4278   else if (elementName == "parameter")
4279   {
4280     return createParameter();
4281   }
4282   else if (elementName == "initialAssignment")
4283   {
4284     return createInitialAssignment();
4285   }
4286   else if (elementName == "constraint")
4287   {
4288     return createConstraint();
4289   }
4290   else if (elementName == "reaction")
4291   {
4292     return createReaction();
4293   }
4294   else if (elementName == "event")
4295   {
4296     return createEvent();
4297   }
4298   else if (elementName == "assignmentRule")
4299   {
4300     return createAssignmentRule();
4301   }
4302   else if (elementName == "parameterAssignmentRule")
4303   {
4304     AssignmentRule *ar = createAssignmentRule();
4305     ar->setL1TypeCode(SBML_PARAMETER_RULE);
4306     return ar;
4307   }
4308   else if (elementName == "speciesAssignmentRule")
4309   {
4310     AssignmentRule *ar = createAssignmentRule();
4311     ar->setL1TypeCode(SBML_SPECIES_CONCENTRATION_RULE);
4312     return ar;
4313   }
4314   else if (elementName == "compartmentAssignmentRule")
4315   {
4316     AssignmentRule *ar = createAssignmentRule();
4317     ar->setL1TypeCode(SBML_COMPARTMENT_VOLUME_RULE);
4318     return ar;
4319   }
4320   else if (elementName == "parameterRateRule")
4321   {
4322     RateRule *ar = createRateRule();
4323     ar->setL1TypeCode(SBML_PARAMETER_RULE);
4324     return ar;
4325   }
4326   else if (elementName == "speciesRateRule")
4327   {
4328     RateRule *ar = createRateRule();
4329     ar->setL1TypeCode(SBML_SPECIES_CONCENTRATION_RULE);
4330     return ar;
4331   }
4332   else if (elementName == "compartmentRateRule")
4333   {
4334     RateRule *ar = createRateRule();
4335     ar->setL1TypeCode(SBML_COMPARTMENT_VOLUME_RULE);
4336     return ar;
4337   }
4338   else if (elementName == "rateRule")
4339   {
4340     return createRateRule();
4341   }
4342   else if (elementName == "algebraicRule")
4343   {
4344     return createAlgebraicRule();
4345   }
4346   else if (elementName == "compartmentType")
4347   {
4348     return createCompartmentType();
4349   }
4350   else if (elementName == "speciesType")
4351   {
4352     return createSpeciesType();
4353   }
4354 
4355   return obj;
4356 }
4357 
4358 /** @endcond */
4359 
4360 
4361 
4362 /** @cond doxygenLibsbmlInternal */
4363 
4364 /*
4365  * Adds an new "elementName" object in this Model.
4366  */
4367 int
addChildObject(const std::string & elementName,const SBase * element)4368 Model::addChildObject(const std::string& elementName, const SBase* element)
4369 {
4370   if (elementName == "functionDefinition" && element->getTypeCode() == SBML_FUNCTION_DEFINITION)
4371   {
4372     return addFunctionDefinition((const FunctionDefinition*)(element));
4373   }
4374   else if (elementName == "unitDefinition"  && element->getTypeCode() == SBML_UNIT_DEFINITION)
4375   {
4376     return addUnitDefinition((const UnitDefinition*)(element));
4377   }
4378   else if (elementName == "compartment"  && element->getTypeCode() == SBML_COMPARTMENT)
4379   {
4380     return addCompartment((const Compartment*)(element));
4381   }
4382   else if (elementName == "species"  && element->getTypeCode() == SBML_SPECIES)
4383   {
4384     return addSpecies((const Species*)(element));
4385   }
4386   else if (elementName == "parameter"  && element->getTypeCode() == SBML_PARAMETER)
4387   {
4388     return addParameter((const Parameter*)(element));
4389   }
4390   else if (elementName == "initialAssignment"  && element->getTypeCode() == SBML_INITIAL_ASSIGNMENT)
4391   {
4392     return addInitialAssignment((const InitialAssignment*)(element));
4393   }
4394   else if (elementName == "constraint"  && element->getTypeCode() == SBML_CONSTRAINT)
4395   {
4396     return addConstraint((const Constraint*)(element));
4397   }
4398   else if (elementName == "reaction"  && element->getTypeCode() == SBML_REACTION)
4399   {
4400     return addReaction((const Reaction*)(element));
4401   }
4402   else if (elementName == "event"  && element->getTypeCode() == SBML_EVENT)
4403   {
4404     return addEvent((const Event*)(element));
4405   }
4406   else if (elementName == "assignmentRule"  && element->getTypeCode() == SBML_ASSIGNMENT_RULE)
4407   {
4408     return addRule((const Rule*)(element));
4409   }
4410   else if (elementName == "rateRule"  && element->getTypeCode() == SBML_RATE_RULE)
4411   {
4412     return addRule((const Rule*)(element));
4413   }
4414   else if (elementName == "algebraicRule"  && element->getTypeCode() == SBML_ALGEBRAIC_RULE)
4415   {
4416     return addRule((const Rule*)(element));
4417   }
4418   else if (elementName == "compartmentType"  && element->getTypeCode() == SBML_COMPARTMENT_TYPE)
4419   {
4420     return addCompartmentType((const CompartmentType*)(element));
4421   }
4422   else if (elementName == "speciesType"  && element->getTypeCode() == SBML_SPECIES_TYPE)
4423   {
4424     return addSpeciesType((const SpeciesType*)(element));
4425   }
4426 
4427   return LIBSBML_OPERATION_FAILED;
4428 }
4429 
4430 /** @endcond */
4431 
4432 
4433 /** @cond doxygenLibsbmlInternal */
4434 
4435 /*
4436  * Adds an new "elementName" object in this Model.
4437  */
4438 SBase*
removeChildObject(const std::string & elementName,const std::string & id)4439 Model::removeChildObject(const std::string& elementName, const std::string& id)
4440 {
4441   if (elementName == "functionDefinition")
4442   {
4443     return removeFunctionDefinition(id);
4444   }
4445   else if (elementName == "unitDefinition")
4446   {
4447     return removeUnitDefinition(id);
4448   }
4449   else if (elementName == "compartment")
4450   {
4451     return removeCompartment(id);
4452   }
4453   else if (elementName == "species")
4454   {
4455     return removeSpecies(id);
4456   }
4457   else if (elementName == "parameter")
4458   {
4459     return removeParameter(id);
4460   }
4461   else if (elementName == "initialAssignment")
4462   {
4463     return removeInitialAssignment(id);
4464   }
4465   else if (elementName == "constraint")
4466   {
4467  //   return removeConstraint(id);
4468   }
4469   else if (elementName == "reaction")
4470   {
4471     return removeReaction(id);
4472   }
4473   else if (elementName == "event")
4474   {
4475     return removeEvent(id);
4476   }
4477   else if (elementName == "assignmentRule")
4478   {
4479     return removeRule(id);
4480   }
4481   else if (elementName == "rateRule")
4482   {
4483     return removeRule(id);
4484   }
4485   else if (elementName == "algebraicRule")
4486   {
4487     return removeRule(id);
4488   }
4489   else if (elementName == "compartmentType")
4490   {
4491     return removeCompartmentType(id);
4492   }
4493   else if (elementName == "speciesType")
4494   {
4495     return removeSpeciesType(id);
4496   }
4497 
4498   return NULL;
4499 }
4500 
4501 /** @endcond */
4502 
4503 
4504 
4505 /** @cond doxygenLibsbmlInternal */
4506 
4507 /*
4508  * Returns the number of "elementName" in this Model.
4509  */
4510 unsigned int
getNumObjects(const std::string & elementName)4511 Model::getNumObjects(const std::string& elementName)
4512 {
4513   unsigned int n = 0;
4514 
4515   if (elementName == "functionDefinition")
4516   {
4517     return getNumFunctionDefinitions();
4518   }
4519   else if (elementName == "unitDefinition")
4520   {
4521     return getNumUnitDefinitions();
4522   }
4523   else if (elementName == "compartment")
4524   {
4525     return getNumCompartments();
4526   }
4527   else if (elementName == "species")
4528   {
4529     return getNumSpecies();
4530   }
4531   else if (elementName == "parameter")
4532   {
4533     return getNumParameters();
4534   }
4535   else if (elementName == "initialAssignment")
4536   {
4537     return getNumInitialAssignments();
4538   }
4539   else if (elementName == "constraint")
4540   {
4541     return getNumConstraints();
4542   }
4543   else if (elementName == "reaction")
4544   {
4545     return getNumReactions();
4546   }
4547   else if (elementName == "event")
4548   {
4549     return getNumEvents();
4550   }
4551   else if (elementName == "rule")
4552   {
4553     return getNumRules();
4554   }
4555   else if (elementName == "assignmentRule")
4556   {
4557     return getNumRules();
4558   }
4559   else if (elementName == "parameterAssignmentRule")
4560   {
4561     return getNumRules();
4562   }
4563   else if (elementName == "speciesAssignmentRule")
4564   {
4565     return getNumRules();
4566   }
4567   else if (elementName == "compartmentAssignmentRule")
4568   {
4569     return getNumRules();
4570   }
4571   else if (elementName == "parameterRateRule")
4572   {
4573     return getNumRules();
4574   }
4575   else if (elementName == "speciesRateRule")
4576   {
4577     return getNumRules();
4578   }
4579   else if (elementName == "compartmentRateRule")
4580   {
4581     return getNumRules();
4582   }
4583   else if (elementName == "rateRule")
4584   {
4585     return getNumRules();
4586   }
4587   else if (elementName == "algebraicRule")
4588   {
4589     return getNumRules();
4590   }
4591   else if (elementName == "compartmentType")
4592   {
4593     return getNumCompartmentTypes();
4594   }
4595   else if (elementName == "speciesType")
4596   {
4597     return getNumSpeciesTypes();
4598   }
4599 
4600   return n;
4601 }
4602 
4603 /** @endcond */
4604 
4605 
4606 
4607 /** @cond doxygenLibsbmlInternal */
4608 
4609 /*
4610  * Returns the nth object of "objectName" in this Model.
4611  */
4612 SBase*
getObject(const std::string & elementName,unsigned int index)4613 Model::getObject(const std::string& elementName, unsigned int index)
4614 {
4615   SBase* obj = NULL;
4616 
4617   if (elementName == "functionDefinition")
4618   {
4619     return getFunctionDefinition(index);
4620   }
4621   else if (elementName == "unitDefinition")
4622   {
4623     return getUnitDefinition(index);
4624   }
4625   else if (elementName == "compartment")
4626   {
4627     return getCompartment(index);
4628   }
4629   else if (elementName == "species")
4630   {
4631     return getSpecies(index);
4632   }
4633   else if (elementName == "parameter")
4634   {
4635     return getParameter(index);
4636   }
4637   else if (elementName == "initialAssignment")
4638   {
4639     return getInitialAssignment(index);
4640   }
4641   else if (elementName == "constraint")
4642   {
4643     return getConstraint(index);
4644   }
4645   else if (elementName == "reaction")
4646   {
4647     return getReaction(index);
4648   }
4649   else if (elementName == "event")
4650   {
4651     return getEvent(index);
4652   }
4653   else if (elementName == "rule")
4654   {
4655     return getRule(index);
4656   }
4657   else if (elementName == "assignmentRule")
4658   {
4659     return getRule(index);
4660   }
4661   else if (elementName == "parameterAssignmentRule")
4662   {
4663     return getRule(index);
4664   }
4665   else if (elementName == "speciesAssignmentRule")
4666   {
4667     return getRule(index);
4668   }
4669   else if (elementName == "compartmentAssignmentRule")
4670   {
4671     return getRule(index);
4672   }
4673   else if (elementName == "parameterRateRule")
4674   {
4675     return getRule(index);
4676   }
4677   else if (elementName == "speciesRateRule")
4678   {
4679     return getRule(index);
4680   }
4681   else if (elementName == "compartmentRateRule")
4682   {
4683     return getRule(index);
4684   }
4685   else if (elementName == "rateRule")
4686  {
4687     return getRule(index);
4688   }
4689   else if (elementName == "algebraicRule")
4690   {
4691     return getRule(index);
4692   }
4693   else if (elementName == "compartmentType")
4694   {
4695     return getCompartmentType(index);
4696   }
4697   else if (elementName == "speciesType")
4698   {
4699     return getSpeciesType(index);
4700   }
4701 
4702   return obj;
4703 }
4704 
4705 /** @endcond */
4706 
4707 
4708 
4709 int
appendFrom(const Model * model)4710 Model::appendFrom(const Model* model)
4711 {
4712   int ret = LIBSBML_OPERATION_SUCCESS;
4713   ret = mFunctionDefinitions.appendFrom(&model->mFunctionDefinitions);
4714   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4715   ret = mUnitDefinitions    .appendFrom(&model->mUnitDefinitions);
4716   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4717   ret = mCompartmentTypes   .appendFrom(&model->mCompartmentTypes);
4718   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4719   ret = mSpeciesTypes       .appendFrom(&model->mSpeciesTypes);
4720   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4721   ret = mCompartments       .appendFrom(&model->mCompartments);
4722   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4723   ret = mSpecies            .appendFrom(&model->mSpecies);
4724   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4725   ret = mParameters         .appendFrom(&model->mParameters);
4726   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4727   ret = mInitialAssignments .appendFrom(&model->mInitialAssignments);
4728   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4729   ret = mRules              .appendFrom(&model->mRules);
4730   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4731   ret = mConstraints        .appendFrom(&model->mConstraints);
4732   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4733   ret = mReactions          .appendFrom(&model->mReactions);
4734   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4735   ret = mEvents             .appendFrom(&model->mEvents);
4736   if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4737 
4738   for (size_t i=0; i < mPlugins.size(); i++) {
4739     ret = mPlugins[i]->appendFrom(model);
4740     if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
4741   }
4742   return ret;
4743 }
4744 
4745 void
renameSIdRefs(const std::string & oldid,const std::string & newid)4746 Model::renameSIdRefs(const std::string& oldid, const std::string& newid)
4747 {
4748   SBase::renameSIdRefs(oldid, newid);
4749   if (isSetConversionFactor()) {
4750     if (getConversionFactor()==oldid) {
4751       setConversionFactor(newid);
4752     }
4753   }
4754 }
4755 
4756 void
renameUnitSIdRefs(const std::string & oldid,const std::string & newid)4757 Model::renameUnitSIdRefs(const std::string& oldid, const std::string& newid)
4758 {
4759   SBase::renameUnitSIdRefs(oldid, newid);
4760   if (mSubstanceUnits == oldid) mSubstanceUnits = newid;
4761   if (mTimeUnits == oldid)      mTimeUnits = newid;
4762   if (mVolumeUnits == oldid)    mVolumeUnits = newid;
4763   if (mAreaUnits == oldid)      mAreaUnits = newid;
4764   if (mLengthUnits == oldid)    mLengthUnits = newid;
4765   if (mExtentUnits == oldid)    mExtentUnits = newid;
4766 }
4767 
4768 /** @cond doxygenLibsbmlInternal */
4769 /*
4770  * Subclasses should override this method to read (and store) XHTML,
4771  * MathML, etc. directly from the XMLInputStream.
4772  *
4773  * @return @c true if the subclass read from the stream, false otherwise.
4774  */
4775 bool
readOtherXML(XMLInputStream & stream)4776 Model::readOtherXML (XMLInputStream& stream)
4777 {
4778   bool          read = false;
4779   const string& name = stream.peek().getName();
4780 
4781   // This has to do additional work for reading annotations, so the code
4782   // here is copied and expanded from SBase::readNotes().
4783 
4784   if (name == "annotation")
4785   {
4786 //    XMLNode* new_annotation = NULL;
4787     /* if annotation already exists then it is an error
4788      */
4789     if (mAnnotation != NULL)
4790     {
4791       if (getLevel() < 3)
4792       {
4793         logError(NotSchemaConformant, getLevel(), getVersion(),
4794           "Only one <annotation> element is permitted inside a "
4795           "particular containing element.");
4796       }
4797       else
4798       {
4799         logError(MultipleAnnotations, getLevel(), getVersion(),
4800           "The SBML <model> element has multiple <annotation> children.");
4801       }
4802     }
4803 
4804     delete mAnnotation;
4805     mAnnotation = new XMLNode(stream);
4806     checkAnnotation();
4807     if (mCVTerms != NULL)
4808     {
4809       unsigned int size = mCVTerms->getSize();
4810       while (size--) delete static_cast<CVTerm*>( mCVTerms->remove(0) );
4811       delete mCVTerms;
4812     }
4813     mCVTerms = new List();
4814     delete mHistory;
4815     if (RDFAnnotationParser::hasHistoryRDFAnnotation(mAnnotation))
4816     {
4817       mHistory = RDFAnnotationParser::parseRDFAnnotation(mAnnotation,
4818                                             getMetaId().c_str(), &(stream));
4819 
4820       if (mHistory != NULL && mHistory->hasRequiredAttributes() == false)
4821       {
4822         logError(RDFNotCompleteModelHistory, getLevel(), getVersion(),
4823           "An invalid ModelHistory element has been stored.");
4824       }
4825       setModelHistory(mHistory);
4826     }
4827     else
4828       mHistory = NULL;
4829     if (RDFAnnotationParser::hasCVTermRDFAnnotation(mAnnotation))
4830       RDFAnnotationParser::parseRDFAnnotation(mAnnotation, mCVTerms,
4831                                                 getMetaId().c_str(), &(stream));
4832 //    new_annotation = RDFAnnotationParser::deleteRDFAnnotation(mAnnotation);
4833 //    delete mAnnotation;
4834 //    mAnnotation = new_annotation;
4835 
4836     // need to call set annotation
4837     for (size_t i=0; i < mPlugins.size(); i++)
4838     {
4839       mPlugins[i]->parseAnnotation(this, mAnnotation);
4840     }
4841 
4842     read = true;
4843   }
4844 
4845   /* ------------------------------
4846    *
4847    *   (EXTENSION)
4848    *
4849    * ------------------------------ */
4850   if ( SBase::readOtherXML(stream) )
4851     read = true;
4852 
4853   return read;
4854 }
4855 /** @endcond */
4856 
4857 
4858 /** @cond doxygenLibsbmlInternal */
4859 /*
4860  * @return the SBML object corresponding to next XMLToken in the
4861  * XMLInputStream or @c NULL if the token was not recognized.
4862  */
4863 SBase*
createObject(XMLInputStream & stream)4864 Model::createObject (XMLInputStream& stream)
4865 {
4866   const string& name   = stream.peek().getName();
4867   SBase*        object = NULL;
4868   unsigned int level = getLevel();
4869   unsigned int version = getVersion();
4870 
4871   /* dont create objects for wrong levels/versions */
4872   if (name == "listOfFunctionDefinitions")
4873   {
4874     if (level == 1)
4875     {
4876       return NULL;
4877     }
4878 
4879     if (mFunctionDefinitions.size() != 0)
4880     {
4881       if (getLevel() < 3)
4882       {
4883         logError(NotSchemaConformant);
4884       }
4885       else
4886       {
4887         logError(OneOfEachListOf);
4888       }
4889     }
4890     mFunctionDefinitions.setExplicitlyListed();
4891     object = &mFunctionDefinitions;
4892   }
4893 
4894   else if ( name == "listOfUnitDefinitions"    )
4895   {
4896     if (mUnitDefinitions.size() != 0)
4897     {
4898       if (getLevel() < 3)
4899       {
4900         logError(NotSchemaConformant);
4901       }
4902       else
4903       {
4904         logError(OneOfEachListOf);
4905       }
4906     }
4907     mUnitDefinitions.setExplicitlyListed();
4908     object = &mUnitDefinitions;
4909   }
4910 
4911   else if ( name == "listOfCompartmentTypes"   )
4912   {
4913     if (level == 1
4914       || (level == 2 && version == 1)
4915       || level == 3)
4916     {
4917       return NULL;
4918     }
4919     if (mCompartmentTypes.size() != 0)
4920     {
4921       logError(NotSchemaConformant);
4922     }
4923     mCompartmentTypes.setExplicitlyListed();
4924     object = &mCompartmentTypes;
4925   }
4926 
4927   else if ( name == "listOfSpeciesTypes"       )
4928   {
4929     if (level == 1
4930       || (level == 2 && version == 1)
4931       || level == 3)
4932     {
4933       return NULL;
4934     }
4935     if (mSpeciesTypes.size() != 0)
4936     {
4937       logError(NotSchemaConformant);
4938     }
4939     mSpeciesTypes.setExplicitlyListed();
4940     object = &mSpeciesTypes;
4941   }
4942 
4943   else if ( name == "listOfCompartments"       )
4944   {
4945     if (mCompartments.size() != 0)
4946     {
4947       if (getLevel() < 3)
4948       {
4949         logError(NotSchemaConformant);
4950       }
4951       else
4952       {
4953         logError(OneOfEachListOf);
4954       }
4955     }
4956     mCompartments.setExplicitlyListed();
4957     object = &mCompartments;
4958   }
4959 
4960   else if ( name == "listOfSpecies"            )
4961   {
4962     if (mSpecies.size() != 0)
4963     {
4964       if (getLevel() < 3)
4965       {
4966         logError(NotSchemaConformant);
4967       }
4968       else
4969       {
4970         logError(OneOfEachListOf);
4971       }
4972     }
4973     mSpecies.setExplicitlyListed();
4974     object = &mSpecies;
4975   }
4976 
4977   else if ( name == "listOfParameters"         )
4978   {
4979     if (mParameters.size() != 0)
4980     {
4981       if (getLevel() < 3)
4982       {
4983         logError(NotSchemaConformant);
4984       }
4985       else
4986       {
4987         logError(OneOfEachListOf);
4988       }
4989     }
4990     mParameters.setExplicitlyListed();
4991     object = &mParameters;
4992   }
4993 
4994   else if ( name == "listOfInitialAssignments" )
4995   {
4996     if (level == 1  || (level == 2 && version == 1))
4997     {
4998       return NULL;
4999     }
5000     if (mInitialAssignments.size() != 0)
5001     {
5002       if (getLevel() < 3)
5003       {
5004         logError(NotSchemaConformant);
5005       }
5006       else
5007       {
5008         logError(OneOfEachListOf);
5009       }
5010     }
5011     mInitialAssignments.setExplicitlyListed();
5012     object = &mInitialAssignments;
5013   }
5014 
5015   else if ( name == "listOfRules"              )
5016   {
5017     if (mRules.size() != 0)
5018     {
5019       if (getLevel() < 3)
5020       {
5021         logError(NotSchemaConformant);
5022       }
5023       else
5024       {
5025         logError(OneOfEachListOf);
5026       }
5027     }
5028     mRules.setExplicitlyListed();
5029     object = &mRules;
5030   }
5031 
5032   else if ( name == "listOfConstraints"        )
5033   {
5034     if (level == 1  || (level == 2 && version == 1))
5035     {
5036       return NULL;
5037     }
5038     if (mConstraints.size() != 0)
5039     {
5040       if (getLevel() < 3)
5041       {
5042         logError(NotSchemaConformant);
5043       }
5044       else
5045       {
5046         logError(OneOfEachListOf);
5047       }
5048     }
5049     mConstraints.setExplicitlyListed();
5050     object = &mConstraints;
5051   }
5052 
5053   else if ( name == "listOfReactions"          )
5054   {
5055     if (mReactions.size() != 0)
5056     {
5057       if (getLevel() < 3)
5058       {
5059         logError(NotSchemaConformant);
5060       }
5061       else
5062       {
5063         logError(OneOfEachListOf);
5064       }
5065     }
5066     mReactions.setExplicitlyListed();
5067     object = &mReactions;
5068   }
5069 
5070   else if ( name == "listOfEvents"             )
5071   {
5072     if (level == 1)
5073     {
5074       return NULL;
5075     }
5076     if (mEvents.size() != 0)
5077     {
5078       if (getLevel() < 3)
5079       {
5080         logError(NotSchemaConformant);
5081       }
5082       else
5083       {
5084         logError(OneOfEachListOf);
5085       }
5086     }
5087     mEvents.setExplicitlyListed();
5088     object = &mEvents;
5089   }
5090 
5091   else if ( level == 1 && version == 1 )
5092   {
5093     if (name == "listOfSpecie")
5094     {
5095       if (mSpecies.size() != 0)
5096       {
5097         logError(NotSchemaConformant);
5098       }
5099       object = &mSpecies;
5100     }
5101   }
5102 
5103   return object;
5104 }
5105 /** @endcond */
5106 
5107 
5108 /** @cond doxygenLibsbmlInternal */
5109 /**
5110  * Subclasses should override this method to get the list of
5111  * expected attributes.
5112  * This function is invoked from corresponding readAttributes()
5113  * function.
5114  */
5115 void
addExpectedAttributes(ExpectedAttributes & attributes)5116 Model::addExpectedAttributes(ExpectedAttributes& attributes)
5117 {
5118   SBase::addExpectedAttributes(attributes);
5119 
5120   const unsigned int level   = getLevel  ();
5121   const unsigned int version = getVersion();
5122 
5123   switch (level)
5124   {
5125   case 1:
5126     attributes.add("name");
5127     break;
5128   case 2:
5129     attributes.add("name");
5130     attributes.add("id");
5131     if (version == 2)
5132     {
5133       attributes.add("sboTerm");
5134     }
5135     break;
5136   case 3:
5137   default:
5138     attributes.add("name");
5139     attributes.add("id");
5140     attributes.add("substanceUnits");
5141     attributes.add("timeUnits");
5142     attributes.add("volumeUnits");
5143     attributes.add("areaUnits");
5144     attributes.add("lengthUnits");
5145     attributes.add("extentUnits");
5146     attributes.add("conversionFactor");
5147     break;
5148   }
5149 }
5150 
5151 /*
5152  * Subclasses should override this method to read values from the given
5153  * XMLAttributes set into their specific fields.  Be sure to call your
5154  * parent's implementation of this method as well.
5155  */
5156 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)5157 Model::readAttributes (const XMLAttributes& attributes,
5158                        const ExpectedAttributes& expectedAttributes)
5159 {
5160   const unsigned int level   = getLevel  ();
5161 
5162   SBase::readAttributes(attributes, expectedAttributes);
5163 
5164   switch (level)
5165   {
5166   case 1:
5167     readL1Attributes(attributes);
5168     break;
5169   case 2:
5170     readL2Attributes(attributes);
5171     break;
5172   case 3:
5173   default:
5174     readL3Attributes(attributes);
5175     break;
5176   }
5177 }
5178 /** @endcond */
5179 
5180 
5181 /** @cond doxygenLibsbmlInternal */
5182 /*
5183  * Subclasses should override this method to read values from the given
5184  * XMLAttributes set into their specific fields.  Be sure to call your
5185  * parent's implementation of this method as well.
5186  */
5187 void
readL1Attributes(const XMLAttributes & attributes)5188 Model::readL1Attributes (const XMLAttributes& attributes)
5189 {
5190   const unsigned int level   = getLevel  ();
5191   const unsigned int version = getVersion();
5192 
5193   //
5194   // name: SName  { use="optional" }  (L1v1, L1v2)
5195   //   id: SId    { use="optional" }  (L2v1 -> )
5196   //
5197   bool assigned = attributes.readInto("name", mId, getErrorLog(), false, getLine(), getColumn());
5198   if (assigned && mId.size() == 0)
5199   {
5200     logEmptyString("name", level, version, "<model>");
5201   }
5202   if (!SyntaxChecker::isValidInternalSId(mId))
5203     logError(InvalidIdSyntax, level, version, "The id '" + mId + "' does not conform to the syntax.");
5204 
5205 }
5206 /** @endcond */
5207 
5208 
5209 /** @cond doxygenLibsbmlInternal */
5210 /*
5211  * Subclasses should override this method to read values from the given
5212  * XMLAttributes set into their specific fields.  Be sure to call your
5213  * parent's implementation of this method as well.
5214  */
5215 void
readL2Attributes(const XMLAttributes & attributes)5216 Model::readL2Attributes (const XMLAttributes& attributes)
5217 {
5218   const unsigned int level   = getLevel  ();
5219   const unsigned int version = getVersion();
5220 
5221   //
5222   //   id: SId    { use="optional" }  (L2v1 -> )
5223   //
5224   bool assigned = attributes.readInto("id", mId, getErrorLog(), false, getLine(), getColumn());
5225   if (assigned && mId.size() == 0)
5226   {
5227     logEmptyString("id", level, version, "<model>");
5228   }
5229   if (!SyntaxChecker::isValidInternalSId(mId))
5230     logError(InvalidIdSyntax, level, version, "The id '" + mId + "' does not conform to the syntax.");
5231 
5232   //
5233   // name: string  { use="optional" }  (L2v1 ->)
5234   //
5235   attributes.readInto("name", mName, getErrorLog(), false, getLine(), getColumn());
5236 
5237   //
5238   // sboTerm: SBOTerm { use="optional" }  (L2v2 ->)
5239   //
5240   if (version == 2)
5241     mSBOTerm = SBO::readTerm(attributes, this->getErrorLog(), level, version,
5242         getLine(), getColumn());
5243 
5244 }
5245 /** @endcond */
5246 
5247 
5248 /** @cond doxygenLibsbmlInternal */
5249 /*
5250  * Subclasses should override this method to read values from the given
5251  * XMLAttributes set into their specific fields.  Be sure to call your
5252  * parent's implementation of this method as well.
5253  */
5254 void
readL3Attributes(const XMLAttributes & attributes)5255 Model::readL3Attributes (const XMLAttributes& attributes)
5256 {
5257   const unsigned int level   = getLevel  ();
5258   const unsigned int version = getVersion();
5259 
5260   bool assigned;
5261   //
5262   //   id: SId    { use="optional" }  (L2v1 -> )
5263   //
5264   // for l3v2 sbase will read this as generically optional
5265   // we want to log errors relating to the specific object
5266   if (version == 1)
5267   {
5268     assigned = attributes.readInto("id", mId, getErrorLog(), false,
5269       getLine(), getColumn());
5270     if (assigned && mId.size() == 0)
5271     {
5272       logEmptyString("id", level, version, "<model>");
5273     }
5274     if (!SyntaxChecker::isValidInternalSId(mId))
5275     {
5276       logError(InvalidIdSyntax, level, version, "The id '" + mId +
5277       "' does not conform to the syntax.");
5278     }
5279 
5280     //
5281     // name: string  { use="optional" }  (L2v1 ->)
5282     //
5283     attributes.readInto("name", mName, getErrorLog(), false,
5284                                        getLine(), getColumn());
5285   }
5286 
5287 
5288   //
5289   // substanceUnits: string  { use="optional" }  (L3v1 ->)
5290   //
5291   assigned = attributes.readInto("substanceUnits", mSubstanceUnits, getErrorLog(), false, getLine(), getColumn());
5292   if (assigned && mSubstanceUnits.size() == 0)
5293   {
5294     logEmptyString("substanceUnits", level, version, "<model>");
5295   }
5296   if (!SyntaxChecker::isValidInternalUnitSId(mSubstanceUnits))
5297   {
5298     logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The substanceUnits attribute '" + mSubstanceUnits + "' does not conform to the syntax.");
5299   }
5300 
5301   //
5302   // timeUnits: string  { use="optional" }  (L3v1 ->)
5303   //
5304   assigned = attributes.readInto("timeUnits", mTimeUnits, getErrorLog(), false, getLine(), getColumn());
5305   if (assigned && mTimeUnits.size() == 0)
5306   {
5307     logEmptyString("timeUnits", level, version, "<model>");
5308   }
5309   if (!SyntaxChecker::isValidInternalUnitSId(mTimeUnits))
5310   {
5311     logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The timeUnits attribute '" + mTimeUnits + "' does not conform to the syntax.");
5312   }
5313 
5314   //
5315   // volumeUnits: string  { use="optional" }  (L3v1 ->)
5316   //
5317   assigned = attributes.readInto("volumeUnits", mVolumeUnits, getErrorLog(), false, getLine(), getColumn());
5318   if (assigned && mVolumeUnits.size() == 0)
5319   {
5320     logEmptyString("volumeUnits", level, version, "<model>");
5321   }
5322   if (!SyntaxChecker::isValidInternalUnitSId(mVolumeUnits))
5323   {
5324     logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The volumeUnits attribute '" + mVolumeUnits + "' does not conform to the syntax.");
5325   }
5326 
5327   //
5328   // areaUnits: string  { use="optional" }  (L3v1 ->)
5329   //
5330   assigned = attributes.readInto("areaUnits", mAreaUnits, getErrorLog(), false, getLine(), getColumn());
5331   if (assigned && mAreaUnits.size() == 0)
5332   {
5333     logEmptyString("areaUnits", level, version, "<model>");
5334   }
5335   if (!SyntaxChecker::isValidInternalUnitSId(mAreaUnits))
5336   {
5337     logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The areaUnits attribute '" + mAreaUnits + "' does not conform to the syntax.");
5338   }
5339 
5340   //
5341   // lengthUnits: string  { use="optional" }  (L3v1 ->)
5342   //
5343   assigned = attributes.readInto("lengthUnits", mLengthUnits, getErrorLog(), false, getLine(), getColumn());
5344   if (assigned && mLengthUnits.size() == 0)
5345   {
5346     logEmptyString("lengthUnits", level, version, "<model>");
5347   }
5348   if (!SyntaxChecker::isValidInternalUnitSId(mLengthUnits))
5349   {
5350     logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The lengthUnits attribute '" + mLengthUnits + "' does not conform to the syntax.");
5351   }
5352 
5353   //
5354   // extentUnits: string  { use="optional" }  (L3v1 ->)
5355   //
5356   assigned = attributes.readInto("extentUnits", mExtentUnits, getErrorLog(), false, getLine(), getColumn());
5357   if (assigned && mExtentUnits.size() == 0)
5358   {
5359     logEmptyString("extentUnits", level, version, "<model>");
5360   }
5361   if (!SyntaxChecker::isValidInternalUnitSId(mExtentUnits))
5362   {
5363     logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The extentUnits attribute '" + mExtentUnits + "' does not conform to the syntax.");
5364   }
5365 
5366   //
5367   // conversionFactor: string  { use="optional" }  (L3v1 ->)
5368   //
5369   attributes.readInto("conversionFactor", mConversionFactor, getErrorLog(), false, getLine(), getColumn());
5370 }
5371 /** @endcond */
5372 
5373 
5374 /** @cond doxygenLibsbmlInternal */
5375 /*
5376  * Subclasses should override this method to write their XML attributes
5377  * to the XMLOutputStream.  Be sure to call your parent's implementation
5378  * of this method as well.
5379  */
5380 void
writeAttributes(XMLOutputStream & stream) const5381 Model::writeAttributes (XMLOutputStream& stream) const
5382 {
5383   SBase::writeAttributes(stream);
5384 
5385   const unsigned int level   = getLevel  ();
5386   const unsigned int version = getVersion();
5387 
5388   //
5389   // sboTerm: SBOTerm { use="optional" }  (L2v2->)
5390   //
5391   // sboTerm for L2V3 or later is written in SBase::writeAttributes()
5392   //
5393   if ( (level == 2) && (version == 2) )
5394   {
5395     SBO::writeTerm(stream, mSBOTerm);
5396   }
5397 
5398   // for L3V2 and above SBase will write this out
5399   if (level < 3 || (level == 3 && version == 1))
5400   {
5401   //
5402   // name: SName   { use="required" }  (L1v1, L1v2)
5403   //   id: SId     { use="required" }  (L2v1->)
5404   //
5405   const string id = (level == 1) ? "name" : "id";
5406   stream.writeAttribute(id, mId);
5407   }
5408   if (level > 1)
5409   {
5410     // for L3V2 and above SBase will write this out
5411     if (level < 3 || (level == 3 && version == 1))
5412     {
5413       //
5414       // name: string  { use="optional" }  (L2v1->)
5415       //
5416       stream.writeAttribute("name", mName);
5417     }
5418   }
5419 
5420   if (level > 2)
5421   {
5422     //
5423     // substanceUnits: string  { use="optional" }  (L3v1 ->)
5424     //
5425     stream.writeAttribute("substanceUnits", mSubstanceUnits);
5426 
5427     //
5428     // timeUnits: string  { use="optional" }  (L3v1 ->)
5429     //
5430     stream.writeAttribute("timeUnits", mTimeUnits);
5431 
5432     //
5433     // volumeUnits: string  { use="optional" }  (L3v1 ->)
5434     //
5435     stream.writeAttribute("volumeUnits", mVolumeUnits);
5436 
5437     //
5438     // areaUnits: string  { use="optional" }  (L3v1 ->)
5439     //
5440     stream.writeAttribute("areaUnits", mAreaUnits);
5441 
5442     //
5443     // lengthUnits: string  { use="optional" }  (L3v1 ->)
5444     //
5445     stream.writeAttribute("lengthUnits", mLengthUnits);
5446 
5447     //
5448     // extentUnits: string  { use="optional" }  (L3v1 ->)
5449     //
5450     stream.writeAttribute("extentUnits", mExtentUnits);
5451 
5452     //
5453     // conversionFactor: string  { use="optional" }  (L3v1 ->)
5454     //
5455     stream.writeAttribute("conversionFactor", mConversionFactor);
5456 
5457   }
5458 
5459   //
5460   // (EXTENSION)
5461   //
5462   SBase::writeExtensionAttributes(stream);
5463 }
5464 /** @endcond */
5465 
5466 
5467 /** @cond doxygenLibsbmlInternal */
5468 /*
5469  * Subclasses should override this method to write out their contained
5470  * SBML objects as XML elements.  Be sure to call your parent's
5471  * implementation of this method as well.
5472  */
5473 void
writeElements(XMLOutputStream & stream) const5474 Model::writeElements (XMLOutputStream& stream) const
5475 {
5476   if (mNotes != NULL)
5477   {
5478     mNotes->writeToStream(stream);
5479   }
5480   Model * m = const_cast <Model *> (this);
5481   m->syncAnnotation();
5482   if ( mAnnotation ) stream << *mAnnotation;
5483 
5484   const unsigned int level   = getLevel  ();
5485   const unsigned int version = getVersion();
5486 
5487   // for l3v2 there may not be any elements in the listOf but
5488   // if there is other information i.e. attributes/notes/annotations
5489   // we write out the empty wrapper with this information
5490   if (level == 3 && version > 1)
5491   {
5492     if (mFunctionDefinitions.hasOptionalElements() == true ||
5493         mFunctionDefinitions.hasOptionalAttributes() == true ||
5494         mFunctionDefinitions.isExplicitlyListed())
5495     {
5496       mFunctionDefinitions.write(stream);
5497     }
5498 
5499     if (mUnitDefinitions.hasOptionalElements() == true ||
5500         mUnitDefinitions.hasOptionalAttributes() == true ||
5501         mUnitDefinitions.isExplicitlyListed())
5502     {
5503       mUnitDefinitions.write(stream);
5504     }
5505 
5506     if (mCompartments.hasOptionalElements() == true ||
5507         mCompartments.hasOptionalAttributes() == true ||
5508         mCompartments.isExplicitlyListed())
5509     {
5510       mCompartments.write(stream);
5511     }
5512 
5513     if (mSpecies.hasOptionalElements() == true ||
5514         mSpecies.hasOptionalAttributes() == true ||
5515         mSpecies.isExplicitlyListed())
5516     {
5517       mSpecies.write(stream);
5518     }
5519 
5520     if (mParameters.hasOptionalElements() == true ||
5521         mParameters.hasOptionalAttributes() == true ||
5522         mParameters.isExplicitlyListed())
5523     {
5524       mParameters.write(stream);
5525     }
5526 
5527     if (mInitialAssignments.hasOptionalElements() == true ||
5528         mInitialAssignments.hasOptionalAttributes() == true ||
5529         mInitialAssignments.isExplicitlyListed())
5530     {
5531       mInitialAssignments.write(stream);
5532     }
5533 
5534     if (mRules.hasOptionalElements() == true ||
5535         mRules.hasOptionalAttributes() == true ||
5536         mRules.isExplicitlyListed())
5537     {
5538       mRules.write(stream);
5539     }
5540 
5541     if (mConstraints.hasOptionalElements() == true ||
5542         mConstraints.hasOptionalAttributes() == true ||
5543         mConstraints.isExplicitlyListed())
5544     {
5545       mConstraints.write(stream);
5546     }
5547 
5548     if (mReactions.hasOptionalElements() == true ||
5549         mReactions.hasOptionalAttributes() == true ||
5550         mReactions.isExplicitlyListed())
5551     {
5552       mReactions.write(stream);
5553     }
5554 
5555     if (mEvents.hasOptionalElements() == true ||
5556         mEvents.hasOptionalAttributes() == true ||
5557         mEvents.isExplicitlyListed())
5558     {
5559       mEvents.write(stream);
5560     }
5561   }
5562   else
5563   {
5564       // code as before
5565     if (level > 1 && getNumFunctionDefinitions() > 0 )
5566     {
5567       mFunctionDefinitions.write(stream);
5568     }
5569 
5570     if ( getNumUnitDefinitions() > 0 ) mUnitDefinitions.write(stream);
5571 
5572     if (level == 2 && version > 1)
5573     {
5574       if ( getNumCompartmentTypes() > 0 ) mCompartmentTypes.write(stream);
5575       if ( getNumSpeciesTypes    () > 0 ) mSpeciesTypes    .write(stream);
5576     }
5577 
5578     if ( getNumCompartments() > 0 ) mCompartments.write(stream);
5579     if ( getNumSpecies     () > 0 ) mSpecies     .write(stream);
5580     if ( getNumParameters  () > 0 ) mParameters  .write(stream);
5581 
5582     if (level > 2 || (level == 2 && version > 1))
5583     {
5584       if ( getNumInitialAssignments() > 0 ) mInitialAssignments.write(stream);
5585     }
5586 
5587     if ( getNumRules() > 0 ) mRules.write(stream);
5588 
5589     if (level > 2 || (level == 2 && version > 1))
5590     {
5591       if ( getNumConstraints() > 0 ) mConstraints.write(stream);
5592     }
5593 
5594     if ( getNumReactions() > 0 ) mReactions.write(stream);
5595 
5596     if (level > 1 && getNumEvents () > 0 )
5597     {
5598       mEvents.write(stream);
5599     }
5600   }
5601 
5602   //
5603   // (EXTENSION)
5604   //
5605   SBase::writeExtensionElements(stream);
5606 }
5607 /** @endcond */
5608 
5609 
5610 /** @cond doxygenLibsbmlInternal */
5611 /*
5612  * @return the ordinal position of the element with respect to its siblings
5613  * or -1 (default) to indicate the position is not significant.
5614  */
5615 int
getElementPosition() const5616 Model::getElementPosition () const
5617 {
5618   return 2;
5619 }
5620 /** @endcond */
5621 
5622 
5623 /** @cond doxygenLibsbmlInternal */
populatePerTimeUnitDefinition(FormulaUnitsData * fud)5624 void Model::populatePerTimeUnitDefinition(FormulaUnitsData *fud)
5625 {
5626   FormulaUnitsData *tempFUD = getFormulaUnitsData("time", SBML_MODEL);
5627 
5628   // if time is undeclared so we do not set the perTime unit
5629   if (tempFUD->getContainsUndeclaredUnits() == false)
5630   {
5631     UnitDefinition * temp = tempFUD->getUnitDefinition();
5632     UnitDefinition *existingUD = fud->getUnitDefinition()->clone();
5633 
5634     for (unsigned int n = 0; n < temp->getNumUnits(); n++)
5635     {
5636       Unit * u = temp->getUnit(n)->clone();
5637       u->setExponent(u->getExponent() * -1);
5638       existingUD->addUnit(u);
5639       delete u;
5640     }
5641 
5642     UnitDefinition::simplify(existingUD);
5643 
5644     fud->setPerTimeUnitDefinition(existingUD);
5645   }
5646 }
5647 /** @endcond */
5648 
5649 /** @cond doxygenLibsbmlInternal */
createSpeciesReferenceUnitsData(SpeciesReference * sr,UnitFormulaFormatter * unitFormatter)5650 void Model::createSpeciesReferenceUnitsData(SpeciesReference* sr,
5651                                   UnitFormulaFormatter* unitFormatter)
5652 {
5653   FormulaUnitsData * fud;
5654 
5655   if (sr->isSetStoichiometryMath())
5656   {
5657     fud = createFormulaUnitsData(sr->getSpecies(), SBML_STOICHIOMETRY_MATH);
5658     //fud->setUnitReferenceId(sr->getSpecies());
5659     sr->getStoichiometryMath()->setInternalId(sr->getSpecies());
5660     //fud->setComponentTypecode(SBML_STOICHIOMETRY_MATH);
5661 
5662     createUnitsDataFromMath(unitFormatter, fud,
5663                             sr->getStoichiometryMath()->getMath());
5664   }
5665   else if (sr->getLevel() > 2 && sr->isSetId())
5666   {
5667     fud = createFormulaUnitsData(sr->getId(), SBML_SPECIES_REFERENCE);
5668     //fud->setUnitReferenceId(sr->getId());
5669     //fud->setComponentTypecode(SBML_SPECIES_REFERENCE);
5670 
5671     /* units will be dimensionless */
5672     UnitDefinition* ud;
5673     try
5674     {
5675       ud = new UnitDefinition(getSBMLNamespaces());
5676     }
5677     catch ( ... )
5678     {
5679       ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
5680         SBMLDocument::getDefaultVersion());
5681     }
5682     Unit* u = ud->createUnit();
5683     u->setKind(UNIT_KIND_DIMENSIONLESS);
5684     u->initDefaults();
5685 
5686     fud->setUnitDefinition(ud);
5687     fud->setContainsParametersWithUndeclaredUnits(false);
5688     fud->setCanIgnoreUndeclaredUnits(true);
5689 
5690     populatePerTimeUnitDefinition(fud);
5691   }
5692 }
5693 /** @endcond */
5694 
5695 /** @cond doxygenLibsbmlInternal */
5696 /**
5697   * Populates the ListFormulaDataUnits with the units of each
5698   * set of math encountered in the model
5699   */
5700 void
populateListFormulaUnitsData()5701 Model::populateListFormulaUnitsData()
5702 {
5703   removeListFormulaUnitsData();
5704 
5705   UnitFormulaFormatter *unitFormatter = new UnitFormulaFormatter(this);
5706 
5707   /* create the model wide units data */
5708   createSubstanceUnitsData();
5709   createVolumeUnitsData();
5710   createAreaUnitsData();
5711   createLengthUnitsData();
5712   createTimeUnitsData();
5713   createExtentUnitsData();
5714   createSubstancePerTimeUnitsData();
5715 
5716   /* create the units data for 'variables' */
5717   createCompartmentUnitsData();
5718   createSpeciesUnitsData();
5719   createParameterUnitsData();
5720   if (getLevel() > 2)
5721   {
5722     createL3SpeciesUnitsData();
5723   }
5724 
5725   /* create the units data from math elements */
5726 
5727   // pass the unitFormatter as this will save data
5728   // for math expressions already evaluated
5729 
5730   createInitialAssignmentUnitsData(unitFormatter);
5731   createConstraintUnitsData(unitFormatter);
5732   createRuleUnitsData(unitFormatter);
5733   createReactionUnitsData(unitFormatter);
5734   createEventUnitsData(unitFormatter);
5735 
5736   delete unitFormatter;
5737 }
5738 /** @endcond */
5739 
5740 
5741 /** @cond doxygenLibsbmlInternal */
5742 void
removeListFormulaUnitsData()5743 Model::removeListFormulaUnitsData()
5744 {
5745   if (mFormulaUnitsData != NULL)
5746   {
5747     unsigned int size = mFormulaUnitsData->getSize();
5748     while (size--)
5749       delete static_cast<FormulaUnitsData*>( mFormulaUnitsData->remove(0) );
5750     delete mFormulaUnitsData;
5751     mFormulaUnitsData = NULL;
5752   }
5753 
5754   mUnitsDataMap.clear();
5755 }
5756 /** @endcond */
5757 
5758 
5759 /** @cond doxygenLibsbmlInternal */
5760 void
createSubstanceUnitsData()5761 Model::createSubstanceUnitsData()
5762 {
5763   UnitDefinition *ud = NULL;
5764   FormulaUnitsData *fud = createFormulaUnitsData("substance", SBML_MODEL);
5765 
5766   //fud->setUnitReferenceId("substance");
5767   //fud->setComponentTypecode(SBML_MODEL);
5768 
5769   if (getLevel() < 3)
5770   {
5771     ud = getSubstanceUD();
5772   }
5773   else
5774   {
5775     ud = getL3SubstanceUD();
5776 
5777     if (ud->getNumUnits() == 0)
5778     {
5779       fud->setContainsParametersWithUndeclaredUnits(true);
5780       fud->setCanIgnoreUndeclaredUnits(false);
5781     }
5782   }
5783 
5784   fud->setUnitDefinition(ud);
5785 }
5786 /** @endcond */
5787 
5788 
5789 /** @cond doxygenLibsbmlInternal */
5790 UnitDefinition *
getSubstanceUD()5791 Model::getSubstanceUD()
5792 {
5793   UnitDefinition* ud;
5794   try
5795   {
5796     ud = new UnitDefinition(getSBMLNamespaces());
5797   }
5798   catch ( ... )
5799   {
5800     ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
5801       SBMLDocument::getDefaultVersion());
5802   }
5803 
5804   // units will be mole unless substance has been overridden
5805   if (getUnitDefinition("substance") != NULL)
5806   {
5807     for (unsigned int n = 0; n < getUnitDefinition("substance")->getNumUnits(); n++)
5808     {
5809       Unit* uFromModel = getUnitDefinition("substance")->getUnit(n);
5810       if (uFromModel  != NULL)
5811       {
5812         ud->addUnit(uFromModel);
5813       }
5814     }
5815   }
5816   else
5817   {
5818     Unit* u = ud->createUnit();
5819     u->setKind(UNIT_KIND_MOLE);
5820     u->initDefaults();
5821   }
5822 
5823   return ud;
5824 }
5825 /** @endcond */
5826 
5827 
5828 /** @cond doxygenLibsbmlInternal */
5829 UnitDefinition *
getL3SubstanceUD()5830 Model::getL3SubstanceUD()
5831 {
5832   UnitDefinition* ud;
5833   try
5834   {
5835     ud = new UnitDefinition(getSBMLNamespaces());
5836   }
5837   catch ( ... )
5838   {
5839     ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
5840       SBMLDocument::getDefaultVersion());
5841   }
5842 
5843   /* in L3 the units will be possibly not declared at all !
5844    */
5845   std::string substanceUnits = getSubstanceUnits();
5846   if (UnitKind_isValidUnitKindString(substanceUnits.c_str(),
5847                                      getLevel(), getVersion()))
5848   {
5849     Unit* u = ud->createUnit();
5850     u->setKind(UnitKind_forName(substanceUnits.c_str()));
5851     u->initDefaults();
5852   }
5853   else if (getUnitDefinition(substanceUnits) != NULL)
5854   {
5855     for (unsigned int n = 0; n < getUnitDefinition(substanceUnits)->getNumUnits(); n++)
5856     {
5857       Unit* uFromModel = getUnitDefinition(substanceUnits)->getUnit(n);
5858       if (uFromModel  != NULL)
5859       {
5860         ud->addUnit(uFromModel);
5861       }
5862     }
5863   }
5864 
5865   return ud;
5866 }
5867 /** @endcond */
5868 
5869 
5870 /** @cond doxygenLibsbmlInternal */
5871 void
createTimeUnitsData()5872 Model::createTimeUnitsData()
5873 {
5874   UnitDefinition *ud = NULL;
5875   FormulaUnitsData *fud = createFormulaUnitsData("time", SBML_MODEL);
5876 
5877   //fud->setUnitReferenceId("time");
5878   //fud->setComponentTypecode(SBML_MODEL);
5879 
5880   if (getLevel() < 3)
5881   {
5882     ud = getTimeUD();
5883   }
5884   else
5885   {
5886     ud = getL3TimeUD();
5887 
5888     if (ud->getNumUnits() == 0)
5889     {
5890       fud->setContainsParametersWithUndeclaredUnits(true);
5891       fud->setCanIgnoreUndeclaredUnits(false);
5892     }
5893   }
5894 
5895   fud->setUnitDefinition(ud);
5896 }
5897 /** @endcond */
5898 
5899 
5900 /** @cond doxygenLibsbmlInternal */
5901 UnitDefinition *
getTimeUD()5902 Model::getTimeUD()
5903 {
5904   UnitDefinition* ud;
5905   try
5906   {
5907     ud = new UnitDefinition(getSBMLNamespaces());
5908   }
5909   catch ( ... )
5910   {
5911     ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
5912       SBMLDocument::getDefaultVersion());
5913   }
5914 
5915   // units are second unless time has been overridden
5916   if (getUnitDefinition("time") != NULL)
5917   {
5918     for (unsigned int n = 0; n < getUnitDefinition("time")->getNumUnits(); n++)
5919     {
5920       Unit* uFromModel = getUnitDefinition("time")->getUnit(n);
5921       if (uFromModel  != NULL)
5922       {
5923         ud->addUnit(uFromModel);
5924       }
5925     }
5926   }
5927   else
5928   {
5929     Unit* u = ud->createUnit();
5930     u->setKind(UNIT_KIND_SECOND);
5931     u->initDefaults();
5932   }
5933 
5934   return ud;
5935 }
5936 /** @endcond */
5937 
5938 
5939 /** @cond doxygenLibsbmlInternal */
5940 UnitDefinition *
getL3TimeUD()5941 Model::getL3TimeUD()
5942 {
5943   UnitDefinition* ud;
5944   try
5945   {
5946     ud = new UnitDefinition(getSBMLNamespaces());
5947   }
5948   catch ( ... )
5949   {
5950     ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
5951       SBMLDocument::getDefaultVersion());
5952   }
5953 
5954   /* in L3 the units will be possibly not declared at all !
5955    */
5956   std::string timeUnits = getTimeUnits();
5957   if (UnitKind_isValidUnitKindString(timeUnits.c_str(),
5958                                      getLevel(), getVersion()))
5959   {
5960     Unit* u = ud->createUnit();
5961     u->setKind(UnitKind_forName(timeUnits.c_str()));
5962     u->initDefaults();
5963   }
5964   else if (getUnitDefinition(timeUnits) != NULL)
5965   {
5966     for (unsigned int n = 0; n < getUnitDefinition(timeUnits)->getNumUnits(); n++)
5967     {
5968       Unit* uFromModel = getUnitDefinition(timeUnits)->getUnit(n);
5969       if (uFromModel  != NULL)
5970       {
5971         ud->addUnit(uFromModel);
5972       }
5973     }
5974   }
5975 
5976   return ud;
5977 }
5978 /** @endcond */
5979 
5980 
5981 /** @cond doxygenLibsbmlInternal */
5982 void
createVolumeUnitsData()5983 Model::createVolumeUnitsData()
5984 {
5985   UnitDefinition *ud = NULL;
5986   FormulaUnitsData *fud = createFormulaUnitsData("volume", SBML_MODEL);
5987 
5988   //fud->setUnitReferenceId("volume");
5989   //fud->setComponentTypecode(SBML_MODEL);
5990 
5991   if (getLevel() < 3)
5992   {
5993     ud = getVolumeUD();
5994   }
5995   else
5996   {
5997     ud = getL3VolumeUD();
5998 
5999     if (ud->getNumUnits() == 0)
6000     {
6001       fud->setContainsParametersWithUndeclaredUnits(true);
6002       fud->setCanIgnoreUndeclaredUnits(false);
6003     }
6004   }
6005 
6006   fud->setUnitDefinition(ud);
6007 }
6008 /** @endcond */
6009 
6010 
6011 /** @cond doxygenLibsbmlInternal */
6012 UnitDefinition *
getVolumeUD()6013 Model::getVolumeUD()
6014 {
6015   UnitDefinition* ud;
6016   try
6017   {
6018     ud = new UnitDefinition(getSBMLNamespaces());
6019   }
6020   catch ( ... )
6021   {
6022     ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6023       SBMLDocument::getDefaultVersion());
6024   }
6025 
6026   // units will be litre unless volume has been overridden
6027   if (getUnitDefinition("volume") != NULL)
6028   {
6029     for (unsigned int n = 0; n < getUnitDefinition("volume")->getNumUnits(); n++)
6030     {
6031       Unit* uFromModel = getUnitDefinition("volume")->getUnit(n);
6032       if (uFromModel  != NULL)
6033       {
6034         ud->addUnit(uFromModel);
6035       }
6036     }
6037   }
6038   else
6039   {
6040     Unit* u = ud->createUnit();
6041     u->setKind(UNIT_KIND_LITRE);
6042     u->initDefaults();
6043   }
6044 
6045   return ud;
6046 }
6047 /** @endcond */
6048 
6049 
6050 /** @cond doxygenLibsbmlInternal */
6051 UnitDefinition *
getL3VolumeUD()6052 Model::getL3VolumeUD()
6053 {
6054   UnitDefinition* ud;
6055   try
6056   {
6057     ud = new UnitDefinition(getSBMLNamespaces());
6058   }
6059   catch ( ... )
6060   {
6061     ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6062       SBMLDocument::getDefaultVersion());
6063   }
6064 
6065   /* in L3 the units will be possibly not declared at all !
6066    */
6067   std::string volumeUnits = getVolumeUnits();
6068   if (UnitKind_isValidUnitKindString(volumeUnits.c_str(),
6069                                      getLevel(), getVersion()))
6070   {
6071     Unit* u = ud->createUnit();
6072     u->setKind(UnitKind_forName(volumeUnits.c_str()));
6073     u->initDefaults();
6074   }
6075   else if (getUnitDefinition(volumeUnits) != NULL)
6076   {
6077     for (unsigned int n = 0; n < getUnitDefinition(volumeUnits)->getNumUnits(); n++)
6078     {
6079       Unit* uFromModel = getUnitDefinition(volumeUnits)->getUnit(n);
6080       if (uFromModel  != NULL)
6081       {
6082         ud->addUnit(uFromModel);
6083       }
6084     }
6085   }
6086 
6087   return ud;
6088 }
6089 /** @endcond */
6090 
6091 
6092 /** @cond doxygenLibsbmlInternal */
6093 void
createAreaUnitsData()6094 Model::createAreaUnitsData()
6095 {
6096   UnitDefinition *ud = NULL;
6097   FormulaUnitsData *fud = createFormulaUnitsData("area", SBML_MODEL);
6098 
6099   //fud->setUnitReferenceId("area");
6100   //fud->setComponentTypecode(SBML_MODEL);
6101 
6102   if (getLevel() < 3)
6103   {
6104     ud = getAreaUD();
6105   }
6106   else
6107   {
6108     ud = getL3AreaUD();
6109 
6110     if (ud->getNumUnits() == 0)
6111     {
6112       fud->setContainsParametersWithUndeclaredUnits(true);
6113       fud->setCanIgnoreUndeclaredUnits(false);
6114     }
6115   }
6116 
6117   fud->setUnitDefinition(ud);
6118 }
6119 /** @endcond */
6120 
6121 
6122 /** @cond doxygenLibsbmlInternal */
6123 UnitDefinition *
getAreaUD()6124 Model::getAreaUD()
6125 {
6126   UnitDefinition* ud;
6127   try
6128   {
6129     ud = new UnitDefinition(getSBMLNamespaces());
6130   }
6131   catch ( ... )
6132   {
6133     ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6134       SBMLDocument::getDefaultVersion());
6135   }
6136 
6137   // units will be metre squared unless area has been overridden
6138   if (getUnitDefinition("area") != NULL)
6139   {
6140     for (unsigned int n = 0; n < getUnitDefinition("area")->getNumUnits(); n++)
6141     {
6142       Unit* uFromModel = getUnitDefinition("area")->getUnit(n);
6143       if (uFromModel  != NULL)
6144       {
6145         ud->addUnit(uFromModel);
6146       }
6147     }
6148   }
6149   else
6150   {
6151     Unit* u = ud->createUnit();
6152     u->setKind(UNIT_KIND_METRE);
6153     u->initDefaults();
6154     u->setExponent(2);
6155   }
6156 
6157   return ud;
6158 }
6159 /** @endcond */
6160 
6161 
6162 /** @cond doxygenLibsbmlInternal */
6163 UnitDefinition *
getL3AreaUD()6164 Model::getL3AreaUD()
6165 {
6166   UnitDefinition* ud;
6167   try
6168   {
6169     ud = new UnitDefinition(getSBMLNamespaces());
6170   }
6171   catch ( ... )
6172   {
6173     ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6174       SBMLDocument::getDefaultVersion());
6175   }
6176 
6177 
6178   /* in L3 the units will be possibly not declared at all !
6179    */
6180   std::string areaUnits = getAreaUnits();
6181   if (UnitKind_isValidUnitKindString(areaUnits.c_str(),
6182                                      getLevel(), getVersion()))
6183   {
6184     Unit* u = ud->createUnit();
6185     u->setKind(UnitKind_forName(areaUnits.c_str()));
6186     u->initDefaults();
6187   }
6188   else if (getUnitDefinition(areaUnits) != NULL)
6189   {
6190     for (unsigned int n = 0; n < getUnitDefinition(areaUnits)->getNumUnits(); n++)
6191     {
6192       Unit* uFromModel = getUnitDefinition(areaUnits)->getUnit(n);
6193       if (uFromModel  != NULL)
6194       {
6195         ud->addUnit(uFromModel);
6196       }
6197     }
6198   }
6199 
6200   return ud;
6201 }
6202 /** @endcond */
6203 
6204 
6205 /** @cond doxygenLibsbmlInternal */
6206 void
createLengthUnitsData()6207 Model::createLengthUnitsData()
6208 {
6209   UnitDefinition *ud = NULL;
6210   FormulaUnitsData *fud = createFormulaUnitsData("length", SBML_MODEL);
6211 
6212   //fud->setUnitReferenceId("length");
6213   //fud->setComponentTypecode(SBML_MODEL);
6214 
6215   if (getLevel() < 3)
6216   {
6217     ud = getLengthUD();
6218   }
6219   else
6220   {
6221     ud = getL3LengthUD();
6222 
6223     if (ud->getNumUnits() == 0)
6224     {
6225       fud->setContainsParametersWithUndeclaredUnits(true);
6226       fud->setCanIgnoreUndeclaredUnits(false);
6227     }
6228   }
6229 
6230   fud->setUnitDefinition(ud);
6231 }
6232 /** @endcond */
6233 
6234 
6235 /** @cond doxygenLibsbmlInternal */
6236 UnitDefinition *
getLengthUD()6237 Model::getLengthUD()
6238 {
6239   UnitDefinition* ud;
6240   try
6241   {
6242     ud = new UnitDefinition(getSBMLNamespaces());
6243   }
6244   catch ( ... )
6245   {
6246     ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6247       SBMLDocument::getDefaultVersion());
6248   }
6249 
6250   // units will be metre unless length has been overridden
6251   if (getUnitDefinition("length") != NULL)
6252   {
6253     for (unsigned int n = 0; n < getUnitDefinition("length")->getNumUnits(); n++)
6254     {
6255       Unit* uFromModel = getUnitDefinition("length")->getUnit(n);
6256       if (uFromModel  != NULL)
6257       {
6258         ud->addUnit(uFromModel);
6259       }
6260     }
6261   }
6262   else
6263   {
6264     Unit* u = ud->createUnit();
6265     u->setKind(UNIT_KIND_METRE);
6266     u->initDefaults();
6267   }
6268 
6269   return ud;
6270 }
6271 /** @endcond */
6272 
6273 
6274 /** @cond doxygenLibsbmlInternal */
6275 UnitDefinition *
getL3LengthUD()6276 Model::getL3LengthUD()
6277 {
6278   UnitDefinition* ud;
6279   try
6280   {
6281     ud = new UnitDefinition(getSBMLNamespaces());
6282   }
6283   catch ( ... )
6284   {
6285     ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6286       SBMLDocument::getDefaultVersion());
6287   }
6288 
6289   /* in L3 the units will be possibly not declared at all !
6290    */
6291   std::string lengthUnits = getLengthUnits();
6292   if (UnitKind_isValidUnitKindString(lengthUnits.c_str(),
6293                                      getLevel(), getVersion()))
6294   {
6295     Unit* u = ud->createUnit();
6296     u->setKind(UnitKind_forName(lengthUnits.c_str()));
6297     u->initDefaults();
6298   }
6299   else if (getUnitDefinition(lengthUnits) != NULL)
6300   {
6301     for (unsigned int n = 0; n < getUnitDefinition(lengthUnits)->getNumUnits(); n++)
6302     {
6303       Unit* uFromModel = getUnitDefinition(lengthUnits)->getUnit(n);
6304       if (uFromModel  != NULL)
6305       {
6306         ud->addUnit(uFromModel);
6307       }
6308     }
6309   }
6310 
6311   return ud;
6312 }
6313 /** @endcond */
6314 
6315 
6316 /** @cond doxygenLibsbmlInternal */
6317 void
createExtentUnitsData()6318 Model::createExtentUnitsData()
6319 {
6320   UnitDefinition *ud = NULL;
6321   FormulaUnitsData *fud = createFormulaUnitsData("extent", SBML_MODEL);
6322 
6323   //fud->setUnitReferenceId("extent");
6324   //fud->setComponentTypecode(SBML_MODEL);
6325 
6326   if (getLevel() < 3)
6327   {
6328     // create a unitDefinition with no children
6329     try
6330     {
6331       ud = new UnitDefinition(getSBMLNamespaces());
6332     }
6333     catch ( ... )
6334     {
6335       ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6336         SBMLDocument::getDefaultVersion());
6337     }
6338     fud->setContainsParametersWithUndeclaredUnits(true);
6339     fud->setCanIgnoreUndeclaredUnits(false);
6340 
6341   }
6342   else
6343   {
6344     ud = getL3ExtentUD();
6345 
6346     if (ud->getNumUnits() == 0)
6347     {
6348       fud->setContainsParametersWithUndeclaredUnits(true);
6349       fud->setCanIgnoreUndeclaredUnits(false);
6350     }
6351   }
6352 
6353   fud->setUnitDefinition(ud);
6354 }
6355 /** @endcond */
6356 
6357 
6358 /** @cond doxygenLibsbmlInternal */
6359 UnitDefinition *
getL3ExtentUD()6360 Model::getL3ExtentUD()
6361 {
6362   UnitDefinition* ud;
6363   try
6364   {
6365     ud = new UnitDefinition(getSBMLNamespaces());
6366   }
6367   catch ( ... )
6368   {
6369     ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6370       SBMLDocument::getDefaultVersion());
6371   }
6372 
6373   /* in L3 the units will be possibly not declared at all !
6374    */
6375   std::string extentUnits = getExtentUnits();
6376   if (UnitKind_isValidUnitKindString(extentUnits.c_str(),
6377                                      getLevel(), getVersion()))
6378   {
6379     Unit* u = ud->createUnit();
6380     u->setKind(UnitKind_forName(extentUnits.c_str()));
6381     u->initDefaults();
6382   }
6383   else if (getUnitDefinition(extentUnits) != NULL)
6384   {
6385     for (unsigned int n = 0; n < getUnitDefinition(extentUnits)->getNumUnits(); n++)
6386     {
6387       // need to prevent level/version mismatches
6388       // ud will have default level and veersion
6389       Unit* uFromModel = getUnitDefinition(extentUnits)->getUnit(n);
6390       if (uFromModel  != NULL)
6391       {
6392         Unit* u = ud->createUnit();
6393         u->setKind(uFromModel->getKind());
6394         u->setExponent(uFromModel->getExponent());
6395         u->setScale(uFromModel->getScale());
6396         u->setMultiplier(uFromModel->getMultiplier());
6397       }
6398     }
6399   }
6400 
6401   return ud;
6402 }
6403 /** @endcond */
6404 
6405 /** @cond doxygenLibsbmlInternal */
6406 void
createSubstancePerTimeUnitsData()6407 Model::createSubstancePerTimeUnitsData()
6408 {
6409   UnitDefinition *ud = NULL;
6410   FormulaUnitsData *fud = createFormulaUnitsData("subs_per_time", SBML_UNKNOWN);
6411 
6412   //fud->setUnitReferenceId("subs_per_time");
6413   //fud->setComponentTypecode(SBML_UNKNOWN);
6414 
6415   if (getLevel() < 3)
6416   {
6417     ud = getSubstancePerTimeUD();
6418   }
6419   else
6420   {
6421     //need to pass the formulaUnitsData object
6422     // as we need to log whether extent or time has undeclared
6423     // one might be
6424     ud = getL3SubstancePerTimeUD(fud);
6425 
6426     if (ud->getNumUnits() == 0)
6427     {
6428       fud->setContainsParametersWithUndeclaredUnits(true);
6429       fud->setCanIgnoreUndeclaredUnits(false);
6430     }
6431   }
6432 
6433   fud->setUnitDefinition(ud);
6434 }
6435 /** @endcond */
6436 
6437 
6438 /** @cond doxygenLibsbmlInternal */
6439 UnitDefinition *
getSubstancePerTimeUD()6440 Model::getSubstancePerTimeUD()
6441 {
6442   UnitDefinition *ud = getFormulaUnitsData("substance", SBML_MODEL)
6443                                         ->getUnitDefinition()->clone();
6444 
6445   UnitDefinition * temp = getFormulaUnitsData("time", SBML_MODEL)
6446                                                       ->getUnitDefinition();
6447 
6448   for (unsigned int n = 0; n < temp->getNumUnits(); n++)
6449   {
6450     Unit * u = temp->getUnit(n)->clone();
6451     u->setExponent(u->getExponent() * -1);
6452     ud->addUnit(u);
6453     delete u;
6454   }
6455 
6456   return ud;
6457 }
6458 /** @endcond */
6459 
6460 
6461 /** @cond doxygenLibsbmlInternal */
6462 UnitDefinition *
getL3SubstancePerTimeUD(FormulaUnitsData * fud)6463 Model::getL3SubstancePerTimeUD(FormulaUnitsData * fud)
6464 {
6465   FormulaUnitsData * tempFUD = getFormulaUnitsData("extent", SBML_MODEL);
6466 
6467   // extent is undeclared
6468   if (tempFUD->getContainsUndeclaredUnits() == true)
6469   {
6470       fud->setContainsParametersWithUndeclaredUnits(true);
6471       fud->setCanIgnoreUndeclaredUnits(false);
6472   }
6473 
6474 
6475   UnitDefinition *ud = tempFUD->getUnitDefinition()->clone();
6476 
6477   tempFUD = getFormulaUnitsData("time", SBML_MODEL);
6478 
6479   // time is undeclared
6480   if (tempFUD->getContainsUndeclaredUnits() == true)
6481   {
6482       fud->setContainsParametersWithUndeclaredUnits(true);
6483       fud->setCanIgnoreUndeclaredUnits(false);
6484   }
6485 
6486   UnitDefinition * temp = tempFUD->getUnitDefinition();
6487 
6488   for (unsigned int n = 0; n < temp->getNumUnits(); n++)
6489   {
6490     Unit * u = temp->getUnit(n)->clone();
6491     u->setExponent(u->getExponent() * -1);
6492     ud->addUnit(u);
6493     delete u;
6494   }
6495 
6496   return ud;
6497 }
6498 /** @endcond */
6499 
6500 /** @cond doxygenLibsbmlInternal */
6501 void
createCompartmentUnitsData()6502 Model::createCompartmentUnitsData()
6503 {
6504   UnitDefinition *ud = NULL;
6505   FormulaUnitsData *fud = NULL;
6506   UnitFormulaFormatter unitFormatter = this;
6507 
6508   for (unsigned int n = 0; n < getNumCompartments(); n++)
6509   {
6510     Compartment* c = getCompartment(n);
6511 
6512     fud = createFormulaUnitsData(c->getId(), SBML_COMPARTMENT);
6513     //fud->setUnitReferenceId(c->getId());
6514     //fud->setComponentTypecode(SBML_COMPARTMENT);
6515 
6516     ud = unitFormatter.getUnitDefinitionFromCompartment(c);
6517 
6518     if (ud->getNumUnits() == 0)
6519     {
6520       fud->setContainsParametersWithUndeclaredUnits(true);
6521       fud->setCanIgnoreUndeclaredUnits(false);
6522     }
6523 
6524     fud->setUnitDefinition(ud);
6525     populatePerTimeUnitDefinition(fud);
6526   }
6527 }
6528 /** @endcond */
6529 
6530 
6531 /** @cond doxygenLibsbmlInternal */
6532 void
createSpeciesUnitsData()6533 Model::createSpeciesUnitsData()
6534 {
6535   UnitDefinition *ud = NULL;
6536   FormulaUnitsData *fud = NULL;
6537   UnitFormulaFormatter unitFormatter = this;
6538 
6539   for (unsigned int n=0; n < getNumSpecies(); n++)
6540   {
6541     Species* s = getSpecies(n);
6542 
6543     fud = createFormulaUnitsData(s->getId(), SBML_SPECIES);
6544     //fud->setUnitReferenceId(s->getId());
6545     //fud->setComponentTypecode(SBML_SPECIES);
6546 
6547     /* TO DO - sort out getUDFromSpecies
6548      */
6549     if (getCompartment(s->getCompartment()) == NULL)
6550     {
6551       try
6552       {
6553         ud = new UnitDefinition(getSBMLNamespaces());
6554       }
6555       catch ( ... )
6556       {
6557         ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6558           SBMLDocument::getDefaultVersion());
6559       }
6560     }
6561     else
6562     {
6563       ud = unitFormatter.getUnitDefinitionFromSpecies(s);
6564     }
6565 
6566     if (ud->getNumUnits() == 0)
6567     {
6568       fud->setContainsParametersWithUndeclaredUnits(true);
6569       fud->setCanIgnoreUndeclaredUnits(false);
6570     }
6571 
6572     fud->setUnitDefinition(ud);
6573     populatePerTimeUnitDefinition(fud);
6574   }
6575 }
6576 /** @endcond */
6577 
6578 
6579 /** @cond doxygenLibsbmlInternal */
6580 void
createL3SpeciesUnitsData()6581 Model::createL3SpeciesUnitsData()
6582 {
6583   UnitDefinition *ud = NULL;
6584   FormulaUnitsData *fud = NULL;
6585   UnitFormulaFormatter unitFormatter = this;
6586 
6587   for (unsigned int n=0; n < getNumSpecies(); n++)
6588   {
6589     Species* s = getSpecies(n);
6590 
6591     /* create the substance unit */
6592     unitFormatter.resetFlags();
6593 
6594     fud = createFormulaUnitsData(s->getId() + "subs", SBML_SPECIES);
6595     //fud->setUnitReferenceId(s->getId()+"subs");
6596     //fud->setComponentTypecode(SBML_SPECIES);
6597 
6598     ud = unitFormatter.getSpeciesSubstanceUnitDefinition(s);
6599 
6600     if (ud->getNumUnits() == 0)
6601     {
6602       fud->setContainsParametersWithUndeclaredUnits(true);
6603       fud->setCanIgnoreUndeclaredUnits(false);
6604     }
6605     else
6606     {
6607       fud->setContainsParametersWithUndeclaredUnits
6608                               (unitFormatter.getContainsUndeclaredUnits());
6609       fud->setCanIgnoreUndeclaredUnits
6610                                 (unitFormatter.canIgnoreUndeclaredUnits());
6611     }
6612 
6613     fud->setSpeciesSubstanceUnitDefinition(ud);
6614 
6615     /* create the extent unit */
6616     unitFormatter.resetFlags();
6617 
6618     fud = createFormulaUnitsData(s->getId() + "extent", SBML_SPECIES);
6619     //fud->setUnitReferenceId(s->getId()+"extent");
6620     //fud->setComponentTypecode(SBML_SPECIES);
6621 
6622     ud = unitFormatter.getSpeciesExtentUnitDefinition(s);
6623 
6624     if (ud->getNumUnits() == 0)
6625     {
6626       fud->setContainsParametersWithUndeclaredUnits(true);
6627       fud->setCanIgnoreUndeclaredUnits(false);
6628     }
6629     else
6630     {
6631       fud->setContainsParametersWithUndeclaredUnits
6632                               (unitFormatter.getContainsUndeclaredUnits());
6633       fud->setCanIgnoreUndeclaredUnits
6634                                 (unitFormatter.canIgnoreUndeclaredUnits());
6635     }
6636 
6637     fud->setSpeciesExtentUnitDefinition(ud);
6638   }
6639 }
6640 /** @endcond */
6641 
6642 
6643 /** @cond doxygenLibsbmlInternal */
6644 void
createParameterUnitsData()6645 Model::createParameterUnitsData()
6646 {
6647   UnitDefinition *ud = NULL;
6648   FormulaUnitsData *fud = NULL;
6649   UnitFormulaFormatter unitFormatter = this;
6650 
6651   for (unsigned int n=0; n < getNumParameters(); n++)
6652   {
6653     Parameter* p = getParameter(n);
6654 
6655     unitFormatter.resetFlags();
6656 
6657     fud = createFormulaUnitsData(p->getId(), SBML_PARAMETER);
6658     //fud->setUnitReferenceId(p->getId());
6659     //fud->setComponentTypecode(SBML_PARAMETER);
6660 
6661     unitFormatter.resetFlags();
6662     ud = unitFormatter.getUnitDefinitionFromParameter(p);
6663 
6664     fud->setUnitDefinition(ud);
6665     fud->setContainsParametersWithUndeclaredUnits
6666                                 (unitFormatter.getContainsUndeclaredUnits());
6667     fud->setCanIgnoreUndeclaredUnits
6668                                   (unitFormatter.canIgnoreUndeclaredUnits());
6669 
6670     populatePerTimeUnitDefinition(fud);
6671   }
6672 }
6673 /** @endcond */
6674 
6675 
6676 /** @cond doxygenLibsbmlInternal */
6677 void
createUnitsDataFromMath(UnitFormulaFormatter * unitFormatter,FormulaUnitsData * fud,const ASTNode * math)6678 Model::createUnitsDataFromMath(UnitFormulaFormatter * unitFormatter,
6679                                FormulaUnitsData *fud, const ASTNode * math)
6680 {
6681   UnitDefinition * ud = NULL;
6682 
6683   if (math != NULL)
6684   {
6685     unitFormatter->resetFlags();
6686     ud = unitFormatter->getUnitDefinition(math);
6687 
6688     fud->setContainsParametersWithUndeclaredUnits
6689                               (unitFormatter->getContainsUndeclaredUnits());
6690     fud->setCanIgnoreUndeclaredUnits
6691                                 (unitFormatter->canIgnoreUndeclaredUnits());
6692     fud->setContainsInconsistency(unitFormatter->getContainsInconsistentUnits());
6693   }
6694 
6695   fud->setUnitDefinition(ud);
6696 }
6697 /** @endcond */
6698 
6699 
6700 /** @cond doxygenLibsbmlInternal */
6701 void
createInitialAssignmentUnitsData(UnitFormulaFormatter * unitFormatter)6702 Model::createInitialAssignmentUnitsData(UnitFormulaFormatter * unitFormatter)
6703 {
6704   FormulaUnitsData *fud = NULL;
6705 
6706   for (unsigned int n=0; n < getNumInitialAssignments(); n++)
6707   {
6708     InitialAssignment* ia = getInitialAssignment(n);
6709 
6710     fud = createFormulaUnitsData(ia->getSymbol(), SBML_INITIAL_ASSIGNMENT);
6711     //fud->setUnitReferenceId(ia->getSymbol());
6712     //fud->setComponentTypecode(SBML_INITIAL_ASSIGNMENT);
6713 
6714     createUnitsDataFromMath(unitFormatter, fud, ia->getMath());
6715   }
6716 }
6717 /** @endcond */
6718 
6719 
6720 /** @cond doxygenLibsbmlInternal */
6721 void
createConstraintUnitsData(UnitFormulaFormatter * unitFormatter)6722 Model::createConstraintUnitsData(UnitFormulaFormatter * unitFormatter)
6723 {
6724   FormulaUnitsData *fud = NULL;
6725   char newId[15];
6726   std::string newID;
6727 
6728   for (unsigned int n = 0; n < getNumConstraints(); n++)
6729   {
6730     Constraint* c = getConstraint(n);
6731     sprintf(newId, "constraint_%u", n);
6732     newID.assign(newId);
6733     c->setInternalId(newID);
6734 
6735     fud = createFormulaUnitsData(newID, SBML_CONSTRAINT);
6736     //fud->setUnitReferenceId(newID);
6737     //fud->setComponentTypecode(SBML_CONSTRAINT);
6738 
6739     createUnitsDataFromMath(unitFormatter, fud, c->getMath());
6740   }
6741 }
6742 /** @endcond */
6743 
6744 /** @cond doxygenLibsbmlInternal */
6745 void
createRuleUnitsData(UnitFormulaFormatter * unitFormatter)6746 Model::createRuleUnitsData(UnitFormulaFormatter * unitFormatter)
6747 {
6748   FormulaUnitsData *fud = NULL;
6749   char newId[12];
6750   std::string newID;
6751   unsigned int countAlg = 0;
6752 
6753   for (unsigned int n=0; n < getNumRules(); n++)
6754   {
6755     Rule* r = getRule(n);
6756 
6757     //fud = createFormulaUnitsData();
6758     // need to create an id for an algebbraic rule
6759     if (r->getTypeCode() == SBML_ALGEBRAIC_RULE)
6760     {
6761       sprintf(newId, "alg_rule_%u", countAlg);
6762       newID.assign(newId);
6763       r->setInternalId(newID);
6764       static_cast <AlgebraicRule *> (r)->setInternalIdOnly();
6765       countAlg++;
6766 
6767       fud = createFormulaUnitsData(newID, r->getTypeCode());
6768       //fud->setUnitReferenceId(newID);
6769     }
6770     else
6771     {
6772       fud = createFormulaUnitsData(r->getVariable(), r->getTypeCode());
6773       //fud->setUnitReferenceId(r->getVariable());
6774     }
6775     //fud->setComponentTypecode(r->getTypeCode());
6776 
6777     createUnitsDataFromMath(unitFormatter, fud, r->getMath());
6778   }
6779 }
6780 /** @endcond */
6781 
6782 
6783 /** @cond doxygenLibsbmlInternal */
6784 void
createReactionUnitsData(UnitFormulaFormatter * unitFormatter)6785 Model::createReactionUnitsData(UnitFormulaFormatter * unitFormatter)
6786 {
6787   UnitDefinition *ud = NULL;
6788   FormulaUnitsData *fud = NULL;
6789 
6790   for (unsigned int n=0; n < getNumReactions(); n++)
6791   {
6792     Reaction* react = getReaction(n);
6793 
6794     /* get units returned by kineticLaw formula */
6795     if (react->isSetKineticLaw())
6796     {
6797       fud = createFormulaUnitsData(react->getId(), SBML_KINETIC_LAW);
6798       //fud->setUnitReferenceId(react->getId());
6799 
6800       /* set the id of the kinetic law
6801        * normally a kinetic law doesnt have an id
6802        * but since it is an sbase object it can
6803        * so we set it to be the reaction id so
6804        * that searching the listFormulaUnitsData can find it
6805        */
6806       react->getKineticLaw()->setInternalId(react->getId());
6807 
6808       //fud->setComponentTypecode(SBML_KINETIC_LAW);
6809 
6810       // have to use the old way for now as unitFormatter needs to know
6811       // if we are in a reaction so it can access localParameters
6812       unitFormatter->resetFlags();
6813       if(react->getKineticLaw()->isSetMath())
6814       {
6815         ud = unitFormatter->getUnitDefinition
6816                                   (react->getKineticLaw()->getMath(), true, (int)n);
6817         fud->setContainsParametersWithUndeclaredUnits
6818                                  (unitFormatter->getContainsUndeclaredUnits());
6819         fud->setCanIgnoreUndeclaredUnits
6820                                    (unitFormatter->canIgnoreUndeclaredUnits());
6821       }
6822 
6823       fud->setUnitDefinition(ud);
6824 
6825       createLocalParameterUnitsData(react->getKineticLaw(), unitFormatter);
6826     }
6827 
6828     ///* get units returned by any stoichiometryMath set */
6829     for (unsigned int j = 0; j < react->getNumReactants(); j++)
6830     {
6831       SpeciesReference* sr = react->getReactant(j);
6832       createSpeciesReferenceUnitsData(sr, unitFormatter);
6833     }
6834 
6835     for (unsigned int j = 0; j < react->getNumProducts(); j++)
6836     {
6837       SpeciesReference* sr = react->getProduct(j);
6838       createSpeciesReferenceUnitsData(sr, unitFormatter);
6839     }
6840   }
6841 
6842 }
6843 /** @endcond */
6844 
6845 
6846 /** @cond doxygenLibsbmlInternal */
6847 void
createLocalParameterUnitsData(KineticLaw * kl,UnitFormulaFormatter *)6848 Model::createLocalParameterUnitsData(KineticLaw * kl,
6849                                      UnitFormulaFormatter*)
6850 {
6851   UnitDefinition *ud = NULL;
6852   FormulaUnitsData *fud = NULL;
6853 
6854   for (unsigned int n=0; n < kl->getNumParameters(); n++)
6855   {
6856     Parameter * lp = kl->getParameter(n);
6857     std::string lpId = lp->getId() + '_' + kl->getInternalId();
6858 
6859     fud = createFormulaUnitsData(lpId, SBML_LOCAL_PARAMETER);
6860 
6861     //fud->setUnitReferenceId(lpId);
6862     //fud->setComponentTypecode(SBML_LOCAL_PARAMETER);
6863 
6864     std::string units = lp->getUnits();
6865     if (units.empty() == false)
6866     {
6867       char * charUnits = safe_strdup(units.c_str());
6868       fud->setContainsParametersWithUndeclaredUnits(false);
6869 
6870       if (UnitKind_isValidUnitKindString(units.c_str(),
6871                             getLevel(), getVersion()))
6872       {
6873         try
6874         {
6875           ud = new UnitDefinition(getSBMLNamespaces());
6876         }
6877         catch ( ... )
6878         {
6879           ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6880             SBMLDocument::getDefaultVersion());
6881         }
6882         Unit * unit = ud->createUnit();
6883         unit->setKind(UnitKind_forName(charUnits));
6884         unit->initDefaults();
6885       }
6886       else
6887       {
6888         /* must be a unit definition */
6889         UnitDefinition * existingUD = getUnitDefinition(units);
6890         if (existingUD != NULL)
6891         {
6892           ud = new UnitDefinition(*(getUnitDefinition(units)));
6893           ud->setId("");
6894         }
6895         else
6896         {
6897           try
6898           {
6899             ud = new UnitDefinition(getSBMLNamespaces());
6900           }
6901           catch ( ... )
6902           {
6903             ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6904               SBMLDocument::getDefaultVersion());
6905           }
6906           fud->setContainsParametersWithUndeclaredUnits(true);
6907         }
6908       }
6909 
6910       safe_free(charUnits);
6911       fud->setUnitDefinition(ud);
6912       fud->setCanIgnoreUndeclaredUnits(false);
6913     }
6914     else
6915     {
6916       // here we have none but for consistency return a unitDefinition
6917       // with no units
6918       try
6919       {
6920         ud = new UnitDefinition(getSBMLNamespaces());
6921       }
6922       catch ( ... )
6923       {
6924         ud = new UnitDefinition(SBMLDocument::getDefaultLevel(),
6925           SBMLDocument::getDefaultVersion());
6926       }
6927       fud->setUnitDefinition(ud);
6928       fud->setContainsParametersWithUndeclaredUnits(true);
6929       fud->setCanIgnoreUndeclaredUnits(false);
6930     }
6931   }
6932 }
6933 /** @endcond */
6934 
6935 
6936 /** @cond doxygenLibsbmlInternal */
6937 void
createEventUnitsData(UnitFormulaFormatter * unitFormatter)6938 Model::createEventUnitsData(UnitFormulaFormatter * unitFormatter)
6939 {
6940   char newId[12];
6941   std::string newID;
6942   unsigned int countEvents = 0;
6943 
6944   for (unsigned int n=0; n < getNumEvents(); n++)
6945   {
6946     Event* e = getEvent(n);
6947 
6948     sprintf(newId, "event_%u", countEvents);
6949     newID.assign(newId);
6950     e->setInternalId(newID);
6951     countEvents++;
6952 
6953     /* dont need units returned by trigger formula -
6954      * should be boolean
6955      * but we might want to check they are defined
6956      */
6957     if (e->isSetTrigger())
6958     {
6959       createTriggerUnitsData(unitFormatter, e, newID);
6960     }
6961 
6962 
6963     /* get units returned by dely */
6964     if (e->isSetDelay())
6965     {
6966       createDelayUnitsData(unitFormatter, e, newID);
6967     }
6968 
6969     /* get units returned by priority */
6970     if (e->isSetPriority())
6971     {
6972       createPriorityUnitsData(unitFormatter, e->getPriority(), newID);
6973     }
6974 
6975     /* get units returned by any event assignments */
6976     for (unsigned int j = 0; j < e->getNumEventAssignments(); j++)
6977     {
6978       createEventAssignmentUnitsData(unitFormatter,
6979                                      e->getEventAssignment(j), newID);
6980     }
6981   }
6982 }
6983 /** @endcond */
6984 
6985 /** @cond doxygenLibsbmlInternal */
6986 void
createDelayUnitsData(UnitFormulaFormatter * unitFormatter,Event * e,const std::string & eventId)6987 Model::createDelayUnitsData(UnitFormulaFormatter* unitFormatter, Event * e,
6988                             const std::string& eventId)
6989 {
6990   UnitDefinition *ud = NULL;
6991   FormulaUnitsData *fud = createFormulaUnitsData(eventId, SBML_EVENT);
6992 
6993   Delay * d = e->getDelay();
6994 
6995   //fud->setUnitReferenceId(eventId);
6996   d->setInternalId(eventId);
6997 
6998   //fud->setComponentTypecode(SBML_EVENT);
6999 
7000   createUnitsDataFromMath(unitFormatter, fud, d->getMath());
7001 
7002   /* get event time definition */
7003   unitFormatter->resetFlags();
7004   ud = unitFormatter->getUnitDefinitionFromEventTime(e);
7005   if (ud->getNumUnits() == 0)
7006   {
7007     fud->setContainsParametersWithUndeclaredUnits(true);
7008     fud->setCanIgnoreUndeclaredUnits(false);
7009   }
7010   fud->setEventTimeUnitDefinition(ud);
7011 }
7012 /** @endcond */
7013 
7014 /** @cond doxygenLibsbmlInternal */
7015 void
createTriggerUnitsData(UnitFormulaFormatter * unitFormatter,Event * e,const std::string & eventId)7016 Model::createTriggerUnitsData(UnitFormulaFormatter* unitFormatter, Event * e,
7017   const std::string& eventId)
7018 {
7019   //UnitDefinition *ud = NULL;
7020   FormulaUnitsData *fud = createFormulaUnitsData(eventId, SBML_TRIGGER);
7021 
7022   Trigger * d = e->getTrigger();
7023 
7024   //fud->setUnitReferenceId(eventId);
7025   d->setInternalId(eventId);
7026 
7027   //fud->setComponentTypecode(SBML_TRIGGER);
7028 
7029   createUnitsDataFromMath(unitFormatter, fud, d->getMath());
7030 
7031   fud->setEventTimeUnitDefinition(NULL);
7032 }
7033 /** @endcond */
7034 /** @cond doxygenLibsbmlInternal */
7035 void
createPriorityUnitsData(UnitFormulaFormatter * unitFormatter,Priority * p,const std::string & eventId)7036 Model::createPriorityUnitsData(UnitFormulaFormatter* unitFormatter,
7037                                Priority * p, const std::string& eventId)
7038 {
7039   FormulaUnitsData *fud = createFormulaUnitsData(eventId, SBML_PRIORITY);
7040 
7041   //fud->setUnitReferenceId(eventId);
7042   p->setInternalId(eventId);
7043 
7044   //fud->setComponentTypecode(SBML_PRIORITY);
7045 
7046   createUnitsDataFromMath(unitFormatter, fud, p->getMath());
7047 }
7048 /** @endcond */
7049 
7050 /** @cond doxygenLibsbmlInternal */
7051 void
createEventAssignmentUnitsData(UnitFormulaFormatter * unitFormatter,EventAssignment * ea,const std::string & eventId)7052 Model::createEventAssignmentUnitsData(UnitFormulaFormatter* unitFormatter,
7053                             EventAssignment * ea, const std::string& eventId)
7054 {
7055   std::string eaId = ea->getVariable() + eventId;
7056   FormulaUnitsData *fud = createFormulaUnitsData(eaId, SBML_EVENT_ASSIGNMENT);
7057 
7058   //fud->setUnitReferenceId(eaId);
7059   //fud->setComponentTypecode(SBML_EVENT_ASSIGNMENT);
7060 
7061   createUnitsDataFromMath(unitFormatter, fud, ea->getMath());
7062 }
7063 /** @endcond */
7064 
7065 
7066 /** @cond doxygenLibsbmlInternal */
7067 /*
7068  * Adds a copy of the given FormulaUnitsData to this Model.
7069  */
7070 void
addFormulaUnitsData(const FormulaUnitsData * fud)7071 Model::addFormulaUnitsData (const FormulaUnitsData* fud)
7072 {
7073   if (mFormulaUnitsData == NULL)
7074   {
7075     mFormulaUnitsData = new List();
7076   }
7077 
7078   FormulaUnitsData *newFud = fud->clone();
7079   mFormulaUnitsData->add((void *)newFud);
7080   std::string id =  fud->getUnitReferenceId();
7081   int typecode = fud->getComponentTypecode();
7082 
7083   KeyValue key(id, typecode);
7084   mUnitsDataMap.insert(make_pair(key, newFud));
7085 }
7086 /** @endcond */
7087 
7088 
7089 /** @cond doxygenLibsbmlInternal */
7090 /**
7091   * Creates a new FormulaUnitsData inside this Model and returns it.
7092   */
7093 FormulaUnitsData*
createFormulaUnitsData()7094 Model::createFormulaUnitsData ()
7095 {
7096   FormulaUnitsData* fud = new FormulaUnitsData();
7097   if (mFormulaUnitsData == NULL)
7098   {
7099     mFormulaUnitsData = new List();
7100   }
7101   mFormulaUnitsData->add(fud);
7102 
7103   return fud;
7104 }
7105 /** @endcond */
7106 
7107 
7108 /** @cond doxygenLibsbmlInternal */
7109 /**
7110 * Creates a new FormulaUnitsData inside this Model and returns it.
7111 */
7112 FormulaUnitsData*
createFormulaUnitsData(const std::string & id,int typecode)7113 Model::createFormulaUnitsData(const std::string& id, int typecode)
7114 {
7115   FormulaUnitsData* fud = new FormulaUnitsData();
7116   if (mFormulaUnitsData == NULL)
7117   {
7118     mFormulaUnitsData = new List();
7119   }
7120   fud->setUnitReferenceId(id);
7121   fud->setComponentTypecode(typecode);
7122 
7123   KeyValue key(id, typecode);
7124   mUnitsDataMap.insert(make_pair(key, fud));
7125   mFormulaUnitsData->add(fud);
7126 
7127   return fud;
7128 }
7129 /** @endcond */
7130 
7131 /** @cond doxygenLibsbmlInternal */
7132 /*
7133  * @return the nth FormulaUnitsData of this Model.
7134  */
7135 const FormulaUnitsData*
getFormulaUnitsData(unsigned int n) const7136 Model::getFormulaUnitsData (unsigned int n) const
7137 {
7138   if (mFormulaUnitsData == NULL) return NULL;
7139   return static_cast<const FormulaUnitsData*>( mFormulaUnitsData->get(n) );
7140 }
7141 /** @endcond */
7142 
7143 
7144 /** @cond doxygenLibsbmlInternal */
7145 /*
7146  * @return the nth FormulaUnitsData of this Model.
7147  */
7148 FormulaUnitsData*
getFormulaUnitsData(unsigned int n)7149 Model::getFormulaUnitsData (unsigned int n)
7150 {
7151   if (mFormulaUnitsData == NULL) return NULL;
7152   return static_cast<FormulaUnitsData*>( mFormulaUnitsData->get(n) );
7153 }
7154 /** @endcond */
7155 
7156 
7157 /** @cond doxygenLibsbmlInternal */
7158 /*
7159  * @return the FormulaUnitsData in this Model with the given @p id
7160  * or @c NULL if no such
7161  * FormulaUnitsData exists.
7162  */
7163 const FormulaUnitsData*
getFormulaUnitsData(const std::string & sid,int typecode) const7164 Model::getFormulaUnitsData (const std::string& sid,
7165                             int typecode) const
7166 {
7167   return const_cast<Model*>(this)->getFormulaUnitsData(sid,typecode);
7168 }
7169 /** @endcond */
7170 
7171 
7172 /** @cond doxygenLibsbmlInternal */
7173 /*
7174  * @return the FormulaUnitsData in this Model with the given @p id  and typecode
7175  * or @c NULL if no such FormulaUnitsData exists.
7176  */
7177 FormulaUnitsData*
getFormulaUnitsData(const std::string & sid,int typecode)7178 Model::getFormulaUnitsData (const std::string& sid, int typecode)
7179 {
7180   FormulaUnitsData * fud = NULL;
7181 
7182   //for (unsigned int n = 0; n < getNumFormulaUnitsData(); n++)
7183   //{
7184   //  fud = static_cast <FormulaUnitsData*> (mFormulaUnitsData->get(n));
7185   //  if (!strcmp(fud->getUnitReferenceId().c_str(), sid.c_str()))
7186   //  {
7187   //    if (fud->getComponentTypecode() == typecode)
7188   //    {
7189   //      return fud;
7190   //    }
7191   //  }
7192   //}
7193 
7194   KeyValue key(sid, typecode);
7195   UnitsValueIter it = mUnitsDataMap.find(key);
7196   if (it != mUnitsDataMap.end())
7197   {
7198     fud = it->second;
7199   }
7200   return fud;
7201 }
7202 /** @endcond */
7203 
7204 
7205 /** @cond doxygenLibsbmlInternal */
7206 /*
7207  * @return the FormulaUnitsData in this Model with the given @p id  and typecode
7208  * or @c NULL if no such FormulaUnitsData exists.
7209  */
7210 FormulaUnitsData*
getFormulaUnitsDataForVariable(const std::string & sid)7211 Model::getFormulaUnitsDataForVariable (const std::string& sid)
7212 {
7213   FormulaUnitsData * fud = NULL;
7214 
7215   if (getParameter(sid) != NULL)
7216   {
7217     fud = getFormulaUnitsData(sid, SBML_PARAMETER);
7218   }
7219   else if (getCompartment(sid) != NULL)
7220   {
7221     fud = getFormulaUnitsData(sid, SBML_COMPARTMENT);
7222   }
7223   else if (getSpecies(sid) != NULL)
7224   {
7225     fud = getFormulaUnitsData(sid, SBML_SPECIES);
7226   }
7227   else if (getSpeciesReference(sid) != NULL)
7228   {
7229     fud = getFormulaUnitsData(sid, SBML_SPECIES_REFERENCE);
7230   }
7231 
7232   return fud;
7233 }
7234 /** @endcond */
7235 
7236 
7237 /** @cond doxygenLibsbmlInternal */
7238 /*
7239  * @return the FormulaUnitsData in this Model with the given @p id  and typecode
7240  * or @c NULL if no such FormulaUnitsData exists.
7241  */
7242 FormulaUnitsData*
getFormulaUnitsDataForAssignment(const std::string & sid)7243 Model::getFormulaUnitsDataForAssignment(const std::string& sid)
7244 {
7245   FormulaUnitsData * fud = NULL;
7246 
7247   if (getInitialAssignment(sid) != NULL)
7248   {
7249     fud = getFormulaUnitsData(sid, SBML_INITIAL_ASSIGNMENT);
7250   }
7251   else if (getAssignmentRule(sid) != NULL)
7252   {
7253     fud = getFormulaUnitsData(sid, SBML_ASSIGNMENT_RULE);
7254   }
7255 
7256   return fud;
7257 }
7258 /** @endcond */
7259 
7260 
7261 /** @cond doxygenLibsbmlInternal */
7262 /*
7263  * @return the number of FormulaUnitsDatas in this Model.
7264  */
7265 unsigned int
getNumFormulaUnitsData() const7266 Model::getNumFormulaUnitsData () const
7267 {
7268   if (mFormulaUnitsData == NULL) return 0;
7269   return mFormulaUnitsData->getSize();
7270 }
7271 /** @endcond */
7272 
7273 
7274 /** @cond doxygenLibsbmlInternal */
7275 /**
7276   * Get the list of FormulaUnitsData object in this Model.
7277   *
7278   * @return the list of FormulaUnitsData for this Model.
7279   */
7280 List*
getListFormulaUnitsData()7281 Model::getListFormulaUnitsData ()
7282 {
7283   return mFormulaUnitsData;
7284 }
7285 /** @endcond */
7286 
7287 
7288 /** @cond doxygenLibsbmlInternal */
7289 /**
7290   * Get the list of FormulaUnitsData object in this Model.
7291   *
7292   * @return the list of FormulaUnitsData for this Model.
7293   */
7294 const List*
getListFormulaUnitsData() const7295 Model::getListFormulaUnitsData () const
7296 {
7297   return mFormulaUnitsData;
7298 }
7299 /** @endcond */
7300 
7301 
7302 /** @cond doxygenLibsbmlInternal */
7303 /*
7304  * returns true if the list has been populated, false otherwise
7305  */
7306 bool
isPopulatedListFormulaUnitsData()7307 Model::isPopulatedListFormulaUnitsData()
7308 {
7309   if (mFormulaUnitsData != NULL)
7310     return true;
7311   else
7312     return false;
7313 }
7314 /** @endcond */
7315 
7316 
7317 /**
7318  * Populates the internal list of the identifiers of all elements within this Model object.
7319  */
7320 void
populateAllElementIdList()7321 Model::populateAllElementIdList()
7322 {
7323   mIdList.clear();
7324   IdFilter filter;
7325   List* allElements = this->getAllElements(&filter);
7326 
7327   //for (unsigned int i = 0; i < allElements->getSize(); i++)
7328   //{
7329   //  mIdList.append(static_cast<SBase*>(allElements->get(i))->getId());
7330   //}
7331 
7332   for (ListIterator iter = allElements->begin(); iter != allElements->end(); ++iter)
7333   {
7334     mIdList.append(static_cast<SBase*>(*iter)->getId());
7335   }
7336 
7337   delete allElements;
7338 }
7339 
7340 
7341 /**
7342   * @return @c true if the id list has already been populated, @c false
7343   * otherwise.
7344   */
7345 bool
isPopulatedAllElementIdList() const7346 Model::isPopulatedAllElementIdList() const
7347 {
7348   return (mIdList.size() != 0);
7349 }
7350 
7351 
7352 /**
7353   * Returns the internal list of the identifiers of all elements within this Model object.
7354   */
7355 IdList
getAllElementIdList() const7356 Model::getAllElementIdList() const
7357 {
7358   return mIdList;
7359 }
7360 
7361 
7362 /**
7363   * Clears the internal list of the identifiers of all elements within this Model object.
7364   */
7365 void
clearAllElementIdList()7366 Model::clearAllElementIdList()
7367 {
7368   mIdList.clear();
7369 }
7370 
7371 
7372 /**
7373  * Populates the internal list of the metaids of all elements within this Model object.
7374  */
7375 void
populateAllElementMetaIdList()7376 Model::populateAllElementMetaIdList()
7377 {
7378   mMetaidList.clear();
7379   MetaIdFilter filter;
7380   List* allElements = this->getAllElements(&filter);
7381 
7382   for (ListIterator iter = allElements->begin(); iter != allElements->end(); ++iter)
7383   {
7384     mMetaidList.append(static_cast<SBase*>(*iter)->getMetaId());
7385   }
7386 
7387   delete allElements;
7388 }
7389 
7390 
7391 /**
7392   * @return @c true if the metaid list has already been populated, @c false
7393   * otherwise.
7394   */
7395 bool
isPopulatedAllElementMetaIdList() const7396 Model::isPopulatedAllElementMetaIdList() const
7397 {
7398   return (mMetaidList.size() != 0);
7399 }
7400 
7401 
7402 /**
7403   * Returns the internal list of the metaids of all elements within this Model object.
7404   */
7405 IdList
getAllElementMetaIdList() const7406 Model::getAllElementMetaIdList() const
7407 {
7408   return mMetaidList;
7409 }
7410 
7411 
7412 /**
7413   * Clears the internal list of the metaids of all elements within this Model object.
7414   */
7415 void
clearAllElementMetaIdList()7416 Model::clearAllElementMetaIdList()
7417 {
7418   mMetaidList.clear();
7419 }
7420 
7421 
7422 #endif /* __cplusplus */
7423 /** @cond doxygenIgnored */
7424 LIBSBML_EXTERN
7425 Model_t *
Model_create(unsigned int level,unsigned int version)7426 Model_create (unsigned int level, unsigned int version)
7427 {
7428   try
7429   {
7430     Model* obj = new Model(level,version);
7431     return obj;
7432   }
7433   catch (SBMLConstructorException)
7434   {
7435     return NULL;
7436   }
7437 }
7438 
7439 
7440 LIBSBML_EXTERN
7441 Model_t *
Model_createWithNS(SBMLNamespaces_t * sbmlns)7442 Model_createWithNS (SBMLNamespaces_t* sbmlns)
7443 {
7444   try
7445   {
7446     Model* obj = new Model(sbmlns);
7447     return obj;
7448   }
7449   catch (SBMLConstructorException)
7450   {
7451     return NULL;
7452   }
7453 }
7454 
7455 
7456 LIBSBML_EXTERN
7457 Model_t *
Model_clone(const Model_t * m)7458 Model_clone (const Model_t *m)
7459 {
7460   return (m != NULL) ? static_cast<Model*>( m->clone() ) : NULL;
7461 }
7462 
7463 
7464 LIBSBML_EXTERN
7465 void
Model_free(Model_t * m)7466 Model_free (Model_t *m)
7467 {
7468   if (m != NULL)
7469   delete m;
7470 }
7471 
7472 
7473 LIBSBML_EXTERN
7474 const XMLNamespaces_t *
Model_getNamespaces(Model_t * m)7475 Model_getNamespaces(Model_t *m)
7476 {
7477   return (m != NULL) ? m->getNamespaces() : NULL;
7478 }
7479 
7480 
7481 LIBSBML_EXTERN
7482 const char *
Model_getId(const Model_t * m)7483 Model_getId (const Model_t *m)
7484 {
7485   return (m != NULL && m->isSetId()) ? m->getId().c_str() : NULL;
7486 }
7487 
7488 
7489 LIBSBML_EXTERN
7490 const char *
Model_getName(const Model_t * m)7491 Model_getName (const Model_t *m)
7492 {
7493   return (m != NULL && m->isSetName()) ? m->getName().c_str() : NULL;
7494 }
7495 
7496 
7497 LIBSBML_EXTERN
7498 const char *
Model_getSubstanceUnits(const Model_t * m)7499 Model_getSubstanceUnits (const Model_t *m)
7500 {
7501   return (m != NULL && m->isSetSubstanceUnits()) ?
7502                        m->getSubstanceUnits().c_str() : NULL;
7503 }
7504 
7505 
7506 LIBSBML_EXTERN
7507 const char *
Model_getTimeUnits(const Model_t * m)7508 Model_getTimeUnits (const Model_t *m)
7509 {
7510   return (m != NULL && m->isSetTimeUnits()) ? m->getTimeUnits().c_str() : NULL;
7511 }
7512 
7513 
7514 LIBSBML_EXTERN
7515 const char *
Model_getVolumeUnits(const Model_t * m)7516 Model_getVolumeUnits (const Model_t *m)
7517 {
7518   return (m != NULL && m->isSetVolumeUnits()) ?
7519                        m->getVolumeUnits().c_str() : NULL;
7520 }
7521 
7522 
7523 LIBSBML_EXTERN
7524 const char *
Model_getAreaUnits(const Model_t * m)7525 Model_getAreaUnits (const Model_t *m)
7526 {
7527   return (m != NULL && m->isSetAreaUnits()) ? m->getAreaUnits().c_str() : NULL;
7528 }
7529 
7530 
7531 LIBSBML_EXTERN
7532 const char *
Model_getLengthUnits(const Model_t * m)7533 Model_getLengthUnits (const Model_t *m)
7534 {
7535   return (m != NULL && m->isSetLengthUnits()) ?
7536                        m->getLengthUnits().c_str() : NULL;
7537 }
7538 
7539 
7540 LIBSBML_EXTERN
7541 const char *
Model_getExtentUnits(const Model_t * m)7542 Model_getExtentUnits (const Model_t *m)
7543 {
7544   return (m != NULL && m->isSetExtentUnits()) ?
7545                        m->getExtentUnits().c_str() : NULL;
7546 }
7547 
7548 
7549 LIBSBML_EXTERN
7550 const char *
Model_getConversionFactor(const Model_t * m)7551 Model_getConversionFactor (const Model_t *m)
7552 {
7553   return (m != NULL && m->isSetConversionFactor()) ?
7554                        m->getConversionFactor().c_str() : NULL;
7555 }
7556 
7557 
7558 LIBSBML_EXTERN
7559 int
Model_isSetId(const Model_t * m)7560 Model_isSetId (const Model_t *m)
7561 {
7562   return (m != NULL) ? static_cast<int>( m->isSetId() ) : 0;
7563 }
7564 
7565 
7566 LIBSBML_EXTERN
7567 int
Model_isSetName(const Model_t * m)7568 Model_isSetName (const Model_t *m)
7569 {
7570   return (m != NULL) ? static_cast<int>( m->isSetName() ) : 0;
7571 }
7572 
7573 
7574 LIBSBML_EXTERN
7575 int
Model_isSetSubstanceUnits(const Model_t * m)7576 Model_isSetSubstanceUnits (const Model_t *m)
7577 {
7578   return (m != NULL) ? static_cast<int>( m->isSetSubstanceUnits() ) : 0;
7579 }
7580 
7581 
7582 LIBSBML_EXTERN
7583 int
Model_isSetTimeUnits(const Model_t * m)7584 Model_isSetTimeUnits (const Model_t *m)
7585 {
7586   return (m != NULL) ? static_cast<int>( m->isSetTimeUnits() ) : 0;
7587 }
7588 
7589 
7590 LIBSBML_EXTERN
7591 int
Model_isSetVolumeUnits(const Model_t * m)7592 Model_isSetVolumeUnits (const Model_t *m)
7593 {
7594   return (m != NULL) ? static_cast<int>( m->isSetVolumeUnits() ) : 0;
7595 }
7596 
7597 
7598 LIBSBML_EXTERN
7599 int
Model_isSetAreaUnits(const Model_t * m)7600 Model_isSetAreaUnits (const Model_t *m)
7601 {
7602   return (m != NULL) ? static_cast<int>( m->isSetAreaUnits() ) : 0;
7603 }
7604 
7605 
7606 LIBSBML_EXTERN
7607 int
Model_isSetLengthUnits(const Model_t * m)7608 Model_isSetLengthUnits (const Model_t *m)
7609 {
7610   return (m != NULL) ? static_cast<int>( m->isSetLengthUnits() ) : 0;
7611 }
7612 
7613 
7614 LIBSBML_EXTERN
7615 int
Model_isSetExtentUnits(const Model_t * m)7616 Model_isSetExtentUnits (const Model_t *m)
7617 {
7618   return (m != NULL) ? static_cast<int>( m->isSetExtentUnits() ) : 0;
7619 }
7620 
7621 
7622 LIBSBML_EXTERN
7623 int
Model_isSetConversionFactor(const Model_t * m)7624 Model_isSetConversionFactor (const Model_t *m)
7625 {
7626   return (m != NULL) ? static_cast<int>( m->isSetConversionFactor() ) : 0;
7627 }
7628 
7629 
7630 LIBSBML_EXTERN
7631 int
Model_setId(Model_t * m,const char * sid)7632 Model_setId (Model_t *m, const char *sid)
7633 {
7634   if (m != NULL)
7635     return (sid == NULL) ? m->unsetId() : m->setId(sid);
7636   else
7637     return LIBSBML_INVALID_OBJECT;
7638 }
7639 
7640 
7641 LIBSBML_EXTERN
7642 int
Model_setName(Model_t * m,const char * name)7643 Model_setName (Model_t *m, const char *name)
7644 {
7645   if (m != NULL)
7646     return (name == NULL) ? m->unsetName() : m->setName(name);
7647   else
7648     return LIBSBML_INVALID_OBJECT;
7649 }
7650 
7651 
7652 LIBSBML_EXTERN
7653 int
Model_setSubstanceUnits(Model_t * m,const char * units)7654 Model_setSubstanceUnits (Model_t *m, const char *units)
7655 {
7656   if (m != NULL)
7657     return (units == NULL) ? m->unsetSubstanceUnits() :
7658                                      m->setSubstanceUnits(units);
7659   else
7660     return LIBSBML_INVALID_OBJECT;
7661 }
7662 
7663 
7664 LIBSBML_EXTERN
7665 int
Model_setTimeUnits(Model_t * m,const char * units)7666 Model_setTimeUnits (Model_t *m, const char *units)
7667 {
7668   if (m != NULL)
7669     return (units == NULL) ? m->unsetTimeUnits() :
7670                                      m->setTimeUnits(units);
7671   else
7672     return LIBSBML_INVALID_OBJECT;
7673 }
7674 
7675 
7676 LIBSBML_EXTERN
7677 int
Model_setVolumeUnits(Model_t * m,const char * units)7678 Model_setVolumeUnits (Model_t *m, const char *units)
7679 {
7680   if (m != NULL)
7681     return (units == NULL) ? m->unsetVolumeUnits() :
7682                                      m->setVolumeUnits(units);
7683   else
7684     return LIBSBML_INVALID_OBJECT;
7685 }
7686 
7687 
7688 LIBSBML_EXTERN
7689 int
Model_setAreaUnits(Model_t * m,const char * units)7690 Model_setAreaUnits (Model_t *m, const char *units)
7691 {
7692   if (m != NULL)
7693     return (units == NULL) ? m->unsetAreaUnits() :
7694                                      m->setAreaUnits(units);
7695   else
7696     return LIBSBML_INVALID_OBJECT;
7697 }
7698 
7699 
7700 LIBSBML_EXTERN
7701 int
Model_setLengthUnits(Model_t * m,const char * units)7702 Model_setLengthUnits (Model_t *m, const char *units)
7703 {
7704   if (m != NULL)
7705     return (units == NULL) ? m->unsetLengthUnits() :
7706                                      m->setLengthUnits(units);
7707   else
7708     return LIBSBML_INVALID_OBJECT;
7709 }
7710 
7711 
7712 LIBSBML_EXTERN
7713 int
Model_setExtentUnits(Model_t * m,const char * units)7714 Model_setExtentUnits (Model_t *m, const char *units)
7715 {
7716   if (m != NULL)
7717     return (units == NULL) ? m->unsetExtentUnits() :
7718                                      m->setExtentUnits(units);
7719   else
7720     return LIBSBML_INVALID_OBJECT;
7721 }
7722 
7723 
7724 LIBSBML_EXTERN
7725 int
Model_setConversionFactor(Model_t * m,const char * sid)7726 Model_setConversionFactor (Model_t *m, const char *sid)
7727 {
7728   if (m != NULL)
7729     return (sid == NULL) ? m->unsetConversionFactor() :
7730                                      m->setConversionFactor(sid);
7731   else
7732     return LIBSBML_INVALID_OBJECT;
7733 }
7734 
7735 
7736 LIBSBML_EXTERN
7737 int
Model_unsetId(Model_t * m)7738 Model_unsetId (Model_t *m)
7739 {
7740   if (m != NULL)
7741     return m->unsetId();
7742   else
7743     return LIBSBML_INVALID_OBJECT;
7744 }
7745 
7746 
7747 LIBSBML_EXTERN
7748 int
Model_unsetName(Model_t * m)7749 Model_unsetName (Model_t *m)
7750 {
7751   if (m != NULL)
7752     return m->unsetName();
7753   else
7754     return LIBSBML_INVALID_OBJECT;
7755 }
7756 
7757 
7758 LIBSBML_EXTERN
7759 int
Model_unsetSubstanceUnits(Model_t * m)7760 Model_unsetSubstanceUnits (Model_t *m)
7761 {
7762   if (m != NULL)
7763     return m->unsetSubstanceUnits();
7764   else
7765     return LIBSBML_INVALID_OBJECT;
7766 }
7767 
7768 
7769 LIBSBML_EXTERN
7770 int
Model_unsetTimeUnits(Model_t * m)7771 Model_unsetTimeUnits (Model_t *m)
7772 {
7773   if (m != NULL)
7774     return m->unsetTimeUnits();
7775   else
7776     return LIBSBML_INVALID_OBJECT;
7777 }
7778 
7779 
7780 LIBSBML_EXTERN
7781 int
Model_unsetVolumeUnits(Model_t * m)7782 Model_unsetVolumeUnits (Model_t *m)
7783 {
7784   if (m != NULL)
7785     return m->unsetVolumeUnits();
7786   else
7787     return LIBSBML_INVALID_OBJECT;
7788 }
7789 
7790 
7791 LIBSBML_EXTERN
7792 int
Model_unsetAreaUnits(Model_t * m)7793 Model_unsetAreaUnits (Model_t *m)
7794 {
7795   if (m != NULL)
7796     return m->unsetAreaUnits();
7797   else
7798     return LIBSBML_INVALID_OBJECT;
7799 }
7800 
7801 
7802 LIBSBML_EXTERN
7803 int
Model_unsetLengthUnits(Model_t * m)7804 Model_unsetLengthUnits (Model_t *m)
7805 {
7806   if (m != NULL)
7807     return m->unsetLengthUnits();
7808   else
7809     return LIBSBML_INVALID_OBJECT;
7810 }
7811 
7812 
7813 LIBSBML_EXTERN
7814 int
Model_unsetExtentUnits(Model_t * m)7815 Model_unsetExtentUnits (Model_t *m)
7816 {
7817   if (m != NULL)
7818     return m->unsetExtentUnits();
7819   else
7820     return LIBSBML_INVALID_OBJECT;
7821 }
7822 
7823 
7824 LIBSBML_EXTERN
7825 int
Model_unsetConversionFactor(Model_t * m)7826 Model_unsetConversionFactor (Model_t *m)
7827 {
7828   if (m != NULL)
7829     return m->unsetConversionFactor();
7830   else
7831     return LIBSBML_INVALID_OBJECT;
7832 }
7833 
7834 
7835 LIBSBML_EXTERN
7836 ModelHistory_t *
Model_getModelHistory(Model_t * m)7837 Model_getModelHistory(Model_t *m)
7838 {
7839   return (m != NULL) ? m->getModelHistory() : NULL;
7840 }
7841 
7842 
7843 LIBSBML_EXTERN
7844 int
Model_isSetModelHistory(Model_t * m)7845 Model_isSetModelHistory(Model_t *m)
7846 {
7847   return (m != NULL) ? static_cast<int>( m->isSetModelHistory() ) : 0;
7848 }
7849 
7850 
7851 LIBSBML_EXTERN
7852 int
Model_setModelHistory(Model_t * m,ModelHistory_t * history)7853 Model_setModelHistory(Model_t *m, ModelHistory_t *history)
7854 {
7855   return (m != NULL) ? m->setModelHistory(history) : LIBSBML_INVALID_OBJECT;
7856 }
7857 
7858 LIBSBML_EXTERN
7859 int
Model_unsetModelHistory(Model_t * m)7860 Model_unsetModelHistory(Model_t *m)
7861 {
7862   return (m != NULL) ? m->unsetModelHistory() : LIBSBML_INVALID_OBJECT;
7863 }
7864 
7865 
7866 LIBSBML_EXTERN
7867 int
Model_addFunctionDefinition(Model_t * m,const FunctionDefinition_t * fd)7868 Model_addFunctionDefinition (Model_t *m, const FunctionDefinition_t *fd)
7869 {
7870   return  (m != NULL) ? m->addFunctionDefinition(fd) : LIBSBML_INVALID_OBJECT;
7871 }
7872 
7873 
7874 LIBSBML_EXTERN
7875 int
Model_addUnitDefinition(Model_t * m,const UnitDefinition_t * ud)7876 Model_addUnitDefinition (Model_t *m, const UnitDefinition_t *ud)
7877 {
7878   return (m != NULL) ? m->addUnitDefinition(ud) : LIBSBML_INVALID_OBJECT;
7879 }
7880 
7881 
7882 LIBSBML_EXTERN
7883 int
Model_addCompartmentType(Model_t * m,const CompartmentType_t * ct)7884 Model_addCompartmentType (Model_t *m, const CompartmentType_t *ct)
7885 {
7886   return (m != NULL) ? m->addCompartmentType(ct) : LIBSBML_INVALID_OBJECT;
7887 }
7888 
7889 
7890 LIBSBML_EXTERN
7891 int
Model_addSpeciesType(Model_t * m,const SpeciesType_t * st)7892 Model_addSpeciesType (Model_t *m, const SpeciesType_t *st)
7893 {
7894   return (m != NULL) ? m->addSpeciesType(st) : LIBSBML_INVALID_OBJECT;
7895 }
7896 
7897 
7898 LIBSBML_EXTERN
7899 int
Model_addCompartment(Model_t * m,const Compartment_t * c)7900 Model_addCompartment (Model_t *m, const Compartment_t *c)
7901 {
7902   return (m != NULL) ? m->addCompartment(c) : LIBSBML_INVALID_OBJECT;
7903 }
7904 
7905 
7906 LIBSBML_EXTERN
7907 int
Model_addSpecies(Model_t * m,const Species_t * s)7908 Model_addSpecies (Model_t *m, const Species_t *s)
7909 {
7910   return (m != NULL) ? m->addSpecies(s) : LIBSBML_INVALID_OBJECT;
7911 }
7912 
7913 
7914 LIBSBML_EXTERN
7915 int
Model_addParameter(Model_t * m,const Parameter_t * p)7916 Model_addParameter (Model_t *m, const Parameter_t *p)
7917 {
7918   return (m != NULL) ? m->addParameter(p) : LIBSBML_INVALID_OBJECT;
7919 }
7920 
7921 
7922 LIBSBML_EXTERN
7923 int
Model_addInitialAssignment(Model_t * m,const InitialAssignment_t * ia)7924 Model_addInitialAssignment (Model_t *m, const InitialAssignment_t *ia)
7925 {
7926   return (m != NULL) ? m->addInitialAssignment(ia) : LIBSBML_INVALID_OBJECT;
7927 }
7928 
7929 
7930 LIBSBML_EXTERN
7931 int
Model_addRule(Model_t * m,const Rule_t * r)7932 Model_addRule (Model_t *m, const Rule_t *r)
7933 {
7934   return (m != NULL) ? m->addRule(r) : LIBSBML_INVALID_OBJECT;
7935 }
7936 
7937 
7938 LIBSBML_EXTERN
7939 int
Model_addConstraint(Model_t * m,const Constraint_t * c)7940 Model_addConstraint (Model_t *m, const Constraint_t *c)
7941 {
7942   return (m != NULL) ? m->addConstraint(c) : LIBSBML_INVALID_OBJECT;
7943 }
7944 
7945 
7946 LIBSBML_EXTERN
7947 int
Model_addReaction(Model_t * m,const Reaction_t * r)7948 Model_addReaction (Model_t *m, const Reaction_t *r)
7949 {
7950   return (m != NULL) ? m->addReaction(r) : LIBSBML_INVALID_OBJECT;
7951 }
7952 
7953 
7954 LIBSBML_EXTERN
7955 int
Model_addEvent(Model_t * m,const Event_t * e)7956 Model_addEvent (Model_t *m, const Event_t *e)
7957 {
7958   return (m != NULL) ? m->addEvent(e) : LIBSBML_INVALID_OBJECT;
7959 }
7960 
7961 
7962 LIBSBML_EXTERN
7963 FunctionDefinition_t *
Model_createFunctionDefinition(Model_t * m)7964 Model_createFunctionDefinition (Model_t *m)
7965 {
7966   return (m != NULL) ? m->createFunctionDefinition() : NULL;
7967 }
7968 
7969 
7970 LIBSBML_EXTERN
7971 UnitDefinition_t *
Model_createUnitDefinition(Model_t * m)7972 Model_createUnitDefinition (Model_t *m)
7973 {
7974   return (m != NULL) ? m->createUnitDefinition() : NULL;
7975 }
7976 
7977 
7978 LIBSBML_EXTERN
7979 Unit_t *
Model_createUnit(Model_t * m)7980 Model_createUnit (Model_t *m)
7981 {
7982   return (m != NULL) ? m->createUnit() : NULL;
7983 }
7984 
7985 
7986 LIBSBML_EXTERN
7987 CompartmentType_t *
Model_createCompartmentType(Model_t * m)7988 Model_createCompartmentType (Model_t *m)
7989 {
7990   return (m != NULL) ? m->createCompartmentType() : NULL;
7991 }
7992 
7993 
7994 LIBSBML_EXTERN
7995 SpeciesType_t *
Model_createSpeciesType(Model_t * m)7996 Model_createSpeciesType (Model_t *m)
7997 {
7998   return (m != NULL) ? m->createSpeciesType() : NULL;
7999 }
8000 
8001 
8002 LIBSBML_EXTERN
8003 Compartment_t *
Model_createCompartment(Model_t * m)8004 Model_createCompartment (Model_t *m)
8005 {
8006   return (m != NULL) ? m->createCompartment() : NULL;
8007 }
8008 
8009 
8010 LIBSBML_EXTERN
8011 Species_t *
Model_createSpecies(Model_t * m)8012 Model_createSpecies (Model_t *m)
8013 {
8014   return (m != NULL) ? m->createSpecies() : NULL;
8015 }
8016 
8017 
8018 LIBSBML_EXTERN
8019 Parameter_t *
Model_createParameter(Model_t * m)8020 Model_createParameter (Model_t *m)
8021 {
8022   return (m != NULL) ? m->createParameter() : NULL;
8023 }
8024 
8025 
8026 LIBSBML_EXTERN
8027 InitialAssignment_t *
Model_createInitialAssignment(Model_t * m)8028 Model_createInitialAssignment (Model_t *m)
8029 {
8030   return (m != NULL) ? m->createInitialAssignment() : NULL;
8031 }
8032 
8033 
8034 LIBSBML_EXTERN
8035 Rule_t *
Model_createAlgebraicRule(Model_t * m)8036 Model_createAlgebraicRule (Model_t *m)
8037 {
8038   return (m != NULL) ? m->createAlgebraicRule() : NULL;
8039 }
8040 
8041 
8042 LIBSBML_EXTERN
8043 Rule_t *
Model_createAssignmentRule(Model_t * m)8044 Model_createAssignmentRule (Model_t *m)
8045 {
8046   return (m != NULL) ? m->createAssignmentRule() : NULL;
8047 }
8048 
8049 
8050 LIBSBML_EXTERN
8051 Rule_t *
Model_createRateRule(Model_t * m)8052 Model_createRateRule (Model_t *m)
8053 {
8054   return (m != NULL) ? m->createRateRule() : NULL;
8055 }
8056 
8057 
8058 LIBSBML_EXTERN
8059 Constraint_t *
Model_createConstraint(Model_t * m)8060 Model_createConstraint (Model_t *m)
8061 {
8062   return (m != NULL) ? m->createConstraint() : NULL;
8063 }
8064 
8065 LIBSBML_EXTERN
8066 Reaction_t *
Model_createReaction(Model_t * m)8067 Model_createReaction (Model_t *m)
8068 {
8069   return (m != NULL) ? m->createReaction() : NULL;
8070 }
8071 
8072 
8073 LIBSBML_EXTERN
8074 SpeciesReference_t *
Model_createReactant(Model_t * m)8075 Model_createReactant (Model_t *m)
8076 {
8077   return (m != NULL) ? m->createReactant() : NULL;
8078 }
8079 
8080 
8081 LIBSBML_EXTERN
8082 SpeciesReference_t *
Model_createProduct(Model_t * m)8083 Model_createProduct (Model_t *m)
8084 {
8085   return (m != NULL) ? m->createProduct() : NULL;
8086 }
8087 
8088 
8089 LIBSBML_EXTERN
8090 SpeciesReference_t *
Model_createModifier(Model_t * m)8091 Model_createModifier (Model_t *m)
8092 {
8093   return (m != NULL) ?
8094           static_cast<SpeciesReference_t*>( m->createModifier() ) : NULL;
8095 }
8096 
8097 
8098 LIBSBML_EXTERN
8099 KineticLaw_t *
Model_createKineticLaw(Model_t * m)8100 Model_createKineticLaw (Model_t *m)
8101 {
8102   return (m != NULL) ? m->createKineticLaw() : NULL;
8103 }
8104 
8105 
8106 LIBSBML_EXTERN
8107 Parameter_t *
Model_createKineticLawParameter(Model_t * m)8108 Model_createKineticLawParameter (Model_t *m)
8109 {
8110   return (m != NULL) ? m->createKineticLawParameter() : NULL;
8111 }
8112 
8113 
8114 LIBSBML_EXTERN
8115 LocalParameter_t *
Model_createKineticLawLocalParameter(Model_t * m)8116 Model_createKineticLawLocalParameter (Model_t *m)
8117 {
8118   return (m != NULL) ? m->createKineticLawLocalParameter() : NULL;
8119 }
8120 
8121 
8122 LIBSBML_EXTERN
8123 Event_t *
Model_createEvent(Model_t * m)8124 Model_createEvent (Model_t *m)
8125 {
8126   return (m != NULL) ? m->createEvent() : NULL;
8127 }
8128 
8129 
8130 LIBSBML_EXTERN
8131 EventAssignment_t *
Model_createEventAssignment(Model_t * m)8132 Model_createEventAssignment (Model_t *m)
8133 {
8134   return (m != NULL) ? m->createEventAssignment() : NULL;
8135 }
8136 
8137 
8138 LIBSBML_EXTERN
8139 Trigger_t *
Model_createTrigger(Model_t * m)8140 Model_createTrigger (Model_t *m)
8141 {
8142   return (m != NULL) ? m->createTrigger() : NULL;
8143 }
8144 
8145 
8146 LIBSBML_EXTERN
8147 Delay_t *
Model_createDelay(Model_t * m)8148 Model_createDelay (Model_t *m)
8149 {
8150   return (m != NULL) ? m->createDelay() : NULL;
8151 }
8152 
8153 
8154 LIBSBML_EXTERN
8155 ListOf_t *
Model_getListOfFunctionDefinitions(Model_t * m)8156 Model_getListOfFunctionDefinitions (Model_t *m)
8157 {
8158   return (m != NULL) ? m->getListOfFunctionDefinitions() : NULL;
8159 }
8160 
8161 
8162 LIBSBML_EXTERN
8163 ListOf_t *
Model_getListOfUnitDefinitions(Model_t * m)8164 Model_getListOfUnitDefinitions (Model_t *m)
8165 {
8166   return (m != NULL) ? m->getListOfUnitDefinitions() : NULL;
8167 }
8168 
8169 
8170 LIBSBML_EXTERN
8171 ListOf_t *
Model_getListOfCompartmentTypes(Model_t * m)8172 Model_getListOfCompartmentTypes (Model_t *m)
8173 {
8174   return (m != NULL) ? m->getListOfCompartmentTypes() : NULL;
8175 }
8176 
8177 
8178 LIBSBML_EXTERN
8179 ListOf_t *
Model_getListOfSpeciesTypes(Model_t * m)8180 Model_getListOfSpeciesTypes (Model_t *m)
8181 {
8182   return (m != NULL) ? m->getListOfSpeciesTypes() : NULL;
8183 }
8184 
8185 
8186 LIBSBML_EXTERN
8187 ListOf_t *
Model_getListOfCompartments(Model_t * m)8188 Model_getListOfCompartments (Model_t *m)
8189 {
8190   return (m != NULL) ? m->getListOfCompartments() : NULL;
8191 }
8192 
8193 
8194 LIBSBML_EXTERN
8195 ListOf_t *
Model_getListOfSpecies(Model_t * m)8196 Model_getListOfSpecies (Model_t *m)
8197 {
8198   return (m != NULL) ? m->getListOfSpecies() : NULL;
8199 }
8200 
8201 
8202 LIBSBML_EXTERN
8203 ListOf_t *
Model_getListOfParameters(Model_t * m)8204 Model_getListOfParameters (Model_t *m)
8205 {
8206   return (m != NULL) ? m->getListOfParameters() : NULL;
8207 }
8208 
8209 
8210 LIBSBML_EXTERN
8211 ListOf_t *
Model_getListOfInitialAssignments(Model_t * m)8212 Model_getListOfInitialAssignments (Model_t* m)
8213 {
8214   return (m != NULL) ? m->getListOfInitialAssignments() : NULL;
8215 }
8216 
8217 
8218 LIBSBML_EXTERN
8219 ListOf_t *
Model_getListOfRules(Model_t * m)8220 Model_getListOfRules (Model_t *m)
8221 {
8222   return (m != NULL) ? m->getListOfRules() : NULL;
8223 }
8224 
8225 
8226 LIBSBML_EXTERN
8227 ListOf_t *
Model_getListOfConstraints(Model_t * m)8228 Model_getListOfConstraints (Model_t* m)
8229 {
8230   return (m != NULL) ? m->getListOfConstraints() : NULL;
8231 }
8232 
8233 
8234 LIBSBML_EXTERN
8235 ListOf_t *
Model_getListOfReactions(Model_t * m)8236 Model_getListOfReactions (Model_t *m)
8237 {
8238   return (m != NULL) ? m->getListOfReactions() : NULL;
8239 }
8240 
8241 
8242 LIBSBML_EXTERN
8243 ListOf_t *
Model_getListOfEvents(Model_t * m)8244 Model_getListOfEvents (Model_t *m)
8245 {
8246   return (m != NULL) ? m->getListOfEvents() : NULL;
8247 }
8248 
8249 
8250 LIBSBML_EXTERN
8251 FunctionDefinition_t *
Model_getFunctionDefinition(Model_t * m,unsigned int n)8252 Model_getFunctionDefinition (Model_t *m, unsigned int n)
8253 {
8254   return (m != NULL) ? m->getFunctionDefinition(n) : NULL;
8255 }
8256 
8257 
8258 LIBSBML_EXTERN
8259 FunctionDefinition_t *
Model_getFunctionDefinitionById(Model_t * m,const char * sid)8260 Model_getFunctionDefinitionById (Model_t *m, const char *sid)
8261 {
8262   return (m != NULL && sid != NULL) ? m->getFunctionDefinition(sid) : NULL;
8263 }
8264 
8265 
8266 LIBSBML_EXTERN
8267 UnitDefinition_t *
Model_getUnitDefinition(Model_t * m,unsigned int n)8268 Model_getUnitDefinition (Model_t *m, unsigned int n)
8269 {
8270   return (m != NULL) ? m->getUnitDefinition(n) : NULL;
8271 }
8272 
8273 
8274 LIBSBML_EXTERN
8275 UnitDefinition_t *
Model_getUnitDefinitionById(Model_t * m,const char * sid)8276 Model_getUnitDefinitionById (Model_t *m, const char *sid)
8277 {
8278   return (m != NULL && sid != NULL) ? m->getUnitDefinition(sid) : NULL;
8279 }
8280 
8281 
8282 LIBSBML_EXTERN
8283 CompartmentType_t *
Model_getCompartmentType(Model_t * m,unsigned int n)8284 Model_getCompartmentType (Model_t *m, unsigned int n)
8285 {
8286   return (m != NULL) ? m->getCompartmentType(n) : NULL;
8287 }
8288 
8289 
8290 LIBSBML_EXTERN
8291 CompartmentType_t *
Model_getCompartmentTypeById(Model_t * m,const char * sid)8292 Model_getCompartmentTypeById (Model_t *m, const char *sid)
8293 {
8294   return (m != NULL && sid != NULL) ? m->getCompartmentType(sid) : NULL;
8295 }
8296 
8297 
8298 LIBSBML_EXTERN
8299 SpeciesType_t *
Model_getSpeciesType(Model_t * m,unsigned int n)8300 Model_getSpeciesType (Model_t *m, unsigned int n)
8301 {
8302   return (m != NULL) ? m->getSpeciesType(n) : NULL;
8303 }
8304 
8305 
8306 LIBSBML_EXTERN
8307 SpeciesType_t *
Model_getSpeciesTypeById(Model_t * m,const char * sid)8308 Model_getSpeciesTypeById (Model_t *m, const char *sid)
8309 {
8310   return (m != NULL && sid != NULL) ? m->getSpeciesType(sid) : NULL;
8311 }
8312 
8313 
8314 LIBSBML_EXTERN
8315 Compartment_t *
Model_getCompartment(Model_t * m,unsigned int n)8316 Model_getCompartment (Model_t *m, unsigned int n)
8317 {
8318   return (m != NULL) ? m->getCompartment(n) : NULL;
8319 }
8320 
8321 
8322 LIBSBML_EXTERN
8323 Compartment_t *
Model_getCompartmentById(Model_t * m,const char * sid)8324 Model_getCompartmentById (Model_t *m, const char *sid)
8325 {
8326   return (m != NULL && sid != NULL) ? m->getCompartment(sid) : NULL;
8327 }
8328 
8329 
8330 LIBSBML_EXTERN
8331 Species_t *
Model_getSpecies(Model_t * m,unsigned int n)8332 Model_getSpecies (Model_t *m, unsigned int n)
8333 {
8334   return (m != NULL) ? m->getSpecies(n) : NULL;
8335 }
8336 
8337 
8338 LIBSBML_EXTERN
8339 Species_t *
Model_getSpeciesById(Model_t * m,const char * sid)8340 Model_getSpeciesById (Model_t *m, const char *sid)
8341 {
8342   return (m != NULL && sid != NULL) ? m->getSpecies(sid) : NULL;
8343 }
8344 
8345 
8346 LIBSBML_EXTERN
8347 Parameter_t *
Model_getParameter(Model_t * m,unsigned int n)8348 Model_getParameter (Model_t *m, unsigned int n)
8349 {
8350   return (m != NULL) ? m->getParameter(n) : NULL;
8351 }
8352 
8353 
8354 LIBSBML_EXTERN
8355 Parameter_t *
Model_getParameterById(Model_t * m,const char * sid)8356 Model_getParameterById (Model_t *m, const char *sid)
8357 {
8358   return (m != NULL && sid != NULL) ? m->getParameter(sid) : NULL;
8359 }
8360 
8361 
8362 LIBSBML_EXTERN
8363 InitialAssignment_t *
Model_getInitialAssignment(Model_t * m,unsigned int n)8364 Model_getInitialAssignment (Model_t *m, unsigned int n)
8365 {
8366   return (m != NULL) ? m->getInitialAssignment(n) : NULL;
8367 }
8368 
8369 
8370 LIBSBML_EXTERN
8371 InitialAssignment_t *
Model_getInitialAssignmentBySym(Model_t * m,const char * symbol)8372 Model_getInitialAssignmentBySym (Model_t *m, const char *symbol)
8373 {
8374   return (symbol != NULL) ? m->getInitialAssignment(symbol) : NULL;
8375 }
8376 
8377 
8378 LIBSBML_EXTERN
8379 Rule_t *
Model_getRule(Model_t * m,unsigned int n)8380 Model_getRule (Model_t *m, unsigned int n)
8381 {
8382   return (m != NULL) ? m->getRule(n) : NULL;
8383 }
8384 
8385 
8386 LIBSBML_EXTERN
8387 Rule_t *
Model_getRuleByVar(Model_t * m,const char * variable)8388 Model_getRuleByVar (Model_t *m, const char *variable)
8389 {
8390   return (variable != NULL) ? m->getRule(variable) : NULL;
8391 }
8392 
8393 
8394 LIBSBML_EXTERN
8395 Constraint_t *
Model_getConstraint(Model_t * m,unsigned int n)8396 Model_getConstraint (Model_t *m, unsigned int n)
8397 {
8398   return (m != NULL) ? m->getConstraint(n) : NULL;
8399 }
8400 
8401 
8402 LIBSBML_EXTERN
8403 Reaction_t *
Model_getReaction(Model_t * m,unsigned int n)8404 Model_getReaction (Model_t *m, unsigned int n)
8405 {
8406   return (m != NULL) ? m->getReaction(n) : NULL;
8407 }
8408 
8409 
8410 LIBSBML_EXTERN
8411 Reaction_t *
Model_getReactionById(Model_t * m,const char * sid)8412 Model_getReactionById (Model_t *m, const char *sid)
8413 {
8414   return (m != NULL && sid != NULL) ? m->getReaction(sid) : NULL;
8415 }
8416 
8417 LIBSBML_EXTERN
8418 SpeciesReference_t *
Model_getSpeciesReferenceById(Model_t * m,const char * sid)8419 Model_getSpeciesReferenceById (Model_t *m, const char *sid)
8420 {
8421   return (m != NULL && sid != NULL) ? m->getSpeciesReference(sid) : NULL;
8422 }
8423 
8424 
8425 
8426 LIBSBML_EXTERN
8427 Event_t *
Model_getEvent(Model_t * m,unsigned int n)8428 Model_getEvent (Model_t *m, unsigned int n)
8429 {
8430   return (m != NULL) ? m->getEvent(n) : NULL;
8431 }
8432 
8433 
8434 LIBSBML_EXTERN
8435 Event_t *
Model_getEventById(Model_t * m,const char * sid)8436 Model_getEventById (Model_t *m, const char *sid)
8437 {
8438   return (m != NULL && sid != NULL) ? m->getEvent(sid) : NULL;
8439 }
8440 
8441 
8442 LIBSBML_EXTERN
8443 unsigned int
Model_getNumFunctionDefinitions(const Model_t * m)8444 Model_getNumFunctionDefinitions (const Model_t *m)
8445 {
8446   return (m != NULL) ? m->getNumFunctionDefinitions() : SBML_INT_MAX;
8447 }
8448 
8449 
8450 LIBSBML_EXTERN
8451 unsigned int
Model_getNumUnitDefinitions(const Model_t * m)8452 Model_getNumUnitDefinitions (const Model_t *m)
8453 {
8454   return (m != NULL) ? m->getNumUnitDefinitions() : SBML_INT_MAX;
8455 }
8456 
8457 
8458 LIBSBML_EXTERN
8459 unsigned int
Model_getNumCompartmentTypes(const Model_t * m)8460 Model_getNumCompartmentTypes (const Model_t *m)
8461 {
8462   return (m != NULL) ? m->getNumCompartmentTypes() : SBML_INT_MAX;
8463 }
8464 
8465 
8466 LIBSBML_EXTERN
8467 unsigned int
Model_getNumSpeciesTypes(const Model_t * m)8468 Model_getNumSpeciesTypes (const Model_t *m)
8469 {
8470   return (m != NULL) ? m->getNumSpeciesTypes() : SBML_INT_MAX;
8471 }
8472 
8473 
8474 LIBSBML_EXTERN
8475 unsigned int
Model_getNumCompartments(const Model_t * m)8476 Model_getNumCompartments (const Model_t *m)
8477 {
8478   return (m != NULL) ? m->getNumCompartments() : SBML_INT_MAX;
8479 }
8480 
8481 
8482 LIBSBML_EXTERN
8483 unsigned int
Model_getNumSpecies(const Model_t * m)8484 Model_getNumSpecies (const Model_t *m)
8485 {
8486   return (m != NULL) ? m->getNumSpecies() : SBML_INT_MAX;
8487 }
8488 
8489 
8490 LIBSBML_EXTERN
8491 unsigned int
Model_getNumSpeciesWithBoundaryCondition(const Model_t * m)8492 Model_getNumSpeciesWithBoundaryCondition (const Model_t *m)
8493 {
8494   return (m != NULL) ? m->getNumSpeciesWithBoundaryCondition() : SBML_INT_MAX;
8495 }
8496 
8497 
8498 LIBSBML_EXTERN
8499 unsigned int
Model_getNumParameters(const Model_t * m)8500 Model_getNumParameters (const Model_t *m)
8501 {
8502   return (m != NULL) ? m->getNumParameters() : SBML_INT_MAX;
8503 }
8504 
8505 
8506 LIBSBML_EXTERN
8507 unsigned int
Model_getNumInitialAssignments(const Model_t * m)8508 Model_getNumInitialAssignments (const Model_t *m)
8509 {
8510   return (m != NULL) ? m->getNumInitialAssignments() : SBML_INT_MAX;
8511 }
8512 
8513 
8514 LIBSBML_EXTERN
8515 unsigned int
Model_getNumRules(const Model_t * m)8516 Model_getNumRules (const Model_t *m)
8517 {
8518   return (m != NULL) ? m->getNumRules() : SBML_INT_MAX;
8519 }
8520 
8521 
8522 LIBSBML_EXTERN
8523 unsigned int
Model_getNumConstraints(const Model_t * m)8524 Model_getNumConstraints (const Model_t *m)
8525 {
8526   return (m != NULL) ? m->getNumConstraints() : SBML_INT_MAX;
8527 }
8528 
8529 LIBSBML_EXTERN
8530 unsigned int
Model_getNumReactions(const Model_t * m)8531 Model_getNumReactions (const Model_t *m)
8532 {
8533   return (m != NULL) ? m->getNumReactions() : SBML_INT_MAX;
8534 }
8535 
8536 
8537 LIBSBML_EXTERN
8538 unsigned int
Model_getNumEvents(const Model_t * m)8539 Model_getNumEvents (const Model_t *m)
8540 {
8541   return (m != NULL) ? m->getNumEvents() : SBML_INT_MAX;
8542 }
8543 
8544 
8545 LIBSBML_EXTERN
8546 void
Model_populateListFormulaUnitsData(Model_t * m)8547 Model_populateListFormulaUnitsData(Model_t *m)
8548 {
8549   if (m != NULL)
8550     m->populateListFormulaUnitsData();
8551 }
8552 
8553 
8554 LIBSBML_EXTERN
8555 int
Model_isPopulatedListFormulaUnitsData(Model_t * m)8556 Model_isPopulatedListFormulaUnitsData(Model_t *m)
8557 {
8558   return (m != NULL) ?
8559     static_cast<int>( m->isPopulatedListFormulaUnitsData()) : 0;
8560 }
8561 
8562 
8563 LIBSBML_EXTERN
8564 FunctionDefinition_t*
Model_removeFunctionDefinition(Model_t * m,unsigned int n)8565 Model_removeFunctionDefinition (Model_t *m, unsigned int n)
8566 {
8567   if (m != NULL)
8568     return m->removeFunctionDefinition(n);
8569   else
8570     return NULL;
8571 }
8572 
8573 
8574 LIBSBML_EXTERN
8575 FunctionDefinition_t*
Model_removeFunctionDefinitionById(Model_t * m,const char * sid)8576 Model_removeFunctionDefinitionById (Model_t *m, const char* sid)
8577 {
8578   if (m != NULL)
8579     return (sid != NULL) ? m->removeFunctionDefinition(sid) : NULL;
8580   else
8581     return NULL;
8582 }
8583 
8584 
8585 LIBSBML_EXTERN
8586 UnitDefinition_t*
Model_removeUnitDefinition(Model_t * m,unsigned int n)8587 Model_removeUnitDefinition (Model_t *m, unsigned int n)
8588 {
8589   if (m != NULL)
8590     return m->removeUnitDefinition(n);
8591   else
8592     return NULL;
8593 }
8594 
8595 
8596 LIBSBML_EXTERN
8597 UnitDefinition_t*
Model_removeUnitDefinitionById(Model_t * m,const char * sid)8598 Model_removeUnitDefinitionById (Model_t *m, const char* sid)
8599 {
8600   if (m != NULL)
8601     return (sid != NULL) ? m->removeUnitDefinition(sid) : NULL;
8602   else
8603     return NULL;
8604 }
8605 
8606 
8607 LIBSBML_EXTERN
8608 CompartmentType_t*
Model_removeCompartmentType(Model_t * m,unsigned int n)8609 Model_removeCompartmentType (Model_t *m, unsigned int n)
8610 {
8611   if (m != NULL)
8612     return m->removeCompartmentType(n);
8613   else
8614     return NULL;
8615 }
8616 
8617 
8618 LIBSBML_EXTERN
8619 CompartmentType_t*
Model_removeCompartmentTypeById(Model_t * m,const char * sid)8620 Model_removeCompartmentTypeById (Model_t *m, const char* sid)
8621 {
8622   if (m != NULL)
8623     return (sid != NULL) ? m->removeCompartmentType(sid) : NULL;
8624   else
8625     return NULL;
8626 }
8627 
8628 
8629 LIBSBML_EXTERN
8630 SpeciesType_t*
Model_removeSpeciesType(Model_t * m,unsigned int n)8631 Model_removeSpeciesType (Model_t *m, unsigned int n)
8632 {
8633   if (m != NULL)
8634     return m->removeSpeciesType(n);
8635   else
8636     return NULL;
8637 }
8638 
8639 
8640 LIBSBML_EXTERN
8641 SpeciesType_t*
Model_removeSpeciesTypeById(Model_t * m,const char * sid)8642 Model_removeSpeciesTypeById (Model_t *m, const char* sid)
8643 {
8644   if (m != NULL)
8645     return (sid != NULL) ? m->removeSpeciesType(sid) : NULL;
8646   else
8647     return NULL;
8648 }
8649 
8650 
8651 LIBSBML_EXTERN
8652 Compartment_t*
Model_removeCompartment(Model_t * m,unsigned int n)8653 Model_removeCompartment (Model_t *m, unsigned int n)
8654 {
8655   if (m != NULL)
8656     return m->removeCompartment(n);
8657   else
8658     return NULL;
8659 }
8660 
8661 
8662 LIBSBML_EXTERN
8663 Compartment_t*
Model_removeCompartmentById(Model_t * m,const char * sid)8664 Model_removeCompartmentById (Model_t *m, const char* sid)
8665 {
8666   if (m != NULL)
8667     return (sid != NULL) ? m->removeCompartment(sid) : NULL;
8668   else
8669     return NULL;
8670 }
8671 
8672 
8673 LIBSBML_EXTERN
8674 Species_t*
Model_removeSpecies(Model_t * m,unsigned int n)8675 Model_removeSpecies (Model_t *m, unsigned int n)
8676 {
8677   if (m != NULL)
8678     return m->removeSpecies(n);
8679   else
8680     return NULL;
8681 }
8682 
8683 
8684 LIBSBML_EXTERN
8685 Species_t*
Model_removeSpeciesById(Model_t * m,const char * sid)8686 Model_removeSpeciesById (Model_t *m, const char* sid)
8687 {
8688   if (m != NULL)
8689     return (sid != NULL) ? m->removeSpecies(sid) : NULL;
8690   else
8691     return NULL;
8692 }
8693 
8694 
8695 LIBSBML_EXTERN
8696 Parameter_t*
Model_removeParameter(Model_t * m,unsigned int n)8697 Model_removeParameter (Model_t *m, unsigned int n)
8698 {
8699   if (m != NULL)
8700     return m->removeParameter(n);
8701   else
8702     return NULL;
8703 }
8704 
8705 
8706 LIBSBML_EXTERN
8707 Parameter_t*
Model_removeParameterById(Model_t * m,const char * sid)8708 Model_removeParameterById (Model_t *m, const char* sid)
8709 {
8710   if (m != NULL)
8711     return (sid != NULL) ? m->removeParameter(sid) : NULL;
8712   else
8713     return NULL;
8714 }
8715 
8716 
8717 LIBSBML_EXTERN
8718 InitialAssignment_t*
Model_removeInitialAssignment(Model_t * m,unsigned int n)8719 Model_removeInitialAssignment (Model_t *m, unsigned int n)
8720 {
8721   if (m != NULL)
8722     return m->removeInitialAssignment(n);
8723   else
8724     return NULL;
8725 }
8726 
8727 
8728 LIBSBML_EXTERN
8729 InitialAssignment_t*
Model_removeInitialAssignmentBySym(Model_t * m,const char * symbol)8730 Model_removeInitialAssignmentBySym (Model_t *m, const char* symbol)
8731 {
8732   if (m != NULL)
8733     return (symbol != NULL) ? m->removeInitialAssignment(symbol) : NULL;
8734   else
8735     return NULL;
8736 }
8737 
8738 
8739 LIBSBML_EXTERN
8740 Rule_t*
Model_removeRule(Model_t * m,unsigned int n)8741 Model_removeRule (Model_t *m, unsigned int n)
8742 {
8743   if (m != NULL)
8744     return m->removeRule(n);
8745   else
8746     return NULL;
8747 }
8748 
8749 
8750 LIBSBML_EXTERN
8751 Rule_t*
Model_removeRuleByVar(Model_t * m,const char * variable)8752 Model_removeRuleByVar (Model_t *m, const char* variable)
8753 {
8754   if (m != NULL)
8755     return (variable != NULL) ? m->removeRule(variable) : NULL;
8756   else
8757     return NULL;
8758 }
8759 
8760 
8761 LIBSBML_EXTERN
8762 Constraint_t*
Model_removeConstraint(Model_t * m,unsigned int n)8763 Model_removeConstraint (Model_t *m, unsigned int n)
8764 {
8765   if (m != NULL)
8766     return m->removeConstraint(n);
8767   else
8768     return NULL;
8769 }
8770 
8771 
8772 LIBSBML_EXTERN
8773 Reaction_t*
Model_removeReaction(Model_t * m,unsigned int n)8774 Model_removeReaction (Model_t *m, unsigned int n)
8775 {
8776   if (m != NULL)
8777     return m->removeReaction(n);
8778   else
8779     return NULL;
8780 }
8781 
8782 
8783 LIBSBML_EXTERN
8784 Reaction_t*
Model_removeReactionById(Model_t * m,const char * sid)8785 Model_removeReactionById (Model_t *m, const char* sid)
8786 {
8787   if (m != NULL)
8788     return (sid != NULL) ? m->removeReaction(sid) : NULL;
8789   else
8790     return NULL;
8791 }
8792 
8793 
8794 LIBSBML_EXTERN
8795 Event_t*
Model_removeEvent(Model_t * m,unsigned int n)8796 Model_removeEvent (Model_t *m, unsigned int n)
8797 {
8798   if (m != NULL)
8799     return m->removeEvent(n);
8800   else
8801     return NULL;
8802 }
8803 
8804 
8805 LIBSBML_EXTERN
8806 Event_t*
Model_removeEventById(Model_t * m,const char * sid)8807 Model_removeEventById (Model_t *m, const char* sid)
8808 {
8809   if (m != NULL)
8810     return (sid != NULL) ? m->removeEvent(sid) : NULL;
8811   else
8812     return NULL;
8813 }
8814 
8815 
8816 /* NOT YET USED but leave in case of future need
8817 
8818 LIBSBML_EXTERN
8819 void
8820 Model_addFormulaUnitsData (Model_t *m, FormulaUnitsData_t* fud)
8821 {
8822   m->addFormulaUnitsData(fud);
8823 }
8824 
8825 
8826 LIBSBML_EXTERN
8827 FormulaUnitsData_t*
8828 Model_createFormulaUnitsData (Model_t *m)
8829 {
8830   return m->createFormulaUnitsData();
8831 }
8832 
8833 
8834 LIBSBML_EXTERN
8835 FormulaUnitsData_t*
8836 Model_getFormulaUnitsData (Model_t *m, unsigned int n)
8837 {
8838   return m->getFormulaUnitsData(n);
8839 }
8840 
8841 
8842 LIBSBML_EXTERN
8843 FormulaUnitsData_t*
8844 Model_getFormulaUnitsDataById(Model_t *m, const char* sid,
8845                                           int typecode)
8846 {
8847   return m->getFormulaUnitsData(sid, typecode);
8848 }
8849 
8850 
8851 LIBSBML_EXTERN
8852 unsigned int
8853 Model_getNumFormulaUnitsData (Model_t *m)
8854 {
8855   return m->getNumFormulaUnitsData();
8856 }
8857 
8858 
8859 LIBSBML_EXTERN
8860 List_t*
8861 Model_getListFormulaUnitsData (Model_t *m)
8862 {
8863   return m->getListFormulaUnitsData();
8864 }
8865 
8866 */
8867 /** @endcond */
8868 LIBSBML_CPP_NAMESPACE_END
8869