1 /**
2  * @file    QualModelPlugin.cpp
3  * @brief   Implementation of QualModelPlugin, the plugin class of
4  *          qual package for the Model element.
5  * @author  Akiya Jouraku
6  *
7  * <!--------------------------------------------------------------------------
8  * This file is part of libSBML.  Please visit http://sbml.org for more
9  * information about SBML, and the latest version of libSBML.
10  *
11  * Copyright (C) 2020 jointly by the following organizations:
12  *     1. California Institute of Technology, Pasadena, CA, USA
13  *     2. University of Heidelberg, Heidelberg, Germany
14  *     3. University College London, London, UK
15  *
16  * Copyright (C) 2019 jointly by the following organizations:
17  *     1. California Institute of Technology, Pasadena, CA, USA
18  *     2. University of Heidelberg, Heidelberg, Germany
19  *
20  * Copyright (C) 2013-2018 jointly by the following organizations:
21  *     1. California Institute of Technology, Pasadena, CA, USA
22  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
23  *     3. University of Heidelberg, Heidelberg, Germany
24  *
25  * Copyright (C) 2009-2011 jointly by the following organizations:
26  *     1. California Institute of Technology, Pasadena, CA, USA
27  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
28  *
29  * Copyright (C) 2006-2008 by the California Institute of Technology,
30  *     Pasadena, CA, USA
31  *
32  * Copyright (C) 2002-2005 jointly by the following organizations:
33  *     1. California Institute of Technology, Pasadena, CA, USA
34  *     2. Japan Science and Technology Agency, Japan
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the GNU Lesser General Public License as published by
38  * the Free Software Foundation.  A copy of the license agreement is provided
39  * in the file named "LICENSE.txt" included with this software distribution
40  * and also available online as http://sbml.org/software/libsbml/license.html
41  * ------------------------------------------------------------------------ -->
42  */
43 
44 #include <sbml/packages/qual/extension/QualModelPlugin.h>
45 #include <sbml/packages/qual/validator/QualSBMLError.h>
46 #include <sbml/util/ElementFilter.h>
47 #include <sbml/Model.h>
48 
49 #include <iostream>
50 using namespace std;
51 
52 
53 #ifdef __cplusplus
54 
55 LIBSBML_CPP_NAMESPACE_BEGIN
56 
57 /*
58  * Constructor
59  */
QualModelPlugin(const std::string & uri,const std::string & prefix,QualPkgNamespaces * qualns)60 QualModelPlugin::QualModelPlugin (const std::string &uri,
61                                   const std::string &prefix,
62                                   QualPkgNamespaces *qualns)
63   : SBasePlugin(uri,prefix, qualns)
64    ,mQualitativeSpecies(qualns)
65    ,mTransitions(qualns)
66 {
67   // connect child elements to this element.
68   connectToChild();
69 }
70 
71 
72 /*
73  * Copy constructor. Creates a copy of this SBase object.
74  */
QualModelPlugin(const QualModelPlugin & orig)75 QualModelPlugin::QualModelPlugin(const QualModelPlugin& orig)
76   : SBasePlugin(orig)
77   , mQualitativeSpecies(orig.mQualitativeSpecies)
78   , mTransitions(orig.mTransitions)
79 {
80   // connect child elements to this element.
81   connectToChild();
82 }
83 
84 
85 /*
86  * Destroy this object.
87  */
~QualModelPlugin()88 QualModelPlugin::~QualModelPlugin () {}
89 
90 /*
91  * Assignment operator for QualModelPlugin.
92  */
93 QualModelPlugin&
operator =(const QualModelPlugin & orig)94 QualModelPlugin::operator=(const QualModelPlugin& orig)
95 {
96   if(&orig!=this)
97   {
98     this->SBasePlugin::operator =(orig);
99     mQualitativeSpecies    = orig.mQualitativeSpecies;
100     mTransitions    = orig.mTransitions;
101     // connect child elements to this element.
102     connectToChild();
103   }
104   return *this;
105 }
106 
107 
108 /*
109  * Creates and returns a deep copy of this QualModelPlugin object.
110  *
111  * @return a (deep) copy of this SBase object
112  */
113 QualModelPlugin*
clone() const114 QualModelPlugin::clone () const
115 {
116   return new QualModelPlugin(*this);
117 }
118 
119 
120 /** @cond doxygenLibsbmlInternal */
121 SBase*
createObject(XMLInputStream & stream)122 QualModelPlugin::createObject(XMLInputStream& stream)
123 {
124   SBase*        object = 0;
125 
126   const std::string&   name   = stream.peek().getName();
127   const XMLNamespaces& xmlns  = stream.peek().getNamespaces();
128   const std::string&   prefix = stream.peek().getPrefix();
129 
130   const std::string& targetPrefix = (xmlns.hasURI(mURI)) ? xmlns.getPrefix(mURI) : mPrefix;
131 
132   if (prefix == targetPrefix)
133   {
134     if ( name == "listOfQualitativeSpecies" )
135     {
136       if (mQualitativeSpecies.size() != 0)
137       {
138         getErrorLog()->logPackageError("qual", QualOneListOfTransOrQS,
139           getPackageVersion(), getLevel(), getVersion(), "", getLine(), getColumn());
140       }
141 
142       object = &mQualitativeSpecies;
143 
144       if (targetPrefix.empty())
145       {
146         //
147         // (NOTE)
148         //
149         // A top-level element (listOfQualitativeSpecies) of the qual extension is located
150         // in a default namespace, and thus xmlns=".." attribute must be added to
151         // the element.
152         // This is done by invoking SBMLDocument::enableDefaultNS() function with
153         // the two arguments (the uri of this package and true value).
154         //
155         mQualitativeSpecies.getSBMLDocument()->enableDefaultNS(mURI,true);
156       }
157     }
158     else if ( name == "listOfTransitions" )
159     {
160       if (mTransitions.size() != 0)
161       {
162         getErrorLog()->logPackageError("qual", QualOneListOfTransOrQS,
163           getPackageVersion(), getLevel(), getVersion(), "", getLine(), getColumn());
164       }
165 
166       object = &mTransitions;
167 
168       if (targetPrefix.empty())
169       {
170         //
171         // (NOTE)
172         //
173         // A top-level element (listOfTransitions) of the qual extension is located
174         // in a default namespace, and thus xmlns=".." attribute must be added to
175         // the element.
176         // This is done by invoking SBMLDocument::enableDefaultNS() function with
177         // the two arguments (the uri of this package and true value).
178         //
179         mTransitions.getSBMLDocument()->enableDefaultNS(mURI,true);
180       }
181     }
182   }
183 
184   return object;
185 }
186 /** @endcond */
187 
188 
189 /** @cond doxygenLibsbmlInternal */
190 bool
accept(SBMLVisitor & v) const191 QualModelPlugin::accept(SBMLVisitor& v) const
192 {
193   const Model * model = static_cast<const Model * >(this->getParentSBMLObject());
194 
195   v.visit(*model);
196   v.leave(*model);
197 
198   for (unsigned int i = 0; i < getNumQualitativeSpecies(); i++)
199   {
200     getQualitativeSpecies(i)->accept(v);
201   }
202   for (unsigned int i = 0; i < getNumTransitions(); i++)
203   {
204     getTransition(i)->accept(v);
205   }
206   return true;
207 }
208 /** @endcond */
209 
210 
211 /** @cond doxygenLibsbmlInternal */
212 void
writeElements(XMLOutputStream & stream) const213 QualModelPlugin::writeElements (XMLOutputStream& stream) const
214 {
215   if (getNumQualitativeSpecies() > 0)
216   {
217     mQualitativeSpecies.write(stream);
218   }
219   if (getNumTransitions() > 0)
220   {
221     mTransitions.write(stream);
222   }
223 }
224 /** @endcond */
225 
226 
227 /** @cond doxygenLibsbmlInternal */
228 
229 /*
230  * Returns the value of the "attributeName" attribute of this QualModelPlugin.
231  */
232 int
getAttribute(const std::string & attributeName,bool & value) const233 QualModelPlugin::getAttribute(const std::string& attributeName,
234                               bool& value) const
235 {
236   int return_value = SBasePlugin::getAttribute(attributeName, value);
237 
238   return return_value;
239 }
240 
241 /** @endcond */
242 
243 
244 
245 /** @cond doxygenLibsbmlInternal */
246 
247 /*
248  * Returns the value of the "attributeName" attribute of this QualModelPlugin.
249  */
250 int
getAttribute(const std::string & attributeName,int & value) const251 QualModelPlugin::getAttribute(const std::string& attributeName,
252                               int& value) const
253 {
254   int return_value = SBasePlugin::getAttribute(attributeName, value);
255 
256   return return_value;
257 }
258 
259 /** @endcond */
260 
261 
262 
263 /** @cond doxygenLibsbmlInternal */
264 
265 /*
266  * Returns the value of the "attributeName" attribute of this QualModelPlugin.
267  */
268 int
getAttribute(const std::string & attributeName,double & value) const269 QualModelPlugin::getAttribute(const std::string& attributeName,
270                               double& value) const
271 {
272   int return_value = SBasePlugin::getAttribute(attributeName, value);
273 
274   return return_value;
275 }
276 
277 /** @endcond */
278 
279 
280 
281 /** @cond doxygenLibsbmlInternal */
282 
283 /*
284  * Returns the value of the "attributeName" attribute of this QualModelPlugin.
285  */
286 int
getAttribute(const std::string & attributeName,unsigned int & value) const287 QualModelPlugin::getAttribute(const std::string& attributeName,
288                               unsigned int& value) const
289 {
290   int return_value = SBasePlugin::getAttribute(attributeName, value);
291 
292   return return_value;
293 }
294 
295 /** @endcond */
296 
297 
298 
299 /** @cond doxygenLibsbmlInternal */
300 
301 /*
302  * Returns the value of the "attributeName" attribute of this QualModelPlugin.
303  */
304 int
getAttribute(const std::string & attributeName,std::string & value) const305 QualModelPlugin::getAttribute(const std::string& attributeName,
306                               std::string& value) const
307 {
308   int return_value = SBasePlugin::getAttribute(attributeName, value);
309 
310   return return_value;
311 }
312 
313 /** @endcond */
314 
315 
316 
317 /** @cond doxygenLibsbmlInternal */
318 
319 /*
320  * Predicate returning @c true if this QualModelPlugin's attribute
321  * "attributeName" is set.
322  */
323 bool
isSetAttribute(const std::string & attributeName) const324 QualModelPlugin::isSetAttribute(const std::string& attributeName) const
325 {
326   bool value = SBasePlugin::isSetAttribute(attributeName);
327 
328   return value;
329 }
330 
331 /** @endcond */
332 
333 
334 
335 /** @cond doxygenLibsbmlInternal */
336 
337 /*
338  * Sets the value of the "attributeName" attribute of this QualModelPlugin.
339  */
340 int
setAttribute(const std::string & attributeName,bool value)341 QualModelPlugin::setAttribute(const std::string& attributeName, bool value)
342 {
343   int return_value = SBasePlugin::setAttribute(attributeName, value);
344 
345   return return_value;
346 }
347 
348 /** @endcond */
349 
350 
351 
352 /** @cond doxygenLibsbmlInternal */
353 
354 /*
355  * Sets the value of the "attributeName" attribute of this QualModelPlugin.
356  */
357 int
setAttribute(const std::string & attributeName,int value)358 QualModelPlugin::setAttribute(const std::string& attributeName, int value)
359 {
360   int return_value = SBasePlugin::setAttribute(attributeName, value);
361 
362   return return_value;
363 }
364 
365 /** @endcond */
366 
367 
368 
369 /** @cond doxygenLibsbmlInternal */
370 
371 /*
372  * Sets the value of the "attributeName" attribute of this QualModelPlugin.
373  */
374 int
setAttribute(const std::string & attributeName,double value)375 QualModelPlugin::setAttribute(const std::string& attributeName, double value)
376 {
377   int return_value = SBasePlugin::setAttribute(attributeName, value);
378 
379   return return_value;
380 }
381 
382 /** @endcond */
383 
384 
385 
386 /** @cond doxygenLibsbmlInternal */
387 
388 /*
389  * Sets the value of the "attributeName" attribute of this QualModelPlugin.
390  */
391 int
setAttribute(const std::string & attributeName,unsigned int value)392 QualModelPlugin::setAttribute(const std::string& attributeName,
393                               unsigned int value)
394 {
395   int return_value = SBasePlugin::setAttribute(attributeName, value);
396 
397   return return_value;
398 }
399 
400 /** @endcond */
401 
402 
403 
404 /** @cond doxygenLibsbmlInternal */
405 
406 /*
407  * Sets the value of the "attributeName" attribute of this QualModelPlugin.
408  */
409 int
setAttribute(const std::string & attributeName,const std::string & value)410 QualModelPlugin::setAttribute(const std::string& attributeName,
411                               const std::string& value)
412 {
413   int return_value = SBasePlugin::setAttribute(attributeName, value);
414 
415   return return_value;
416 }
417 
418 /** @endcond */
419 
420 
421 
422 /** @cond doxygenLibsbmlInternal */
423 
424 /*
425  * Unsets the value of the "attributeName" attribute of this QualModelPlugin.
426  */
427 int
unsetAttribute(const std::string & attributeName)428 QualModelPlugin::unsetAttribute(const std::string& attributeName)
429 {
430   int value = SBasePlugin::unsetAttribute(attributeName);
431 
432   return value;
433 }
434 
435 /** @endcond */
436 
437 
438 
439 /** @cond doxygenLibsbmlInternal */
440 
441 /*
442  * Creates and returns an new "elementName" object in this QualModelPlugin.
443  */
444 SBase*
createChildObject(const std::string & elementName)445 QualModelPlugin::createChildObject(const std::string& elementName)
446 {
447   SBase* obj = NULL;
448 
449   if (elementName == "qualitativeSpecies")
450   {
451     return createQualitativeSpecies();
452   }
453   else if (elementName == "transition")
454   {
455     return createTransition();
456   }
457 
458   return obj;
459 }
460 
461 /** @endcond */
462 
463 
464 
465 /** @cond doxygenLibsbmlInternal */
466 
467 /*
468  * Adds a new "elementName" object to this QualModelPlugin.
469  */
470 int
addChildObject(const std::string & elementName,const SBase * element)471 QualModelPlugin::addChildObject(const std::string& elementName,
472                                 const SBase* element)
473 {
474   if (elementName == "qualitativeSpecies" && element->getTypeCode() ==
475     SBML_QUAL_QUALITATIVE_SPECIES)
476   {
477     return addQualitativeSpecies((const QualitativeSpecies*)(element));
478   }
479   else if (elementName == "transition" && element->getTypeCode() ==
480     SBML_QUAL_TRANSITION)
481   {
482     return addTransition((const Transition*)(element));
483   }
484 
485   return LIBSBML_OPERATION_FAILED;
486 }
487 
488 /** @endcond */
489 
490 
491 
492 /** @cond doxygenLibsbmlInternal */
493 
494 /*
495  * Removes and returns the new "elementName" object with the given id in this
496  * QualModelPlugin.
497  */
498 SBase*
removeChildObject(const std::string & elementName,const std::string & id)499 QualModelPlugin::removeChildObject(const std::string& elementName,
500                                    const std::string& id)
501 {
502   if (elementName == "qualitativeSpecies")
503   {
504     return removeQualitativeSpecies(id);
505   }
506   else if (elementName == "transition")
507   {
508     return removeTransition(id);
509   }
510 
511   return NULL;
512 }
513 
514 /** @endcond */
515 
516 
517 
518 /** @cond doxygenLibsbmlInternal */
519 
520 /*
521  * Returns the number of "elementName" in this QualModelPlugin.
522  */
523 unsigned int
getNumObjects(const std::string & elementName)524 QualModelPlugin::getNumObjects(const std::string& elementName)
525 {
526   unsigned int n = 0;
527 
528   if (elementName == "qualitativeSpecies")
529   {
530     return getNumQualitativeSpecies();
531   }
532   else if (elementName == "transition")
533   {
534     return getNumTransitions();
535   }
536 
537   return n;
538 }
539 
540 /** @endcond */
541 
542 
543 
544 /** @cond doxygenLibsbmlInternal */
545 
546 /*
547  * Returns the nth object of "objectName" in this QualModelPlugin.
548  */
549 SBase*
getObject(const std::string & elementName,unsigned int index)550 QualModelPlugin::getObject(const std::string& elementName, unsigned int index)
551 {
552   SBase* obj = NULL;
553 
554   if (elementName == "qualitativeSpecies")
555   {
556     return getQualitativeSpecies(index);
557   }
558   else if (elementName == "transition")
559   {
560     return getTransition(index);
561   }
562 
563   return obj;
564 }
565 
566 /** @endcond */
567 
568 
569 /*
570  * Returns the first child element that has the given @p id in the model-wide
571  * SId namespace, or @c NULL if no such object is found.
572  */
573 SBase*
getElementBySId(const std::string & id)574 QualModelPlugin::getElementBySId(const std::string& id)
575 {
576   if (id.empty())
577   {
578     return NULL;
579   }
580 
581   SBase* obj = NULL;
582 
583   obj = mQualitativeSpecies.getElementBySId(id);
584 
585   if (obj != NULL)
586   {
587     return obj;
588   }
589 
590   obj = mTransitions.getElementBySId(id);
591 
592   if (obj != NULL)
593   {
594     return obj;
595   }
596 
597   return obj;
598 }
599 
600 
601 /*
602  * Returns the first child element that has the given @p metaid, or @c NULL if
603  * no such object is found.
604  */
605 SBase*
getElementByMetaId(const std::string & metaid)606 QualModelPlugin::getElementByMetaId(const std::string& metaid)
607 {
608   if (metaid.empty())
609   {
610     return NULL;
611   }
612 
613   SBase* obj = NULL;
614 
615   if (mQualitativeSpecies.getMetaId() == metaid)
616   {
617     return &mQualitativeSpecies;
618   }
619 
620   if (mTransitions.getMetaId() == metaid)
621   {
622     return &mTransitions;
623   }
624 
625   obj = mQualitativeSpecies.getElementByMetaId(metaid);
626 
627   if (obj != NULL)
628   {
629     return obj;
630   }
631 
632   obj = mTransitions.getElementByMetaId(metaid);
633 
634   if (obj != NULL)
635   {
636     return obj;
637   }
638 
639   return obj;
640 }
641 
642 
643 /*
644  *
645  *  (EXTENSION) Additional public functions
646  *
647  */
648 
649 /** @cond doxygenLibsbmlInternal */
650 int
appendFrom(const Model * model)651 QualModelPlugin::appendFrom(const Model* model)
652 {
653   int ret = LIBSBML_OPERATION_SUCCESS;
654 
655   if (model==NULL)
656   {
657     return LIBSBML_INVALID_OBJECT;
658   }
659 
660   const QualModelPlugin* modplug =
661     static_cast<const QualModelPlugin*>(model->getPlugin(getPrefix()));
662 
663   // absence of a plugin is not an error
664   if (modplug==NULL)
665   {
666     return LIBSBML_OPERATION_SUCCESS;
667   }
668 
669 
670   Model* parent = static_cast<Model*>(getParentSBMLObject());
671 
672   if (parent==NULL)
673   {
674     return LIBSBML_INVALID_OBJECT;
675   }
676 
677   ret = mQualitativeSpecies.appendFrom(modplug->getListOfQualitativeSpecies());
678 
679   if (ret != LIBSBML_OPERATION_SUCCESS)
680   {
681     return ret;
682   }
683 
684   ret = mTransitions.appendFrom(modplug->getListOfTransitions());
685 
686   return ret;
687 }
688 /** @endcond */
689 
690 
691 
692 List*
getAllElements(ElementFilter * filter)693 QualModelPlugin::getAllElements(ElementFilter* filter)
694 {
695   List* ret = new List();
696   List* sublist = NULL;
697 
698   ADD_FILTERED_LIST(ret, sublist, mQualitativeSpecies, filter);
699   ADD_FILTERED_LIST(ret, sublist, mTransitions, filter);
700 
701   return ret;
702 }
703 
704 
705 /** @cond doxygenLibsbmlInternal */
706 /*
707  * Returns the ListOf Qual for this Model.
708  */
709 const ListOfQualitativeSpecies*
getListOfQualitativeSpecies() const710 QualModelPlugin::getListOfQualitativeSpecies () const
711 {
712   return &this->mQualitativeSpecies;
713 }
714 /** @endcond */
715 
716 
717 /** @cond doxygenLibsbmlInternal */
718 /*
719  * Returns the ListOf Qual for this Model.
720  */
721 ListOfQualitativeSpecies*
getListOfQualitativeSpecies()722 QualModelPlugin::getListOfQualitativeSpecies ()
723 {
724   return &this->mQualitativeSpecies;
725 }
726 /** @endcond */
727 
728 
729 /** @cond doxygenLibsbmlInternal */
730 /*
731  * Returns the qual object that belongs to the given index. If the index
732  * is invalid, NULL is returned.
733  */
734 const QualitativeSpecies*
getQualitativeSpecies(unsigned int index) const735 QualModelPlugin::getQualitativeSpecies (unsigned int index) const
736 {
737   return static_cast<const QualitativeSpecies*>( mQualitativeSpecies.get(index) );
738 }
739 /** @endcond */
740 
741 
742 /** @cond doxygenLibsbmlInternal */
743 /*
744  * Returns the qual object that belongs to the given index. If the index
745  * is invalid, NULL is returned.
746  */
747 QualitativeSpecies*
getQualitativeSpecies(unsigned int index)748 QualModelPlugin::getQualitativeSpecies (unsigned int index)
749 {
750   return static_cast<QualitativeSpecies*>( mQualitativeSpecies.get(index) );
751 }
752 /** @endcond */
753 
754 
755 /** @cond doxygenLibsbmlInternal */
756 /*
757  * Returns the qualitativeSpecies object based on its identifier.
758  */
759 QualitativeSpecies*
getQualitativeSpecies(const std::string & sid)760 QualModelPlugin::getQualitativeSpecies (const std::string& sid)
761 {
762   return static_cast<QualitativeSpecies*>( mQualitativeSpecies.get(sid) );
763 }
764 /** @endcond */
765 
766 
767 /** @cond doxygenLibsbmlInternal */
768 /*
769  * Returns the qualitativeSpecies object based on its identifier.
770  */
771 const QualitativeSpecies*
getQualitativeSpecies(const std::string & sid) const772 QualModelPlugin::getQualitativeSpecies (const std::string& sid) const
773 {
774   return static_cast<const QualitativeSpecies*>( mQualitativeSpecies.get(sid) );
775 }
776 /** @endcond */
777 
778 
779 /** @cond doxygenLibsbmlInternal */
780 /*
781  * Returns the number of QualitativeSpecies objects.
782  */
783 unsigned int
getNumQualitativeSpecies() const784 QualModelPlugin::getNumQualitativeSpecies() const
785 {
786   return mQualitativeSpecies.size();
787 }
788 /** @endcond */
789 
790 
791 
792 /** @cond doxygenLibsbmlInternal */
793 /*
794  * Adds a copy of the qual object to the list of quals.
795  */
796 int
addQualitativeSpecies(const QualitativeSpecies * qual)797 QualModelPlugin::addQualitativeSpecies (const QualitativeSpecies* qual)
798 {
799   if (!qual)
800   {
801     return LIBSBML_OPERATION_FAILED;
802   }
803   else if (!qual->hasRequiredElements())
804   {
805     return LIBSBML_INVALID_OBJECT;
806   }
807   else if (getLevel() != qual->getLevel())
808   {
809     return LIBSBML_LEVEL_MISMATCH;
810   }
811   else if (getVersion() != qual->getVersion())
812   {
813     return LIBSBML_VERSION_MISMATCH;
814   }
815   else if (getPackageVersion() != qual->getPackageVersion())
816   {
817     return LIBSBML_PKG_VERSION_MISMATCH;
818   }
819   else
820   {
821     return mQualitativeSpecies.append(qual);
822   }
823 }
824 /** @endcond */
825 
826 
827 /** @cond doxygenLibsbmlInternal */
828 /*
829  * Creates a new qual object and adds it to the list of qual objects.
830  * A reference to the newly created object is returned.
831  */
832 QualitativeSpecies*
createQualitativeSpecies()833 QualModelPlugin::createQualitativeSpecies ()
834 {
835   QualitativeSpecies* g = 0;
836 
837   try
838   {
839     QUAL_CREATE_NS(qualns, getSBMLNamespaces());
840     g = new QualitativeSpecies(qualns);
841     mQualitativeSpecies.appendAndOwn(g);
842     delete qualns;
843   }
844   catch(...)
845   {
846     /*
847      * NULL will be returned if the mSBMLNS is invalid (basically this
848      * should not happen) or some exception is thrown (e.g. std::bad_alloc)
849      *
850      * (Maybe this should be changed so that caller can detect what kind
851      *  of error happened in this function.)
852      */
853   }
854 
855   return g;
856 }
857 /** @endcond */
858 
859 
860 /** @cond doxygenLibsbmlInternal */
861 /*
862  * Removes the nth QualitativeSpecies object from this Model object and
863  * returns a pointer to it.
864  */
865 QualitativeSpecies*
removeQualitativeSpecies(unsigned int n)866 QualModelPlugin::removeQualitativeSpecies (unsigned int n)
867 {
868   return static_cast<QualitativeSpecies*>(mQualitativeSpecies.remove(n));
869 }
870 /** @endcond */
871 
872 
873 /** @cond doxygenLibsbmlInternal */
874 /*
875  * Removes the QualitativeSpecies object with the given id attribute from
876  * this plugin object and returns a pointer to it.
877  */
878 QualitativeSpecies*
removeQualitativeSpecies(const std::string & sid)879 QualModelPlugin::removeQualitativeSpecies (const std::string& sid)
880 {
881   return static_cast<QualitativeSpecies*>(mQualitativeSpecies.remove(sid));
882 }
883 /** @endcond */
884 
885 
886 /** @cond doxygenLibsbmlInternal */
887 /*
888  * Returns the ListOf Qual for this Model.
889  */
890 const ListOfTransitions*
getListOfTransitions() const891 QualModelPlugin::getListOfTransitions () const
892 {
893   return &this->mTransitions;
894 }
895 /** @endcond */
896 
897 
898 /** @cond doxygenLibsbmlInternal */
899 /*
900  * Returns the ListOfTransitions for this Model.
901  */
902 ListOfTransitions*
getListOfTransitions()903 QualModelPlugin::getListOfTransitions ()
904 {
905   return &this->mTransitions;
906 }
907 /** @endcond */
908 
909 
910 /** @cond doxygenLibsbmlInternal */
911 /*
912  * Returns the qual object that belongs to the given index. If the index
913  * is invalid, NULL is returned.
914  */
915 const Transition*
getTransition(unsigned int index) const916 QualModelPlugin::getTransition (unsigned int index) const
917 {
918   return static_cast<const Transition*>( mTransitions.get(index) );
919 }
920 /** @endcond */
921 
922 
923 /** @cond doxygenLibsbmlInternal */
924 /*
925  * Returns the qual object that belongs to the given index. If the index
926  * is invalid, NULL is returned.
927  */
928 Transition*
getTransition(unsigned int index)929 QualModelPlugin::getTransition (unsigned int index)
930 {
931   return static_cast<Transition*>( mTransitions.get(index) );
932 }
933 /** @endcond */
934 
935 
936 /** @cond doxygenLibsbmlInternal */
937 /*
938  * Returns the group object based on its identifier.
939  */
940 Transition*
getTransition(const std::string & sid)941 QualModelPlugin::getTransition (const std::string& sid)
942 {
943   return static_cast<Transition*>( mTransitions.get(sid) );
944 }
945 /** @endcond */
946 
947 
948 /** @cond doxygenLibsbmlInternal */
949 /*
950  * Returns the group object based on its identifier.
951  */
952 const Transition*
getTransition(const std::string & sid) const953 QualModelPlugin::getTransition (const std::string& sid) const
954 {
955   return static_cast<const Transition*>( mTransitions.get(sid) );
956 }
957 /** @endcond */
958 
959 
960 /** @cond doxygenLibsbmlInternal */
961 /*
962  * Returns the number of Transition objects.
963  */
964 unsigned int
getNumTransitions() const965 QualModelPlugin::getNumTransitions() const
966 {
967   return mTransitions.size();
968 }
969 /** @endcond */
970 
971 
972 
973 /** @cond doxygenLibsbmlInternal */
974 /** @cond doxygenLibsbmlInternal */
975 /*
976  * Adds a copy of the qual object to the list of quals.
977  */
978 int
addTransition(const Transition * qual)979 QualModelPlugin::addTransition (const Transition* qual)
980 {
981   if (!qual)
982   {
983     return LIBSBML_OPERATION_FAILED;
984   }
985   else if (!qual->hasRequiredElements())
986   {
987     return LIBSBML_INVALID_OBJECT;
988   }
989   else if (getLevel() != qual->getLevel())
990   {
991     return LIBSBML_LEVEL_MISMATCH;
992   }
993   else if (getVersion() != qual->getVersion())
994   {
995     return LIBSBML_VERSION_MISMATCH;
996   }
997   else if (getPackageVersion() != qual->getPackageVersion())
998   {
999     return LIBSBML_PKG_VERSION_MISMATCH;
1000   }
1001   else
1002   {
1003     return mTransitions.append(qual);
1004   }
1005 }
1006 /** @endcond */
1007 
1008 
1009 /** @cond doxygenLibsbmlInternal */
1010 /*
1011  * Creates a new qual object and adds it to the list of qual objects.
1012  * A reference to the newly created object is returned.
1013  */
1014 Transition*
createTransition()1015 QualModelPlugin::createTransition ()
1016 {
1017   Transition* g = 0;
1018 
1019   try
1020   {
1021     QUAL_CREATE_NS(qualns, getSBMLNamespaces());
1022     g = new Transition(qualns);
1023     mTransitions.appendAndOwn(g);
1024     delete qualns;
1025   }
1026   catch(...)
1027   {
1028     /*
1029      * NULL will be returned if the mSBMLNS is invalid (basically this
1030      * should not happen) or some exception is thrown (e.g. std::bad_alloc)
1031      *
1032      * (Maybe this should be changed so that caller can detect what kind
1033      *  of error happened in this function.)
1034      */
1035   }
1036 
1037   return g;
1038 }
1039 /** @endcond */
1040 
1041 
1042 /** @cond doxygenLibsbmlInternal */
1043 /*
1044  * Removes the nth Transition object from this Model object and
1045  * returns a pointer to it.
1046  */
1047 Transition*
removeTransition(unsigned int n)1048 QualModelPlugin::removeTransition (unsigned int n)
1049 {
1050   return static_cast<Transition*>(mTransitions.remove(n));
1051 }
1052 /** @endcond */
1053 
1054 
1055 /** @cond doxygenLibsbmlInternal */
1056 /*
1057  * Removes the Transition object with the given id attribute from
1058  * this plugin object and returns a pointer to it.
1059  */
1060 Transition*
removeTransition(const std::string & sid)1061 QualModelPlugin::removeTransition (const std::string& sid)
1062 {
1063   return static_cast<Transition*>(mTransitions.remove(sid));
1064 }
1065 /** @endcond */
1066 
1067 
1068 /** @cond doxygenLibsbmlInternal */
1069 /*
1070  * Sets the parent SBMLDocument of this SBML object.
1071  *
1072  * @param d the SBMLDocument object to use.
1073  */
1074 void
setSBMLDocument(SBMLDocument * d)1075 QualModelPlugin::setSBMLDocument (SBMLDocument* d)
1076 {
1077   SBasePlugin::setSBMLDocument(d);
1078 
1079   mQualitativeSpecies.setSBMLDocument(d);
1080   mTransitions.setSBMLDocument(d);
1081 }
1082 /** @endcond */
1083 
1084 
1085 /** @cond doxygenLibsbmlInternal */
1086 void
connectToChild()1087 QualModelPlugin::connectToChild()
1088 {
1089   connectToParent(getParentSBMLObject());
1090 }
1091 /** @endcond */
1092 
1093 
1094 /** @cond doxygenLibsbmlInternal */
1095 /*
1096  * Sets the parent SBML object of this plugin object to
1097  * this object and child elements (if any).
1098  * (Creates a child-parent relationship by this plugin object)
1099  */
1100 void
connectToParent(SBase * sbase)1101 QualModelPlugin::connectToParent (SBase* sbase)
1102 {
1103   SBasePlugin::connectToParent(sbase);
1104 
1105   mQualitativeSpecies.connectToParent(sbase);
1106   mTransitions.connectToParent(sbase);
1107 }
1108 /** @endcond */
1109 
1110 
1111 /** @cond doxygenLibsbmlInternal */
1112 /*
1113  * Enables/Disables the given package with child elements in this plugin
1114  * object (if any).
1115  */
1116 void
enablePackageInternal(const std::string & pkgURI,const std::string & pkgPrefix,bool flag)1117 QualModelPlugin::enablePackageInternal(const std::string& pkgURI,
1118                                         const std::string& pkgPrefix, bool flag)
1119 {
1120   mQualitativeSpecies.enablePackageInternal(pkgURI,pkgPrefix,flag);
1121   mTransitions.enablePackageInternal(pkgURI,pkgPrefix,flag);
1122 }
1123 /** @endcond */
1124 
1125 
1126 #endif  /* __cplusplus */
1127 
1128 
1129 /*
1130  * Returns a ListOf_t * containing QualitativeSpecies_t objects from this
1131  * QualModelPlugin_t.
1132  */
1133 LIBSBML_EXTERN
1134 ListOf_t*
QualModelPlugin_getListOfQualitativeSpecies(QualModelPlugin_t * qmp)1135 QualModelPlugin_getListOfQualitativeSpecies(QualModelPlugin_t* qmp)
1136 {
1137   return (qmp != NULL) ? qmp->getListOfQualitativeSpecies() : NULL;
1138 }
1139 
1140 
1141 /*
1142  * Get a QualitativeSpecies_t from the QualModelPlugin_t.
1143  */
1144 LIBSBML_EXTERN
1145 const QualitativeSpecies_t*
QualModelPlugin_getQualitativeSpecies(QualModelPlugin_t * qmp,unsigned int n)1146 QualModelPlugin_getQualitativeSpecies(QualModelPlugin_t* qmp, unsigned int n)
1147 {
1148   return (qmp != NULL) ? qmp->getQualitativeSpecies(n) : NULL;
1149 }
1150 
1151 
1152 /*
1153  * Get a QualitativeSpecies_t from the QualModelPlugin_t based on its
1154  * identifier.
1155  */
1156 LIBSBML_EXTERN
1157 const QualitativeSpecies_t*
QualModelPlugin_getQualitativeSpeciesById(QualModelPlugin_t * qmp,const char * sid)1158 QualModelPlugin_getQualitativeSpeciesById(QualModelPlugin_t* qmp,
1159                                           const char *sid)
1160 {
1161   return (qmp != NULL && sid != NULL) ? qmp->getQualitativeSpecies(sid) : NULL;
1162 }
1163 
1164 
1165 /*
1166  * Adds a copy of the given QualitativeSpecies_t to this QualModelPlugin_t.
1167  */
1168 LIBSBML_EXTERN
1169 int
QualModelPlugin_addQualitativeSpecies(QualModelPlugin_t * qmp,const QualitativeSpecies_t * qs)1170 QualModelPlugin_addQualitativeSpecies(QualModelPlugin_t* qmp,
1171                                       const QualitativeSpecies_t* qs)
1172 {
1173   return (qmp != NULL) ? qmp->addQualitativeSpecies(qs) :
1174     LIBSBML_INVALID_OBJECT;
1175 }
1176 
1177 
1178 /*
1179  * Get the number of QualitativeSpecies_t objects in this QualModelPlugin_t.
1180  */
1181 LIBSBML_EXTERN
1182 unsigned int
QualModelPlugin_getNumQualitativeSpecies(QualModelPlugin_t * qmp)1183 QualModelPlugin_getNumQualitativeSpecies(QualModelPlugin_t* qmp)
1184 {
1185   return (qmp != NULL) ? qmp->getNumQualitativeSpecies() : SBML_INT_MAX;
1186 }
1187 
1188 
1189 /*
1190  * Creates a new QualitativeSpecies_t object, adds it to this QualModelPlugin_t
1191  * object and returns the QualitativeSpecies_t object created.
1192  */
1193 LIBSBML_EXTERN
1194 QualitativeSpecies_t*
QualModelPlugin_createQualitativeSpecies(QualModelPlugin_t * qmp)1195 QualModelPlugin_createQualitativeSpecies(QualModelPlugin_t* qmp)
1196 {
1197   return (qmp != NULL) ? qmp->createQualitativeSpecies() : NULL;
1198 }
1199 
1200 
1201 /*
1202  * Removes the nth QualitativeSpecies_t from this QualModelPlugin_t and returns
1203  * a pointer to it.
1204  */
1205 LIBSBML_EXTERN
1206 QualitativeSpecies_t*
QualModelPlugin_removeQualitativeSpecies(QualModelPlugin_t * qmp,unsigned int n)1207 QualModelPlugin_removeQualitativeSpecies(QualModelPlugin_t* qmp,
1208                                          unsigned int n)
1209 {
1210   return (qmp != NULL) ? qmp->removeQualitativeSpecies(n) : NULL;
1211 }
1212 
1213 
1214 /*
1215  * Removes the QualitativeSpecies_t from this QualModelPlugin_t based on its
1216  * identifier and returns a pointer to it.
1217  */
1218 LIBSBML_EXTERN
1219 QualitativeSpecies_t*
QualModelPlugin_removeQualitativeSpeciesById(QualModelPlugin_t * qmp,const char * sid)1220 QualModelPlugin_removeQualitativeSpeciesById(QualModelPlugin_t* qmp,
1221                                              const char* sid)
1222 {
1223   return (qmp != NULL && sid != NULL) ? qmp->removeQualitativeSpecies(sid) :
1224     NULL;
1225 }
1226 
1227 
1228 /*
1229  * Returns a ListOf_t * containing Transition_t objects from this
1230  * QualModelPlugin_t.
1231  */
1232 LIBSBML_EXTERN
1233 ListOf_t*
QualModelPlugin_getListOfTransitions(QualModelPlugin_t * qmp)1234 QualModelPlugin_getListOfTransitions(QualModelPlugin_t* qmp)
1235 {
1236   return (qmp != NULL) ? qmp->getListOfTransitions() : NULL;
1237 }
1238 
1239 
1240 /*
1241  * Get a Transition_t from the QualModelPlugin_t.
1242  */
1243 LIBSBML_EXTERN
1244 const Transition_t*
QualModelPlugin_getTransition(QualModelPlugin_t * qmp,unsigned int n)1245 QualModelPlugin_getTransition(QualModelPlugin_t* qmp, unsigned int n)
1246 {
1247   return (qmp != NULL) ? qmp->getTransition(n) : NULL;
1248 }
1249 
1250 
1251 /*
1252  * Get a Transition_t from the QualModelPlugin_t based on its identifier.
1253  */
1254 LIBSBML_EXTERN
1255 const Transition_t*
QualModelPlugin_getTransitionById(QualModelPlugin_t * qmp,const char * sid)1256 QualModelPlugin_getTransitionById(QualModelPlugin_t* qmp, const char *sid)
1257 {
1258   return (qmp != NULL && sid != NULL) ? qmp->getTransition(sid) : NULL;
1259 }
1260 
1261 
1262 /*
1263  * Adds a copy of the given Transition_t to this QualModelPlugin_t.
1264  */
1265 LIBSBML_EXTERN
1266 int
QualModelPlugin_addTransition(QualModelPlugin_t * qmp,const Transition_t * t)1267 QualModelPlugin_addTransition(QualModelPlugin_t* qmp, const Transition_t* t)
1268 {
1269   return (qmp != NULL) ? qmp->addTransition(t) : LIBSBML_INVALID_OBJECT;
1270 }
1271 
1272 
1273 /*
1274  * Get the number of Transition_t objects in this QualModelPlugin_t.
1275  */
1276 LIBSBML_EXTERN
1277 unsigned int
QualModelPlugin_getNumTransitions(QualModelPlugin_t * qmp)1278 QualModelPlugin_getNumTransitions(QualModelPlugin_t* qmp)
1279 {
1280   return (qmp != NULL) ? qmp->getNumTransitions() : SBML_INT_MAX;
1281 }
1282 
1283 
1284 /*
1285  * Creates a new Transition_t object, adds it to this QualModelPlugin_t object
1286  * and returns the Transition_t object created.
1287  */
1288 LIBSBML_EXTERN
1289 Transition_t*
QualModelPlugin_createTransition(QualModelPlugin_t * qmp)1290 QualModelPlugin_createTransition(QualModelPlugin_t* qmp)
1291 {
1292   return (qmp != NULL) ? qmp->createTransition() : NULL;
1293 }
1294 
1295 
1296 /*
1297  * Removes the nth Transition_t from this QualModelPlugin_t and returns a
1298  * pointer to it.
1299  */
1300 LIBSBML_EXTERN
1301 Transition_t*
QualModelPlugin_removeTransition(QualModelPlugin_t * qmp,unsigned int n)1302 QualModelPlugin_removeTransition(QualModelPlugin_t* qmp, unsigned int n)
1303 {
1304   return (qmp != NULL) ? qmp->removeTransition(n) : NULL;
1305 }
1306 
1307 
1308 /*
1309  * Removes the Transition_t from this QualModelPlugin_t based on its identifier
1310  * and returns a pointer to it.
1311  */
1312 LIBSBML_EXTERN
1313 Transition_t*
QualModelPlugin_removeTransitionById(QualModelPlugin_t * qmp,const char * sid)1314 QualModelPlugin_removeTransitionById(QualModelPlugin_t* qmp, const char* sid)
1315 {
1316   return (qmp != NULL && sid != NULL) ? qmp->removeTransition(sid) : NULL;
1317 }
1318 
1319 
1320 
1321 
1322 LIBSBML_CPP_NAMESPACE_END
1323 
1324 
1325