1 /**
2  * @file    FbcModelPlugin.cpp
3  * @brief   Implementation of FbcModelPlugin, the plugin class of
4  *          the fbc package for the Model element.
5  * @author  Frank T. Bergmann
6  *
7  *
8  *<!---------------------------------------------------------------------------
9  * This file is part of libSBML.  Please visit http://sbml.org for more
10  * information about SBML, and the latest version of libSBML.
11  *
12  * Copyright (C) 2020 jointly by the following organizations:
13  *     1. California Institute of Technology, Pasadena, CA, USA
14  *     2. University of Heidelberg, Heidelberg, Germany
15  *     3. University College London, London, UK
16  *
17  * Copyright (C) 2019 jointly by the following organizations:
18  *     1. California Institute of Technology, Pasadena, CA, USA
19  *     2. University of Heidelberg, Heidelberg, Germany
20  *
21  * Copyright (C) 2013-2018 jointly by the following organizations:
22  *     1. California Institute of Technology, Pasadena, CA, USA
23  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
24  *     3. University of Heidelberg, Heidelberg, Germany
25  *
26  * Copyright (C) 2009-2013 jointly by the following organizations:
27  *     1. California Institute of Technology, Pasadena, CA, USA
28  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
29  *
30  * This library is free software; you can redistribute it and/or modify it
31  * under the terms of the GNU Lesser General Public License as published by
32  * the Free Software Foundation.  A copy of the license agreement is provided
33  * in the file named "LICENSE.txt" included with this software distribution
34  * and also available online as http://sbml.org/software/libsbml/license.html
35  *------------------------------------------------------------------------- -->
36  */
37 
38 
39 #include <sbml/packages/fbc/extension/FbcModelPlugin.h>
40 #include <sbml/packages/fbc/extension/FbcExtension.h>
41 #include <sbml/packages/fbc/validator/FbcSBMLError.h>
42 #include <sbml/util/ElementFilter.h>
43 #include <sbml/Model.h>
44 
45 
46 #include <iostream>
47 using namespace std;
48 
49 
50 #ifdef __cplusplus
51 
52 
53 LIBSBML_CPP_NAMESPACE_BEGIN
54 
55 
56 /*
57  * Creates a new FbcModelPlugin
58  */
FbcModelPlugin(const std::string & uri,const std::string & prefix,FbcPkgNamespaces * fbcns)59 FbcModelPlugin::FbcModelPlugin(const std::string& uri,
60                                const std::string& prefix,
61                                FbcPkgNamespaces* fbcns) :
62     SBasePlugin(uri, prefix, fbcns)
63   , mStrict (false)
64   , mIsSetStrict (false)
65   , mObjectives (fbcns)
66   , mGeneProducts (fbcns)
67   , mBounds(fbcns)
68   , mAssociations(fbcns)
69 {
70   // connect child elements to this element.
71   connectToChild();
72 }
73 
74 
75 /*
76  * Copy constructor for FbcModelPlugin.
77  */
FbcModelPlugin(const FbcModelPlugin & orig)78 FbcModelPlugin::FbcModelPlugin(const FbcModelPlugin& orig)
79   :  SBasePlugin(orig)
80   , mStrict (orig.mStrict)
81   , mIsSetStrict (orig.mIsSetStrict)
82   , mObjectives (orig.mObjectives)
83   , mGeneProducts (orig.mGeneProducts)
84   , mBounds(orig.mBounds)
85   , mAssociations(orig.mAssociations)
86 {
87   // connect child elements to this element.
88   connectToChild();
89 }
90 
91 
92 /*
93  * Assignment operator for FbcModelPlugin.
94  */
95 FbcModelPlugin&
operator =(const FbcModelPlugin & rhs)96 FbcModelPlugin::operator=(const FbcModelPlugin& rhs)
97 {
98   if (&rhs != this)
99   {
100     this->SBasePlugin::operator=(rhs);
101     mStrict  = rhs.mStrict;
102     mIsSetStrict  = rhs.mIsSetStrict;
103     mBounds       = rhs.mBounds;
104     mObjectives   = rhs.mObjectives;
105     mAssociations = rhs.mAssociations;
106     mGeneProducts  = rhs.mGeneProducts;
107     // connect child elements to this element.
108     connectToChild();
109   }
110 
111   return *this;
112 }
113 
114 
115 /*
116  * Creates and returns a deep copy of this FbcModelPlugin object.
117  */
118 FbcModelPlugin*
clone() const119 FbcModelPlugin::clone () const
120 {
121   return new FbcModelPlugin(*this);
122 }
123 
124 
125 /*
126  * Destructor for FbcModelPlugin.
127  */
~FbcModelPlugin()128 FbcModelPlugin::~FbcModelPlugin()
129 {
130 }
131 
132 
133 /** @cond doxygenLibsbmlInternal */
134 int
appendFrom(const Model * model)135 FbcModelPlugin::appendFrom(const Model* model)
136 {
137   int ret = LIBSBML_OPERATION_SUCCESS;
138 
139   if (model == NULL)
140   {
141     return LIBSBML_INVALID_OBJECT;
142   }
143 
144   const FbcModelPlugin* modplug =
145     static_cast<const FbcModelPlugin*>(model->getPlugin(getPrefix()));
146 
147   // absence of a plugin is not an error
148   if (modplug == NULL)
149   {
150     return LIBSBML_OPERATION_SUCCESS;
151   }
152 
153   Model* parent = static_cast<Model*>(getParentSBMLObject());
154 
155   if (parent == NULL)
156   {
157     return LIBSBML_INVALID_OBJECT;
158   }
159 
160   ret = mBounds.appendFrom(modplug->getListOfFluxBounds());
161 
162   if (ret != LIBSBML_OPERATION_SUCCESS)
163   {
164     return ret;
165   }
166 
167   ret = mObjectives.appendFrom(modplug->getListOfObjectives());
168 
169   if (ret != LIBSBML_OPERATION_SUCCESS)
170   {
171     return ret;
172   }
173 
174   ret = mGeneProducts.appendFrom(modplug->getListOfGeneProducts());
175 
176   return ret;
177 }
178 /** @endcond */
179 //---------------------------------------------------------------
180 //
181 // overridden virtual functions for read/write/check
182 //
183 //---------------------------------------------------------------
184 
185 /** @cond doxygenLibsbmlInternal */
186 /*
187  * create object
188  */
189 SBase*
createObject(XMLInputStream & stream)190 FbcModelPlugin::createObject (XMLInputStream& stream)
191 {
192   SBase* object = NULL;
193 
194   const std::string&      name   = stream.peek().getName();
195   const XMLNamespaces&    xmlns1  = stream.peek().getNamespaces();
196   const std::string&      prefix = stream.peek().getPrefix();
197 
198   const std::string& targetPrefix = (xmlns1.hasURI(mURI)) ? xmlns1.getPrefix(mURI) : mPrefix;
199 
200   if (prefix == targetPrefix)
201   {
202     FBC_CREATE_NS_WITH_VERSION(fbcns, getSBMLNamespaces(), getPackageVersion());
203     if ( name == "listOfFluxBounds" )
204     {
205       if (mBounds.size() != 0)
206       {
207         getErrorLog()->logPackageError("fbc", FbcOnlyOneEachListOf,
208           getPackageVersion(), getLevel(), getVersion(), "", getLine(), getColumn());
209       }
210 
211       object = &mBounds;
212 
213       if (targetPrefix.empty())
214       {
215         mBounds.getSBMLDocument()->enableDefaultNS(mURI,true);
216       }
217     }
218     else if (name == "listOfObjectives" )
219     {
220       if (mObjectives.size() != 0)
221       {
222         getErrorLog()->logPackageError("fbc", FbcOnlyOneEachListOf,
223           getPackageVersion(), getLevel(), getVersion(), "", getLine(), getColumn());
224       }
225 
226       object = &mObjectives;
227 
228       if (targetPrefix.empty())
229       {
230         mObjectives.getSBMLDocument()->enableDefaultNS(mURI, true);
231       }
232     }
233     else if ( name == "listOfGeneAssociations" )
234     {
235       if (mAssociations.size() != 0)
236       {
237         getErrorLog()->logPackageError("fbc", FbcOnlyOneEachListOf,
238           getPackageVersion(), getLevel(), getVersion(), "", getLine(), getColumn());
239       }
240 
241       object = &mAssociations;
242 
243       if (targetPrefix.empty())
244       {
245         mAssociations.getSBMLDocument()->enableDefaultNS(mURI,true);
246       }
247     }
248     else if (name == "listOfGeneProducts" )
249     {
250       if (mGeneProducts.size() != 0)
251       {
252         getErrorLog()->logPackageError("fbc", FbcOnlyOneEachListOf,
253           getPackageVersion(), getLevel(), getVersion(), "", getLine(), getColumn());
254       }
255 
256       object = &mGeneProducts;
257 
258       if (targetPrefix.empty() == true)
259       {
260         mGeneProducts.getSBMLDocument()->enableDefaultNS(mURI, true);
261       }
262     }
263 
264     delete fbcns;
265   }
266 
267   return object;
268 }
269 /** @endcond */
270 
271 /** @cond doxygenLibsbmlInternal */
272 /*
273  * write elements
274  */
275 void
writeElements(XMLOutputStream & stream) const276 FbcModelPlugin::writeElements (XMLOutputStream& stream) const
277 {
278   if (getLevel() == 2) return;
279 
280   if (getNumFluxBounds() > 0)
281   {
282     mBounds.write(stream);
283   }
284   if (getNumObjectives() > 0)
285   {
286     mObjectives.write(stream);
287   }
288   if (getNumGeneProducts() > 0)
289   {
290     mGeneProducts.write(stream);
291   }
292 }
293 /** @endcond */
294 
295 LIBSBML_EXTERN
296 void
parseFbcAnnotation(XMLNode * annotation,ListOfGeneAssociations & associations,FbcPkgNamespaces * fbcns)297 parseFbcAnnotation(XMLNode * annotation, ListOfGeneAssociations& associations,
298                    FbcPkgNamespaces* fbcns)
299 {
300 
301   if (!annotation) return;
302 
303   const string&  name = annotation->getName();
304   const XMLNode*  plOGATop = NULL;
305   GeneAssociation* ga;
306   unsigned int n = 0;
307 
308   // need to find the layout desciption opening annotation
309   if (name == "annotation" && annotation->getNumChildren() > 0)
310   {
311     while (n < annotation->getNumChildren())
312     {
313       const string &name1 = annotation->getChild(n).getName();
314       if (name1 == "listOfGeneAssociations") // also check the namespace
315       {
316         const XMLNamespaces& namespaces=annotation->getChild(n).getNamespaces();
317         if(namespaces.getIndex(FbcExtension::getXmlnsL3V1V1())!=-1)
318         {
319           plOGATop = &(annotation->getChild(n));
320           break;
321         }
322       }
323       n++;
324     }
325   }
326 
327   // find qualifier nodes and create
328 
329 
330   n = 0;
331   if (plOGATop)
332   {
333     while (n < plOGATop->getNumChildren())
334     {
335       const string &name2 = plOGATop->getChild(n).getName();
336 
337       if (name2 == "annotation")
338       {
339         const XMLNode &annot = plOGATop->getChild(n);
340         associations.setAnnotation(&annot);
341       }
342 
343       if (name2 == "geneAssociation")
344       {
345         ga = new GeneAssociation(plOGATop->getChild(n), fbcns);
346         associations.appendAndOwn(ga);
347       }
348 
349       n++;
350     }
351   }
352 }
353 
354 
355 LIBSBML_EXTERN
deleteFbcAnnotation(XMLNode * pAnnotation)356 XMLNode* deleteFbcAnnotation(XMLNode* pAnnotation)
357 {
358   if (pAnnotation == NULL)
359     return NULL;
360 
361   const string&  name = pAnnotation->getName();
362   unsigned int n = 0;
363 
364   if (!(name == "annotation" && pAnnotation->getNumChildren() > 0))
365     return pAnnotation;
366 
367 
368   // need to find each annotation and remove it if it is a list of gene associations
369   while (n < pAnnotation->getNumChildren())
370   {
371     const string &name1 = pAnnotation->getChild(n).getName();
372     if (name1 == "listOfGeneAssociations" ||
373         pAnnotation->getChild(n).getNamespaces().getIndex(FbcExtension::getXmlnsL3V1V1()) !=-1)
374     {
375       // delete the anotation
376       delete pAnnotation->removeChild(n);
377 
378       continue;
379     }
380     n++;
381   }
382 
383   return pAnnotation;
384 }
385 
386 
387 
388 
389   /** @cond doxygenLibsbmlInternal */
390 
391 /*
392  * Get the list of expected attributes for this element.
393  */
394 void
addExpectedAttributes(ExpectedAttributes & attributes)395 FbcModelPlugin::addExpectedAttributes(ExpectedAttributes& attributes)
396 {
397   SBasePlugin::addExpectedAttributes(attributes);
398 
399   attributes.add("strict");
400 }
401 
402 
403   /** @endcond */
404 
405 
406 /** @cond doxygenLibsbmlInternal */
407 void
parseAnnotation(SBase * parentObject,XMLNode * pAnnotation)408 FbcModelPlugin::parseAnnotation(SBase *parentObject, XMLNode *pAnnotation)
409 {
410   mAssociations.setSBMLDocument(mSBML);
411   // don't read if we have an invalid node or already a gene associations object
412   if (pAnnotation == NULL || mAssociations.size() > 0)
413     return;
414 
415   // annotation element has been parsed by the parent element
416   // (Model) of this plugin object, thus the annotation element
417   // set to the above pAnnotation variable is parsed in this block.
418 
419   XMLNode& listOfGeneAssociations = pAnnotation->getChild("listOfGeneAssociations");
420   if (listOfGeneAssociations.getNumChildren() == 0)
421     return;
422 
423   // read the xml node, overriding that all errors are flagged as
424   // warnings
425   mAssociations.read(listOfGeneAssociations, LIBSBML_OVERRIDE_WARNING);
426   // remove listOfLayouts annotation
427   parentObject->removeTopLevelAnnotationElement("listOfGeneAssociations", "", false);
428 }
429 /** @endcond */
430 
431 
432 /** @cond doxygenLibsbmlInternal */
433 #ifndef ANNOATION
434 bool
readOtherXML(SBase *,XMLInputStream &)435 FbcModelPlugin::readOtherXML (SBase* /*parentObject*/, XMLInputStream& /*stream*/)
436 {
437   return false;
438 }
439 #else
440 bool
readOtherXML(SBase * parentObject,XMLInputStream & stream)441 FbcModelPlugin::readOtherXML (SBase* parentObject, XMLInputStream& stream)
442 {
443   bool readAnnotationFromStream = false;
444   const string& name = stream.peek().getName();
445 
446   if (!(name.empty()) && name != "annotation")
447   {
448     return readAnnotationFromStream;
449   }
450 
451   try
452   {
453     XMLNode *pAnnotation = parentObject->getAnnotation();
454     FBC_CREATE_NS_WITH_VERSION(fbcns, getSBMLNamespaces(), getPackageVersion());
455 
456     if (!pAnnotation)
457     {
458       //
459       // (NOTES)
460       //
461       // annotation element has not been parsed by the parent element
462       // (Model) of this plugin object, thus annotation element is
463       // parsed via the given XMLInputStream object in this block.
464       //
465 
466       const string& name = stream.peek().getName();
467 
468 
469       if (name == "annotation")
470       {
471         pAnnotation = new XMLNode(stream);
472 
473         parseFbcAnnotation(pAnnotation, mAssociations, fbcns);
474 
475         if (mAssociations.size() > 0)
476         {
477           //
478           // Removes the annotation for layout extension from the annotation
479           // of parent element (pAnnotation) and then set the new annotation
480           // (newAnnotation) to the parent element.
481           //
482           XMLNode *newAnnotation = deleteFbcAnnotation(pAnnotation);
483           parentObject->setAnnotation(newAnnotation);
484           delete newAnnotation;
485         }
486         else
487         {
488           //
489           // No layout annotation is included in the read annotation
490           // (pAnnotation) and thus just set the annotation to the parent
491           // element.
492           //
493           parentObject->setAnnotation(pAnnotation);
494         }
495 
496         delete pAnnotation;
497 
498         readAnnotationFromStream = true;
499       }
500 
501     }
502     else if (mAssociations.size() == 0)
503     {
504       //
505       // (NOTES)
506       //
507       // annotation element has been parsed by the parent element
508       // (Model) of this plugin object, thus the annotation element
509       // set to the above pAnnotation variable is parsed in this block.
510       //
511       parseFbcAnnotation(pAnnotation, mAssociations, fbcns);
512 
513       if (mAssociations.size() > 0)
514       {
515         //
516         // Removes the annotation for layout extension from the annotation
517         // of parent element (pAnnotation) and then set the new annotation
518         // (newAnnotation) to the parent element.
519         //
520         XMLNode *newAnnotation = deleteFbcAnnotation(pAnnotation);
521         parentObject->setAnnotation(newAnnotation);
522       }
523 
524       readAnnotationFromStream = true;
525     }
526 
527     delete fbcns;
528   }
529   catch(...)
530   {
531     // an exception occured, most likely becase a namespace constructor
532     // threw an exception, catching this here, and return false, to indicate
533     // that the annotation wasn't read.
534     readAnnotationFromStream = false;
535   }
536 
537   return readAnnotationFromStream;
538 }
539 #endif
540 /** @endcond */
541 
542 
543 /** @cond doxygenLibsbmlInternal */
544 
545 /*
546  * Read values from the given XMLAttributes set into their specific fields.
547  */
548 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)549 FbcModelPlugin::readAttributes (const XMLAttributes& attributes,
550                              const ExpectedAttributes& expectedAttributes)
551 {
552   const unsigned int sbmlLevel   = getLevel  ();
553   const unsigned int sbmlVersion = getVersion();
554 
555   unsigned int numErrs;
556 
557   SBasePlugin::readAttributes(attributes, expectedAttributes);
558 
559   // look to see whether an unknown attribute error was logged
560   if (getErrorLog() != NULL)
561   {
562     numErrs = getErrorLog()->getNumErrors();
563     for (int n = (int)numErrs-1; n >= 0; n--)
564     {
565       if (getErrorLog()->getError((unsigned int)n)->getErrorId() == UnknownPackageAttribute)
566       {
567         const std::string details =
568                           getErrorLog()->getError((unsigned int)n)->getMessage();
569         getErrorLog()->remove(UnknownPackageAttribute);
570         getErrorLog()->logPackageError("fbc", FbcUnknown,
571                        getPackageVersion(), sbmlLevel, sbmlVersion, details, getLine(), getColumn());
572       }
573       else if (getErrorLog()->getError((unsigned int)n)->getErrorId() == UnknownCoreAttribute)
574       {
575         const std::string details =
576                           getErrorLog()->getError((unsigned int)n)->getMessage();
577         getErrorLog()->remove(UnknownCoreAttribute);
578         getErrorLog()->logPackageError("fbc", FbcUnknown,
579                        getPackageVersion(), sbmlLevel, sbmlVersion, details, getLine(), getColumn());
580       }
581     }
582   }
583 
584   //
585   // strict bool   ( use = "required" )
586   //
587   numErrs = getErrorLog()->getNumErrors();
588   mIsSetStrict = attributes.readInto("strict", mStrict);
589 
590   if (mIsSetStrict == false && getPackageVersion() > 1)
591   {
592     if (getErrorLog() != NULL)
593     {
594       if (getErrorLog()->getNumErrors() == numErrs + 1 &&
595               getErrorLog()->contains(XMLAttributeTypeMismatch))
596       {
597         getErrorLog()->remove(XMLAttributeTypeMismatch);
598         getErrorLog()->logPackageError("fbc", FbcModelStrictMustBeBoolean,
599                      getPackageVersion(), sbmlLevel, sbmlVersion, "", getLine(), getColumn());
600       }
601       else
602       {
603         std::string message = "Fbc attribute 'strict' is missing from <Model> object.";
604         getErrorLog()->logPackageError("fbc", FbcModelMustHaveStrict,
605                        getPackageVersion(), sbmlLevel, sbmlVersion, message, getLine(), getColumn());
606       }
607     }
608   }
609 
610 }
611 
612 
613   /** @endcond */
614 
615 
616   /** @cond doxygenLibsbmlInternal */
617 
618 /*
619  * Write values of XMLAttributes to the output stream.
620  */
621   void
writeAttributes(XMLOutputStream & stream) const622 FbcModelPlugin::writeAttributes (XMLOutputStream& stream) const
623 {
624   SBasePlugin::writeAttributes(stream);
625 
626   if (isSetStrict() == true && getPackageVersion() != 1 && getLevel() == 3)
627     stream.writeAttribute("strict", getPrefix(), mStrict);
628 
629   Model *parent = static_cast<Model*>(const_cast<SBase*>(getParentSBMLObject()));
630   if (parent == NULL) return;
631 
632 
633   XMLNode *parentAnnotation = parent->getAnnotation();
634   if (parentAnnotation != NULL && parentAnnotation->getNumChildren() > 0)
635   {
636     deleteFbcAnnotation(parentAnnotation);
637   }
638 
639   XMLToken ann_token = XMLToken(XMLTriple("annotation", "", ""), XMLAttributes());
640   XMLNode* annt = new XMLNode(ann_token);
641 
642 
643 
644   if (mAssociations.size() > 0)
645   {
646     XMLAttributes loga_attr = XMLAttributes();
647     loga_attr.add("xmlns", FbcExtension::getXmlnsL3V1V1());
648     XMLToken loga_token = XMLToken(XMLTriple("listOfGeneAssociations", FbcExtension::getXmlnsL3V1V1(), ""), loga_attr);
649     XMLNode loga = XMLNode(loga_token);
650 
651     for (unsigned int i = 0; i < mAssociations.size(); ++i)
652       loga.addChild(mAssociations.get(i)->toXML());
653 
654     // then add the ones toXML()
655     annt->addChild(loga);
656   }
657 
658 
659   if (annt && annt->getNumChildren() > 0)
660   {
661     parent->appendAnnotation(annt);
662   }
663   delete annt;
664 }
665 
666 
667   /** @endcond */
668 
669 
670 //---------------------------------------------------------------
671 //
672 // Functions for interacting with the members of the plugin
673 //
674 //---------------------------------------------------------------
675 
676 List*
getAllElements(ElementFilter * filter)677 FbcModelPlugin::getAllElements(ElementFilter* filter)
678 {
679   List* ret = new List();
680   List* sublist = NULL;
681 
682   ADD_FILTERED_LIST(ret, sublist, mObjectives, filter);
683   ADD_FILTERED_LIST(ret, sublist, mGeneProducts, filter);
684   ADD_FILTERED_LIST(ret, sublist, mBounds, filter);
685   ADD_FILTERED_LIST(ret, sublist, mAssociations, filter);
686 
687   return ret;
688 }
689 
690 
691 
692 /*
693  * Returns the ListOfFluxBounds in this plugin object.
694  *
695  * @return ListOfFluxBounds object in this plugin object.
696  */
697 const ListOfFluxBounds*
getListOfFluxBounds() const698   FbcModelPlugin::getListOfFluxBounds () const
699 {
700   return &mBounds;
701 }
702 
703 
704 /*
705  * Returns the ListOfFluxBounds in this plugin object.
706  *
707  * @return ListOfFluxBounds object in this plugin object.
708  */
709 ListOfFluxBounds*
getListOfFluxBounds()710   FbcModelPlugin::getListOfFluxBounds ()
711 {
712   return &mBounds;
713 }
714 
715 
716 /*
717  * Returns the FluxBound object that belongs to the given index. If the
718  * index is invalid, @c NULL is returned.
719  *
720  * @param n the index number of the FluxBound to get.
721  *
722  * @return the nth FluxBound in the ListOfFluxBounds.
723  * If the index @p n is invalid, @c NULL is returned.
724  */
725 const FluxBound*
getFluxBound(unsigned int n) const726   FbcModelPlugin::getFluxBound (unsigned int n) const
727 {
728   return static_cast<const FluxBound*>(mBounds.get(n));
729 }
730 
731 
732 /*
733  * Returns the FluxBound object that belongs to the given index. If the
734  * index is invalid, @c NULL is returned.
735  *
736  * @param n the index number of the FluxBound to get.
737  *
738  * @return the nth FluxBound in the ListOfFluxBounds.
739  * If the index @p n is invalid, @c NULL is returned.
740  */
741 FluxBound*
getFluxBound(unsigned int n)742   FbcModelPlugin::getFluxBound (unsigned int n)
743 {
744   return static_cast<FluxBound*>(mBounds.get(n));
745 }
746 
747 
748 /*
749  * Returns the FluxBound object based on its identifier.
750  *
751  * @param sid a string representing the identifier
752  * of the FluxBound to get.
753  *
754  * @return FluxBound in the ListOfFluxBounds with the given @p id
755  * or NULL if no such FluxBound exists.
756  *
757  * @see get(unsigned int n)
758  * @see size()
759  */
760 FluxBound*
getFluxBound(const std::string & sid)761   FbcModelPlugin::getFluxBound (const std::string& sid)
762 {
763   return static_cast<FluxBound*>(mBounds.get(sid));
764 }
765 
766 
767 /*
768  * Returns the FluxBound object based on its identifier.
769  *
770  * @param sid a string representing the identifier
771  * of the FluxBound to get.
772  *
773  * @return FluxBound in the ListOfFluxBounds with the given @p id
774  * or NULL if no such FluxBound exists.
775  *
776  * @see get(unsigned int n)
777  * @see size()
778  */
779 const FluxBound*
getFluxBound(const std::string & sid) const780   FbcModelPlugin::getFluxBound (const std::string& sid) const
781 {
782 
783   return static_cast<const FluxBound*>(mBounds.get(sid));
784 
785 }
786 
787 /*
788  * Adds a copy of the given FluxBound object to the list of FluxBounds.
789  *
790  * @param bound the FluxBound object to be added to the list of FluxBounds.
791  *
792  * @copydetails doc_returns_success_code
793  * @li LIBSBML_OPERATION_SUCCESS
794  */
795 int
addFluxBound(const FluxBound * bound)796   FbcModelPlugin::addFluxBound (const FluxBound* bound)
797 {
798   if (!bound)
799   {
800     return LIBSBML_OPERATION_FAILED;
801   }
802   else if (!bound->hasRequiredElements())
803   {
804     return LIBSBML_INVALID_OBJECT;
805   }
806   else if (getLevel() != bound->getLevel())
807   {
808     return LIBSBML_LEVEL_MISMATCH;
809   }
810   else if (getVersion() != bound->getVersion())
811   {
812     return LIBSBML_VERSION_MISMATCH;
813   }
814   else if (getPackageVersion() != bound->getPackageVersion())
815   {
816     return LIBSBML_PKG_VERSION_MISMATCH;
817   }
818   else
819   {
820     return mBounds.append(bound);
821   }
822 }
823 
824 
825 /*
826  * Creates a new FluxBound object and adds it to the list of FluxBound objects
827  * and returns it.
828  *
829  * @return a newly created FluxBound object
830  */
831 FluxBound*
createFluxBound()832   FbcModelPlugin::createFluxBound()
833 {
834   FluxBound* bound = NULL;
835 
836   try
837   {
838     FBC_CREATE_NS_WITH_VERSION(fbcns, getSBMLNamespaces(), getPackageVersion());
839     bound = new FluxBound(fbcns);
840     delete fbcns;
841   }
842   catch(...)
843   {
844     /*
845     * NULL will be returned if the mSBMLNS is invalid (basically this
846     * should not happen) or some exception is thrown (e.g. std::bad_alloc)
847     *
848     * (Maybe this should be changed so that caller can detect what kind
849     *  of error happened in this function.)
850     */
851   }
852 
853   if (bound) mBounds.appendAndOwn(bound);
854 
855   return bound;
856 }
857 
858 
859 /*
860  * Removes the nth FluxBound object from this plugin object and
861  * returns a pointer to it.
862  *
863  * The caller owns the returned object and is responsible for
864  *  deleting it.
865  *
866  * @param n the index of the FluxBound object to remove.
867  *
868  * @return the FluxBound object removed.  As mentioned above, the
869  * caller owns the returned object. @c NULL is returned if the
870  * given index is out of range.
871  */
872 FluxBound*
removeFluxBound(unsigned int n)873   FbcModelPlugin::removeFluxBound (unsigned int n)
874 {
875   return static_cast<FluxBound*>(mBounds.remove(n));
876 }
877 
878 
879 /*
880  * Removes the FluxBound object with the given @p id attribute from
881  * this plugin object and returns a pointer to it.
882  *
883  * The caller owns the returned object and is responsible for
884  * deleting it.
885  *
886  * @param sid the id attribute of the FluxBound object to remove.
887  *
888  * @return the FluxBound object removed.  As mentioned above, the
889  * caller owns the returned object. @c NULL is returned if the
890  * given index is out of range.
891  */
892 FluxBound*
removeFluxBound(const std::string & sid)893   FbcModelPlugin::removeFluxBound (const std::string& sid)
894 {
895   return static_cast<FluxBound*>(mBounds.remove(sid));
896 }
897 
898 
899 /*
900  * Returns the number of FluxBound object in this plugin object.
901  *
902  * @return the number of FluxBound object in this plugin object.
903  */
904 unsigned int
getNumFluxBounds() const905   FbcModelPlugin::getNumFluxBounds() const
906 {
907   return mBounds.size();
908 }
909 
910 
911 
912 
913 /*
914  * Returns the value of the "strict" attribute of this FbcModelPlugin.
915  */
916 bool
getStrict() const917 FbcModelPlugin::getStrict() const
918 {
919   return mStrict;
920 }
921 
922 
923 /*
924  * Returns true/false if strict is set.
925  */
926 bool
isSetStrict() const927 FbcModelPlugin::isSetStrict() const
928 {
929   return mIsSetStrict;
930 }
931 
932 
933 /*
934  * Sets strict and returns value indicating success.
935  */
936 int
setStrict(bool strict)937 FbcModelPlugin::setStrict(bool strict)
938 {
939   mStrict = strict;
940   mIsSetStrict = true;
941   return LIBSBML_OPERATION_SUCCESS;
942 }
943 
944 
945 /*
946  * Unsets strict and returns value indicating success.
947  */
948 int
unsetStrict()949 FbcModelPlugin::unsetStrict()
950 {
951   mStrict = false;
952   mIsSetStrict = false;
953   return LIBSBML_OPERATION_SUCCESS;
954 }
955 
956 
957 /*
958  * Returns the  "ListOfObjectives" in this FbcModelPlugin object.
959  */
960 const ListOfObjectives*
getListOfObjectives() const961 FbcModelPlugin::getListOfObjectives() const
962 {
963   return &mObjectives;
964 }
965 
966 
967 /*
968  * Returns the  "ListOfObjectives" in this FbcModelPlugin object.
969  */
970 ListOfObjectives*
getListOfObjectives()971 FbcModelPlugin::getListOfObjectives()
972 {
973   return &mObjectives;
974 }
975 
976 
977 /*
978  * Removes the nth Objective from the ListOfObjectives.
979  */
980 Objective*
removeObjective(unsigned int n)981 FbcModelPlugin::removeObjective(unsigned int n)
982 {
983   return mObjectives.remove(n);
984 }
985 
986 
987 /*
988  * Removes the a Objective with given id from the ListOfObjectives.
989  */
990 Objective*
removeObjective(const std::string & sid)991 FbcModelPlugin::removeObjective(const std::string& sid)
992 {
993   return mObjectives.remove(sid);
994 }
995 
996 
997 /*
998  * Return the nth Objective in the ListOfObjectives within this FbcModelPlugin.
999  */
1000 Objective*
getObjective(unsigned int n)1001 FbcModelPlugin::getObjective(unsigned int n)
1002 {
1003   return mObjectives.get(n);
1004 }
1005 
1006 
1007 /*
1008  * Return the nth Objective in the ListOfObjectives within this FbcModelPlugin.
1009  */
1010 const Objective*
getObjective(unsigned int n) const1011 FbcModelPlugin::getObjective(unsigned int n) const
1012 {
1013   return mObjectives.get(n);
1014 }
1015 
1016 
1017 /*
1018  * Return a Objective from the ListOfObjectives by id.
1019  */
1020 Objective*
getObjective(const std::string & sid)1021 FbcModelPlugin::getObjective(const std::string& sid)
1022 {
1023   return mObjectives.get(sid);
1024 }
1025 
1026 
1027 /*
1028  * Return a Objective from the ListOfObjectives by id.
1029  */
1030 const Objective*
getObjective(const std::string & sid) const1031 FbcModelPlugin::getObjective(const std::string& sid) const
1032 {
1033   return mObjectives.get(sid);
1034 }
1035 
1036 
1037 /*
1038  * Adds a copy the given Objective to this FbcModelPlugin.
1039  *
1040  * @param o the Objective object to add.
1041  *
1042  * @copydetails doc_returns_success_code
1043  * @li LIBSBML_OPERATION_SUCCESS
1044  * @li LIBSBML_INVALID_ATTRIBUTE_VALUE
1045  */
1046 int
addObjective(const Objective * o)1047 FbcModelPlugin::addObjective(const Objective* o)
1048 {
1049   if (o == NULL)
1050   {
1051     return LIBSBML_OPERATION_FAILED;
1052   }
1053   else if (o->hasRequiredAttributes() == false)
1054   {
1055     return LIBSBML_INVALID_OBJECT;
1056   }
1057   else if (getLevel() != o->getLevel())
1058   {
1059     return LIBSBML_LEVEL_MISMATCH;
1060   }
1061   else if (getVersion() != o->getVersion())
1062   {
1063     return LIBSBML_VERSION_MISMATCH;
1064   }
1065   else if (getPackageVersion() != o->getPackageVersion())
1066   {
1067     return LIBSBML_PKG_VERSION_MISMATCH;
1068   }
1069   else
1070   {
1071     return mObjectives.append(o);
1072   }
1073 }
1074 
1075 
1076 /*
1077  * Get the number of Objective objects in this FbcModelPlugin.
1078  *
1079  * @return the number of Objective objects in this FbcModelPlugin
1080  */
1081 unsigned int
getNumObjectives() const1082 FbcModelPlugin::getNumObjectives() const
1083 {
1084   return mObjectives.size();
1085 }
1086 
1087 
1088 /*
1089  * Creates a new Objective object, adds it to this FbcModelPlugin's
1090  * FbcModelPlugin and returns the Objective object created.
1091  *
1092  * @return a new Objective object instance
1093  *
1094  * @see addObjective(const Objective* o)
1095  */
1096 Objective*
createObjective()1097 FbcModelPlugin::createObjective()
1098 {
1099   Objective* o = NULL;
1100 
1101   try
1102   {
1103     FBC_CREATE_NS_WITH_VERSION(fbcns, getSBMLNamespaces(), getPackageVersion());
1104     o = new Objective(fbcns);
1105     delete fbcns;
1106   }
1107   catch (...)
1108   {
1109     /* here we do not create a default object as the level/version must
1110      * match the parent object
1111      *
1112      * do nothing
1113      */
1114   }
1115 
1116   if(o != NULL)
1117   {
1118     mObjectives.appendAndOwn(o);
1119   }
1120 
1121   return o;
1122 }
1123 
1124 
1125 /*
1126  * Returns the  "ListOfGeneProducts" in this FbcModelPlugin object.
1127  */
1128 const ListOfGeneProducts*
getListOfGeneProducts() const1129 FbcModelPlugin::getListOfGeneProducts() const
1130 {
1131   return &mGeneProducts;
1132 }
1133 
1134 
1135 /*
1136  * Returns the  "ListOfGeneProducts" in this FbcModelPlugin object.
1137  */
1138 ListOfGeneProducts*
getListOfGeneProducts()1139 FbcModelPlugin::getListOfGeneProducts()
1140 {
1141   return &mGeneProducts;
1142 }
1143 
1144 
1145 /*
1146  * Removes the nth GeneProduct from the ListOfGeneProducts.
1147  */
1148 GeneProduct*
removeGeneProduct(unsigned int n)1149 FbcModelPlugin::removeGeneProduct(unsigned int n)
1150 {
1151   return mGeneProducts.remove(n);
1152 }
1153 
1154 
1155 /*
1156  * Removes the a GeneProduct with given id from the ListOfGeneProducts.
1157  */
1158 GeneProduct*
removeGeneProduct(const std::string & sid)1159 FbcModelPlugin::removeGeneProduct(const std::string& sid)
1160 {
1161   return mGeneProducts.remove(sid);
1162 }
1163 
1164 
1165 /*
1166  * Return the nth GeneProduct in the ListOfGeneProducts within this FbcModelPlugin.
1167  */
1168 GeneProduct*
getGeneProduct(unsigned int n)1169 FbcModelPlugin::getGeneProduct(unsigned int n)
1170 {
1171   return mGeneProducts.get(n);
1172 }
1173 
1174 
1175 /*
1176  * Return the nth GeneProduct in the ListOfGeneProducts within this FbcModelPlugin.
1177  */
1178 const GeneProduct*
getGeneProduct(unsigned int n) const1179 FbcModelPlugin::getGeneProduct(unsigned int n) const
1180 {
1181   return mGeneProducts.get(n);
1182 }
1183 
1184 
1185 /*
1186  * Return a GeneProduct from the ListOfGeneProducts by id.
1187  */
1188 GeneProduct*
getGeneProduct(const std::string & sid)1189 FbcModelPlugin::getGeneProduct(const std::string& sid)
1190 {
1191   return mGeneProducts.get(sid);
1192 }
1193 
1194 GeneProduct*
getGeneProductByLabel(const std::string & label)1195 FbcModelPlugin::getGeneProductByLabel(const std::string& label)
1196 {
1197   for (unsigned int i = 0; i < mGeneProducts.size(); ++i)
1198   {
1199     GeneProduct* current = mGeneProducts.get(i);
1200     if (current != NULL && current->getLabel() == label)
1201       return current;
1202   }
1203   return NULL;
1204 }
1205 
1206 
1207 /*
1208  * Return a GeneProduct from the ListOfGeneProducts by id.
1209  */
1210 const GeneProduct*
getGeneProduct(const std::string & sid) const1211 FbcModelPlugin::getGeneProduct(const std::string& sid) const
1212 {
1213   return mGeneProducts.get(sid);
1214 }
1215 
1216 
1217 /*
1218  * Adds a copy the given GeneProduct to this FbcModelPlugin.
1219  *
1220  * @param gp the GeneProduct object to add.
1221  *
1222    * @copydetails doc_returns_success_code
1223  * @li LIBSBML_OPERATION_SUCCESS
1224  * @li LIBSBML_INVALID_ATTRIBUTE_VALUE
1225  */
1226 int
addGeneProduct(const GeneProduct * gp)1227 FbcModelPlugin::addGeneProduct(const GeneProduct* gp)
1228 {
1229   if (gp == NULL)
1230   {
1231     return LIBSBML_OPERATION_FAILED;
1232   }
1233   else if (gp->hasRequiredAttributes() == false)
1234   {
1235     return LIBSBML_INVALID_OBJECT;
1236   }
1237   else if (getLevel() != gp->getLevel())
1238   {
1239     return LIBSBML_LEVEL_MISMATCH;
1240   }
1241   else if (getVersion() != gp->getVersion())
1242   {
1243     return LIBSBML_VERSION_MISMATCH;
1244   }
1245   else if (getPackageVersion() != gp->getPackageVersion())
1246   {
1247     return LIBSBML_PKG_VERSION_MISMATCH;
1248   }
1249   else
1250   {
1251     return mGeneProducts.append(gp);
1252   }
1253 }
1254 
1255 
1256 /*
1257  * Get the number of GeneProduct objects in this FbcModelPlugin.
1258  *
1259  * @return the number of GeneProduct objects in this FbcModelPlugin
1260  */
1261 unsigned int
getNumGeneProducts() const1262 FbcModelPlugin::getNumGeneProducts() const
1263 {
1264   return mGeneProducts.size();
1265 }
1266 
1267 
1268 /*
1269  * Creates a new GeneProduct object, adds it to this FbcModelPlugin's
1270  * FbcModelPlugin and returns the GeneProduct object created.
1271  *
1272  * @return a new GeneProduct object instance
1273  *
1274  * @see addGeneProduct(const GeneProduct* gp)
1275  */
1276 GeneProduct*
createGeneProduct()1277 FbcModelPlugin::createGeneProduct()
1278 {
1279   GeneProduct* gp = NULL;
1280 
1281   try
1282   {
1283     FBC_CREATE_NS_WITH_VERSION(fbcns, getSBMLNamespaces(), getPackageVersion());
1284     gp = new GeneProduct(fbcns);
1285     delete fbcns;
1286   }
1287   catch (...)
1288   {
1289     /* here we do not create a default object as the level/version must
1290      * match the parent object
1291      *
1292      * do nothing
1293      */
1294   }
1295 
1296   if(gp != NULL)
1297   {
1298     mGeneProducts.appendAndOwn(gp);
1299   }
1300 
1301   return gp;
1302 }
1303 
1304 
1305 
1306 /*
1307  * Returns the current active objective.
1308  */
1309 Objective*
getActiveObjective()1310 FbcModelPlugin::getActiveObjective()
1311 {
1312   return getObjective(getActiveObjectiveId());
1313 }
1314 
1315 /*
1316  * Returns the current active objective.
1317  */
1318 const Objective *
getActiveObjective() const1319 FbcModelPlugin::getActiveObjective() const
1320 {
1321   return getObjective(getActiveObjectiveId());
1322 }
1323 
1324 /*
1325  * Sets the id of the active objective.
1326  */
1327 int
setActiveObjectiveId(const std::string & objectiveId)1328 FbcModelPlugin::setActiveObjectiveId(const std::string& objectiveId)
1329 {
1330   return mObjectives.setActiveObjective(objectiveId);
1331 }
1332 
1333 /*
1334  * returns the id of the current active objective.
1335  */
1336 std::string
getActiveObjectiveId() const1337 FbcModelPlugin::getActiveObjectiveId() const
1338 {
1339   return mObjectives.getActiveObjective();
1340 }
1341 
1342 /*
1343  * Unsets the active objective.
1344  */
1345 int
unsetActiveObjectiveId()1346 FbcModelPlugin::unsetActiveObjectiveId()
1347 {
1348   mObjectives.unsetActiveObjective();
1349   return LIBSBML_OPERATION_SUCCESS;
1350 }
1351 
1352 /*
1353  * Returns the ListOfObjectives in this plugin object.
1354  *
1355  * @return ListOfObjectives object in this plugin object.
1356  */
1357 const ListOfGeneAssociations*
getListOfGeneAssociations() const1358   FbcModelPlugin::getListOfGeneAssociations () const
1359 {
1360   return &mAssociations;
1361 }
1362 
1363 /*
1364  * Returns the ListOfGeneAssociations in this plugin object.
1365  *
1366  * @return ListOfGeneAssociations object in this plugin object.
1367  */
1368 ListOfGeneAssociations*
getListOfGeneAssociations()1369   FbcModelPlugin::getListOfGeneAssociations ()
1370 {
1371   return &mAssociations;
1372 }
1373 
1374 /*
1375  * Returns the GeneAssociation object that belongs to the given index. If the
1376  * index is invalid, @c NULL is returned.
1377  *
1378  * @param n the index number of the GeneAssociation to get.
1379  *
1380  * @return the nth GeneAssociation in the ListOfGeneAssociations.
1381  * If the index @p n is invalid, @c NULL is returned.
1382  */
1383 const GeneAssociation*
getGeneAssociation(unsigned int n) const1384   FbcModelPlugin::getGeneAssociation (unsigned int n) const
1385 {
1386   return static_cast<const GeneAssociation*>(mAssociations.get(n));
1387 }
1388 
1389 /*
1390  * Returns the GeneAssociation object that belongs to the given index. If the
1391  * index is invalid, @c NULL is returned.
1392  *
1393  * @param n the index number of the GeneAssociation to get.
1394  *
1395  * @return the nth GeneAssociation in the ListOfGeneAssociations.
1396  * If the index @p n is invalid, @c NULL is returned.
1397  */
1398 GeneAssociation*
getGeneAssociation(unsigned int n)1399   FbcModelPlugin::getGeneAssociation (unsigned int n)
1400 {
1401   return static_cast<GeneAssociation*>(mAssociations.get(n));
1402 }
1403 
1404 /*
1405  * Returns the GeneAssociation object based on its identifier.
1406  *
1407  * @param sid a string representing the identifier
1408  * of the GeneAssociation to get.
1409  *
1410  * @return GeneAssociation in the ListOfGeneAssociations with the given @p id
1411  * or NULL if no such GeneAssociation exists.
1412  *
1413  * @see get(unsigned int n)
1414  * @see size()
1415  */
1416 GeneAssociation*
getGeneAssociation(const std::string & sid)1417   FbcModelPlugin::getGeneAssociation (const std::string& sid)
1418 {
1419   return static_cast<GeneAssociation*>(mAssociations.get(sid));
1420 }
1421 
1422 /*
1423  * Returns the GeneAssociation object based on its identifier.
1424  *
1425  * @param sid a string representing the identifier
1426  * of the GeneAssociation to get.
1427  *
1428  * @return GeneAssociation in the ListOfGeneAssociations with the given @p id
1429  * or NULL if no such GeneAssociation exists.
1430  *
1431  * @see get(unsigned int n)
1432  * @see size()
1433  */
1434 const GeneAssociation*
getGeneAssociation(const std::string & sid) const1435   FbcModelPlugin::getGeneAssociation (const std::string& sid) const
1436 {
1437   return static_cast<const GeneAssociation*>(mAssociations.get(sid));
1438 }
1439 
1440 /*
1441  * Adds a copy of the given GeneAssociation object to the list of GeneAssociations.
1442  *
1443  * @param association the GeneAssociation object to be added to the list of GeneAssociations.
1444  *
1445  * @copydetails doc_returns_success_code
1446  * @li LIBSBML_OPERATION_SUCCESS
1447  */
1448 int
addGeneAssociation(const GeneAssociation * association)1449   FbcModelPlugin::addGeneAssociation (const GeneAssociation* association)
1450 {
1451   if (!association)
1452   {
1453     return LIBSBML_OPERATION_FAILED;
1454   }
1455   else if (!association->hasRequiredElements())
1456   {
1457     return LIBSBML_INVALID_OBJECT;
1458   }
1459   else if (getLevel() != association->getLevel())
1460   {
1461     return LIBSBML_LEVEL_MISMATCH;
1462   }
1463   else if (getVersion() != association->getVersion())
1464   {
1465     return LIBSBML_VERSION_MISMATCH;
1466   }
1467   else if (getPackageVersion() != association->getPackageVersion())
1468   {
1469     return LIBSBML_PKG_VERSION_MISMATCH;
1470   }
1471   else
1472   {
1473     return mAssociations.append(association);
1474   }
1475 }
1476 
1477 /*
1478  * Creates a new GeneAssociation object and adds it to the list of GeneAssociation objects
1479  * and returns it.
1480  *
1481  * @return a newly created GeneAssociation object
1482  */
1483 GeneAssociation*
createGeneAssociation()1484   FbcModelPlugin::createGeneAssociation()
1485 {
1486   GeneAssociation* association = NULL;
1487 
1488   try
1489   {
1490     FBC_CREATE_NS_WITH_VERSION(fbcns, getSBMLNamespaces(), getPackageVersion());
1491     association = new GeneAssociation(fbcns);
1492     delete fbcns;
1493   }
1494   catch(...)
1495   {
1496     /*
1497     * NULL will be returned if the mSBMLNS is invalid (basically this
1498     * should not happen) or some exception is thrown (e.g. std::bad_alloc)
1499     *
1500     * (Maybe this should be changed so that caller can detect what kind
1501     *  of error happened in this function.)
1502     */
1503   }
1504 
1505   if (association) mAssociations.appendAndOwn(association);
1506 
1507   return association;
1508 }
1509 
1510 /*
1511  * Removes the nth GeneAssociation object from this plugin object and
1512  * returns a pointer to it.
1513  *
1514  * The caller owns the returned object and is responsible for
1515  *  deleting it.
1516  *
1517  * @param n the index of the GeneAssociation object to remove.
1518  *
1519  * @return the GeneAssociation object removed.  As mentioned above, the
1520  * caller owns the returned object. @c NULL is returned if the
1521  * given index is out of range.
1522  */
1523 GeneAssociation*
removeGeneAssociation(unsigned int n)1524   FbcModelPlugin::removeGeneAssociation (unsigned int n)
1525 {
1526   return static_cast<GeneAssociation*>(mAssociations.remove(n));
1527 }
1528 
1529 /*
1530  * Removes the GeneAssociation object with the given @p id attribute from
1531  * this plugin object and returns a pointer to it.
1532  *
1533  * The caller owns the returned object and is responsible for
1534  * deleting it.
1535  *
1536  * @param sid the id attribute of the GeneAssociation object to remove.
1537  *
1538  * @return the GeneAssociation object removed.  As mentioned above, the
1539  * caller owns the returned object. @c NULL is returned if the
1540  * given index is out of range.
1541  */
1542 GeneAssociation*
removeGeneAssociation(const std::string & sid)1543   FbcModelPlugin::removeGeneAssociation (const std::string& sid)
1544 {
1545   return static_cast<GeneAssociation*>(mAssociations.remove(sid));
1546 }
1547 
1548 /*
1549  * Returns the number of GeneAssociation object in this plugin object.
1550  *
1551  * @return the number of GeneAssociation object in this plugin object.
1552  */
1553 int
getNumGeneAssociations() const1554   FbcModelPlugin::getNumGeneAssociations() const
1555 {
1556   return (int)mAssociations.size();
1557 }
1558 
1559 
1560 //---------------------------------------------------------------
1561 
1562 
1563 /** @cond doxygenLibsbmlInternal */
1564 /*
1565  * Sets the parent SBMLDocument of this SBML object.
1566  *
1567  * @param d the SBMLDocument object to use.
1568  */
1569 void
setSBMLDocument(SBMLDocument * d)1570 FbcModelPlugin::setSBMLDocument(SBMLDocument* d)
1571 {
1572   SBasePlugin::setSBMLDocument(d);
1573 
1574   mBounds.setSBMLDocument(d);
1575   mAssociations.setSBMLDocument(d);
1576   mObjectives.setSBMLDocument(d);
1577   mGeneProducts.setSBMLDocument(d);
1578 }
1579 /** @endcond */
1580 
1581 
1582 /** @cond doxygenLibsbmlInternal */
1583 void
connectToChild()1584 FbcModelPlugin::connectToChild()
1585 {
1586   connectToParent(getParentSBMLObject());
1587 }
1588 /** @endcond */
1589 
1590 /** @cond doxygenLibsbmlInternal */
1591 /*
1592  * Connect to parent.
1593  */
1594 void
connectToParent(SBase * sbase)1595 FbcModelPlugin::connectToParent(SBase* sbase)
1596 {
1597   SBasePlugin::connectToParent(sbase);
1598 
1599   if (getNumObjectives() > 0)
1600   {
1601     mObjectives.connectToParent(sbase);
1602   }
1603   mAssociations.connectToParent(sbase);
1604   mBounds.connectToParent(sbase);
1605   if (getNumGeneProducts() > 0)
1606   {
1607     mGeneProducts.connectToParent(sbase);
1608   }
1609 }
1610 /** @endcond */
1611 
1612 
1613 /** @cond doxygenLibsbmlInternal */
1614 /*
1615  * Enables the given package.
1616  */
1617 void
enablePackageInternal(const std::string & pkgURI,const std::string & pkgPrefix,bool flag)1618 FbcModelPlugin::enablePackageInternal(const std::string& pkgURI,
1619                                    const std::string& pkgPrefix, bool flag)
1620 {
1621   mAssociations.enablePackageInternal(pkgURI,pkgPrefix,flag);
1622   mBounds.enablePackageInternal(pkgURI,pkgPrefix,flag);
1623   if (getNumObjectives() > 0)
1624   {
1625     mObjectives.enablePackageInternal(pkgURI, pkgPrefix, flag);
1626   }
1627   if (getNumGeneProducts() > 0)
1628   {
1629     mGeneProducts.enablePackageInternal(pkgURI, pkgPrefix, flag);
1630   }
1631 }
1632 /** @endcond */
1633 /** @cond doxygenLibsbmlInternal */
1634 
1635 /*
1636  * Returns the value of the "attributeName" attribute of this FbcModelPlugin.
1637  */
1638 int
getAttribute(const std::string & attributeName,bool & value) const1639 FbcModelPlugin::getAttribute(const std::string& attributeName,
1640                              bool& value) const
1641 {
1642   int return_value = SBasePlugin::getAttribute(attributeName, value);
1643 
1644   if (return_value == LIBSBML_OPERATION_SUCCESS)
1645   {
1646     return return_value;
1647   }
1648 
1649   if (attributeName == "strict")
1650   {
1651     value = getStrict();
1652     return_value = LIBSBML_OPERATION_SUCCESS;
1653   }
1654 
1655   return return_value;
1656 }
1657 
1658 /** @endcond */
1659 
1660 
1661 
1662 /** @cond doxygenLibsbmlInternal */
1663 
1664 /*
1665  * Returns the value of the "attributeName" attribute of this FbcModelPlugin.
1666  */
1667 int
getAttribute(const std::string & attributeName,int & value) const1668 FbcModelPlugin::getAttribute(const std::string& attributeName,
1669                              int& value) const
1670 {
1671   int return_value = SBasePlugin::getAttribute(attributeName, value);
1672 
1673   return return_value;
1674 }
1675 
1676 /** @endcond */
1677 
1678 
1679 
1680 /** @cond doxygenLibsbmlInternal */
1681 
1682 /*
1683  * Returns the value of the "attributeName" attribute of this FbcModelPlugin.
1684  */
1685 int
getAttribute(const std::string & attributeName,double & value) const1686 FbcModelPlugin::getAttribute(const std::string& attributeName,
1687                              double& value) const
1688 {
1689   int return_value = SBasePlugin::getAttribute(attributeName, value);
1690 
1691   return return_value;
1692 }
1693 
1694 /** @endcond */
1695 
1696 
1697 
1698 /** @cond doxygenLibsbmlInternal */
1699 
1700 /*
1701  * Returns the value of the "attributeName" attribute of this FbcModelPlugin.
1702  */
1703 int
getAttribute(const std::string & attributeName,unsigned int & value) const1704 FbcModelPlugin::getAttribute(const std::string& attributeName,
1705                              unsigned int& value) const
1706 {
1707   int return_value = SBasePlugin::getAttribute(attributeName, value);
1708 
1709   return return_value;
1710 }
1711 
1712 /** @endcond */
1713 
1714 
1715 
1716 /** @cond doxygenLibsbmlInternal */
1717 
1718 /*
1719  * Returns the value of the "attributeName" attribute of this FbcModelPlugin.
1720  */
1721 int
getAttribute(const std::string & attributeName,std::string & value) const1722 FbcModelPlugin::getAttribute(const std::string& attributeName,
1723                              std::string& value) const
1724 {
1725   int return_value = SBasePlugin::getAttribute(attributeName, value);
1726 
1727   if (attributeName == "activeObjective")
1728   {
1729     value = getActiveObjectiveId();
1730     return_value = LIBSBML_OPERATION_SUCCESS;
1731   }
1732   return return_value;
1733 }
1734 
1735 /** @endcond */
1736 
1737 
1738 
1739 /** @cond doxygenLibsbmlInternal */
1740 
1741 /*
1742  * Predicate returning @c true if this FbcModelPlugin's attribute
1743  * "attributeName" is set.
1744  */
1745 bool
isSetAttribute(const std::string & attributeName) const1746 FbcModelPlugin::isSetAttribute(const std::string& attributeName) const
1747 {
1748   bool value = SBasePlugin::isSetAttribute(attributeName);
1749 
1750   if (attributeName == "strict")
1751   {
1752     value = isSetStrict();
1753   }
1754   else if (attributeName == "activeObjective")
1755   {
1756     value = (getActiveObjectiveId().empty() == false);
1757   }
1758 
1759   return value;
1760 }
1761 
1762 /** @endcond */
1763 
1764 
1765 
1766 /** @cond doxygenLibsbmlInternal */
1767 
1768 /*
1769  * Sets the value of the "attributeName" attribute of this FbcModelPlugin.
1770  */
1771 int
setAttribute(const std::string & attributeName,bool value)1772 FbcModelPlugin::setAttribute(const std::string& attributeName, bool value)
1773 {
1774   int return_value = SBasePlugin::setAttribute(attributeName, value);
1775 
1776   if (attributeName == "strict")
1777   {
1778     return_value = setStrict(value);
1779   }
1780 
1781   return return_value;
1782 }
1783 
1784 /** @endcond */
1785 
1786 
1787 
1788 /** @cond doxygenLibsbmlInternal */
1789 
1790 /*
1791  * Sets the value of the "attributeName" attribute of this FbcModelPlugin.
1792  */
1793 int
setAttribute(const std::string & attributeName,int value)1794 FbcModelPlugin::setAttribute(const std::string& attributeName, int value)
1795 {
1796   int return_value = SBasePlugin::setAttribute(attributeName, value);
1797 
1798   return return_value;
1799 }
1800 
1801 /** @endcond */
1802 
1803 
1804 
1805 /** @cond doxygenLibsbmlInternal */
1806 
1807 /*
1808  * Sets the value of the "attributeName" attribute of this FbcModelPlugin.
1809  */
1810 int
setAttribute(const std::string & attributeName,double value)1811 FbcModelPlugin::setAttribute(const std::string& attributeName, double value)
1812 {
1813   int return_value = SBasePlugin::setAttribute(attributeName, value);
1814 
1815   return return_value;
1816 }
1817 
1818 /** @endcond */
1819 
1820 
1821 
1822 /** @cond doxygenLibsbmlInternal */
1823 
1824 /*
1825  * Sets the value of the "attributeName" attribute of this FbcModelPlugin.
1826  */
1827 int
setAttribute(const std::string & attributeName,unsigned int value)1828 FbcModelPlugin::setAttribute(const std::string& attributeName,
1829                              unsigned int value)
1830 {
1831   int return_value = SBasePlugin::setAttribute(attributeName, value);
1832 
1833   return return_value;
1834 }
1835 
1836 /** @endcond */
1837 
1838 
1839 
1840 /** @cond doxygenLibsbmlInternal */
1841 
1842 /*
1843  * Sets the value of the "attributeName" attribute of this FbcModelPlugin.
1844  */
1845 int
setAttribute(const std::string & attributeName,const std::string & value)1846 FbcModelPlugin::setAttribute(const std::string& attributeName,
1847                              const std::string& value)
1848 {
1849   int return_value = SBasePlugin::setAttribute(attributeName, value);
1850 
1851   if (attributeName == "activeObjective")
1852   {
1853     return_value = setActiveObjectiveId(value);
1854   }
1855   return return_value;
1856 }
1857 
1858 /** @endcond */
1859 
1860 
1861 
1862 /** @cond doxygenLibsbmlInternal */
1863 
1864 /*
1865  * Unsets the value of the "attributeName" attribute of this FbcModelPlugin.
1866  */
1867 int
unsetAttribute(const std::string & attributeName)1868 FbcModelPlugin::unsetAttribute(const std::string& attributeName)
1869 {
1870   int value = SBasePlugin::unsetAttribute(attributeName);
1871 
1872   if (attributeName == "strict")
1873   {
1874     value = unsetStrict();
1875   }
1876   if (attributeName == "activeObjective")
1877   {
1878     value = unsetActiveObjectiveId();
1879   }
1880 
1881   return value;
1882 }
1883 
1884 /** @endcond */
1885 
1886 
1887 
1888 /** @cond doxygenLibsbmlInternal */
1889 
1890 /*
1891  * Creates and returns an new "elementName" object in this FbcModelPlugin.
1892  */
1893 SBase*
createChildObject(const std::string & elementName)1894 FbcModelPlugin::createChildObject(const std::string& elementName)
1895 {
1896   SBase* obj = NULL;
1897 
1898   if (elementName == "objective")
1899   {
1900     return createObjective();
1901   }
1902   else if (elementName == "fluxBound")
1903   {
1904     return createFluxBound();
1905   }
1906   else if (elementName == "geneProduct")
1907   {
1908     return createGeneProduct();
1909   }
1910 
1911   return obj;
1912 }
1913 
1914 /** @endcond */
1915 
1916 
1917 
1918 /** @cond doxygenLibsbmlInternal */
1919 
1920 /*
1921  * Returns the number of "elementName" in this FbcModelPlugin.
1922  */
1923 unsigned int
getNumObjects(const std::string & elementName)1924 FbcModelPlugin::getNumObjects(const std::string& elementName)
1925 {
1926   unsigned int n = 0;
1927 
1928   if (elementName == "objective")
1929   {
1930     return getNumObjectives();
1931   }
1932   else if (elementName == "fluxBound")
1933   {
1934     return getNumFluxBounds();
1935   }
1936   else if (elementName == "geneProduct")
1937   {
1938     return getNumGeneProducts();
1939   }
1940 
1941   return n;
1942 }
1943 
1944 /** @endcond */
1945 
1946 
1947 
1948 /** @cond doxygenLibsbmlInternal */
1949 
1950 /*
1951  * Returns the nth object of "objectName" in this FbcModelPlugin.
1952  */
1953 SBase*
getObject(const std::string & elementName,unsigned int index)1954 FbcModelPlugin::getObject(const std::string& elementName, unsigned int index)
1955 {
1956   SBase* obj = NULL;
1957 
1958   if (elementName == "objective")
1959   {
1960     return getObjective(index);
1961   }
1962   else if (elementName == "fluxBound")
1963   {
1964     return getFluxBound(index);
1965   }
1966   else if (elementName == "geneProduct")
1967   {
1968     return getGeneProduct(index);
1969   }
1970 
1971   return obj;
1972 }
1973 
1974 /** @endcond */
1975 
1976 
1977 /** @cond doxygenLibsbmlInternal */
1978 
1979 /*
1980  * Accept the SBMLVisitor.
1981  */
1982 bool
accept(SBMLVisitor & v) const1983 FbcModelPlugin::accept(SBMLVisitor& v) const
1984 {
1985   const Model * model = static_cast<const Model * >(this->getParentSBMLObject());
1986 
1987   v.visit(*model);
1988   v.leave(*model);
1989 
1990   for (unsigned int i = 0; i < getNumFluxBounds(); i++)
1991   {
1992     getFluxBound(i)->accept(v);
1993   }
1994   for (unsigned int i = 0; i < getNumObjectives(); i++)
1995   {
1996     getListOfObjectives()->accept(v);
1997     getObjective(i)->accept(v);
1998   }
1999 
2000   for(unsigned int i = 0; i < getNumGeneProducts(); i++)
2001   {
2002     getGeneProduct(i)->accept(v);
2003   }
2004 
2005   return true;
2006 }
2007 /** @endcond */
2008 
2009 
2010 
2011 ListOfFluxBounds *
getFluxBoundsForReaction(const std::string & reaction) const2012 FbcModelPlugin::getFluxBoundsForReaction(const std::string& reaction) const
2013 {
2014   ListOfFluxBounds * loFB = new ListOfFluxBounds(getLevel(), getVersion(),
2015     getPackageVersion());
2016 
2017 
2018   for (unsigned int i = 0; i < getNumFluxBounds(); i++)
2019   {
2020     if (getFluxBound(i)->getReaction() == reaction)
2021     {
2022       loFB->append(getFluxBound(i));
2023     }
2024   }
2025 
2026   if (loFB->size() == 0)
2027   {
2028     delete loFB;
2029     loFB = NULL;
2030   }
2031 
2032   return loFB;
2033 }
2034 
2035 #endif /* __cplusplus */
2036 
2037 /** @cond doxygenIgnored */
2038 LIBSBML_EXTERN
2039 int
FbcModelPlugin_addFluxBound(SBasePlugin_t * fbc,FluxBound_t * fb)2040 FbcModelPlugin_addFluxBound(SBasePlugin_t * fbc, FluxBound_t * fb)
2041 {
2042   return (fbc != NULL) ? static_cast<FbcModelPlugin*>(fbc)->addFluxBound(fb)
2043     : LIBSBML_INVALID_OBJECT;
2044 }
2045 
2046 
2047 LIBSBML_EXTERN
2048 FluxBound_t *
FbcModelPlugin_getFluxBound(SBasePlugin_t * fbc,unsigned int n)2049 FbcModelPlugin_getFluxBound(SBasePlugin_t * fbc, unsigned int n)
2050 {
2051   return (fbc != NULL) ? static_cast<FbcModelPlugin*>(fbc)->getFluxBound(n)
2052     : NULL;
2053 }
2054 
2055 
2056 LIBSBML_EXTERN
2057 unsigned int
FbcModelPlugin_getNumFluxBounds(SBasePlugin_t * fbc)2058 FbcModelPlugin_getNumFluxBounds(SBasePlugin_t * fbc)
2059 {
2060   return (fbc != NULL) ? static_cast<FbcModelPlugin*>(fbc)->getNumFluxBounds()
2061     : SBML_INT_MAX;
2062 }
2063 
2064 
2065 LIBSBML_EXTERN
2066 int
FbcModelPlugin_addObjective(SBasePlugin_t * fbc,Objective_t * obj)2067 FbcModelPlugin_addObjective(SBasePlugin_t * fbc, Objective_t * obj)
2068 {
2069   return (fbc != NULL) ? static_cast<FbcModelPlugin*>(fbc)->addObjective(obj)
2070     : LIBSBML_INVALID_OBJECT;
2071 }
2072 
2073 
2074 LIBSBML_EXTERN
2075 Objective_t *
FbcModelPlugin_getObjective(SBasePlugin_t * fbc,unsigned int n)2076 FbcModelPlugin_getObjective(SBasePlugin_t * fbc, unsigned int n)
2077 {
2078   return (fbc != NULL) ? static_cast<FbcModelPlugin*>(fbc)->getObjective(n)
2079     : NULL;
2080 }
2081 
2082 
2083 LIBSBML_EXTERN
2084 unsigned int
FbcModelPlugin_getNumObjectives(SBasePlugin_t * fbc)2085 FbcModelPlugin_getNumObjectives(SBasePlugin_t * fbc)
2086 {
2087   return (fbc != NULL) ? static_cast<FbcModelPlugin*>(fbc)->getNumObjectives()
2088     : SBML_INT_MAX;
2089 }
2090 
2091 
2092 LIBSBML_EXTERN
2093 char *
FbcModelPlugin_getActiveObjectiveId(SBasePlugin_t * fbc)2094 FbcModelPlugin_getActiveObjectiveId(SBasePlugin_t * fbc)
2095 {
2096   if (fbc == NULL)
2097     return NULL;
2098 
2099   return static_cast<FbcModelPlugin *>(fbc)->getActiveObjectiveId().empty()
2100     ? safe_strdup("")
2101     : safe_strdup(static_cast<FbcModelPlugin *>(fbc)->getActiveObjectiveId().c_str());
2102 }
2103 
2104 
2105 LIBSBML_EXTERN
2106 int
FbcModelPlugin_setActiveObjectiveId(SBasePlugin_t * fbc,const char * activeId)2107 FbcModelPlugin_setActiveObjectiveId(SBasePlugin_t * fbc, const char * activeId)
2108 {
2109   return (fbc != NULL)
2110     ? static_cast<FbcModelPlugin *>(fbc)->setActiveObjectiveId(activeId)
2111     : LIBSBML_INVALID_OBJECT;
2112 }
2113 
2114 
2115 LIBSBML_EXTERN
2116 int
FbcModelPlugin_addGeneProduct(SBasePlugin_t * fbc,GeneProduct_t * fb)2117 FbcModelPlugin_addGeneProduct(SBasePlugin_t * fbc, GeneProduct_t * fb)
2118 {
2119   return (fbc != NULL) ? static_cast<FbcModelPlugin*>(fbc)->addGeneProduct(fb)
2120     : LIBSBML_INVALID_OBJECT;
2121 }
2122 
2123 
2124 LIBSBML_EXTERN
2125 GeneProduct_t *
FbcModelPlugin_getGeneProduct(SBasePlugin_t * fbc,unsigned int n)2126 FbcModelPlugin_getGeneProduct(SBasePlugin_t * fbc, unsigned int n)
2127 {
2128   return (fbc != NULL) ? static_cast<FbcModelPlugin*>(fbc)->getGeneProduct(n)
2129     : NULL;
2130 }
2131 
2132 
2133 LIBSBML_EXTERN
2134 unsigned int
FbcModelPlugin_getNumGeneProducts(SBasePlugin_t * fbc)2135 FbcModelPlugin_getNumGeneProducts(SBasePlugin_t * fbc)
2136 {
2137   return (fbc != NULL) ? static_cast<FbcModelPlugin*>(fbc)->getNumGeneProducts()
2138     : SBML_INT_MAX;
2139 }
2140 
2141 LIBSBML_EXTERN
2142 int
FbcModelPlugin_getStrict(SBasePlugin_t * fmp)2143 FbcModelPlugin_getStrict(SBasePlugin_t * fmp)
2144 {
2145   return (int)(((FbcModelPlugin*)(fmp))->getStrict());
2146 }
2147 
2148 
2149 LIBSBML_EXTERN
2150 int
FbcModelPlugin_setStrict(SBasePlugin_t * fmp,int strict)2151 FbcModelPlugin_setStrict(SBasePlugin_t * fmp, int strict)
2152 {
2153   return ((FbcModelPlugin*)(fmp))->setStrict((bool)(strict));
2154 }
2155 
2156 /** @endcond */
2157 
2158 
2159 LIBSBML_CPP_NAMESPACE_END
2160 
2161 
2162 
2163 
2164