1 /**
2 * @file FluxBound.cpp
3 * @brief Implementation of FluxBound, the SBase derived class of the fbc package.
4 * @author Akiya Jouraku
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 * This library is free software; you can redistribute it and/or modify it
29 * under the terms of the GNU Lesser General Public License as published by
30 * the Free Software Foundation. A copy of the license agreement is provided
31 * in the file named "LICENSE.txt" included with this software distribution
32 * and also available online as http://sbml.org/software/libsbml/license.html
33 *------------------------------------------------------------------------- -->
34 */
35
36 #include <iostream>
37
38 #include <sbml/SBMLVisitor.h>
39 #include <sbml/xml/XMLNode.h>
40 #include <sbml/xml/XMLToken.h>
41 #include <sbml/xml/XMLAttributes.h>
42 #include <sbml/xml/XMLInputStream.h>
43 #include <sbml/xml/XMLOutputStream.h>
44
45 #include <sbml/packages/fbc/sbml/FluxBound.h>
46 #include <sbml/packages/fbc/extension/FbcExtension.h>
47 #include <sbml/packages/fbc/validator/FbcSBMLError.h>
48
49 #include <sbml/util/util.h>
50
51
52 using namespace std;
53
54 #ifdef __cplusplus
55
56 LIBSBML_CPP_NAMESPACE_BEGIN
57 #ifdef __cplusplus
58
59 /*
60 * Creates a new FluxBound with the given level, version, and package version.
61 */
FluxBound(unsigned int level,unsigned int version,unsigned int pkgVersion)62 FluxBound::FluxBound (unsigned int level, unsigned int version, unsigned int pkgVersion)
63 : SBase (level,version)
64 // ,mId("")
65 // ,mName("")
66 ,mReaction("")
67 ,mOperation (FLUXBOUND_OPERATION_UNKNOWN)
68 ,mOperationString("")
69 ,mValue(numeric_limits<double>::quiet_NaN())
70 {
71 // set an SBMLNamespaces derived object (FluxBoundsPkgNamespaces) of this package.
72 setSBMLNamespacesAndOwn(new FbcPkgNamespaces(level,version,pkgVersion));
73
74 // connect child elements to this element.
75 connectToChild();
76 }
77
78
79 /*
80 * Creates a new FluxBound with the given FluxBoundsPkgNamespaces object.
81 */
FluxBound(FbcPkgNamespaces * fbcns)82 FluxBound::FluxBound(FbcPkgNamespaces* fbcns)
83 : SBase(fbcns)
84 // ,mId("")
85 // ,mName("")
86 ,mReaction("")
87 ,mOperation (FLUXBOUND_OPERATION_UNKNOWN)
88 ,mOperationString("")
89 ,mValue(numeric_limits<double>::quiet_NaN())
90 {
91 // set the element namespace of this object
92 setElementNamespace(fbcns->getURI());
93
94 // connect child elements to this element.
95 connectToChild();
96
97 // load package extensions bound with this object (if any)
98 loadPlugins(fbcns);
99 }
100
101
102 /*
103 * Copy constructor.
104 */
FluxBound(const FluxBound & source)105 FluxBound::FluxBound(const FluxBound& source) : SBase(source)
106 {
107 this->mId=source.mId;
108 this->mName=source.mName;
109 this->mReaction=source.mReaction;
110 this->mOperation=source.mOperation;
111 this->mOperationString=source.mOperationString;
112 this->mValue=source.mValue;
113
114 // connect child elements to this element.
115 connectToChild();
116 }
117
118 /*
119 * Assignment operator.
120 */
operator =(const FluxBound & source)121 FluxBound& FluxBound::operator=(const FluxBound& source)
122 {
123 if(&source!=this)
124 {
125 this->SBase::operator=(source);
126 this->mId = source.mId;
127 this->mName = source.mName;
128 this->mReaction=source.mReaction;
129 this->mOperation=source.mOperation;
130 this->mOperationString=source.mOperationString;
131 this->mValue=source.mValue;
132
133 // connect child elements to this element.
134 connectToChild();
135 }
136
137 return *this;
138 }
139
140
141 /*
142 * Destructor.
143 */
~FluxBound()144 FluxBound::~FluxBound ()
145 {
146 }
147
148
149 /*
150 * Returns the value of the "id" attribute of this FluxBound.
151 */
152 const std::string&
getId() const153 FluxBound::getId () const
154 {
155 return mId;
156 }
157
158
159 /*
160 * Predicate returning @c true or @c false depending on whether this
161 * FluxBound's "id" attribute has been set.
162 */
163 bool
isSetId() const164 FluxBound::isSetId () const
165 {
166 return (mId.empty() == false);
167 }
168
169 /*
170 * Sets the value of the "id" attribute of this FluxBound.
171 */
172 int
setId(const std::string & id)173 FluxBound::setId (const std::string& id)
174 {
175 return SyntaxChecker::checkAndSetSId(id,mId);
176 }
177
178
179 /*
180 * Unsets the value of the "id" attribute of this FluxBound.
181 */
182 int
unsetId()183 FluxBound::unsetId ()
184 {
185 mId.erase();
186 if (mId.empty())
187 {
188 return LIBSBML_OPERATION_SUCCESS;
189 }
190 else
191 {
192 return LIBSBML_OPERATION_FAILED;
193 }
194 }
195
196
197
198 /*
199 * Returns the value of the "name" attribute of this FluxBound.
200 */
201 const std::string&
getName() const202 FluxBound::getName () const
203 {
204 return mName;
205 }
206
207
208 /*
209 * Predicate returning @c true or @c false depending on whether this
210 * FluxBound's "name" attribute has been set.
211 */
212 bool
isSetName() const213 FluxBound::isSetName () const
214 {
215 return (mName.empty() == false);
216 }
217
218 /*
219 * Sets the value of the "name" attribute of this FluxBound.
220 */
221 int
setName(const std::string & name)222 FluxBound::setName (const std::string& name)
223 {
224 mName = name;
225 return LIBSBML_OPERATION_SUCCESS;
226 }
227
228
229 /*
230 * Unsets the value of the "name" attribute of this FluxBound.
231 */
232 int
unsetName()233 FluxBound::unsetName ()
234 {
235 mName.erase();
236 if (mName.empty())
237 {
238 return LIBSBML_OPERATION_SUCCESS;
239 }
240 else
241 {
242 return LIBSBML_OPERATION_FAILED;
243 }
244 }
245
246
247
248 /*
249 * Sets the reaction of this SBML object to a copy of reaction.
250 */
251 int
setReaction(const std::string & reaction)252 FluxBound::setReaction (const std::string& reaction)
253 {
254 mReaction = reaction;
255 return LIBSBML_OPERATION_SUCCESS;
256 }
257
258
259 /*
260 * @return the reaction of this SBML object.
261 */
262 const string&
getReaction() const263 FluxBound::getReaction () const
264 {
265 return mReaction;
266 }
267
268
269 /*
270 * @return @c true if the reaction of this SBML object has been set, false
271 * otherwise.
272 */
273 bool
isSetReaction() const274 FluxBound::isSetReaction () const
275 {
276 return (mReaction.empty() == false);
277 }
278
279
280 /*
281 * Unsets the reaction of this SBML object.
282 */
283 int
unsetReaction()284 FluxBound::unsetReaction ()
285 {
286 mReaction.erase();
287
288 if (mReaction.empty())
289 {
290 return LIBSBML_OPERATION_SUCCESS;
291 }
292 else
293 {
294 return LIBSBML_OPERATION_FAILED;
295 }
296 }
297
298
299
300 /*
301 * Sets the operation of this SBML object to a copy of operation.
302 */
303 int
setOperation(FluxBoundOperation_t operation)304 FluxBound::setOperation (FluxBoundOperation_t operation)
305 {
306 if (FluxBoundOperation_isValidFluxBoundOperation(operation) == 0)
307 {
308 mOperation = FLUXBOUND_OPERATION_UNKNOWN;
309 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
310 }
311 else
312 {
313 mOperation = operation;
314 return LIBSBML_OPERATION_SUCCESS;
315 }
316 }
317
318
319 /*
320 * Sets the operation of this SBML object to a copy of operation.
321 */
322 int
setOperation(const std::string & operation)323 FluxBound::setOperation (const std::string& operation)
324 {
325 return setOperation(FluxBoundOperation_fromString(operation.c_str()));
326 }
327
328
329 /*
330 * @return the operation of this SBML object.
331 */
332 const string&
getOperation()333 FluxBound::getOperation ()
334 {
335 if (FluxBoundOperation_toString(mOperation) != NULL)
336 {
337 mOperationString.assign(FluxBoundOperation_toString(mOperation));
338 }
339 else
340 {
341 mOperationString.assign("");
342 }
343 return mOperationString;
344 }
345
346
347 /*
348 * @return the operation of this SBML object.
349 */
350 FluxBoundOperation_t
getFluxBoundOperation() const351 FluxBound::getFluxBoundOperation () const
352 {
353 return mOperation;
354 }
355
356
357 /*
358 * @return @c true if the operation of this SBML object has been set, false
359 * otherwise.
360 */
361 bool
isSetOperation() const362 FluxBound::isSetOperation () const
363 {
364 return (mOperation != FLUXBOUND_OPERATION_UNKNOWN);
365 }
366
367
368 /*
369 * Unsets the operation of this SBML object.
370 */
371 int
unsetOperation()372 FluxBound::unsetOperation ()
373 {
374 mOperation = FLUXBOUND_OPERATION_UNKNOWN;
375 return LIBSBML_OPERATION_SUCCESS;
376 }
377
378
379 /*
380 * Sets the value of this SBML object to a copy of value.
381 */
382 int
setValue(const double value)383 FluxBound::setValue (const double value)
384 {
385 mValue = value;
386 return LIBSBML_OPERATION_SUCCESS;
387 }
388
389
390 /*
391 * @return the value of this SBML object.
392 */
393 double
getValue() const394 FluxBound::getValue () const
395 {
396 return mValue;
397 }
398
399
400 /*
401 * @return @c true if the value of this SBML object has been set, false
402 * otherwise.
403 */
404 bool
isSetValue() const405 FluxBound::isSetValue () const
406 {
407 return (!util_isNaN(mValue));
408 }
409
410
411 /*
412 * Unsets the value of this SBML object.
413 */
414 int
unsetValue()415 FluxBound::unsetValue ()
416 {
417 mValue = numeric_limits<double>::quiet_NaN();
418 return LIBSBML_OPERATION_SUCCESS;
419 }
420
421
422 /*
423 * rename attributes that are SIdRefs or instances in math
424 */
425 void
renameSIdRefs(const std::string & oldid,const std::string & newid)426 FluxBound::renameSIdRefs(const std::string& oldid, const std::string& newid)
427 {
428 SBase::renameSIdRefs(oldid, newid);
429 if (isSetReaction() == true && mReaction == oldid)
430 {
431 setReaction(newid);
432 }
433
434 }
435
436
437 /*
438 * Returns the XML element name of
439 * this SBML object.
440 */
441 const std::string&
getElementName() const442 FluxBound::getElementName () const
443 {
444 static const std::string name = "fluxBound";
445 return name;
446 }
447
448
449 /** @cond doxygenLibsbmlInternal */
450 SBase*
createObject(XMLInputStream &)451 FluxBound::createObject (XMLInputStream&)
452 {
453 return NULL;
454 }
455 /** @endcond */
456 /** @cond doxygenLibsbmlInternal */
457
458 /*
459 * Returns the value of the "attributeName" attribute of this FluxBound.
460 */
461 int
getAttribute(const std::string & attributeName,bool & value) const462 FluxBound::getAttribute(const std::string& attributeName, bool& value) const
463 {
464 int return_value = SBase::getAttribute(attributeName, value);
465
466 return return_value;
467 }
468
469 /** @endcond */
470
471
472
473 /** @cond doxygenLibsbmlInternal */
474
475 /*
476 * Returns the value of the "attributeName" attribute of this FluxBound.
477 */
478 int
getAttribute(const std::string & attributeName,int & value) const479 FluxBound::getAttribute(const std::string& attributeName, int& value) const
480 {
481 int return_value = SBase::getAttribute(attributeName, value);
482
483 return return_value;
484 }
485
486 /** @endcond */
487
488
489
490 /** @cond doxygenLibsbmlInternal */
491
492 /*
493 * Returns the value of the "attributeName" attribute of this FluxBound.
494 */
495 int
getAttribute(const std::string & attributeName,double & value) const496 FluxBound::getAttribute(const std::string& attributeName, double& value) const
497 {
498 int return_value = SBase::getAttribute(attributeName, value);
499
500 if (return_value == LIBSBML_OPERATION_SUCCESS)
501 {
502 return return_value;
503 }
504
505 if (attributeName == "value")
506 {
507 value = getValue();
508 return_value = LIBSBML_OPERATION_SUCCESS;
509 }
510
511 return return_value;
512 }
513
514 /** @endcond */
515
516
517
518 /** @cond doxygenLibsbmlInternal */
519
520 /*
521 * Returns the value of the "attributeName" attribute of this FluxBound.
522 */
523 int
getAttribute(const std::string & attributeName,unsigned int & value) const524 FluxBound::getAttribute(const std::string& attributeName,
525 unsigned int& value) const
526 {
527 int return_value = SBase::getAttribute(attributeName, value);
528
529 return return_value;
530 }
531
532 /** @endcond */
533
534
535
536 /** @cond doxygenLibsbmlInternal */
537
538 /*
539 * Returns the value of the "attributeName" attribute of this FluxBound.
540 */
541 int
getAttribute(const std::string & attributeName,std::string & value) const542 FluxBound::getAttribute(const std::string& attributeName,
543 std::string& value) const
544 {
545 int return_value = SBase::getAttribute(attributeName, value);
546
547 if (return_value == LIBSBML_OPERATION_SUCCESS)
548 {
549 return return_value;
550 }
551
552 if (attributeName == "id")
553 {
554 value = getId();
555 return_value = LIBSBML_OPERATION_SUCCESS;
556 }
557 else if (attributeName == "name")
558 {
559 value = getName();
560 return_value = LIBSBML_OPERATION_SUCCESS;
561 }
562 else if (attributeName == "reaction")
563 {
564 value = getReaction();
565 return_value = LIBSBML_OPERATION_SUCCESS;
566 }
567 else if (attributeName == "operation")
568 {
569 value = const_cast<FluxBound*>(this)->getOperation();
570 return_value = LIBSBML_OPERATION_SUCCESS;
571 }
572
573 return return_value;
574 }
575
576 /** @endcond */
577
578
579
580 /** @cond doxygenLibsbmlInternal */
581
582 /*
583 * Predicate returning @c true if this FluxBound's attribute "attributeName" is
584 * set.
585 */
586 bool
isSetAttribute(const std::string & attributeName) const587 FluxBound::isSetAttribute(const std::string& attributeName) const
588 {
589 bool value = SBase::isSetAttribute(attributeName);
590
591 if (attributeName == "id")
592 {
593 value = isSetId();
594 }
595 else if (attributeName == "name")
596 {
597 value = isSetName();
598 }
599 else if (attributeName == "reaction")
600 {
601 value = isSetReaction();
602 }
603 else if (attributeName == "operation")
604 {
605 value = isSetOperation();
606 }
607 else if (attributeName == "value")
608 {
609 value = isSetValue();
610 }
611
612 return value;
613 }
614
615 /** @endcond */
616
617
618
619 /** @cond doxygenLibsbmlInternal */
620
621 /*
622 * Sets the value of the "attributeName" attribute of this FluxBound.
623 */
624 int
setAttribute(const std::string & attributeName,bool value)625 FluxBound::setAttribute(const std::string& attributeName, bool value)
626 {
627 int return_value = SBase::setAttribute(attributeName, value);
628
629 return return_value;
630 }
631
632 /** @endcond */
633
634
635
636 /** @cond doxygenLibsbmlInternal */
637
638 /*
639 * Sets the value of the "attributeName" attribute of this FluxBound.
640 */
641 int
setAttribute(const std::string & attributeName,int value)642 FluxBound::setAttribute(const std::string& attributeName, int value)
643 {
644 int return_value = SBase::setAttribute(attributeName, value);
645
646 return return_value;
647 }
648
649 /** @endcond */
650
651
652
653 /** @cond doxygenLibsbmlInternal */
654
655 /*
656 * Sets the value of the "attributeName" attribute of this FluxBound.
657 */
658 int
setAttribute(const std::string & attributeName,double value)659 FluxBound::setAttribute(const std::string& attributeName, double value)
660 {
661 int return_value = SBase::setAttribute(attributeName, value);
662
663 if (attributeName == "value")
664 {
665 return_value = setValue(value);
666 }
667
668 return return_value;
669 }
670
671 /** @endcond */
672
673
674
675 /** @cond doxygenLibsbmlInternal */
676
677 /*
678 * Sets the value of the "attributeName" attribute of this FluxBound.
679 */
680 int
setAttribute(const std::string & attributeName,unsigned int value)681 FluxBound::setAttribute(const std::string& attributeName, unsigned int value)
682 {
683 int return_value = SBase::setAttribute(attributeName, value);
684
685 return return_value;
686 }
687
688 /** @endcond */
689
690
691
692 /** @cond doxygenLibsbmlInternal */
693
694 /*
695 * Sets the value of the "attributeName" attribute of this FluxBound.
696 */
697 int
setAttribute(const std::string & attributeName,const std::string & value)698 FluxBound::setAttribute(const std::string& attributeName,
699 const std::string& value)
700 {
701 int return_value = SBase::setAttribute(attributeName, value);
702
703 if (attributeName == "id")
704 {
705 return_value = setId(value);
706 }
707 else if (attributeName == "name")
708 {
709 return_value = setName(value);
710 }
711 else if (attributeName == "reaction")
712 {
713 return_value = setReaction(value);
714 }
715 else if (attributeName == "operation")
716 {
717 return_value = setOperation(value);
718 }
719
720 return return_value;
721 }
722
723 /** @endcond */
724
725
726
727 /** @cond doxygenLibsbmlInternal */
728
729 /*
730 * Unsets the value of the "attributeName" attribute of this FluxBound.
731 */
732 int
unsetAttribute(const std::string & attributeName)733 FluxBound::unsetAttribute(const std::string& attributeName)
734 {
735 int value = SBase::unsetAttribute(attributeName);
736
737 if (attributeName == "id")
738 {
739 value = unsetId();
740 }
741 else if (attributeName == "name")
742 {
743 value = unsetName();
744 }
745 else if (attributeName == "reaction")
746 {
747 value = unsetReaction();
748 }
749 else if (attributeName == "operation")
750 {
751 value = unsetOperation();
752 }
753 else if (attributeName == "value")
754 {
755 value = unsetValue();
756 }
757
758 return value;
759 }
760
761 /** @endcond */
762
763
764
765 /** @cond doxygenLibsbmlInternal */
766 void
addExpectedAttributes(ExpectedAttributes & attributes)767 FluxBound::addExpectedAttributes(ExpectedAttributes& attributes)
768 {
769 SBase::addExpectedAttributes(attributes);
770
771 attributes.add("id");
772 attributes.add("name");
773 attributes.add("reaction");
774 attributes.add("operation");
775 attributes.add("value");
776 }
777 /** @endcond */
778
779 /** @cond doxygenLibsbmlInternal */
780 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)781 FluxBound::readAttributes (const XMLAttributes& attributes,
782 const ExpectedAttributes& expectedAttributes)
783 {
784
785 const unsigned int sbmlLevel = getLevel ();
786 const unsigned int sbmlVersion = getVersion();
787
788 // look to see whether an unknown attribute error was logged
789 // during the read of the listOfFluxBounds - which will have
790 // happened immediately prior to this read
791 if (getErrorLog() != NULL &&
792 static_cast<ListOfFluxBounds*>(getParentSBMLObject())->size() < 2)
793 {
794 unsigned int numErrs = getErrorLog()->getNumErrors();
795 for (int n = (int)numErrs-1; n >= 0; n--)
796 {
797 if (getErrorLog()->getError((unsigned int)n)->getErrorId() == UnknownPackageAttribute)
798 {
799 const std::string details =
800 getErrorLog()->getError((unsigned int)n)->getMessage();
801 getErrorLog()->remove(UnknownPackageAttribute);
802 getErrorLog()->logPackageError("fbc", FbcLOFluxBoundsAllowedAttributes,
803 getPackageVersion(), sbmlLevel, sbmlVersion, details, getLine(), getColumn());
804 }
805 else if (getErrorLog()->getError((unsigned int)n)->getErrorId() == UnknownCoreAttribute)
806 {
807 const std::string details =
808 getErrorLog()->getError((unsigned int)n)->getMessage();
809 getErrorLog()->remove(UnknownCoreAttribute);
810 getErrorLog()->logPackageError("fbc", FbcLOFluxBoundsAllowedAttributes,
811 getPackageVersion(), sbmlLevel, sbmlVersion, details, getLine(), getColumn());
812 }
813 }
814 }
815
816 SBase::readAttributes(attributes,expectedAttributes);
817
818 // look to see whether an unknown attribute error was logged
819 if (getErrorLog() != NULL)
820 {
821 unsigned int numErrs = getErrorLog()->getNumErrors();
822 for (int n = (int)numErrs-1; n >= 0; n--)
823 {
824 if (getErrorLog()->getError((unsigned int)n)->getErrorId() == UnknownPackageAttribute)
825 {
826 const std::string details =
827 getErrorLog()->getError((unsigned int)n)->getMessage();
828 getErrorLog()->remove(UnknownPackageAttribute);
829 getErrorLog()->logPackageError("fbc", FbcFluxBoundRequiredAttributes,
830 getPackageVersion(), sbmlLevel, sbmlVersion, details, getLine(), getColumn());
831 }
832 else if (getErrorLog()->getError((unsigned int)n)->getErrorId() == UnknownCoreAttribute)
833 {
834 const std::string details =
835 getErrorLog()->getError((unsigned int)n)->getMessage();
836 getErrorLog()->remove(UnknownCoreAttribute);
837 getErrorLog()->logPackageError("fbc", FbcFluxBoundAllowedL3Attributes,
838 getPackageVersion(), sbmlLevel, sbmlVersion, details, getLine(), getColumn());
839 }
840 }
841 }
842
843
844 //
845 // Reads an attribute "id" (optional)
846 //
847 bool assigned = attributes.readInto("id", mId);
848
849 if (assigned)
850 {
851 // "id" attribute is set to this fbc element
852
853 if (mId.empty())
854 {
855 //
856 // Logs an error if the "id" attribute is empty.
857 //
858 logEmptyString(mId, sbmlLevel, sbmlVersion, "<fbc>");
859 }
860 else if (!SyntaxChecker::isValidSBMLSId(mId))
861 {
862 //
863 // Logs an error if the "id" attribute doesn't
864 // conform to the SBML type SId.
865 //
866 getErrorLog()->logPackageError("fbc", FbcSBMLSIdSyntax,
867 getPackageVersion(), sbmlLevel, sbmlVersion, "", getLine(), getColumn());
868 }
869 }
870
871 attributes.readInto("name", mName);
872
873 assigned = attributes.readInto("reaction", mReaction);
874 if (assigned == false)
875 {
876 std::string message = "Fbc attribute 'reaction' is missing.";
877 getErrorLog()->logPackageError("fbc", FbcFluxBoundRequiredAttributes,
878 getPackageVersion(), sbmlLevel, sbmlVersion, message, getLine(), getColumn());
879 }
880 else
881 {
882 if (mReaction.empty())
883 {
884 //
885 // Logs an error if the "id" attribute is empty.
886 //
887 logEmptyString(mReaction, sbmlLevel, sbmlVersion, "<fbc>");
888 }
889 else if (!SyntaxChecker::isValidSBMLSId(mReaction))
890 {
891 //
892 // Logs an error if the "id" attribute doesn't
893 // conform to the SBML type SId.
894 //
895 getErrorLog()->logPackageError("fbc", FbcFluxBoundRectionMustBeSIdRef,
896 getPackageVersion(), sbmlLevel, sbmlVersion, "", getLine(), getColumn());
897 }
898 }
899
900 //
901 // type string ( use = "required" )
902 //
903 std::string operation;
904 assigned = attributes.readInto("operation", operation);
905
906 if (assigned == true)
907 {
908 // check string is not empty
909
910 if (operation.empty() == true)
911 {
912 logEmptyString(operation, sbmlLevel, sbmlVersion, "<Objective>");
913 }
914 else
915 {
916 mOperation = FluxBoundOperation_fromString( operation.c_str() );
917 if (FluxBoundOperation_isValidFluxBoundOperation(mOperation) == 0)
918 {
919 getErrorLog()->logPackageError("fbc", FbcFluxBoundOperationMustBeEnum,
920 getPackageVersion(), sbmlLevel, sbmlVersion, "", getLine(), getColumn());
921 }
922 }
923 }
924 else
925 {
926 std::string message = "Fbc attribute 'operation' is missing.";
927 getErrorLog()->logPackageError("fbc", FbcFluxBoundRequiredAttributes,
928 getPackageVersion(), sbmlLevel, sbmlVersion, message, getLine(), getColumn());
929 }
930
931 unsigned int numErrs = getErrorLog()->getNumErrors();
932 assigned = attributes.readInto("value", mValue, getErrorLog());
933
934 if (assigned == false)
935 {
936 if (getErrorLog()->getNumErrors() == numErrs + 1 &&
937 getErrorLog()->contains(XMLAttributeTypeMismatch))
938 {
939 getErrorLog()->remove(XMLAttributeTypeMismatch);
940 getErrorLog()->logPackageError("fbc", FbcFluxBoundValueMustBeDouble,
941 getPackageVersion(), sbmlLevel, sbmlVersion, "", getLine(), getColumn());
942 }
943 else
944 {
945 std::string message = "Fbc attribute 'value' is missing.";
946 getErrorLog()->logPackageError("fbc", FbcFluxBoundRequiredAttributes,
947 getPackageVersion(), sbmlLevel, sbmlVersion, message, getLine(), getColumn());
948 }
949 }
950 }
951 /** @endcond */
952
953 /** @cond doxygenLibsbmlInternal */
954 void
writeAttributes(XMLOutputStream & stream) const955 FluxBound::writeAttributes (XMLOutputStream& stream) const
956 {
957 SBase::writeAttributes(stream);
958
959 if (isSetId())
960 stream.writeAttribute("id", getPrefix(), mId);
961 if (isSetName())
962 stream.writeAttribute("name", getPrefix(), mName);
963 if (isSetReaction())
964 stream.writeAttribute("reaction", getPrefix(), mReaction);
965 if (isSetOperation())
966 stream.writeAttribute("operation", getPrefix(),
967 FluxBoundOperation_toString(mOperation));
968 if (isSetValue())
969 stream.writeAttribute("value", getPrefix(), mValue);
970
971 //
972 // (EXTENSION)
973 //
974 SBase::writeExtensionAttributes(stream);
975 }
976 /** @endcond */
977
978 /** @cond doxygenLibsbmlInternal */
979 void
writeElements(XMLOutputStream & stream) const980 FluxBound::writeElements (XMLOutputStream& stream) const
981 {
982 SBase::writeElements(stream);
983
984 //
985 // (EXTENSION)
986 //
987 SBase::writeExtensionElements(stream);
988 }
989 /** @endcond */
990
991
992 /*
993 * @return the typecode (int) of this SBML object or SBML_UNKNOWN
994 * (default).
995 *
996 * @see getElementName()
997 */
998 int
getTypeCode() const999 FluxBound::getTypeCode () const
1000 {
1001 return SBML_FBC_FLUXBOUND;
1002 }
1003
1004 FluxBound*
clone() const1005 FluxBound::clone() const
1006 {
1007 return new FluxBound(*this);
1008 }
1009
1010
1011 /** @cond doxygenLibsbmlInternal */
1012 bool
accept(SBMLVisitor & v) const1013 FluxBound::accept (SBMLVisitor& v) const
1014 {
1015 bool visited = false;
1016 visited = v.visit(*this);
1017 return visited;
1018 }
1019 /** @endcond */
1020
1021
1022 /** @cond doxygenLibsbmlInternal */
1023 /*
1024 * Sets the parent SBMLDocument of this SBML object.
1025 */
1026 void
setSBMLDocument(SBMLDocument * d)1027 FluxBound::setSBMLDocument (SBMLDocument* d)
1028 {
1029 SBase::setSBMLDocument(d);
1030 }
1031 /** @endcond */
1032
1033
1034 /** @cond doxygenLibsbmlInternal */
1035 /*
1036 * Enables/Disables the given package with this element and child
1037 * elements (if any).
1038 * (This is an internal implementation for enablePakcage function)
1039 */
1040 void
enablePackageInternal(const std::string & pkgURI,const std::string & pkgPrefix,bool flag)1041 FluxBound::enablePackageInternal(const std::string& pkgURI,
1042 const std::string& pkgPrefix, bool flag)
1043 {
1044 SBase::enablePackageInternal(pkgURI,pkgPrefix,flag);
1045
1046 }
1047 /** @endcond */
1048
1049
1050 /*
1051 * Constructor.
1052 */
ListOfFluxBounds(FbcPkgNamespaces * fbcns)1053 ListOfFluxBounds::ListOfFluxBounds(FbcPkgNamespaces* fbcns)
1054 : ListOf(fbcns)
1055 {
1056 //
1057 // set the element namespace of this object
1058 //
1059 setElementNamespace(fbcns->getURI());
1060 }
1061
1062
1063 /*
1064 * Constructor.
1065 */
ListOfFluxBounds(unsigned int level,unsigned int version,unsigned int pkgVersion)1066 ListOfFluxBounds::ListOfFluxBounds(unsigned int level, unsigned int version, unsigned int pkgVersion)
1067 : ListOf(level,version)
1068 {
1069 setSBMLNamespacesAndOwn(new FbcPkgNamespaces(level,version,pkgVersion));
1070 };
1071
1072
1073 /*
1074 * @return a (deep) copy of this ListOfFluxBounds.
1075 */
1076 ListOfFluxBounds*
clone() const1077 ListOfFluxBounds::clone () const
1078 {
1079 return new ListOfFluxBounds(*this);
1080 }
1081
1082
1083 /* return nth item in list */
1084 FluxBound *
get(unsigned int n)1085 ListOfFluxBounds::get(unsigned int n)
1086 {
1087 return static_cast<FluxBound*>(ListOf::get(n));
1088 }
1089
1090
1091 /* return nth item in list */
1092 const FluxBound *
get(unsigned int n) const1093 ListOfFluxBounds::get(unsigned int n) const
1094 {
1095 return static_cast<const FluxBound*>(ListOf::get(n));
1096 }
1097
1098
1099 /* return item by id */
1100 FluxBound*
get(const std::string & sid)1101 ListOfFluxBounds::get (const std::string& sid)
1102 {
1103 return const_cast<FluxBound*>(
1104 static_cast<const ListOfFluxBounds&>(*this).get(sid) );
1105 }
1106
1107
1108 /* return item by id */
1109 const FluxBound*
get(const std::string & sid) const1110 ListOfFluxBounds::get (const std::string& sid) const
1111 {
1112 vector<SBase*>::const_iterator result;
1113
1114 result = find_if( mItems.begin(), mItems.end(), IdEq<FluxBound>(sid) );
1115 return (result == mItems.end()) ? 0 : static_cast <FluxBound*> (*result);
1116 }
1117
1118
1119 /* Removes the nth item from this list */
1120 FluxBound*
remove(unsigned int n)1121 ListOfFluxBounds::remove (unsigned int n)
1122 {
1123 return static_cast<FluxBound*>(ListOf::remove(n));
1124 }
1125
1126
1127 /* Removes item in this list by id */
1128 FluxBound*
remove(const std::string & sid)1129 ListOfFluxBounds::remove (const std::string& sid)
1130 {
1131 SBase* item = 0;
1132 vector<SBase*>::iterator result;
1133
1134 result = find_if( mItems.begin(), mItems.end(), IdEq<FluxBound>(sid) );
1135
1136 if (result != mItems.end())
1137 {
1138 item = *result;
1139 mItems.erase(result);
1140 }
1141
1142 return static_cast <FluxBound*> (item);
1143 }
1144
1145
1146 /*
1147 * @return the typecode (int) of SBML objects contained in this ListOf or
1148 * SBML_UNKNOWN (default).
1149 */
1150 int
getItemTypeCode() const1151 ListOfFluxBounds::getItemTypeCode () const
1152 {
1153 return SBML_FBC_FLUXBOUND;
1154 }
1155
1156
1157 /*
1158 * Returns the XML element name of
1159 * this SBML object.
1160 */
1161 const std::string&
getElementName() const1162 ListOfFluxBounds::getElementName () const
1163 {
1164 static const std::string name = "listOfFluxBounds";
1165 return name;
1166 }
1167
1168
1169 /** @cond doxygenLibsbmlInternal */
1170 SBase*
createObject(XMLInputStream & stream)1171 ListOfFluxBounds::createObject (XMLInputStream& stream)
1172 {
1173 const std::string& name = stream.peek().getName();
1174 SBase* object = 0;
1175
1176
1177 if (name == "fluxBound")
1178 {
1179 try
1180 {
1181 FBC_CREATE_NS_WITH_VERSION(fbcns, getSBMLNamespaces(), getPackageVersion());
1182 object = new FluxBound(fbcns);
1183 appendAndOwn(object);
1184 delete fbcns;
1185 //mItems.push_back(object);
1186 }
1187 catch(...)
1188 {
1189 /*
1190 * NULL will be returned if the mSBMLNS is invalid (basically this
1191 * should not happen) or some exception is thrown (e.g. std::bad_alloc)
1192 *
1193 * (Maybe this should be changed so that caller can detect what kind
1194 * of error happened in this function.)
1195 */
1196 }
1197 }
1198
1199 return object;
1200 }
1201 /** @endcond */
1202
1203 /** @cond doxygenLibsbmlInternal */
1204 void
writeXMLNS(XMLOutputStream & stream) const1205 ListOfFluxBounds::writeXMLNS (XMLOutputStream& stream) const
1206 {
1207 XMLNamespaces xmlns;
1208
1209 std::string prefix = getPrefix();
1210
1211 if (prefix.empty())
1212 {
1213 XMLNamespaces* thisxmlns = getNamespaces();
1214 if (thisxmlns && thisxmlns->hasURI(FbcExtension::getXmlnsL3V1V1()))
1215 {
1216 xmlns.add(FbcExtension::getXmlnsL3V1V1(),prefix);
1217 }
1218 }
1219
1220 stream << xmlns;
1221 }
1222 /** @endcond */
1223
1224
1225
1226 #endif /* __cplusplus */
1227 /** @cond doxygenIgnored */
1228 LIBSBML_EXTERN
1229 FluxBound_t *
FluxBound_create(unsigned int level,unsigned int version,unsigned int pkgversion)1230 FluxBound_create(unsigned int level, unsigned int version, unsigned int pkgversion)
1231 {
1232 return new FluxBound(level, version, pkgversion);
1233 }
1234
1235
1236 LIBSBML_EXTERN
1237 const char *
FluxBound_getId(FluxBound_t * fb)1238 FluxBound_getId(FluxBound_t * fb)
1239 {
1240 if (fb == NULL)
1241 return NULL;
1242
1243 return fb->getId().empty() ? "" : safe_strdup(fb->getId().c_str());
1244 }
1245
1246
1247 LIBSBML_EXTERN
1248 int
FluxBound_isSetId(FluxBound_t * fb)1249 FluxBound_isSetId(FluxBound_t * fb)
1250 {
1251 return (fb != NULL) ? static_cast<int>(fb->isSetId()) : 0;
1252 }
1253
1254
1255 LIBSBML_EXTERN
1256 int
FluxBound_setId(FluxBound_t * fb,const char * id)1257 FluxBound_setId(FluxBound_t * fb, const char * id)
1258 {
1259 return (fb != NULL) ? fb->setId(id) : LIBSBML_INVALID_OBJECT;
1260 }
1261
1262
1263 LIBSBML_EXTERN
1264 int
FluxBound_unsetId(FluxBound_t * fb)1265 FluxBound_unsetId(FluxBound_t * fb)
1266 {
1267 return (fb != NULL) ? fb->unsetId() : LIBSBML_INVALID_OBJECT;
1268 }
1269
1270 LIBSBML_EXTERN
1271 const char *
FluxBound_getName(FluxBound_t * fb)1272 FluxBound_getName(FluxBound_t * fb)
1273 {
1274 if (fb == NULL) return NULL;
1275 return fb->getName().c_str();
1276 }
1277
1278
1279 LIBSBML_EXTERN
1280 int
FluxBound_isSetName(FluxBound_t * fb)1281 FluxBound_isSetName(FluxBound_t * fb)
1282 {
1283 if (fb == NULL) return 0;
1284 return fb->isSetName();
1285 }
1286
1287
1288 LIBSBML_EXTERN
1289 int
FluxBound_setName(FluxBound_t * fb,const char * name)1290 FluxBound_setName(FluxBound_t * fb, const char * name)
1291 {
1292 if (fb!=NULL) return fb->setName(name);
1293 return LIBSBML_INVALID_OBJECT;
1294 }
1295
1296
1297 LIBSBML_EXTERN
1298 int
FluxBound_unsetName(FluxBound_t * fb)1299 FluxBound_unsetName(FluxBound_t * fb)
1300 {
1301 if (fb == NULL) return LIBSBML_INVALID_OBJECT;
1302 return fb->unsetName();
1303 }
1304
1305
1306 LIBSBML_EXTERN
1307 const char *
FluxBound_getReaction(FluxBound_t * fb)1308 FluxBound_getReaction(FluxBound_t * fb)
1309 {
1310 if (fb == NULL)
1311 return NULL;
1312
1313 return fb->getReaction().empty() ? "" : safe_strdup(fb->getReaction().c_str());
1314 }
1315
1316
1317 LIBSBML_EXTERN
1318 int
FluxBound_isSetReaction(FluxBound_t * fb)1319 FluxBound_isSetReaction(FluxBound_t * fb)
1320 {
1321 return (fb != NULL) ? static_cast<int>(fb->isSetReaction()) : 0;
1322 }
1323
1324
1325 LIBSBML_EXTERN
1326 int
FluxBound_setReaction(FluxBound_t * fb,const char * reaction)1327 FluxBound_setReaction(FluxBound_t * fb, const char * reaction)
1328 {
1329 return (fb != NULL) ? fb->setReaction(reaction) : LIBSBML_INVALID_OBJECT;
1330 }
1331
1332
1333 LIBSBML_EXTERN
1334 int
FluxBound_unsetReaction(FluxBound_t * fb)1335 FluxBound_unsetReaction(FluxBound_t * fb)
1336 {
1337 return (fb != NULL) ? fb->unsetReaction() : LIBSBML_INVALID_OBJECT;
1338 }
1339
1340
1341 LIBSBML_EXTERN
1342 const char *
FluxBound_getOperation(FluxBound_t * fb)1343 FluxBound_getOperation(FluxBound_t * fb)
1344 {
1345 if (fb == NULL)
1346 return NULL;
1347
1348 return fb->getOperation().empty() ? "" : safe_strdup(fb->getOperation().c_str());
1349 }
1350
1351
1352 LIBSBML_EXTERN
1353 int
FluxBound_isSetOperation(FluxBound_t * fb)1354 FluxBound_isSetOperation(FluxBound_t * fb)
1355 {
1356 return (fb != NULL) ? static_cast<int>(fb->isSetOperation()) : 0;
1357 }
1358
1359
1360 LIBSBML_EXTERN
1361 int
FluxBound_setOperation(FluxBound_t * fb,const char * operation)1362 FluxBound_setOperation(FluxBound_t * fb, const char * operation)
1363 {
1364 return (fb != NULL) ? fb->setOperation(operation) : LIBSBML_INVALID_OBJECT;
1365 }
1366
1367
1368 LIBSBML_EXTERN
1369 int
FluxBound_unsetOperation(FluxBound_t * fb)1370 FluxBound_unsetOperation(FluxBound_t * fb)
1371 {
1372 return (fb != NULL) ? fb->unsetOperation() : LIBSBML_INVALID_OBJECT;
1373 }
1374
1375
1376 LIBSBML_EXTERN
1377 double
FluxBound_getValue(FluxBound_t * fb)1378 FluxBound_getValue(FluxBound_t * fb)
1379 {
1380 return (fb != NULL) ? fb->getValue() : numeric_limits<double>::quiet_NaN();
1381 }
1382
1383
1384 LIBSBML_EXTERN
1385 int
FluxBound_isSetValue(FluxBound_t * fb)1386 FluxBound_isSetValue(FluxBound_t * fb)
1387 {
1388 return (fb != NULL) ? static_cast<int>(fb->isSetValue()) : 0;
1389 }
1390
1391
1392 LIBSBML_EXTERN
1393 int
FluxBound_setValue(FluxBound_t * fb,double value)1394 FluxBound_setValue(FluxBound_t * fb, double value)
1395 {
1396 return (fb != NULL) ? fb->setValue(value) : LIBSBML_INVALID_OBJECT;
1397 }
1398
1399
1400 LIBSBML_EXTERN
1401 int
FluxBound_unsetValue(FluxBound_t * fb)1402 FluxBound_unsetValue(FluxBound_t * fb)
1403 {
1404 return (fb != NULL) ? fb->unsetValue() : LIBSBML_INVALID_OBJECT;
1405 }
1406
1407
1408 static
1409 const char* FLUXBOUND_OPERATION_STRINGS[] =
1410 {
1411 "lessEqual"
1412 , "greaterEqual"
1413 , "less"
1414 , "greater"
1415 , "equal"
1416 , "unknown"
1417 };
1418
1419
1420 LIBSBML_EXTERN
1421 const char*
FluxBoundOperation_toString(FluxBoundOperation_t type)1422 FluxBoundOperation_toString(FluxBoundOperation_t type)
1423 {
1424 int max = FLUXBOUND_OPERATION_UNKNOWN;
1425
1426 if (type < FLUXBOUND_OPERATION_LESS_EQUAL || type >= max)
1427 {
1428 return NULL;
1429 }
1430
1431 if (type == FLUXBOUND_OPERATION_LESS)
1432 return FLUXBOUND_OPERATION_STRINGS[FLUXBOUND_OPERATION_LESS_EQUAL];
1433 if (type == FLUXBOUND_OPERATION_GREATER)
1434 return FLUXBOUND_OPERATION_STRINGS[FLUXBOUND_OPERATION_GREATER_EQUAL];
1435
1436 return FLUXBOUND_OPERATION_STRINGS[type];
1437 }
1438
1439
1440 LIBSBML_EXTERN
1441 FluxBoundOperation_t
FluxBoundOperation_fromString(const char * s)1442 FluxBoundOperation_fromString(const char* s)
1443 {
1444 if (s == NULL)
1445 {
1446 return FLUXBOUND_OPERATION_UNKNOWN;
1447 }
1448
1449 int max = FLUXBOUND_OPERATION_UNKNOWN;
1450 for (int i = 0; i < max; i++)
1451 {
1452 if (strcmp(FLUXBOUND_OPERATION_STRINGS[i], s) == 0)
1453 {
1454 FluxBoundOperation_t current = (FluxBoundOperation_t)i;
1455 if (current == FLUXBOUND_OPERATION_GREATER)
1456 return FLUXBOUND_OPERATION_GREATER_EQUAL;
1457 if (current == FLUXBOUND_OPERATION_LESS)
1458 return FLUXBOUND_OPERATION_LESS_EQUAL;
1459 return current;
1460 }
1461 }
1462 return FLUXBOUND_OPERATION_UNKNOWN;
1463 }
1464
1465
1466 LIBSBML_EXTERN
1467 int
FluxBoundOperation_isValidFluxBoundOperation(FluxBoundOperation_t effect)1468 FluxBoundOperation_isValidFluxBoundOperation(FluxBoundOperation_t effect)
1469 {
1470 int max = FLUXBOUND_OPERATION_UNKNOWN;
1471
1472 if (effect < FLUXBOUND_OPERATION_LESS_EQUAL || effect >= max)
1473 {
1474 return 0;
1475 }
1476 else
1477 {
1478 return 1;
1479 }
1480 }
1481
1482
1483 LIBSBML_EXTERN
1484 int
FluxBoundOperation_isValidFluxBoundOperationString(const char * s)1485 FluxBoundOperation_isValidFluxBoundOperationString(const char* s)
1486 {
1487 return FluxBoundOperation_isValidFluxBoundOperation
1488 (FluxBoundOperation_fromString(s));
1489 }
1490 /** @endcond */
1491 LIBSBML_CPP_NAMESPACE_END
1492
1493 #endif /* __cplusplus */
1494
1495
1496