1 /**
2  * @file    Compartment.cpp
3  * @brief   Implementations of Compartment and ListOfCompartments.
4  * @author  Ben Bornstein
5  *
6  * <!--------------------------------------------------------------------------
7  * This file is part of libSBML.  Please visit http://sbml.org for more
8  * information about SBML, and the latest version of libSBML.
9  *
10  * Copyright (C) 2020 jointly by the following organizations:
11  *     1. California Institute of Technology, Pasadena, CA, USA
12  *     2. University of Heidelberg, Heidelberg, Germany
13  *     3. University College London, London, UK
14  *
15  * Copyright (C) 2019 jointly by the following organizations:
16  *     1. California Institute of Technology, Pasadena, CA, USA
17  *     2. University of Heidelberg, Heidelberg, Germany
18  *
19  * Copyright (C) 2013-2018 jointly by the following organizations:
20  *     1. California Institute of Technology, Pasadena, CA, USA
21  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
22  *     3. University of Heidelberg, Heidelberg, Germany
23  *
24  * Copyright (C) 2009-2013 jointly by the following organizations:
25  *     1. California Institute of Technology, Pasadena, CA, USA
26  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
27  *
28  * Copyright (C) 2006-2008 by the California Institute of Technology,
29  *     Pasadena, CA, USA
30  *
31  * Copyright (C) 2002-2005 jointly by the following organizations:
32  *     1. California Institute of Technology, Pasadena, CA, USA
33  *     2. Japan Science and Technology Agency, Japan
34  *
35  * This library is free software; you can redistribute it and/or modify it
36  * under the terms of the GNU Lesser General Public License as published by
37  * the Free Software Foundation.  A copy of the license agreement is provided
38  * in the file named "LICENSE.txt" included with this software distribution
39  * and also available online as http://sbml.org/software/libsbml/license.html
40  * ---------------------------------------------------------------------- -->*/
41 
42 #include <limits>
43 
44 #include <sbml/xml/XMLNode.h>
45 #include <sbml/xml/XMLAttributes.h>
46 #include <sbml/xml/XMLInputStream.h>
47 #include <sbml/xml/XMLOutputStream.h>
48 
49 #include <sbml/SBMLVisitor.h>
50 #include <sbml/SBMLDocument.h>
51 #include <sbml/SBMLError.h>
52 #include <sbml/Model.h>
53 #include <sbml/Compartment.h>
54 
55 /** @cond doxygenIgnored */
56 using namespace std;
57 /** @endcond */
58 
59 LIBSBML_CPP_NAMESPACE_BEGIN
60 #ifdef __cplusplus
61 
Compartment(unsigned int level,unsigned int version)62 Compartment::Compartment (unsigned int level, unsigned int version) :
63    SBase             ( level, version )
64  , mSpatialDimensions( 3        )
65  , mSpatialDimensionsDouble( 3        )
66  , mSize             ( 1.0      )
67  , mConstant         ( true     )
68  , mIsSetSize        ( false    )
69  , mIsSetSpatialDimensions ( false    )
70  , mIsSetConstant          ( false    )
71  , mExplicitlySetSpatialDimensions ( false )
72  , mExplicitlySetConstant          ( false )
73 {
74   if (!hasValidLevelVersionNamespaceCombination())
75     throw SBMLConstructorException();
76 
77   // if level 3 values have no defaults
78   if (level == 3)
79   {
80     mSize = numeric_limits<double>::quiet_NaN();
81     mSpatialDimensionsDouble = numeric_limits<double>::quiet_NaN();
82   }
83   // before level 3 spatialDimensions and constant were set by default
84   if (level < 3)
85   {
86     mIsSetSpatialDimensions = true;
87   }
88   if (level == 2)
89   {
90     mIsSetConstant = true;
91   }
92 }
93 
Compartment(SBMLNamespaces * sbmlns)94 Compartment::Compartment(SBMLNamespaces * sbmlns) :
95    SBase             ( sbmlns   )
96  , mSpatialDimensions( 3        )
97  , mSpatialDimensionsDouble( 3        )
98  , mSize             ( 1.0      )
99  , mConstant         ( true     )
100  , mIsSetSize        ( false    )
101  , mIsSetSpatialDimensions ( false    )
102  , mIsSetConstant          ( false    )
103  , mExplicitlySetSpatialDimensions ( false )
104  , mExplicitlySetConstant          ( false )
105 {
106   if (!hasValidLevelVersionNamespaceCombination())
107   {
108     throw SBMLConstructorException(getElementName(), sbmlns);
109   }
110 
111   loadPlugins(sbmlns);
112 
113   // if level 3 values have no defaults
114   if (sbmlns->getLevel() == 3)
115   {
116     mSize = numeric_limits<double>::quiet_NaN();
117     mSpatialDimensionsDouble = numeric_limits<double>::quiet_NaN();
118   }
119   // before level 3 spatialDimensions and constant were set by default
120   if (sbmlns->getLevel() < 3)
121   {
122     mIsSetSpatialDimensions = true;
123   }
124   if (sbmlns->getLevel() == 2)
125   {
126     mIsSetConstant = true;
127   }
128 }
129 
130 /** @cond doxygenLibsbmlInternal */
131 /** @endcond */
132 
133 /*
134  * Destroys this Compartment.
135  */
~Compartment()136 Compartment::~Compartment ()
137 {
138 }
139 
140 
141 /*
142  * Copy constructor. Creates a copy of this compartment.
143  */
Compartment(const Compartment & orig)144 Compartment::Compartment(const Compartment& orig) :
145    SBase             ( orig                    )
146 {
147   {
148     mSpatialDimensions       = orig.mSpatialDimensions;
149     mSpatialDimensionsDouble = orig.mSpatialDimensionsDouble;
150     mSize                    = orig.mSize;
151     mConstant                = orig.mConstant;
152     mIsSetSize               = orig.mIsSetSize;
153     mCompartmentType         = orig.mCompartmentType;
154     mUnits                   = orig.mUnits;
155     mOutside                 = orig.mOutside;
156     mIsSetSpatialDimensions  = orig.mIsSetSpatialDimensions;
157     mIsSetConstant           = orig.mIsSetConstant;
158     mExplicitlySetSpatialDimensions = orig.mExplicitlySetSpatialDimensions;
159     mExplicitlySetConstant          = orig.mExplicitlySetConstant;
160   }
161 }
162 
163 
164 /*
165  * Assignment operator
166  */
operator =(const Compartment & rhs)167 Compartment& Compartment::operator=(const Compartment& rhs)
168 {
169   if(&rhs!=this)
170   {
171     this->SBase::operator =(rhs);
172     mSpatialDimensions= rhs.mSpatialDimensions  ;
173     mSpatialDimensionsDouble= rhs.mSpatialDimensionsDouble  ;
174     mSize             = rhs.mSize      ;
175     mConstant         = rhs.mConstant     ;
176     mIsSetSize        = rhs.mIsSetSize    ;
177     mCompartmentType  = rhs.mCompartmentType;
178     mUnits            = rhs.mUnits ;
179     mOutside          = rhs.mOutside ;
180     mIsSetSpatialDimensions = rhs.mIsSetSpatialDimensions;
181     mIsSetConstant          = rhs.mIsSetConstant;
182     mExplicitlySetSpatialDimensions = rhs.mExplicitlySetSpatialDimensions;
183     mExplicitlySetConstant          = rhs.mExplicitlySetConstant;
184   }
185 
186   return *this;
187 }
188 
189 
190 
191 /** @cond doxygenLibsbmlInternal */
192 bool
accept(SBMLVisitor & v) const193 Compartment::accept (SBMLVisitor& v) const
194 {
195   return v.visit(*this);
196 }
197 /** @endcond */
198 
199 
200 /*
201  * @return a (deep) copy of this Compartment.
202  */
203 Compartment*
clone() const204 Compartment::clone () const
205 {
206   return new Compartment(*this);
207 }
208 
209 
210 /*
211  * Initializes the fields of this Compartment to their defaults:
212  *
213  *   - volume            = 1.0          (L1 only)
214  *   - spatialDimensions = 3            (L2 only)
215  *   - constant          = 1    (true)  (L2 only)
216  */
217 LIBSBML_EXTERN
218 void
initDefaults()219 Compartment::initDefaults ()
220 {
221   mSize      = 1.0;    // Actually, setting L1 volume not
222   mIsSetSize = false;  // L2 size.
223 
224   unsigned int dims = 3;
225   setSpatialDimensions(dims);
226   setConstant(1);
227 
228   // not explicilty set
229   mExplicitlySetSpatialDimensions = false;
230   mExplicitlySetConstant = false;
231 
232   if (getLevel() > 2)
233   {
234     setUnits("litre");
235   }
236 }
237 
238 
239 /*
240  * @return the id of this SBML object.
241  */
242 const string&
getId() const243 Compartment::getId () const
244 {
245   return mId;
246 }
247 
248 
249 /*
250  * @return the name of this SBML object.
251  */
252 const string&
getName() const253 Compartment::getName () const
254 {
255   return (getLevel() == 1) ? mId : mName;
256 }
257 
258 
259 /*
260  * @return the compartmentType of this Compartment.
261  */
262 const string&
getCompartmentType() const263 Compartment::getCompartmentType () const
264 {
265   return mCompartmentType;
266 }
267 
268 
269 /*
270  * @return the spatialDimensions of this Compartment.
271  */
272 unsigned int
getSpatialDimensions() const273 Compartment::getSpatialDimensions () const
274 {
275   if (getLevel() < 3)
276   {
277     return mSpatialDimensions;
278   }
279   else
280   {
281     if (isSetSpatialDimensions())
282     {
283       if (ceil(mSpatialDimensionsDouble) ==
284           floor(mSpatialDimensionsDouble))
285       {
286         return static_cast<unsigned int>(mSpatialDimensionsDouble);
287       }
288       else
289       {
290         return numeric_limits<unsigned int>::quiet_NaN();
291       }
292     }
293     else
294     {
295       if (util_isNaN(mSpatialDimensionsDouble))
296       {
297         return 0;
298       }
299       else
300       {
301         return static_cast<unsigned int>(mSpatialDimensionsDouble);
302       }
303     }
304   }
305 }
306 
307 
308 /*
309  * @return the spatialDimensions of this Compartment.
310  */
311 double
getSpatialDimensionsAsDouble() const312 Compartment::getSpatialDimensionsAsDouble () const
313 {
314   if (getLevel() > 2)
315     return mSpatialDimensionsDouble;
316   else
317     return static_cast<double>(mSpatialDimensions);
318 }
319 
320 
321 /*
322  * @return the size (volume in L1) of this Compartment.
323  */
324 double
getSize() const325 Compartment::getSize () const
326 {
327   return mSize;
328 }
329 
330 
331 /*
332  * @return the volume (size in L2) of this Compartment.
333  */
334 double
getVolume() const335 Compartment::getVolume () const
336 {
337   return getSize();
338 }
339 
340 
341 /*
342  * @return the units of this Compartment.
343  */
344 const string&
getUnits() const345 Compartment::getUnits () const
346 {
347   return mUnits;
348 }
349 
350 
351 /*
352  * @return the outside of this Compartment.
353  */
354 const string&
getOutside() const355 Compartment::getOutside () const
356 {
357   return mOutside;
358 }
359 
360 
361 /*
362  * @return @c true if this Compartment is constant, false otherwise.
363  */
364 bool
getConstant() const365 Compartment::getConstant () const
366 {
367   return mConstant;
368 }
369 
370 
371 /*
372  * @return @c true if the id of this SBML object is  set, false
373  * otherwise.
374  */
375 bool
isSetId() const376 Compartment::isSetId () const
377 {
378   return (mId.empty() == false);
379 }
380 
381 
382 /*
383  * @return @c true if the name of this SBML object is  set, false
384  * otherwise.
385  */
386 bool
isSetName() const387 Compartment::isSetName () const
388 {
389   return (getLevel() == 1) ? (mId.empty() == false) :
390                             (mName.empty() == false);
391 }
392 
393 
394 /*
395  * @return @c true if the compartmentType of this Compartment is  set,
396  * false otherwise.
397  */
398 bool
isSetCompartmentType() const399 Compartment::isSetCompartmentType () const
400 {
401   return (mCompartmentType.empty() == false);
402 }
403 
404 
405 /*
406  * @return @c true if the size (volume in L1) of this Compartment is
407  * set, false otherwise.
408  */
409 bool
isSetSize() const410 Compartment::isSetSize () const
411 {
412   return mIsSetSize;
413 }
414 
415 
416 /*
417  * @return @c true if the volume (size in L2) of this Compartment is
418  * set, false otherwise.
419  *
420  * In SBML L1, a Compartment volume has a default value (1.0) and therefore
421  * <b>should always be set</b>.  In L2, volume (size) is optional with no
422  * default value and as such may or may not be set.
423  */
424 bool
isSetVolume() const425 Compartment::isSetVolume () const
426 {
427   return (getLevel() == 1) ? true : isSetSize();
428 }
429 
430 
431 /*
432  * @return @c true if the units of this Compartment is set, false
433  * otherwise.
434  */
435 bool
isSetUnits() const436 Compartment::isSetUnits () const
437 {
438   return (mUnits.empty() == false);
439 }
440 
441 
442 /*
443  * @return @c true if the outside of this Compartment is set, false
444  * otherwise.
445  */
446 bool
isSetOutside() const447 Compartment::isSetOutside () const
448 {
449   return (mOutside.empty() == false);
450 }
451 
452 
453 /*
454  * @return @c true if the spatialDimenions of this Compartment is set, false
455  * otherwise.
456  */
457 bool
isSetSpatialDimensions() const458 Compartment::isSetSpatialDimensions () const
459 {
460   return mIsSetSpatialDimensions;
461 }
462 
463 
464 /*
465  * @return @c true if the constant of this Compartment is set, false
466  * otherwise.
467  */
468 bool
isSetConstant() const469 Compartment::isSetConstant () const
470 {
471   return mIsSetConstant;
472 }
473 
474 
475 /*
476  * Sets the id of this SBML object to a copy of @p sid.
477  */
478 int
setId(const std::string & sid)479 Compartment::setId (const std::string& sid)
480 {
481   /* since the setId function has been used as an
482    * alias for setName we cant require it to only
483    * be used on a L2 model
484    */
485 /*  if (getLevel() == 1)
486   {
487     return LIBSBML_UNEXPECTED_ATTRIBUTE;
488   }
489 */
490   if (!(SyntaxChecker::isValidInternalSId(sid)))
491   {
492     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
493   }
494   else
495   {
496     mId = sid;
497     return LIBSBML_OPERATION_SUCCESS;
498   }
499 }
500 
501 
502 /*
503  * Sets the name of this SBML object to a copy of name.
504  */
505 int
setName(const std::string & name)506 Compartment::setName (const std::string& name)
507 {
508   /* if this is setting an L2 name the type is string
509    * whereas if it is setting an L1 name its type is SId
510    */
511   if (getLevel() == 1)
512   {
513     if (!(SyntaxChecker::isValidInternalSId(name)))
514     {
515       return LIBSBML_INVALID_ATTRIBUTE_VALUE;
516     }
517     else
518     {
519       mId = name;
520       return LIBSBML_OPERATION_SUCCESS;
521     }
522   }
523   else
524   {
525     mName = name;
526     return LIBSBML_OPERATION_SUCCESS;
527   }
528 }
529 
530 
531 /*
532  * Sets the compartmentType field of this Compartment to a copy of @p sid.
533  */
534 int
setCompartmentType(const std::string & sid)535 Compartment::setCompartmentType (const std::string& sid)
536 {
537   if ( (getLevel() < 2)
538     || (getLevel() == 2 && getVersion() == 1))
539   {
540     return LIBSBML_UNEXPECTED_ATTRIBUTE;
541   }
542   else if (!(SyntaxChecker::isValidInternalSId(sid)))
543   {
544     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
545   }
546   else
547   {
548     mCompartmentType = sid;
549     return LIBSBML_OPERATION_SUCCESS;
550   }
551 }
552 
553 
554 /*
555  * Sets the spatialDimensions of this Compartment to value.
556  *
557  * If value is not one of [0, 1, 2, 3] the function will have no effect
558  * (i.e. spatialDimensions will not be set).
559  */
560 int
setSpatialDimensions(unsigned int value)561 Compartment::setSpatialDimensions (unsigned int value)
562 {
563   return setSpatialDimensions((double) value);
564 }
565 
566 
567 /*
568  * Sets the spatialDimensions of this Compartment to value.
569  */
570 int
setSpatialDimensions(double value)571 Compartment::setSpatialDimensions (double value)
572 {
573   bool representsInteger = true;
574   if (floor(value) != value)
575     representsInteger = false;
576 
577   switch (getLevel())
578   {
579   case 1:
580     /* level 1 spatialDimensions was not an attribute */
581     mSpatialDimensions = 3;
582     return LIBSBML_UNEXPECTED_ATTRIBUTE;
583   case 2:
584     if (!representsInteger || value < 0 || value > 3)
585     {
586       return LIBSBML_INVALID_ATTRIBUTE_VALUE;
587     }
588     else
589     {
590       mSpatialDimensions = (unsigned int) value;
591       mSpatialDimensionsDouble = value;
592       mIsSetSpatialDimensions  = true;
593       mExplicitlySetSpatialDimensions = true;
594       return LIBSBML_OPERATION_SUCCESS;
595     }
596   case 3:
597   default:
598       mSpatialDimensions = (unsigned int) value;
599       mSpatialDimensionsDouble = value;
600       mIsSetSpatialDimensions  = true;
601       return LIBSBML_OPERATION_SUCCESS;
602   }
603 }
604 
605 
606 /*
607  * Sets the size (volume in L1) of this Compartment to value.
608  */
609 int
setSize(double value)610 Compartment::setSize (double value)
611 {
612   /* since the setSize function has been used as an
613    * alias for setVolume we cant require it to only
614    * be used on a L2 model
615    */
616 /*  if ( getLevel() < 2 )
617   {
618     return LIBSBML_UNEXPECTED_ATTRIBUTE;
619   }
620 */
621   mSize      = value;
622   mIsSetSize = true;
623   return LIBSBML_OPERATION_SUCCESS;
624 }
625 
626 
627 /*
628  * Sets the volume (size in L2) of this Compartment to value.
629  */
630 int
setVolume(double value)631 Compartment::setVolume (double value)
632 {
633   /* since the setVolume function has been used as an
634    * alias for setSize we cant require it to only
635    * be used on a L1 model
636    */
637 /*  if ( getLevel() != 1 )
638   {
639     return LIBSBML_UNEXPECTED_ATTRIBUTE;
640   }
641 */
642   return setSize(value);
643 }
644 
645 
646 /*
647  * Sets the units of this Compartment to a copy of @p sid.
648  */
649 int
setUnits(const std::string & sid)650 Compartment::setUnits (const std::string& sid)
651 {
652   if (!(SyntaxChecker::isValidInternalUnitSId(sid)))
653   {
654     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
655   }
656   else
657   {
658     mUnits = sid;
659     return LIBSBML_OPERATION_SUCCESS;
660   }
661 }
662 
663 
664 /*
665  * Sets the outside of this Compartment to a copy of @p sid.
666  */
667 int
setOutside(const std::string & sid)668 Compartment::setOutside (const std::string& sid)
669 {
670   if (!(SyntaxChecker::isValidInternalSId(sid)))
671   {
672     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
673   }
674   else
675   {
676     mOutside = sid;
677     return LIBSBML_OPERATION_SUCCESS;
678   }
679 }
680 
681 
682 /*
683  * Sets the constant field of this Compartment to value.
684  */
685 int
setConstant(bool value)686 Compartment::setConstant (bool value)
687 {
688   if ( getLevel() < 2 )
689   {
690     mConstant = value;
691     return LIBSBML_UNEXPECTED_ATTRIBUTE;
692   }
693   else
694   {
695     mConstant = value;
696     mIsSetConstant = true;
697     if (getLevel() < 3)
698     {
699       mExplicitlySetConstant = true;
700     }
701     return LIBSBML_OPERATION_SUCCESS;
702   }
703 }
704 
705 
706 void
renameSIdRefs(const std::string & oldid,const std::string & newid)707 Compartment::renameSIdRefs(const std::string& oldid, const std::string& newid)
708 {
709   SBase::renameSIdRefs(oldid, newid);
710   if (mCompartmentType==oldid) mCompartmentType = newid;
711   if (mOutside==oldid) mOutside= newid; //You know, just in case.
712 }
713 
714 void
renameUnitSIdRefs(const std::string & oldid,const std::string & newid)715 Compartment::renameUnitSIdRefs(const std::string& oldid, const std::string& newid)
716 {
717   SBase::renameUnitSIdRefs(oldid, newid);
718   if (mUnits==oldid) mUnits = newid;
719 }
720 
721 /*
722  * Unsets the name of this SBML object.
723  */
724 int
unsetName()725 Compartment::unsetName ()
726 {
727   if (getLevel() == 1)
728   {
729     mId.erase();
730   }
731   else
732   {
733     mName.erase();
734   }
735 
736   if (getLevel() == 1 && mId.empty())
737   {
738     return LIBSBML_OPERATION_SUCCESS;
739   }
740   else if (mName.empty())
741   {
742     return LIBSBML_OPERATION_SUCCESS;
743   }
744   else
745   {
746     return LIBSBML_OPERATION_FAILED;
747   }
748 }
749 
750 
751 int
unsetConstant()752 Compartment::unsetConstant ()
753 {
754   if ( getLevel() == 1 )
755   {
756     mConstant = false;
757     return LIBSBML_UNEXPECTED_ATTRIBUTE;
758   }
759   else if (getLevel() == 2)
760   {
761     // reset default
762     mConstant = true;
763     mIsSetConstant = true;
764     mExplicitlySetConstant = false;
765     return LIBSBML_UNEXPECTED_ATTRIBUTE;
766   }
767   else
768   {
769     mIsSetConstant = false;
770     mExplicitlySetConstant = false;
771     return LIBSBML_OPERATION_SUCCESS;
772   }
773 }
774 
775 
776 /*
777  * Unsets the compartmentType of this Compartment.
778  */
779 int
unsetCompartmentType()780 Compartment::unsetCompartmentType ()
781 {
782   if ( (getLevel() < 2)
783     || (getLevel() == 2 && getVersion() == 1))
784   {
785     mCompartmentType.erase();
786     return LIBSBML_UNEXPECTED_ATTRIBUTE;
787   }
788 
789   mCompartmentType.erase();
790 
791   if (mCompartmentType.empty())
792   {
793     return LIBSBML_OPERATION_SUCCESS;
794   }
795   else
796   {
797     return LIBSBML_OPERATION_FAILED;
798   }
799 }
800 
801 
802 /*
803  * Unsets the size (volume in L1) of this Compartment.
804  */
805 int
unsetSize()806 Compartment::unsetSize ()
807 {
808   if (getLevel() == 1)
809   {
810     mSize = 1.0;
811   }
812   else
813   {
814     mSize = numeric_limits<double>::quiet_NaN();
815   }
816 
817   mIsSetSize = false;
818 
819   if (!isSetSize())
820   {
821     return LIBSBML_OPERATION_SUCCESS;
822   }
823   else
824   {
825     return LIBSBML_OPERATION_FAILED;
826   }
827 }
828 
829 
830 /*
831  * Unsets the volume (size in L2) of this Compartment.
832  *
833  * In SBML L1, a Compartment volume has a default value (1.0) and therefore
834  * <b>should always be set</b>.  In L2, volume is optional with no default
835  * value and as such may or may not be set.
836  */
837 int
unsetVolume()838 Compartment::unsetVolume ()
839 {
840   return unsetSize();
841 }
842 
843 
844 /*
845  * Unsets the units of this Compartment.
846  */
847 int
unsetUnits()848 Compartment::unsetUnits ()
849 {
850   mUnits.erase();
851 
852   if (mUnits.empty())
853   {
854     return LIBSBML_OPERATION_SUCCESS;
855   }
856   else
857   {
858     return LIBSBML_OPERATION_FAILED;
859   }
860 }
861 
862 
863 /*
864  * Unsets the outside of this Compartment.
865  */
866 int
unsetOutside()867 Compartment::unsetOutside ()
868 {
869   mOutside.erase();
870 
871   if (mOutside.empty())
872   {
873     return LIBSBML_OPERATION_SUCCESS;
874   }
875   else
876   {
877     return LIBSBML_OPERATION_FAILED;
878   }
879 }
880 
881 /*
882  * Unsets the spatialDimensions of this Compartment.
883  */
884 int
unsetSpatialDimensions()885 Compartment::unsetSpatialDimensions ()
886 {
887   if (getLevel() < 3)
888   {
889     mSpatialDimensions = 3;
890     mExplicitlySetSpatialDimensions = false;
891     return LIBSBML_UNEXPECTED_ATTRIBUTE;
892   }
893   else
894   {
895     mSpatialDimensionsDouble = numeric_limits<double>::quiet_NaN();
896   }
897 
898   mIsSetSpatialDimensions = false;
899 
900   if (!isSetSpatialDimensions())
901   {
902     return LIBSBML_OPERATION_SUCCESS;
903   }
904   else
905   {
906     return LIBSBML_OPERATION_FAILED;
907   }
908 }
909 
910 
911 /*
912   * Constructs and returns a UnitDefinition that expresses the units of this
913   * Compartment.
914   */
915 UnitDefinition *
getDerivedUnitDefinition()916 Compartment::getDerivedUnitDefinition()
917 {
918   /* if we have the whole model but it is not in a document
919    * it is still possible to determine the units
920    */
921 
922   /* VERY NASTY HACK THAT WILL WORK IF WE DONT KNOW ABOUT COMP
923    * but will identify if the parent model is a ModelDefinition
924    */
925   Model * m = NULL;
926 
927   if (this->isPackageEnabled("comp"))
928   {
929     m = static_cast <Model *> (getAncestorOfType(251, "comp"));
930   }
931 
932   if (m == NULL)
933   {
934     m = static_cast <Model *> (getAncestorOfType(SBML_MODEL));
935   }
936 
937   /* we should have a model by this point
938    * OR the object is not yet a child of a model
939    */
940 
941   if (m != NULL)
942   {
943     if (!m->isPopulatedListFormulaUnitsData())
944     {
945       m->populateListFormulaUnitsData();
946     }
947 
948     FormulaUnitsData *fud = m->getFormulaUnitsData(getId(), getTypeCode());
949     if (fud != NULL)
950     {
951       return fud->getUnitDefinition();
952     }
953     else
954     {
955       return NULL;
956     }
957   }
958   else
959   {
960     return NULL;
961   }
962 }
963 
964 
965 /*
966   * Constructs and returns a UnitDefinition that expresses the units of this
967   * Compartment.
968   */
969 const UnitDefinition *
getDerivedUnitDefinition() const970 Compartment::getDerivedUnitDefinition() const
971 {
972   return const_cast <Compartment *> (this)->getDerivedUnitDefinition();
973 }
974 
975 
976 /*
977  * @return the typecode (int) of this SBML object or SBML_UNKNOWN
978  * (default).
979  *
980  * @see getElementName()
981  */
982 int
getTypeCode() const983 Compartment::getTypeCode () const
984 {
985   return SBML_COMPARTMENT;
986 }
987 
988 
989 /*
990  * @return the name of this element ie "compartment".
991  */
992 const string&
getElementName() const993 Compartment::getElementName () const
994 {
995   static const string name = "compartment";
996   return name;
997 }
998 
999 
1000 bool
hasRequiredAttributes() const1001 Compartment::hasRequiredAttributes() const
1002 {
1003   bool allPresent = true;
1004 
1005   /* required attributes for compartment: id (name in L1)
1006    * constant (L3 -> )
1007    */
1008 
1009   if (!isSetId())
1010     allPresent = false;
1011 
1012   if (getLevel() > 2 && !isSetConstant())
1013     allPresent = false;
1014 
1015   return allPresent;
1016 }
1017 
1018 
1019 
1020 
1021 
1022 
1023 /** @cond doxygenLibsbmlInternal */
1024 
1025 /*
1026  * Returns the value of the "attributeName" attribute of this Compartment.
1027  */
1028 int
getAttribute(const std::string & attributeName,bool & value) const1029 Compartment::getAttribute(const std::string& attributeName, bool& value) const
1030 {
1031   int return_value = SBase::getAttribute(attributeName, value);
1032 
1033   if (return_value == LIBSBML_OPERATION_SUCCESS)
1034   {
1035     return return_value;
1036   }
1037 
1038   if (attributeName == "constant")
1039   {
1040     value = getConstant();
1041     return_value = LIBSBML_OPERATION_SUCCESS;
1042   }
1043 
1044   return return_value;
1045 }
1046 
1047 /** @endcond */
1048 
1049 
1050 
1051 /** @cond doxygenLibsbmlInternal */
1052 
1053 /*
1054  * Returns the value of the "attributeName" attribute of this Compartment.
1055  */
1056 int
getAttribute(const std::string & attributeName,int & value) const1057 Compartment::getAttribute(const std::string& attributeName, int& value) const
1058 {
1059   int return_value = SBase::getAttribute(attributeName, value);
1060 
1061   return return_value;
1062 }
1063 
1064 /** @endcond */
1065 
1066 
1067 
1068 /** @cond doxygenLibsbmlInternal */
1069 
1070 /*
1071  * Returns the value of the "attributeName" attribute of this Compartment.
1072  */
1073 int
getAttribute(const std::string & attributeName,double & value) const1074 Compartment::getAttribute(const std::string& attributeName,
1075                           double& value) const
1076 {
1077   int return_value = SBase::getAttribute(attributeName, value);
1078 
1079   if (return_value == LIBSBML_OPERATION_SUCCESS)
1080   {
1081     return return_value;
1082   }
1083 
1084   if (attributeName == "size")
1085   {
1086     value = getSize();
1087     return_value = LIBSBML_OPERATION_SUCCESS;
1088   }
1089   else if (attributeName == "volume")
1090   {
1091     value = getVolume();
1092     return_value = LIBSBML_OPERATION_SUCCESS;
1093   }
1094   else if (attributeName == "spatialDimensions")
1095   {
1096     value = getSpatialDimensionsAsDouble();
1097     return_value = LIBSBML_OPERATION_SUCCESS;
1098   }
1099 
1100   return return_value;
1101 }
1102 
1103 /** @endcond */
1104 
1105 
1106 
1107 /** @cond doxygenLibsbmlInternal */
1108 
1109 /*
1110  * Returns the value of the "attributeName" attribute of this Compartment.
1111  */
1112 int
getAttribute(const std::string & attributeName,unsigned int & value) const1113 Compartment::getAttribute(const std::string& attributeName,
1114                           unsigned int& value) const
1115 {
1116   int return_value = SBase::getAttribute(attributeName, value);
1117 
1118   if (return_value == LIBSBML_OPERATION_SUCCESS)
1119   {
1120     return return_value;
1121   }
1122 
1123   if (attributeName == "spatialDimensions")
1124   {
1125     value = getSpatialDimensions();
1126     return_value = LIBSBML_OPERATION_SUCCESS;
1127   }
1128 
1129   return return_value;
1130 }
1131 
1132 /** @endcond */
1133 
1134 
1135 
1136 /** @cond doxygenLibsbmlInternal */
1137 
1138 /*
1139  * Returns the value of the "attributeName" attribute of this Compartment.
1140  */
1141 int
getAttribute(const std::string & attributeName,std::string & value) const1142 Compartment::getAttribute(const std::string& attributeName,
1143                           std::string& value) const
1144 {
1145   int return_value = SBase::getAttribute(attributeName, value);
1146 
1147   if (return_value == LIBSBML_OPERATION_SUCCESS)
1148   {
1149     return return_value;
1150   }
1151 
1152   if (attributeName == "units")
1153   {
1154     value = getUnits();
1155     return_value = LIBSBML_OPERATION_SUCCESS;
1156   }
1157   else if (attributeName == "outside")
1158   {
1159     value = getOutside();
1160     return_value = LIBSBML_OPERATION_SUCCESS;
1161   }
1162   else if (attributeName == "compartmentType")
1163   {
1164     value = getCompartmentType();
1165     return_value = LIBSBML_OPERATION_SUCCESS;
1166   }
1167 
1168   return return_value;
1169 }
1170 
1171 /** @endcond */
1172 
1173 
1174 
1175 /** @cond doxygenLibsbmlInternal */
1176 
1177 /*
1178  * Returns the value of the "attributeName" attribute of this Compartment.
1179  */
1180 //int
1181 //Compartment::getAttribute(const std::string& attributeName,
1182 //                          const char* value) const
1183 //{
1184 //  int return_value = SBase::getAttribute(attributeName, value);
1185 //
1186 //  if (return_value == LIBSBML_OPERATION_SUCCESS)
1187 //  {
1188 //    return return_value;
1189 //  }
1190 //
1191 //  if (attributeName == "units")
1192 //  {
1193 //    value = getUnits().c_str();
1194 //    return_value = LIBSBML_OPERATION_SUCCESS;
1195 //  }
1196 //  else if (attributeName == "outside")
1197 //  {
1198 //    value = getOutside().c_str();
1199 //    return_value = LIBSBML_OPERATION_SUCCESS;
1200 //  }
1201 //  else if (attributeName == "compartmentType")
1202 //  {
1203 //    value = getCompartmentType().c_str();
1204 //    return_value = LIBSBML_OPERATION_SUCCESS;
1205 //  }
1206 //
1207 //  return return_value;
1208 //}
1209 //
1210 /** @endcond */
1211 
1212 
1213 
1214 /** @cond doxygenLibsbmlInternal */
1215 
1216 /*
1217  * Predicate returning @c true if this Compartment's attribute "attributeName"
1218  * is set.
1219  */
1220 bool
isSetAttribute(const std::string & attributeName) const1221 Compartment::isSetAttribute(const std::string& attributeName) const
1222 {
1223   bool value = SBase::isSetAttribute(attributeName);
1224 
1225   if (attributeName == "size")
1226   {
1227     value = isSetSize();
1228   }
1229   else if (attributeName == "volume")
1230   {
1231     value = isSetVolume();
1232   }
1233   else if (attributeName == "units")
1234   {
1235     value = isSetUnits();
1236   }
1237   else if (attributeName == "spatialDimensions")
1238   {
1239     value = isSetSpatialDimensions();
1240   }
1241   else if (attributeName == "constant")
1242   {
1243     value = isSetConstant();
1244   }
1245   else if (attributeName == "outside")
1246   {
1247     value = isSetOutside();
1248   }
1249   else if (attributeName == "compartmentType")
1250   {
1251     value = isSetCompartmentType();
1252   }
1253 
1254   return value;
1255 }
1256 
1257 /** @endcond */
1258 
1259 
1260 
1261 /** @cond doxygenLibsbmlInternal */
1262 
1263 /*
1264  * Sets the value of the "attributeName" attribute of this Compartment.
1265  */
1266 int
setAttribute(const std::string & attributeName,bool value)1267 Compartment::setAttribute(const std::string& attributeName, bool value)
1268 {
1269   int return_value = SBase::setAttribute(attributeName, value);
1270 
1271   if (attributeName == "constant")
1272   {
1273     return_value = setConstant(value);
1274   }
1275 
1276   return return_value;
1277 }
1278 
1279 /** @endcond */
1280 
1281 
1282 
1283 /** @cond doxygenLibsbmlInternal */
1284 
1285 /*
1286  * Sets the value of the "attributeName" attribute of this Compartment.
1287  */
1288 int
setAttribute(const std::string & attributeName,int value)1289 Compartment::setAttribute(const std::string& attributeName, int value)
1290 {
1291   int return_value = SBase::setAttribute(attributeName, value);
1292 
1293   return return_value;
1294 }
1295 
1296 /** @endcond */
1297 
1298 
1299 
1300 /** @cond doxygenLibsbmlInternal */
1301 
1302 /*
1303  * Sets the value of the "attributeName" attribute of this Compartment.
1304  */
1305 int
setAttribute(const std::string & attributeName,double value)1306 Compartment::setAttribute(const std::string& attributeName, double value)
1307 {
1308   int return_value = SBase::setAttribute(attributeName, value);
1309 
1310   if (attributeName == "size")
1311   {
1312     return_value = setSize(value);
1313   }
1314   else if (attributeName == "volume")
1315   {
1316     return_value = setVolume(value);
1317   }
1318   else if (attributeName == "spatialDimensions")
1319   {
1320     return_value = setSpatialDimensions(value);
1321   }
1322 
1323   return return_value;
1324 }
1325 
1326 /** @endcond */
1327 
1328 
1329 
1330 /** @cond doxygenLibsbmlInternal */
1331 
1332 /*
1333  * Sets the value of the "attributeName" attribute of this Compartment.
1334  */
1335 int
setAttribute(const std::string & attributeName,unsigned int value)1336 Compartment::setAttribute(const std::string& attributeName,
1337                           unsigned int value)
1338 {
1339   int return_value = SBase::setAttribute(attributeName, value);
1340 
1341   if (attributeName == "spatialDimensions")
1342   {
1343     return_value = setSpatialDimensions(value);
1344   }
1345 
1346   return return_value;
1347 }
1348 
1349 /** @endcond */
1350 
1351 
1352 
1353 /** @cond doxygenLibsbmlInternal */
1354 
1355 /*
1356  * Sets the value of the "attributeName" attribute of this Compartment.
1357  */
1358 int
setAttribute(const std::string & attributeName,const std::string & value)1359 Compartment::setAttribute(const std::string& attributeName,
1360                           const std::string& value)
1361 {
1362   int return_value = SBase::setAttribute(attributeName, value);
1363 
1364   if (attributeName == "units")
1365   {
1366     return_value = setUnits(value);
1367   }
1368   else if (attributeName == "outside")
1369   {
1370     return_value = setOutside(value);
1371   }
1372   else if (attributeName == "compartmentType")
1373   {
1374     return_value = setCompartmentType(value);
1375   }
1376 
1377   return return_value;
1378 }
1379 
1380 /** @endcond */
1381 
1382 
1383 
1384 /** @cond doxygenLibsbmlInternal */
1385 
1386 /*
1387  * Sets the value of the "attributeName" attribute of this Compartment.
1388  */
1389 //int
1390 //Compartment::setAttribute(const std::string& attributeName, const char* value)
1391 //{
1392 //  int return_value = SBase::setAttribute(attributeName, value);
1393 //
1394 //  if (attributeName == "units")
1395 //  {
1396 //    return_value = setUnits(value);
1397 //  }
1398 //  else if (attributeName == "outside")
1399 //  {
1400 //    return_value = setOutside(value);
1401 //  }
1402 //  else if (attributeName == "compartmentType")
1403 //  {
1404 //    return_value = setCompartmentType(value);
1405 //  }
1406 //
1407 //  return return_value;
1408 //}
1409 //
1410 ///** @endcond */
1411 //
1412 //
1413 
1414 /** @cond doxygenLibsbmlInternal */
1415 
1416 /*
1417  * Unsets the value of the "attributeName" attribute of this Compartment.
1418  */
1419 int
unsetAttribute(const std::string & attributeName)1420 Compartment::unsetAttribute(const std::string& attributeName)
1421 {
1422   int value = SBase::unsetAttribute(attributeName);
1423 
1424   if (attributeName == "size")
1425   {
1426     value = unsetSize();
1427   }
1428   else if (attributeName == "volume")
1429   {
1430     value = unsetVolume();
1431   }
1432   else if (attributeName == "units")
1433   {
1434     value = unsetUnits();
1435   }
1436   else if (attributeName == "spatialDimensions")
1437   {
1438     value = unsetSpatialDimensions();
1439   }
1440   else if (attributeName == "constant")
1441   {
1442     value = unsetConstant();
1443   }
1444   else if (attributeName == "outside")
1445   {
1446     value = unsetOutside();
1447   }
1448   else if (attributeName == "compartmentType")
1449   {
1450     value = unsetCompartmentType();
1451   }
1452 
1453   return value;
1454 }
1455 
1456 /** @endcond */
1457 
1458 /** @cond doxygenLibsbmlInternal */
isExplicitlySetSpatialDimensions() const1459 bool Compartment::isExplicitlySetSpatialDimensions() const
1460 {
1461     return mExplicitlySetSpatialDimensions;
1462 }
1463 /** @endcond */
1464 
1465 /** @cond doxygenLibsbmlInternal */
isExplicitlySetConstant() const1466 bool Compartment::isExplicitlySetConstant() const
1467 {
1468     return mExplicitlySetConstant;
1469 }
1470 /** @endcond */
1471 
1472 
1473 /** @cond doxygenLibsbmlInternal */
1474 /**
1475  * Subclasses should override this method to get the list of
1476  * expected attributes.
1477  * This function is invoked from corresponding readAttributes()
1478  * function.
1479  */
1480 void
addExpectedAttributes(ExpectedAttributes & attributes)1481 Compartment::addExpectedAttributes(ExpectedAttributes& attributes)
1482 {
1483   SBase::addExpectedAttributes(attributes);
1484 
1485   attributes.add("name");
1486   attributes.add("units");
1487 
1488   const unsigned int level   = getLevel  ();
1489   const unsigned int version = getVersion();
1490 
1491   switch (level)
1492   {
1493   case 1:
1494     attributes.add("name");
1495     attributes.add("units");
1496     attributes.add("outside");
1497     attributes.add("volume");
1498     break;
1499   case 2:
1500     attributes.add("name");
1501     attributes.add("units");
1502     attributes.add("outside");
1503     attributes.add("id");
1504     attributes.add("size");
1505     attributes.add("spatialDimensions");
1506     attributes.add("constant");
1507     if (version > 1)
1508     {
1509       attributes.add("compartmentType");
1510     }
1511     break;
1512   case 3:
1513   default:
1514     attributes.add("name");
1515     attributes.add("units");
1516     attributes.add("id");
1517     attributes.add("size");
1518     attributes.add("spatialDimensions");
1519     attributes.add("constant");
1520     break;
1521   }
1522 }
1523 /** @endcond */
1524 
1525 
1526 /** @cond doxygenLibsbmlInternal */
1527 /*
1528  * Subclasses should override this method to read values from the given
1529  * XMLAttributes set into their specific fields.  Be sure to call your
1530  * parent's implementation of this method as well.
1531  */
1532 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)1533 Compartment::readAttributes (const XMLAttributes& attributes,
1534                              const ExpectedAttributes& expectedAttributes)
1535 {
1536   const unsigned int level   = getLevel  ();
1537 
1538   SBase::readAttributes(attributes, expectedAttributes);
1539 
1540   switch (level)
1541   {
1542   case 1:
1543     readL1Attributes(attributes);
1544     break;
1545   case 2:
1546     readL2Attributes(attributes);
1547     break;
1548   case 3:
1549   default:
1550     readL3Attributes(attributes);
1551     break;
1552   }
1553 }
1554 /** @endcond */
1555 
1556 
1557 /** @cond doxygenLibsbmlInternal */
1558 /*
1559  * Subclasses should override this method to read values from the given
1560  * XMLAttributes set into their specific fields.  Be sure to call your
1561  * parent's implementation of this method as well.
1562  */
1563 void
readL1Attributes(const XMLAttributes & attributes)1564 Compartment::readL1Attributes (const XMLAttributes& attributes)
1565 {
1566   const unsigned int level = 1;
1567   const unsigned int version = getVersion();
1568 
1569   //
1570   // name: SName   { use="required" }  (L1v1, L1v2)
1571   //
1572   bool assigned = attributes.readInto("name", mId, getErrorLog(), true, getLine(), getColumn());
1573   if (assigned && mId.size() == 0)
1574   {
1575     logEmptyString("name", level, version, "<compartment>");
1576   }
1577   if (!SyntaxChecker::isValidInternalSId(mId))
1578     logError(InvalidIdSyntax, level, version, "The id '" + mId + "' does not conform to the syntax.");
1579 
1580   //
1581   // volume  { use="optional" default="1" }  (L1v1, L1v2)
1582   //
1583   mIsSetSize = attributes.readInto("volume", mSize, getErrorLog(), false, getLine(), getColumn());
1584 
1585   //
1586   // units  { use="optional" }  (L1v1 ->)
1587   //
1588   assigned = attributes.readInto("units", mUnits, getErrorLog(), false, getLine(), getColumn());
1589   if (assigned && mUnits.size() == 0)
1590   {
1591     logEmptyString("units", level, version, "<compartment>");
1592   }
1593   if (!SyntaxChecker::isValidInternalUnitSId(mUnits))
1594   {
1595     logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The units attribute '" + mUnits + "' does not conform to the syntax.");
1596   }
1597 
1598   //
1599   // outside  { use="optional" }  (L1v1 -> L2v4)
1600   //
1601   attributes.readInto("outside", mOutside, getErrorLog(), false, getLine(), getColumn());
1602 }
1603 /** @endcond */
1604 
1605 
1606 /** @cond doxygenLibsbmlInternal */
1607 /*
1608  * Subclasses should override this method to read values from the given
1609  * XMLAttributes set into their specific fields.  Be sure to call your
1610  * parent's implementation of this method as well.
1611  */
1612 void
readL2Attributes(const XMLAttributes & attributes)1613 Compartment::readL2Attributes (const XMLAttributes& attributes)
1614 {
1615   const unsigned int level = 2;
1616   const unsigned int version = getVersion();
1617 
1618   //
1619   //   id: SId     { use="required" }  (L2v1 ->)
1620   //
1621   bool assigned = attributes.readInto("id", mId, getErrorLog(), true, getLine(), getColumn());
1622   if (assigned && mId.size() == 0)
1623   {
1624     logEmptyString("id", level, version, "<compartment>");
1625   }
1626   if (!SyntaxChecker::isValidInternalSId(mId))
1627     logError(InvalidIdSyntax, level, version, "The id '" + mId + "' does not conform to the syntax.");
1628 
1629   //
1630   // size    { use="optional" }              (L2v1 ->)
1631   //
1632   mIsSetSize = attributes.readInto("size", mSize, getErrorLog(), false, getLine(), getColumn());
1633 
1634   //
1635   // units  { use="optional" }  (L1v1 ->)
1636   //
1637   assigned = attributes.readInto("units", mUnits, getErrorLog(), false, getLine(), getColumn());
1638   if (assigned && mUnits.size() == 0)
1639   {
1640     logEmptyString("units", level, version, "<compartment>");
1641   }
1642   if (!SyntaxChecker::isValidInternalUnitSId(mUnits))
1643   {
1644     logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The units attribute '" + mUnits + "' does not conform to the syntax.");
1645   }
1646 
1647   //
1648   // outside  { use="optional" }  (L1v1 -> L2v4)
1649   //
1650   attributes.readInto("outside", mOutside, getErrorLog(), false, getLine(), getColumn());
1651 
1652   //
1653   // name: string  { use="optional" }  (L2v1 ->)
1654   //
1655   attributes.readInto("name", mName, getErrorLog(), false, getLine(), getColumn());
1656 
1657   //
1658   // spatialDimensions { maxInclusive="3" minInclusive="0" use="optional"
1659   //                     default="3" }  (L2v1 ->)
1660   mExplicitlySetSpatialDimensions = attributes.readInto("spatialDimensions",
1661                                     mSpatialDimensions, getErrorLog(), false, getLine(), getColumn());
1662   if (/*mSpatialDimensions < 0 ||*/ mSpatialDimensions > 3)
1663   {
1664     std::string message = "The spatialDimensions attribute on ";
1665     message += "a <compartment> may only have values 0, 1, 2 or 3.";
1666     logError(NotSchemaConformant, level, version,
1667                                                           message);
1668   }
1669   else
1670   {
1671     // keep record as double
1672     mSpatialDimensionsDouble = (double)(mSpatialDimensions);
1673     mIsSetSpatialDimensions = true;
1674   }
1675 
1676   //
1677   // constant  { use="optional" default="true" }  (L2v1 ->)
1678   //
1679   mExplicitlySetConstant = attributes.readInto("constant", mConstant, getErrorLog(), false, getLine(), getColumn());
1680 
1681   //
1682   // compartmentType: SId  { use="optional" }  (L2v2 -> L2v4)
1683   //
1684   if (version != 1)
1685   {
1686     attributes.readInto("compartmentType", mCompartmentType,
1687                                         getErrorLog(), false, getLine(), getColumn());
1688   }
1689 }
1690 /** @endcond */
1691 
1692 
1693 /** @cond doxygenLibsbmlInternal */
1694 /*
1695  * Subclasses should override this method to read values from the given
1696  * XMLAttributes set into their specific fields.  Be sure to call your
1697  * parent's implementation of this method as well.
1698  */
1699 void
readL3Attributes(const XMLAttributes & attributes)1700 Compartment::readL3Attributes (const XMLAttributes& attributes)
1701 {
1702   const unsigned int level = 3;
1703   const unsigned int version = getVersion();
1704 
1705   //
1706   //   id: SId     { use="required" }  (L2v1 ->)
1707   //
1708   bool assigned;
1709   // for l3v2 sbase will read this as generically optional
1710   // we want to log errors relating to the specific object
1711   if (version == 1)
1712   {
1713     assigned = attributes.readInto("id", mId, getErrorLog(), false, getLine(), getColumn());
1714     if (!assigned)
1715     {
1716       logError(AllowedAttributesOnCompartment, level, version,
1717         "The required attribute 'id' is missing.");
1718     }
1719     if (assigned && mId.size() == 0)
1720     {
1721       logEmptyString("id", level, version, "<compartment>");
1722     }
1723     if (!SyntaxChecker::isValidInternalSId(mId))
1724       logError(InvalidIdSyntax, level, version, "The id '" + mId + "' does not conform to the syntax.");
1725 
1726   }
1727   else
1728   {
1729     // need to check that id was present
1730     // it has already been read and checked for syntax/emptyness
1731     if (attributes.hasAttribute("id") == false)
1732     {
1733       logError(AllowedAttributesOnCompartment, level, version,
1734         "The required attribute 'id' is missing.");
1735     }
1736   }
1737 
1738   string elplusid = "<compartment>";
1739   if (!mId.empty()) {
1740     elplusid += " with the id '" + mId + "'";
1741   }
1742 
1743   //
1744   // size    { use="optional" }              (L2v1 ->)
1745   //
1746   mIsSetSize = attributes.readInto("size", mSize, getErrorLog(), false, getLine(), getColumn());
1747 
1748   //
1749   // units  { use="optional" }  (L1v1 ->)
1750   //
1751   assigned = attributes.readInto("units", mUnits, getErrorLog(), false, getLine(), getColumn());
1752   if (assigned && mUnits.size() == 0)
1753   {
1754     logEmptyString("units", level, version, "<compartment>");
1755   }
1756   if (!SyntaxChecker::isValidInternalUnitSId(mUnits))
1757   {
1758     logError(InvalidUnitIdSyntax, level, version, "The " + elplusid +
1759       " has a substanceUnits with a value of '" + mUnits
1760       + "' which does not conform .");
1761   }
1762 
1763 
1764   //
1765   // name: string  { use="optional" }  (L2v1 ->)
1766   //
1767   // for l3v2 sbase will read this
1768   if (version == 1)
1769   {
1770     attributes.readInto("name", mName, getErrorLog(), false,
1771                                        getLine(), getColumn());
1772   }
1773 
1774   //
1775   // spatialDimensions { use="optional"}  (L3v1 ->)
1776   //
1777   mIsSetSpatialDimensions = attributes.readInto("spatialDimensions",
1778                         mSpatialDimensionsDouble, getErrorLog(), false, getLine(), getColumn());
1779 
1780   // keep integer value as record if spatial dimensions is 0, 1, 2, 3
1781   if (mIsSetSpatialDimensions == true)
1782   {
1783     mSpatialDimensions = (unsigned int) (mSpatialDimensionsDouble);
1784   }
1785 
1786   //
1787   // constant  { use="required" }  (L3v1 ->)
1788   //
1789   mIsSetConstant = attributes.readInto("constant", mConstant,
1790                                           getErrorLog(), false, getLine(), getColumn());
1791   mExplicitlySetConstant = mIsSetConstant;
1792   if (!mIsSetConstant)
1793   {
1794     logError(AllowedAttributesOnCompartment, level, version,
1795       "The required attribute 'constant' is missing from the "
1796       + elplusid + ".");
1797   }
1798 }
1799 /** @endcond */
1800 
1801 
1802 /** @cond doxygenLibsbmlInternal */
1803 /*
1804  * Subclasses should override this method to write their XML attributes
1805  * to the XMLOutputStream.  Be sure to call your parent's implementation
1806  * of this method as well.
1807  */
1808 void
writeAttributes(XMLOutputStream & stream) const1809 Compartment::writeAttributes (XMLOutputStream& stream) const
1810 {
1811   SBase::writeAttributes(stream);
1812 
1813   const unsigned int level   = getLevel  ();
1814   const unsigned int version = getVersion();
1815 
1816   // for L3V2 and above SBase will write this out
1817   if (level < 3 || (level == 3 && version == 1))
1818   {
1819     //
1820     // name: SName   { use="required" }  (L1v1, L1v2)
1821     //   id: SId     { use="required" }  (L2v1, L2v2)
1822     //
1823     const string id = (level == 1) ? "name" : "id";
1824     stream.writeAttribute(id, mId);
1825   }
1826   if (level > 1)
1827   {
1828     // for L3V2 and above SBase will write this out
1829     if (level < 3 || (level == 3 && version == 1))
1830     {
1831       //
1832       // name: string  { use="optional" }  (L2v1->)
1833       //
1834       stream.writeAttribute("name", mName);
1835     }
1836 
1837     //
1838     // compartmentType: SId  { use="optional" }  (L2v2 -> L2v4)
1839     //
1840     if (level == 2 && version > 1)
1841     {
1842       stream.writeAttribute("compartmentType", mCompartmentType);
1843     }
1844 
1845     //
1846     // spatialDimensions { maxInclusive="3" minInclusive="0" use="optional"
1847     //                     default="3" }  (L2v1->L2v4)
1848     // spatialDimensions { use="optional"}  (L3v1 ->)
1849     //
1850     if (level == 2)
1851     {
1852       unsigned int sd = mSpatialDimensions;
1853       if (/*sd >= 0 &&*/ sd <= 2)
1854       {
1855         stream.writeAttribute("spatialDimensions", sd);
1856       }
1857       else if (isExplicitlySetSpatialDimensions())
1858       {
1859         // spatialDimensions has been explicitly set to the default value
1860         stream.writeAttribute("spatialDimensions", sd);
1861       }
1862     }
1863     else
1864     {
1865       if (isSetSpatialDimensions())
1866       {
1867         stream.writeAttribute("spatialDimensions", mSpatialDimensionsDouble);
1868       }
1869     }
1870   }
1871 
1872   //
1873   // volume  { use="optional" default="1" }  (L1v1, L1v2)
1874   // size    { use="optional" }              (L2v1->)
1875   //
1876   if (mIsSetSize)
1877   {
1878     const string size = (level == 1) ? "volume" : "size";
1879     stream.writeAttribute(size, mSize);
1880   }
1881 
1882   //
1883   // units  { use="optional" }  (L1v1, L1v2, L2v1->)
1884   //
1885   stream.writeAttribute("units", mUnits);
1886 
1887   //
1888   // outside  { use="optional" }  (L1v1-> L2v4)
1889   //
1890   if (level < 3)
1891   {
1892     stream.writeAttribute("outside", mOutside);
1893   }
1894 
1895   if (level > 1)
1896   {
1897     //
1898     // constant  { use="optional" default="true" }  (L2v1->)
1899     // constant  { use="required" }  (L3v1 ->)
1900     //
1901     if (level == 2)
1902     {
1903       if (mConstant != true || isExplicitlySetConstant())
1904       {
1905         stream.writeAttribute("constant", mConstant);
1906       }
1907     }
1908     else
1909     {
1910       // in L3 only write it out if it has been set
1911       if (isSetConstant())
1912         stream.writeAttribute("constant", mConstant);
1913     }
1914     //
1915     // sboTerm: SBOTerm { use="optional" }  (L2v3 ->)
1916     // is written in SBase::writeAttributes()
1917     //
1918   }
1919 
1920   //
1921   // (EXTENSION)
1922   //
1923   SBase::writeExtensionAttributes(stream);
1924 }
1925 /** @endcond */
1926 
1927 
1928 /** @cond doxygenLibsbmlInternal */
1929 /*
1930  * Subclasses should override this method to write out their contained
1931  * SBML objects as XML elements.  Be sure to call your parent's
1932  * implementation of this method as well.
1933  */
1934 void
writeElements(XMLOutputStream & stream) const1935 Compartment::writeElements (XMLOutputStream& stream) const
1936 {
1937   SBase::writeElements(stream);
1938   //
1939   // (EXTENSION)
1940   //
1941   SBase::writeExtensionElements(stream);
1942 }
1943 /** @endcond */
1944 
1945 
1946 /*
1947  * Creates a new ListOfCompartments items.
1948  */
ListOfCompartments(unsigned int level,unsigned int version)1949 ListOfCompartments::ListOfCompartments (unsigned int level, unsigned int version)
1950   : ListOf(level,version)
1951 {
1952 }
1953 
1954 
1955 /*
1956  * Creates a new ListOfCompartments items.
1957  */
ListOfCompartments(SBMLNamespaces * sbmlns)1958 ListOfCompartments::ListOfCompartments (SBMLNamespaces* sbmlns)
1959   : ListOf(sbmlns)
1960 {
1961   loadPlugins(sbmlns);
1962 }
1963 
1964 
1965 /*
1966  * @return a (deep) copy of this ListOfCompartments.
1967  */
1968 ListOfCompartments*
clone() const1969 ListOfCompartments::clone () const
1970 {
1971   return new ListOfCompartments(*this);
1972 }
1973 
1974 
1975 /*
1976  * @return the typecode (int) of SBML objects contained in this ListOf or
1977  * SBML_UNKNOWN (default).
1978  */
1979 int
getItemTypeCode() const1980 ListOfCompartments::getItemTypeCode () const
1981 {
1982   return SBML_COMPARTMENT;
1983 }
1984 
1985 
1986 /*
1987  * @return the name of this element ie "listOfCompartments".
1988  */
1989 const string&
getElementName() const1990 ListOfCompartments::getElementName () const
1991 {
1992   static const string name = "listOfCompartments";
1993   return name;
1994 }
1995 
1996 /* return nth item in list */
1997 Compartment *
get(unsigned int n)1998 ListOfCompartments::get(unsigned int n)
1999 {
2000   return static_cast<Compartment*>(ListOf::get(n));
2001 }
2002 
2003 
2004 /* return nth item in list */
2005 const Compartment *
get(unsigned int n) const2006 ListOfCompartments::get(unsigned int n) const
2007 {
2008   return static_cast<const Compartment*>(ListOf::get(n));
2009 }
2010 
2011 
2012 
2013 /* return item by id */
2014 Compartment*
get(const std::string & sid)2015 ListOfCompartments::get (const std::string& sid)
2016 {
2017   return const_cast<Compartment*>(
2018     static_cast<const ListOfCompartments&>(*this).get(sid) );
2019 }
2020 
2021 
2022 /* return item by id */
2023 const Compartment*
get(const std::string & sid) const2024 ListOfCompartments::get (const std::string& sid) const
2025 {
2026   vector<SBase*>::const_iterator result;
2027 
2028   {
2029     result = find_if( mItems.begin(), mItems.end(), IdEq<Compartment>(sid) );
2030     return (result == mItems.end()) ? NULL :
2031                                       static_cast <Compartment*> (*result);
2032   }
2033 }
2034 
2035 
2036 /* Removes the nth item from this list */
2037 Compartment*
remove(unsigned int n)2038 ListOfCompartments::remove (unsigned int n)
2039 {
2040   return static_cast<Compartment*>(ListOf::remove(n));
2041 }
2042 
2043 
2044 /* Removes item in this list by id */
2045 Compartment*
remove(const std::string & sid)2046 ListOfCompartments::remove (const std::string& sid)
2047 {
2048   SBase* item = NULL;
2049   vector<SBase*>::iterator result;
2050 
2051   result = find_if( mItems.begin(), mItems.end(), IdEq<Compartment>(sid) );
2052 
2053   if (result != mItems.end())
2054   {
2055     item = *result;
2056     mItems.erase(result);
2057   }
2058 
2059   return static_cast <Compartment*> (item);
2060 }
2061 
2062 
2063 /** @cond doxygenLibsbmlInternal */
2064 /*
2065  * @return the ordinal position of the element with respect to its siblings
2066  * or -1 (default) to indicate the position is not significant.
2067  */
2068 int
getElementPosition() const2069 ListOfCompartments::getElementPosition () const
2070 {
2071   return 5;
2072 }
2073 /** @endcond */
2074 
2075 
2076 /** @cond doxygenLibsbmlInternal */
2077 /*
2078  * @return the SBML object corresponding to next XMLToken in the
2079  * XMLInputStream or @c NULL if the token was not recognized.
2080  */
2081 SBase*
createObject(XMLInputStream & stream)2082 ListOfCompartments::createObject (XMLInputStream& stream)
2083 {
2084   const string& name   = stream.peek().getName();
2085   SBase*        object = NULL;
2086 
2087 
2088   if (name == "compartment")
2089   {
2090     try
2091     {
2092       object = new Compartment(getSBMLNamespaces());
2093     }
2094     catch (SBMLConstructorException*)
2095     {
2096       object = new Compartment(SBMLDocument::getDefaultLevel(),
2097         SBMLDocument::getDefaultVersion());
2098     }
2099     catch ( ... )
2100     {
2101       object = new Compartment(SBMLDocument::getDefaultLevel(),
2102         SBMLDocument::getDefaultVersion());
2103     }
2104 
2105     if (object != NULL) mItems.push_back(object);
2106   }
2107 
2108   return object;
2109 }
2110 /** @endcond */
2111 
2112 
2113 #endif /* __cplusplus */
2114 /** @cond doxygenIgnored */
2115 LIBSBML_EXTERN
2116 Compartment_t *
Compartment_create(unsigned int level,unsigned int version)2117 Compartment_create (unsigned int level, unsigned int version)
2118 {
2119   try
2120   {
2121     Compartment* obj = new Compartment(level,version);
2122     return obj;
2123   }
2124   catch (SBMLConstructorException)
2125   {
2126     return NULL;
2127   }
2128 }
2129 
2130 
2131 LIBSBML_EXTERN
2132 Compartment_t *
Compartment_createWithNS(SBMLNamespaces_t * sbmlns)2133 Compartment_createWithNS (SBMLNamespaces_t* sbmlns)
2134 {
2135   try
2136   {
2137     Compartment* obj = new Compartment(sbmlns);
2138     return obj;
2139   }
2140   catch (SBMLConstructorException)
2141   {
2142     return NULL;
2143   }
2144 }
2145 
2146 
2147 LIBSBML_EXTERN
2148 void
Compartment_free(Compartment_t * c)2149 Compartment_free (Compartment_t *c)
2150 {
2151   if (c != NULL)
2152   delete c;
2153 }
2154 
2155 
2156 LIBSBML_EXTERN
2157 Compartment_t *
Compartment_clone(const Compartment_t * c)2158 Compartment_clone (const Compartment_t* c)
2159 {
2160   if (c != NULL)
2161   {
2162     return static_cast<Compartment*>(c->clone());
2163   }
2164   else
2165   {
2166     return NULL;
2167   }
2168 }
2169 
2170 
2171 LIBSBML_EXTERN
2172 void
Compartment_initDefaults(Compartment_t * c)2173 Compartment_initDefaults (Compartment_t *c)
2174 {
2175   if (c != NULL) c->initDefaults();
2176 }
2177 
2178 
2179 LIBSBML_EXTERN
2180 const XMLNamespaces_t *
Compartment_getNamespaces(Compartment_t * c)2181 Compartment_getNamespaces(Compartment_t *c)
2182 {
2183   if (c != NULL)
2184   {
2185     return c->getNamespaces();
2186   }
2187   else
2188   {
2189     return NULL;
2190   }
2191 }
2192 
2193 
2194 LIBSBML_EXTERN
2195 const char *
Compartment_getId(const Compartment_t * c)2196 Compartment_getId (const Compartment_t *c)
2197 {
2198   return (c != NULL && c->isSetId()) ? c->getId().c_str() : NULL;
2199 }
2200 
2201 
2202 LIBSBML_EXTERN
2203 const char *
Compartment_getName(const Compartment_t * c)2204 Compartment_getName (const Compartment_t *c)
2205 {
2206   return (c != NULL && c->isSetName()) ? c->getName().c_str() : NULL;
2207 }
2208 
2209 
2210 LIBSBML_EXTERN
2211 const char *
Compartment_getCompartmentType(const Compartment_t * c)2212 Compartment_getCompartmentType (const Compartment_t *c)
2213 {
2214   return (c != NULL && c->isSetCompartmentType())
2215                                      ? c->getCompartmentType().c_str() : NULL;
2216 }
2217 
2218 
2219 LIBSBML_EXTERN
2220 unsigned int
Compartment_getSpatialDimensions(const Compartment_t * c)2221 Compartment_getSpatialDimensions (const Compartment_t *c)
2222 {
2223     return (c != NULL) ? c->getSpatialDimensions() : SBML_INT_MAX;
2224 }
2225 
2226 
2227 LIBSBML_EXTERN
2228 double
Compartment_getSpatialDimensionsAsDouble(const Compartment_t * c)2229 Compartment_getSpatialDimensionsAsDouble (const Compartment_t *c)
2230 {
2231   return (c != NULL) ? c->getSpatialDimensionsAsDouble() :
2232                        numeric_limits<double>::quiet_NaN();
2233 }
2234 
2235 
2236 LIBSBML_EXTERN
2237 double
Compartment_getSize(const Compartment_t * c)2238 Compartment_getSize (const Compartment_t *c)
2239 {
2240   return (c != NULL) ? c->getSize() : numeric_limits<double>::quiet_NaN();
2241 }
2242 
2243 
2244 LIBSBML_EXTERN
2245 double
Compartment_getVolume(const Compartment_t * c)2246 Compartment_getVolume (const Compartment_t *c)
2247 {
2248   return (c != NULL) ? c->getVolume() : numeric_limits<double>::quiet_NaN();
2249 }
2250 
2251 
2252 LIBSBML_EXTERN
2253 const char *
Compartment_getUnits(const Compartment_t * c)2254 Compartment_getUnits (const Compartment_t *c)
2255 {
2256   return (c != NULL && c->isSetUnits()) ? c->getUnits().c_str() : NULL;
2257 }
2258 
2259 
2260 LIBSBML_EXTERN
2261 const char *
Compartment_getOutside(const Compartment_t * c)2262 Compartment_getOutside (const Compartment_t *c)
2263 {
2264   return (c != NULL && c->isSetOutside()) ? c->getOutside().c_str() : NULL;
2265 }
2266 
2267 
2268 LIBSBML_EXTERN
2269 int
Compartment_getConstant(const Compartment_t * c)2270 Compartment_getConstant (const Compartment_t *c)
2271 {
2272   return (c != NULL) ? static_cast<int>( c->getConstant() ) : 0;
2273 }
2274 
2275 
2276 LIBSBML_EXTERN
2277 int
Compartment_isSetId(const Compartment_t * c)2278 Compartment_isSetId (const Compartment_t *c)
2279 {
2280   return (c != NULL) ? static_cast<int>( c->isSetId() ) : 0;
2281 }
2282 
2283 
2284 LIBSBML_EXTERN
2285 int
Compartment_isSetName(const Compartment_t * c)2286 Compartment_isSetName (const Compartment_t *c)
2287 {
2288   return (c != NULL) ? static_cast<int>( c->isSetName() ) : 0;
2289 }
2290 
2291 
2292 LIBSBML_EXTERN
2293 int
Compartment_isSetCompartmentType(const Compartment_t * c)2294 Compartment_isSetCompartmentType (const Compartment_t *c)
2295 {
2296   return (c != NULL) ? static_cast<int>( c->isSetCompartmentType() ) : 0;
2297 }
2298 
2299 
2300 LIBSBML_EXTERN
2301 int
Compartment_isSetSize(const Compartment_t * c)2302 Compartment_isSetSize (const Compartment_t *c)
2303 {
2304   return (c != NULL) ? static_cast<int>( c->isSetSize() ):0;
2305 }
2306 
2307 
2308 LIBSBML_EXTERN
2309 int
Compartment_isSetVolume(const Compartment_t * c)2310 Compartment_isSetVolume (const Compartment_t *c)
2311 {
2312   return (c != NULL) ? static_cast<int>( c->isSetVolume() ) : 0;
2313 }
2314 
2315 
2316 LIBSBML_EXTERN
2317 int
Compartment_isSetUnits(const Compartment_t * c)2318 Compartment_isSetUnits (const Compartment_t *c)
2319 {
2320   return (c != NULL) ? static_cast<int>( c->isSetUnits() ) : 0;
2321 }
2322 
2323 
2324 LIBSBML_EXTERN
2325 int
Compartment_isSetOutside(const Compartment_t * c)2326 Compartment_isSetOutside (const Compartment_t *c)
2327 {
2328   return (c != NULL) ? static_cast<int>( c->isSetOutside() ) : 0;
2329 }
2330 
2331 
2332 LIBSBML_EXTERN
2333 int
Compartment_isSetSpatialDimensions(const Compartment_t * c)2334 Compartment_isSetSpatialDimensions (const Compartment_t *c)
2335 {
2336   return (c != NULL) ? static_cast<int>( c->isSetSpatialDimensions() ) : 0;
2337 }
2338 
2339 
2340 LIBSBML_EXTERN
2341 int
Compartment_isSetConstant(const Compartment_t * c)2342 Compartment_isSetConstant (const Compartment_t *c)
2343 {
2344   return (c != NULL) ? static_cast<int>( c->isSetConstant() ) : 0;
2345 }
2346 
2347 
2348 LIBSBML_EXTERN
2349 int
Compartment_setId(Compartment_t * c,const char * sid)2350 Compartment_setId (Compartment_t *c, const char *sid)
2351 {
2352   if (c != NULL)
2353     return (sid == NULL) ? c->setId("") : c->setId(sid);
2354   else
2355     return LIBSBML_INVALID_OBJECT;
2356 }
2357 
2358 
2359 LIBSBML_EXTERN
2360 int
Compartment_setName(Compartment_t * c,const char * name)2361 Compartment_setName (Compartment_t *c, const char *name)
2362 {
2363    if (c != NULL)
2364     return (name == NULL) ? c->unsetName() : c->setName(name);
2365   else
2366     return LIBSBML_INVALID_OBJECT;
2367 }
2368 
2369 
2370 LIBSBML_EXTERN
2371 int
Compartment_setCompartmentType(Compartment_t * c,const char * sid)2372 Compartment_setCompartmentType (Compartment_t *c, const char *sid)
2373 {
2374   if (c != NULL)
2375     return (sid == NULL) ?
2376              c->unsetCompartmentType() : c->setCompartmentType(sid);
2377   else
2378     return LIBSBML_INVALID_OBJECT;
2379 }
2380 
2381 
2382 LIBSBML_EXTERN
2383 int
Compartment_setSpatialDimensions(Compartment_t * c,unsigned int value)2384 Compartment_setSpatialDimensions (Compartment_t *c, unsigned int value)
2385 {
2386   if (c != NULL)
2387     return c->setSpatialDimensions(value);
2388   else
2389     return LIBSBML_INVALID_OBJECT;
2390 }
2391 
2392 
2393 LIBSBML_EXTERN
2394 int
Compartment_setSpatialDimensionsAsDouble(Compartment_t * c,double value)2395 Compartment_setSpatialDimensionsAsDouble (Compartment_t *c, double value)
2396 {
2397   if (c != NULL)
2398     return c->setSpatialDimensions(value);
2399   else
2400     return LIBSBML_INVALID_OBJECT;
2401 }
2402 
2403 
2404 LIBSBML_EXTERN
2405 int
Compartment_setSize(Compartment_t * c,double value)2406 Compartment_setSize (Compartment_t *c, double value)
2407 {
2408   if (c != NULL)
2409     return c->setSize(value);
2410   else
2411     return LIBSBML_INVALID_OBJECT;
2412 }
2413 
2414 
2415 LIBSBML_EXTERN
2416 int
Compartment_setVolume(Compartment_t * c,double value)2417 Compartment_setVolume (Compartment_t *c, double value)
2418 {
2419   if (c != NULL)
2420     return c->setVolume(value);
2421   else
2422     return LIBSBML_INVALID_OBJECT;
2423 }
2424 
2425 
2426 LIBSBML_EXTERN
2427 int
Compartment_setUnits(Compartment_t * c,const char * sid)2428 Compartment_setUnits (Compartment_t *c, const char *sid)
2429 {
2430   if (c != NULL)
2431     return (sid == NULL) ? c->unsetUnits() : c->setUnits(sid);
2432   else
2433     return LIBSBML_INVALID_OBJECT;
2434 }
2435 
2436 
2437 LIBSBML_EXTERN
2438 int
Compartment_setOutside(Compartment_t * c,const char * sid)2439 Compartment_setOutside (Compartment_t *c, const char *sid)
2440 {
2441   if (c != NULL)
2442     return (sid == NULL) ? c->unsetOutside() : c->setOutside(sid);
2443   else
2444     return LIBSBML_INVALID_OBJECT;
2445 }
2446 
2447 
2448 LIBSBML_EXTERN
2449 int
Compartment_setConstant(Compartment_t * c,int value)2450 Compartment_setConstant (Compartment_t *c, int value)
2451 {
2452   if (c != NULL)
2453     return c->setConstant( static_cast<bool>(value) );
2454   else
2455     return LIBSBML_INVALID_OBJECT;
2456 }
2457 
2458 
2459 LIBSBML_EXTERN
2460 int
Compartment_unsetName(Compartment_t * c)2461 Compartment_unsetName (Compartment_t *c)
2462 {
2463   if (c != NULL)
2464     return c->unsetName();
2465   else
2466     return LIBSBML_INVALID_OBJECT;
2467 }
2468 
2469 
2470 LIBSBML_EXTERN
2471 int
Compartment_unsetCompartmentType(Compartment_t * c)2472 Compartment_unsetCompartmentType (Compartment_t *c)
2473 {
2474   if (c != NULL)
2475     return c->unsetCompartmentType();
2476   else
2477     return LIBSBML_INVALID_OBJECT;
2478 }
2479 
2480 
2481 LIBSBML_EXTERN
2482 int
Compartment_unsetConstant(Compartment_t * c)2483 Compartment_unsetConstant (Compartment_t *c)
2484 {
2485   if (c != NULL)
2486     return c->unsetConstant();
2487   else
2488     return LIBSBML_INVALID_OBJECT;
2489 }
2490 
2491 
2492 LIBSBML_EXTERN
2493 int
Compartment_unsetSize(Compartment_t * c)2494 Compartment_unsetSize (Compartment_t *c)
2495 {
2496   if (c != NULL)
2497     return c->unsetSize();
2498   else
2499     return LIBSBML_INVALID_OBJECT;
2500 }
2501 
2502 
2503 LIBSBML_EXTERN
2504 int
Compartment_unsetVolume(Compartment_t * c)2505 Compartment_unsetVolume (Compartment_t *c)
2506 {
2507   if (c != NULL)
2508     return c->unsetVolume();
2509   else
2510     return LIBSBML_INVALID_OBJECT;
2511 }
2512 
2513 
2514 LIBSBML_EXTERN
2515 int
Compartment_unsetUnits(Compartment_t * c)2516 Compartment_unsetUnits (Compartment_t *c)
2517 {
2518   if (c != NULL)
2519     return c->unsetUnits();
2520   else
2521     return LIBSBML_INVALID_OBJECT;
2522 }
2523 
2524 
2525 LIBSBML_EXTERN
2526 int
Compartment_unsetOutside(Compartment_t * c)2527 Compartment_unsetOutside (Compartment_t *c)
2528 {
2529   if (c != NULL)
2530     return c->unsetOutside();
2531   else
2532     return LIBSBML_INVALID_OBJECT;
2533 }
2534 
2535 
2536 LIBSBML_EXTERN
2537 int
Compartment_unsetSpatialDimensions(Compartment_t * c)2538 Compartment_unsetSpatialDimensions (Compartment_t *c)
2539 {
2540   if (c != NULL)
2541     return c->unsetSpatialDimensions();
2542   else
2543     return LIBSBML_INVALID_OBJECT;
2544 }
2545 
2546 
2547 LIBSBML_EXTERN
2548 UnitDefinition_t *
Compartment_getDerivedUnitDefinition(Compartment_t * c)2549 Compartment_getDerivedUnitDefinition(Compartment_t *c)
2550 {
2551   if (c != NULL)
2552     return c->getDerivedUnitDefinition();
2553   else
2554     return NULL;
2555 }
2556 
2557 
2558 LIBSBML_EXTERN
2559 int
Compartment_hasRequiredAttributes(Compartment_t * c)2560 Compartment_hasRequiredAttributes(Compartment_t *c)
2561 {
2562   return (c != NULL) ? static_cast<int>(c->hasRequiredAttributes()) : 0;
2563 }
2564 
2565 
2566 LIBSBML_EXTERN
2567 Compartment_t *
ListOfCompartments_getById(ListOf_t * lo,const char * sid)2568 ListOfCompartments_getById (ListOf_t *lo, const char *sid)
2569 {
2570   if (lo != NULL)
2571     return (sid != NULL) ?
2572     static_cast <ListOfCompartments *> (lo)->get(sid) : NULL;
2573   else
2574     return NULL;
2575 }
2576 
2577 
2578 LIBSBML_EXTERN
2579 Compartment_t *
ListOfCompartments_removeById(ListOf_t * lo,const char * sid)2580 ListOfCompartments_removeById (ListOf_t *lo, const char *sid)
2581 {
2582   if (lo != NULL)
2583     return (sid != NULL) ?
2584             static_cast <ListOfCompartments *> (lo)->remove(sid) : NULL;
2585   else
2586     return NULL;
2587 }
2588 /** @endcond */
2589 
2590 LIBSBML_CPP_NAMESPACE_END
2591 
2592