1 /**
2 * @file Objective.cpp
3 * @brief Implementation of the Objective class
4 * @author SBMLTeam
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 #include <limits>
38
39 #include <sbml/SBMLVisitor.h>
40 #include <sbml/xml/XMLNode.h>
41 #include <sbml/xml/XMLToken.h>
42 #include <sbml/xml/XMLAttributes.h>
43 #include <sbml/xml/XMLInputStream.h>
44 #include <sbml/xml/XMLOutputStream.h>
45
46 #include <sbml/packages/fbc/sbml/Objective.h>
47 #include <sbml/packages/fbc/extension/FbcExtension.h>
48 #include <sbml/packages/fbc/validator/FbcSBMLError.h>
49 #include <sbml/util/ElementFilter.h>
50
51
52 using namespace std;
53
54
55 LIBSBML_CPP_NAMESPACE_BEGIN
56 #ifdef __cplusplus
57
58 /*
59 * Creates a new Objective with the given level, version, and package version.
60 */
Objective(unsigned int level,unsigned int version,unsigned int pkgVersion)61 Objective::Objective (unsigned int level, unsigned int version, unsigned int pkgVersion)
62 : SBase(level, version)
63 // , mId ("")
64 // , mName ("")
65 , mType (OBJECTIVE_TYPE_UNKNOWN)
66 , mFluxObjectives (level, version, pkgVersion)
67 , mTypeString()
68 {
69 // set an SBMLNamespaces derived object of this package
70 setSBMLNamespacesAndOwn(new FbcPkgNamespaces(level, version, pkgVersion));
71
72 // connect to child objects
73 connectToChild();
74 }
75
76
77 /*
78 * Creates a new Objective with the given FbcPkgNamespaces object.
79 */
Objective(FbcPkgNamespaces * fbcns)80 Objective::Objective (FbcPkgNamespaces* fbcns)
81 : SBase(fbcns)
82 // , mId ("")
83 // , mName ("")
84 , mType (OBJECTIVE_TYPE_UNKNOWN)
85 , mFluxObjectives (fbcns)
86 , mTypeString()
87 {
88 // set the element namespace of this object
89 setElementNamespace(fbcns->getURI());
90
91 // connect to child objects
92 connectToChild();
93
94 // load package extensions bound with this object (if any)
95 loadPlugins(fbcns);
96 }
97
98
99 /*
100 * Copy constructor for Objective.
101 */
Objective(const Objective & orig)102 Objective::Objective (const Objective& orig)
103 : SBase(orig)
104 //, mId (orig.mId)
105 //, mName(orig.mName)
106 , mType(orig.mType)
107 , mFluxObjectives(orig.mFluxObjectives)
108 {
109
110
111 // connect to child objects
112 connectToChild();
113 }
114
115
116 /*
117 * Assignment for Objective.
118 */
119 Objective&
operator =(const Objective & rhs)120 Objective::operator=(const Objective& rhs)
121 {
122 if (&rhs != this)
123 {
124 SBase::operator=(rhs);
125 mId = rhs.mId;
126 mName = rhs.mName;
127 mType = rhs.mType;
128 mFluxObjectives = rhs.mFluxObjectives;
129
130 // connect to child objects
131 connectToChild();
132 }
133 return *this;
134 }
135
136
137 /*
138 * Clone for Objective.
139 */
140 Objective*
clone() const141 Objective::clone () const
142 {
143 return new Objective(*this);
144 }
145
146
147 /*
148 * Destructor for Objective.
149 */
~Objective()150 Objective::~Objective ()
151 {
152 }
153
154
155 /*
156 * Returns the value of the "id" attribute of this Objective.
157 */
158 const std::string&
getId() const159 Objective::getId() const
160 {
161 return mId;
162 }
163
164
165 /*
166 * Returns the value of the "name" attribute of this Objective.
167 */
168 const std::string&
getName() const169 Objective::getName() const
170 {
171 return mName;
172 }
173
174
175 /*
176 * Returns the value of the "type" attribute of this Objective.
177 */
178 const std::string&
getType()179 Objective::getType()
180 {
181 if (ObjectiveType_toString(mType) != NULL)
182 {
183 mTypeString.assign(ObjectiveType_toString(mType));
184 }
185 else
186 {
187 mTypeString.assign("");
188 }
189 return mTypeString;
190 }
191
192 ObjectiveType_t
getObjectiveType() const193 Objective::getObjectiveType() const
194 {
195 return mType;
196 }
197
198
199
200 /*
201 * Returns true/false if id is set.
202 */
203 bool
isSetId() const204 Objective::isSetId() const
205 {
206 return (mId.empty() == false);
207 }
208
209
210 /*
211 * Returns true/false if name is set.
212 */
213 bool
isSetName() const214 Objective::isSetName() const
215 {
216 return (mName.empty() == false);
217 }
218
219
220 /*
221 * Returns true/false if type is set.
222 */
223 bool
isSetType() const224 Objective::isSetType() const
225 {
226 return mType != OBJECTIVE_TYPE_UNKNOWN;
227 }
228
229
230 /*
231 * Sets id and returns value indicating success.
232 */
233 int
setId(const std::string & id)234 Objective::setId(const std::string& id)
235 {
236 return SyntaxChecker::checkAndSetSId(id, mId);
237 }
238
239
240 /*
241 * Sets name and returns value indicating success.
242 */
243 int
setName(const std::string & name)244 Objective::setName(const std::string& name)
245 {
246 {
247 mName = name;
248 return LIBSBML_OPERATION_SUCCESS;
249 }
250 }
251
252
253 /*
254 * Sets type and returns value indicating success.
255 */
256 int
setType(ObjectiveType_t type)257 Objective::setType(ObjectiveType_t type)
258 {
259 if (ObjectiveType_isValidObjectiveType(type) == 0)
260 {
261 mType = OBJECTIVE_TYPE_UNKNOWN;
262 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
263 }
264 else
265 {
266 mType = type;
267 return LIBSBML_OPERATION_SUCCESS;
268 }
269 }
270
271
272 /*
273 * Sets type and returns value indicating success.
274 */
275 int
setType(const std::string & type)276 Objective::setType(const std::string& type)
277 {
278 return setType(ObjectiveType_fromString(type.c_str()));
279 }
280
281
282 /*
283 * Unsets id and returns value indicating success.
284 */
285 int
unsetId()286 Objective::unsetId()
287 {
288 mId.erase();
289
290 if (mId.empty() == true)
291 {
292 return LIBSBML_OPERATION_SUCCESS;
293 }
294 else
295 {
296 return LIBSBML_OPERATION_FAILED;
297 }
298 }
299
300
301 /*
302 * Unsets name and returns value indicating success.
303 */
304 int
unsetName()305 Objective::unsetName()
306 {
307 mName.erase();
308
309 if (mName.empty() == true)
310 {
311 return LIBSBML_OPERATION_SUCCESS;
312 }
313 else
314 {
315 return LIBSBML_OPERATION_FAILED;
316 }
317 }
318
319
320 /*
321 * Unsets type and returns value indicating success.
322 */
323 int
unsetType()324 Objective::unsetType()
325 {
326 mType = OBJECTIVE_TYPE_UNKNOWN;
327 return LIBSBML_OPERATION_SUCCESS;
328 }
329
330
331 /*
332 * Returns the "ListOfFluxObjectives" in this Objective object.
333 */
334 const ListOfFluxObjectives*
getListOfFluxObjectives() const335 Objective::getListOfFluxObjectives() const
336 {
337 return &mFluxObjectives;
338 }
339
340
341 /*
342 * Returns the "ListOfFluxObjectives" in this Objective object.
343 */
344 ListOfFluxObjectives*
getListOfFluxObjectives()345 Objective::getListOfFluxObjectives()
346 {
347 return &mFluxObjectives;
348 }
349
350
351 /*
352 * Removes the nth FluxObjective from the ListOfFluxObjectives.
353 */
354 FluxObjective*
removeFluxObjective(unsigned int n)355 Objective::removeFluxObjective(unsigned int n)
356 {
357 return mFluxObjectives.remove(n);
358 }
359
360
361 /*
362 * Removes the a FluxObjective with given id from the ListOfFluxObjectives.
363 */
364 FluxObjective*
removeFluxObjective(const std::string & sid)365 Objective::removeFluxObjective(const std::string& sid)
366 {
367 return mFluxObjectives.remove(sid);
368 }
369
370
371 /*
372 * Return the nth FluxObjective in the ListOfFluxObjectives within this Objective.
373 */
374 FluxObjective*
getFluxObjective(unsigned int n)375 Objective::getFluxObjective(unsigned int n)
376 {
377 return mFluxObjectives.get(n);
378 }
379
380
381 /*
382 * Return the nth FluxObjective in the ListOfFluxObjectives within this Objective.
383 */
384 const FluxObjective*
getFluxObjective(unsigned int n) const385 Objective::getFluxObjective(unsigned int n) const
386 {
387 return mFluxObjectives.get(n);
388 }
389
390
391 /*
392 * Return a FluxObjective from the ListOfFluxObjectives by id.
393 */
394 FluxObjective*
getFluxObjective(const std::string & sid)395 Objective::getFluxObjective(const std::string& sid)
396 {
397 return mFluxObjectives.get(sid);
398 }
399
400
401 /*
402 * Return a FluxObjective from the ListOfFluxObjectives by id.
403 */
404 const FluxObjective*
getFluxObjective(const std::string & sid) const405 Objective::getFluxObjective(const std::string& sid) const
406 {
407 return mFluxObjectives.get(sid);
408 }
409
410
411 /*
412 * Adds a copy the given FluxObjective to this Objective.
413 *
414 * @param fo the FluxObjective object to add.
415 *
416 * @copydetails doc_returns_success_code
417 * @li LIBSBML_OPERATION_SUCCESS
418 * @li LIBSBML_INVALID_ATTRIBUTE_VALUE
419 */
420 int
addFluxObjective(const FluxObjective * fo)421 Objective::addFluxObjective(const FluxObjective* fo)
422 {
423 if (fo == NULL)
424 {
425 return LIBSBML_OPERATION_FAILED;
426 }
427 else if (fo->hasRequiredAttributes() == false)
428 {
429 return LIBSBML_INVALID_OBJECT;
430 }
431 else if (getLevel() != fo->getLevel())
432 {
433 return LIBSBML_LEVEL_MISMATCH;
434 }
435 else if (getVersion() != fo->getVersion())
436 {
437 return LIBSBML_VERSION_MISMATCH;
438 }
439 else if (matchesRequiredSBMLNamespacesForAddition(static_cast<const SBase *>(fo)) == false)
440 {
441 return LIBSBML_NAMESPACES_MISMATCH;
442 }
443 else
444 {
445 return mFluxObjectives.append(fo);
446 }
447 }
448
449
450 /*
451 * Get the number of FluxObjective objects in this Objective.
452 *
453 * @return the number of FluxObjective objects in this Objective
454 */
455 unsigned int
getNumFluxObjectives() const456 Objective::getNumFluxObjectives() const
457 {
458 return mFluxObjectives.size();
459 }
460
461
462 /*
463 * Creates a new FluxObjective object, adds it to this Objective
464 * and returns the FluxObjective object created.
465 *
466 * @return a new FluxObjective object instance
467 *
468 * @see addFluxObjective(const FluxObjective* fo)
469 */
470 FluxObjective*
createFluxObjective()471 Objective::createFluxObjective()
472 {
473 FluxObjective* fo = NULL;
474
475 try
476 {
477 FBC_CREATE_NS_WITH_VERSION(fbcns, getSBMLNamespaces(), getPackageVersion());
478 fo = new FluxObjective(fbcns);
479 delete fbcns;
480 }
481 catch (...)
482 {
483 /* here we do not create a default object as the level/version must
484 * match the parent object
485 *
486 * do nothing
487 */
488 }
489
490 if(fo != NULL)
491 {
492 mFluxObjectives.appendAndOwn(fo);
493 }
494
495 return fo;
496 }
497
498
499 List*
getAllElements(ElementFilter * filter)500 Objective::getAllElements(ElementFilter* filter)
501 {
502 List* ret = new List();
503 List* sublist = NULL;
504
505 ADD_FILTERED_LIST(ret, sublist, mFluxObjectives, filter);
506
507 ADD_FILTERED_FROM_PLUGIN(ret, sublist, filter);
508
509 return ret;
510 }
511
512
513 /*
514 * Returns the XML element name of this object
515 */
516 const std::string&
getElementName() const517 Objective::getElementName () const
518 {
519 static const string name = "objective";
520 return name;
521 }
522
523
524 /*
525 * Returns the libSBML type code for this SBML object.
526 */
527 int
getTypeCode() const528 Objective::getTypeCode () const
529 {
530 return SBML_FBC_OBJECTIVE;
531 }
532
533
534 /*
535 * check if all the required attributes are set
536 */
537 bool
hasRequiredAttributes() const538 Objective::hasRequiredAttributes () const
539 {
540 bool allPresent = true;
541
542 if (isSetId() == false)
543 allPresent = false;
544
545 if (isSetType() == false)
546 allPresent = false;
547
548 return allPresent;
549 }
550
551
552 /*
553 * check if all the required elements are set
554 */
555 bool
hasRequiredElements() const556 Objective::hasRequiredElements () const
557 {
558 return getNumFluxObjectives() > 0;
559 }
560
561
562 /** @cond doxygenLibsbmlInternal */
563
564 /** @cond doxygenLibsbmlInternal */
565 bool
getIsSetListOfFluxObjectives() const566 Objective::getIsSetListOfFluxObjectives() const
567 {
568 return mFluxObjectives.size() != 0;
569 }
570 /** @endcond */
571
572
573 /** @cond doxygenLibsbmlInternal */
574 /*
575 * write contained elements
576 */
577 void
writeElements(XMLOutputStream & stream) const578 Objective::writeElements (XMLOutputStream& stream) const
579 {
580 SBase::writeElements(stream);
581 if (getNumFluxObjectives() > 0)
582 {
583 mFluxObjectives.write(stream);
584 }
585
586 SBase::writeExtensionElements(stream);
587 }
588 /** @endcond */
589
590
591 /** @endcond */
592
593
594 /** @cond doxygenLibsbmlInternal */
595
596 /*
597 * Accepts the given SBMLVisitor.
598 */
599 bool
accept(SBMLVisitor & v) const600 Objective::accept (SBMLVisitor& v) const
601 {
602 v.visit(*this);
603 for (unsigned int n = 0; n < getNumFluxObjectives(); n++)
604 {
605 getFluxObjective(n)->accept(v);
606 }
607 v.leave(*this);
608
609 return true;
610 }
611
612
613 /** @endcond */
614
615
616 /** @cond doxygenLibsbmlInternal */
617
618 /*
619 * Sets the parent SBMLDocument.
620 */
621 void
setSBMLDocument(SBMLDocument * d)622 Objective::setSBMLDocument (SBMLDocument* d)
623 {
624 SBase::setSBMLDocument(d);
625 mFluxObjectives.setSBMLDocument(d);
626 }
627
628
629 /** @endcond */
630
631
632 /** @cond doxygenLibsbmlInternal */
633
634 /*
635 * Connects to child elements.
636 */
637 void
connectToChild()638 Objective::connectToChild()
639 {
640 SBase::connectToChild();
641
642 mFluxObjectives.connectToParent(this);
643 }
644
645
646 /** @endcond */
647
648
649 /** @cond doxygenLibsbmlInternal */
650
651 /*
652 * Enables/Disables the given package with this element.
653 */
654 void
enablePackageInternal(const std::string & pkgURI,const std::string & pkgPrefix,bool flag)655 Objective::enablePackageInternal(const std::string& pkgURI,
656 const std::string& pkgPrefix, bool flag)
657 {
658 SBase::enablePackageInternal(pkgURI, pkgPrefix, flag);
659 mFluxObjectives.enablePackageInternal(pkgURI, pkgPrefix, flag);
660 }
661
662
663 /** @endcond */
664
665
666 /** @cond doxygenLibsbmlInternal */
667
668 /*
669 * Returns the value of the "attributeName" attribute of this Objective.
670 */
671 int
getAttribute(const std::string & attributeName,bool & value) const672 Objective::getAttribute(const std::string& attributeName, bool& value) const
673 {
674 int return_value = SBase::getAttribute(attributeName, value);
675
676 return return_value;
677 }
678
679 /** @endcond */
680
681
682
683 /** @cond doxygenLibsbmlInternal */
684
685 /*
686 * Returns the value of the "attributeName" attribute of this Objective.
687 */
688 int
getAttribute(const std::string & attributeName,int & value) const689 Objective::getAttribute(const std::string& attributeName, int& value) const
690 {
691 int return_value = SBase::getAttribute(attributeName, value);
692
693 return return_value;
694 }
695
696 /** @endcond */
697
698
699
700 /** @cond doxygenLibsbmlInternal */
701
702 /*
703 * Returns the value of the "attributeName" attribute of this Objective.
704 */
705 int
getAttribute(const std::string & attributeName,double & value) const706 Objective::getAttribute(const std::string& attributeName, double& value) const
707 {
708 int return_value = SBase::getAttribute(attributeName, value);
709
710 return return_value;
711 }
712
713 /** @endcond */
714
715
716
717 /** @cond doxygenLibsbmlInternal */
718
719 /*
720 * Returns the value of the "attributeName" attribute of this Objective.
721 */
722 int
getAttribute(const std::string & attributeName,unsigned int & value) const723 Objective::getAttribute(const std::string& attributeName,
724 unsigned int& value) const
725 {
726 int return_value = SBase::getAttribute(attributeName, value);
727
728 return return_value;
729 }
730
731 /** @endcond */
732
733
734
735 /** @cond doxygenLibsbmlInternal */
736
737 /*
738 * Returns the value of the "attributeName" attribute of this Objective.
739 */
740 int
getAttribute(const std::string & attributeName,std::string & value) const741 Objective::getAttribute(const std::string& attributeName,
742 std::string& value) const
743 {
744 int return_value = SBase::getAttribute(attributeName, value);
745
746 if (return_value == LIBSBML_OPERATION_SUCCESS)
747 {
748 return return_value;
749 }
750
751 if (attributeName == "id")
752 {
753 value = getId();
754 return_value = LIBSBML_OPERATION_SUCCESS;
755 }
756 else if (attributeName == "name")
757 {
758 value = getName();
759 return_value = LIBSBML_OPERATION_SUCCESS;
760 }
761 else if (attributeName == "type")
762 {
763 value = const_cast<Objective*>(this)->getType();
764 return_value = LIBSBML_OPERATION_SUCCESS;
765 }
766
767 return return_value;
768 }
769
770 /** @endcond */
771
772
773
774 /** @cond doxygenLibsbmlInternal */
775
776 /*
777 * Predicate returning @c true if this Objective's attribute "attributeName" is
778 * set.
779 */
780 bool
isSetAttribute(const std::string & attributeName) const781 Objective::isSetAttribute(const std::string& attributeName) const
782 {
783 bool value = SBase::isSetAttribute(attributeName);
784
785 if (attributeName == "id")
786 {
787 value = isSetId();
788 }
789 else if (attributeName == "name")
790 {
791 value = isSetName();
792 }
793 else if (attributeName == "type")
794 {
795 value = isSetType();
796 }
797
798 return value;
799 }
800
801 /** @endcond */
802
803
804
805 /** @cond doxygenLibsbmlInternal */
806
807 /*
808 * Sets the value of the "attributeName" attribute of this Objective.
809 */
810 int
setAttribute(const std::string & attributeName,bool value)811 Objective::setAttribute(const std::string& attributeName, bool value)
812 {
813 int return_value = SBase::setAttribute(attributeName, value);
814
815 return return_value;
816 }
817
818 /** @endcond */
819
820
821
822 /** @cond doxygenLibsbmlInternal */
823
824 /*
825 * Sets the value of the "attributeName" attribute of this Objective.
826 */
827 int
setAttribute(const std::string & attributeName,int value)828 Objective::setAttribute(const std::string& attributeName, int value)
829 {
830 int return_value = SBase::setAttribute(attributeName, value);
831
832 return return_value;
833 }
834
835 /** @endcond */
836
837
838
839 /** @cond doxygenLibsbmlInternal */
840
841 /*
842 * Sets the value of the "attributeName" attribute of this Objective.
843 */
844 int
setAttribute(const std::string & attributeName,double value)845 Objective::setAttribute(const std::string& attributeName, double value)
846 {
847 int return_value = SBase::setAttribute(attributeName, value);
848
849 return return_value;
850 }
851
852 /** @endcond */
853
854
855
856 /** @cond doxygenLibsbmlInternal */
857
858 /*
859 * Sets the value of the "attributeName" attribute of this Objective.
860 */
861 int
setAttribute(const std::string & attributeName,unsigned int value)862 Objective::setAttribute(const std::string& attributeName, unsigned int value)
863 {
864 int return_value = SBase::setAttribute(attributeName, value);
865
866 return return_value;
867 }
868
869 /** @endcond */
870
871
872
873 /** @cond doxygenLibsbmlInternal */
874
875 /*
876 * Sets the value of the "attributeName" attribute of this Objective.
877 */
878 int
setAttribute(const std::string & attributeName,const std::string & value)879 Objective::setAttribute(const std::string& attributeName,
880 const std::string& value)
881 {
882 int return_value = SBase::setAttribute(attributeName, value);
883
884 if (attributeName == "id")
885 {
886 return_value = setId(value);
887 }
888 else if (attributeName == "name")
889 {
890 return_value = setName(value);
891 }
892 else if (attributeName == "type")
893 {
894 return_value = setType(value);
895 }
896
897 return return_value;
898 }
899
900 /** @endcond */
901
902
903
904 /** @cond doxygenLibsbmlInternal */
905
906 /*
907 * Unsets the value of the "attributeName" attribute of this Objective.
908 */
909 int
unsetAttribute(const std::string & attributeName)910 Objective::unsetAttribute(const std::string& attributeName)
911 {
912 int value = SBase::unsetAttribute(attributeName);
913
914 if (attributeName == "id")
915 {
916 value = unsetId();
917 }
918 else if (attributeName == "name")
919 {
920 value = unsetName();
921 }
922 else if (attributeName == "type")
923 {
924 value = unsetType();
925 }
926
927 return value;
928 }
929
930 /** @endcond */
931
932
933
934 /** @cond doxygenLibsbmlInternal */
935
936 /*
937 * Creates and returns an new "elementName" object in this Objective.
938 */
939 SBase*
createChildObject(const std::string & elementName)940 Objective::createChildObject(const std::string& elementName)
941 {
942 SBase* obj = NULL;
943
944 if (elementName == "fluxObjective")
945 {
946 return createFluxObjective();
947 }
948
949 return obj;
950 }
951
952 /** @endcond */
953
954
955
956 /** @cond doxygenLibsbmlInternal */
957
958 /*
959 * Returns the number of "elementName" in this Objective.
960 */
961 unsigned int
getNumObjects(const std::string & elementName)962 Objective::getNumObjects(const std::string& elementName)
963 {
964 unsigned int n = 0;
965
966 if (elementName == "fluxObjective")
967 {
968 return getNumFluxObjectives();
969 }
970
971 return n;
972 }
973
974 /** @endcond */
975
976
977
978 /** @cond doxygenLibsbmlInternal */
979
980 /*
981 * Returns the nth object of "objectName" in this Objective.
982 */
983 SBase*
getObject(const std::string & elementName,unsigned int index)984 Objective::getObject(const std::string& elementName, unsigned int index)
985 {
986 SBase* obj = NULL;
987
988 if (elementName == "fluxObjective")
989 {
990 return getFluxObjective(index);
991 }
992
993 return obj;
994 }
995
996 /** @endcond */
997
998
999 /** @cond doxygenLibsbmlInternal */
1000
1001 /*
1002 * creates object.
1003 */
1004 SBase*
createObject(XMLInputStream & stream)1005 Objective::createObject(XMLInputStream& stream)
1006 {
1007 SBase* object = NULL;
1008
1009 const string& name = stream.peek().getName();
1010
1011 if (name == "listOfFluxes" || name == "listOfFluxObjectives")
1012 {
1013 if (mFluxObjectives.size() != 0)
1014 {
1015 getErrorLog()->logPackageError("fbc", FbcObjectiveOneListOfObjectives,
1016 getPackageVersion(), getLevel(), getVersion(), "", getLine(), getColumn());
1017 }
1018
1019 object = &mFluxObjectives;
1020 }
1021 connectToChild();
1022
1023
1024 return object;
1025 }
1026
1027
1028 /** @endcond */
1029
1030
1031 /** @cond doxygenLibsbmlInternal */
1032
1033 /*
1034 * Get the list of expected attributes for this element.
1035 */
1036 void
addExpectedAttributes(ExpectedAttributes & attributes)1037 Objective::addExpectedAttributes(ExpectedAttributes& attributes)
1038 {
1039 SBase::addExpectedAttributes(attributes);
1040
1041 attributes.add("id");
1042 attributes.add("name");
1043 attributes.add("type");
1044 }
1045
1046
1047 /** @endcond */
1048
1049
1050 /** @cond doxygenLibsbmlInternal */
1051
1052 /*
1053 * Read values from the given XMLAttributes set into their specific fields.
1054 */
1055 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)1056 Objective::readAttributes (const XMLAttributes& attributes,
1057 const ExpectedAttributes& expectedAttributes)
1058 {
1059 const unsigned int sbmlLevel = getLevel ();
1060 const unsigned int sbmlVersion = getVersion();
1061
1062 // look to see whether an unknown attribute error was logged
1063 // during the read of the listOfFluxBounds - which will have
1064 // happened immediately prior to this read
1065 if (getErrorLog() != NULL &&
1066 static_cast<ListOfObjectives*>(getParentSBMLObject())->size() < 2)
1067 {
1068 unsigned int numErrs = getErrorLog()->getNumErrors();
1069 for (int n = (int)numErrs-1; n >= 0; n--)
1070 {
1071 if (getErrorLog()->getError((unsigned int)n)->getErrorId() == UnknownPackageAttribute)
1072 {
1073 const std::string details =
1074 getErrorLog()->getError((unsigned int)n)->getMessage();
1075 getErrorLog()->remove(UnknownPackageAttribute);
1076 getErrorLog()->logPackageError("fbc", FbcLOObjectivesAllowedAttributes,
1077 getPackageVersion(), sbmlLevel, sbmlVersion, details, getLine(), getColumn());
1078 }
1079 else if (getErrorLog()->getError((unsigned int)n)->getErrorId() == UnknownCoreAttribute)
1080 {
1081 const std::string details =
1082 getErrorLog()->getError((unsigned int)n)->getMessage();
1083 getErrorLog()->remove(UnknownCoreAttribute);
1084 getErrorLog()->logPackageError("fbc", FbcLOObjectivesAllowedAttributes,
1085 getPackageVersion(), sbmlLevel, sbmlVersion, details, getLine(), getColumn());
1086 }
1087 }
1088 }
1089
1090 SBase::readAttributes(attributes,expectedAttributes);
1091
1092 // look to see whether an unknown attribute error was logged
1093 if (getErrorLog() != NULL)
1094 {
1095 unsigned int numErrs = getErrorLog()->getNumErrors();
1096 for (int n = (int)numErrs-1; n >= 0; n--)
1097 {
1098 if (getErrorLog()->getError((unsigned int)n)->getErrorId() == UnknownPackageAttribute)
1099 {
1100 const std::string details =
1101 getErrorLog()->getError((unsigned int)n)->getMessage();
1102 getErrorLog()->remove(UnknownPackageAttribute);
1103 getErrorLog()->logPackageError("fbc", FbcObjectiveRequiredAttributes,
1104 getPackageVersion(), sbmlLevel, sbmlVersion, details, getLine(), getColumn());
1105 }
1106 else if (getErrorLog()->getError((unsigned int)n)->getErrorId() == UnknownCoreAttribute)
1107 {
1108 const std::string details =
1109 getErrorLog()->getError((unsigned int)n)->getMessage();
1110 getErrorLog()->remove(UnknownCoreAttribute);
1111 getErrorLog()->logPackageError("fbc", FbcObjectiveAllowedL3Attributes,
1112 getPackageVersion(), sbmlLevel, sbmlVersion, details, getLine(), getColumn());
1113 }
1114 }
1115 }
1116
1117
1118 //
1119 // Reads an attribute "id" (optional)
1120 //
1121 bool assigned = attributes.readInto("id", mId);
1122
1123 if (assigned)
1124 {
1125 // "id" attribute is set to this fbc element
1126
1127 if (mId.empty())
1128 {
1129 //
1130 // Logs an error if the "id" attribute is empty.
1131 //
1132 logEmptyString(mId, sbmlLevel, sbmlVersion, "<fbc>");
1133 }
1134 else if (!SyntaxChecker::isValidSBMLSId(mId))
1135 {
1136 //
1137 // Logs an error if the "id" attribute doesn't
1138 // conform to the SBML type SId.
1139 //
1140 getErrorLog()->logPackageError("fbc", FbcSBMLSIdSyntax,
1141 getPackageVersion(), sbmlLevel, sbmlVersion, "", getLine(), getColumn());
1142 }
1143 }
1144 else
1145 {
1146 std::string message = "Fbc attribute 'id' is missing.";
1147 getErrorLog()->logPackageError("fbc", FbcObjectiveRequiredAttributes,
1148 getPackageVersion(), sbmlLevel, sbmlVersion, message, getLine(), getColumn());
1149 }
1150
1151 attributes.readInto("name", mName);
1152
1153 //
1154 // type string ( use = "required" )
1155 //
1156 std::string type;
1157 assigned = attributes.readInto("type", type);
1158
1159 if (assigned == true)
1160 {
1161 // check string is not empty
1162
1163 if (type.empty() == true)
1164 {
1165 logEmptyString(type, sbmlLevel, sbmlVersion, "<Objective>");
1166 }
1167 else
1168 {
1169 mType = ObjectiveType_fromString( type.c_str() );
1170 if (ObjectiveType_isValidObjectiveType((ObjectiveType_t)(int)mType) == 0)
1171 {
1172 getErrorLog()->logPackageError("fbc", FbcObjectiveTypeMustBeEnum,
1173 getPackageVersion(), sbmlLevel, sbmlVersion, "", getLine(), getColumn());
1174 }
1175 }
1176 }
1177 else
1178 {
1179 std::string message = "Fbc attribute 'type' is missing.";
1180 getErrorLog()->logPackageError("fbc", FbcObjectiveRequiredAttributes,
1181 getPackageVersion(), sbmlLevel, sbmlVersion, message, getLine(), getColumn());
1182 }
1183 }
1184
1185
1186 /** @endcond */
1187
1188
1189 /** @cond doxygenLibsbmlInternal */
1190
1191 /*
1192 * Write values of XMLAttributes to the output stream.
1193 */
1194 void
writeAttributes(XMLOutputStream & stream) const1195 Objective::writeAttributes (XMLOutputStream& stream) const
1196 {
1197 SBase::writeAttributes(stream);
1198
1199 if (isSetId() == true)
1200 stream.writeAttribute("id", getPrefix(), mId);
1201
1202 if (isSetName() == true)
1203 stream.writeAttribute("name", getPrefix(), mName);
1204
1205 if (isSetType() == true)
1206 stream.writeAttribute("type", getPrefix(),
1207 ObjectiveType_toString(mType));
1208
1209 }
1210
1211
1212 /** @endcond */
1213
1214
1215 /*
1216 * Constructor
1217 */
ListOfObjectives(unsigned int level,unsigned int version,unsigned int pkgVersion)1218 ListOfObjectives::ListOfObjectives(unsigned int level,
1219 unsigned int version,
1220 unsigned int pkgVersion)
1221 : ListOf(level, version)
1222 , mActiveObjective()
1223 {
1224 setSBMLNamespacesAndOwn(new FbcPkgNamespaces(level, version, pkgVersion));
1225 }
1226
ListOfObjectives(const ListOfObjectives & other)1227 ListOfObjectives::ListOfObjectives(const ListOfObjectives& other)
1228 : ListOf(other)
1229 , mActiveObjective(other.mActiveObjective)
1230 {
1231
1232 }
1233
1234 /*
1235 * Assignment for Objective.
1236 */
1237 ListOfObjectives&
operator =(const ListOfObjectives & rhs)1238 ListOfObjectives::operator=(const ListOfObjectives& rhs)
1239 {
1240 if (&rhs != this)
1241 {
1242 ListOf::operator=(rhs);
1243 mActiveObjective = rhs.mActiveObjective;
1244
1245 }
1246 return *this;
1247 }
1248
1249 /*
1250 * Constructor
1251 */
ListOfObjectives(FbcPkgNamespaces * fbcns)1252 ListOfObjectives::ListOfObjectives(FbcPkgNamespaces* fbcns)
1253 : ListOf(fbcns)
1254 , mActiveObjective()
1255 {
1256 setElementNamespace(fbcns->getURI());
1257 }
1258
1259
1260 /*
1261 * Returns a deep copy of this ListOfObjectives
1262 */
1263 ListOfObjectives*
clone() const1264 ListOfObjectives::clone () const
1265 {
1266 return new ListOfObjectives(*this);
1267 }
1268
1269
1270 /*
1271 * Get a Objective from the ListOfObjectives by index.
1272 */
1273 Objective*
get(unsigned int n)1274 ListOfObjectives::get(unsigned int n)
1275 {
1276 return static_cast<Objective*>(ListOf::get(n));
1277 }
1278
1279
1280 /*
1281 * Get a Objective from the ListOfObjectives by index.
1282 */
1283 const Objective*
get(unsigned int n) const1284 ListOfObjectives::get(unsigned int n) const
1285 {
1286 return static_cast<const Objective*>(ListOf::get(n));
1287 }
1288
1289
1290 /*
1291 * Get a Objective from the ListOfObjectives by id.
1292 */
1293 Objective*
get(const std::string & sid)1294 ListOfObjectives::get(const std::string& sid)
1295 {
1296 return const_cast<Objective*>(
1297 static_cast<const ListOfObjectives&>(*this).get(sid));
1298 }
1299
1300
1301 /*
1302 * Get a Objective from the ListOfObjectives by id.
1303 */
1304 const Objective*
get(const std::string & sid) const1305 ListOfObjectives::get(const std::string& sid) const
1306 {
1307 vector<SBase*>::const_iterator result;
1308
1309 result = find_if( mItems.begin(), mItems.end(), IdEq<Objective>(sid) );
1310 return (result == mItems.end()) ? 0 : static_cast <Objective*> (*result);
1311 }
1312
1313
1314 /*
1315 * Adds a copy the given Objective to this ListOfObjectives.
1316 *
1317 * @param o the Objective object to add.
1318 *
1319 * @copydetails doc_returns_success_code
1320 * @li LIBSBML_OPERATION_SUCCESS
1321 * @li LIBSBML_INVALID_ATTRIBUTE_VALUE
1322 */
1323 int
addObjective(const Objective * o)1324 ListOfObjectives::addObjective(const Objective* o)
1325 {
1326 if (o == NULL)
1327 {
1328 return LIBSBML_OPERATION_FAILED;
1329 }
1330 else if (o->hasRequiredAttributes() == false)
1331 {
1332 return LIBSBML_INVALID_OBJECT;
1333 }
1334 else if (getLevel() != o->getLevel())
1335 {
1336 return LIBSBML_LEVEL_MISMATCH;
1337 }
1338 else if (getVersion() != o->getVersion())
1339 {
1340 return LIBSBML_VERSION_MISMATCH;
1341 }
1342 else if (matchesRequiredSBMLNamespacesForAddition(static_cast<const SBase *>(o)) == false)
1343 {
1344 return LIBSBML_NAMESPACES_MISMATCH;
1345 }
1346 else
1347 {
1348 return append(o);
1349 }
1350 }
1351
1352
1353 /*
1354 * Get the number of Objective objects in this ListOfObjectives.
1355 *
1356 * @return the number of Objective objects in this ListOfObjectives
1357 */
1358 unsigned int
getNumObjectives() const1359 ListOfObjectives::getNumObjectives() const
1360 {
1361 return size();
1362 }
1363
1364 /*
1365 * Creates a new Objective object, adds it to this ListOfObjectives
1366 * and returns the Objective object created.
1367 *
1368 * @return a new Objective object instance
1369 *
1370 * @see addObjective(const Objective* o)
1371 */
1372 Objective*
createObjective()1373 ListOfObjectives::createObjective()
1374 {
1375 Objective* o = NULL;
1376
1377 try
1378 {
1379 FBC_CREATE_NS_WITH_VERSION(fbcns, getSBMLNamespaces(), getPackageVersion());
1380 o = new Objective(fbcns);
1381 delete fbcns;
1382 }
1383 catch (...)
1384 {
1385 /* here we do not create a default object as the level/version must
1386 * match the parent object
1387 *
1388 * do nothing
1389 */
1390 }
1391
1392 if(o != NULL)
1393 {
1394 appendAndOwn(o);
1395 }
1396
1397 return o;
1398 }
1399
1400 /*
1401 * Removes the nth Objective from this ListOfObjectives
1402 */
1403 Objective*
remove(unsigned int n)1404 ListOfObjectives::remove(unsigned int n)
1405 {
1406 return static_cast<Objective*>(ListOf::remove(n));
1407 }
1408
1409
1410 /*
1411 * Removes the Objective from this ListOfObjectives with the given identifier
1412 */
1413 Objective*
remove(const std::string & sid)1414 ListOfObjectives::remove(const std::string& sid)
1415 {
1416 SBase* item = NULL;
1417 vector<SBase*>::iterator result;
1418
1419 result = find_if( mItems.begin(), mItems.end(), IdEq<Objective>(sid) );
1420
1421 if (result != mItems.end())
1422 {
1423 item = *result;
1424 mItems.erase(result);
1425 }
1426
1427 return static_cast <Objective*> (item);
1428 }
1429
1430
1431 /*
1432 * Returns the XML element name of this object
1433 */
1434 const std::string&
getElementName() const1435 ListOfObjectives::getElementName () const
1436 {
1437 static const string name = "listOfObjectives";
1438 return name;
1439 }
1440
1441
1442 /*
1443 * Returns the libSBML type code for this SBML object.
1444 */
1445 int
getTypeCode() const1446 ListOfObjectives::getTypeCode () const
1447 {
1448 return SBML_LIST_OF;
1449 }
1450
1451
1452 /*
1453 * Returns the libSBML type code for the objects in this LIST_OF.
1454 */
1455 int
getItemTypeCode() const1456 ListOfObjectives::getItemTypeCode () const
1457 {
1458 return SBML_FBC_OBJECTIVE;
1459 }
1460
1461
1462 /** @cond doxygenLibsbmlInternal */
1463
1464
appendFrom(const ListOf * list)1465 int ListOfObjectives::appendFrom(const ListOf* list)
1466 {
1467 int ret = ListOf::appendFrom(list);
1468 if (ret != LIBSBML_OPERATION_SUCCESS) return ret;
1469
1470 const ListOfObjectives* objectives = static_cast<const ListOfObjectives*>(list);
1471 if (objectives == NULL) return LIBSBML_INVALID_OBJECT;
1472
1473 if (!isSetActiveObjective()) {
1474 setActiveObjective(objectives->getActiveObjective());
1475 }
1476 return ret;
1477 }
1478
1479 void
renameSIdRefs(const std::string & oldid,const std::string & newid)1480 ListOfObjectives::renameSIdRefs(const std::string& oldid, const std::string& newid)
1481 {
1482 if (mActiveObjective == oldid) mActiveObjective = newid;
1483 ListOf::renameSIdRefs(oldid, newid);
1484 }
1485
1486
1487 /*
1488 * Creates a new Objective in this ListOfObjectives
1489 */
1490 SBase*
createObject(XMLInputStream & stream)1491 ListOfObjectives::createObject(XMLInputStream& stream)
1492 {
1493 const std::string& name = stream.peek().getName();
1494 SBase* object = NULL;
1495
1496 if (name == "objective")
1497 {
1498 FBC_CREATE_NS_WITH_VERSION(fbcns, getSBMLNamespaces(), getPackageVersion());
1499 object = new Objective(fbcns);
1500 appendAndOwn(object);
1501 delete fbcns;
1502 }
1503
1504 return object;
1505 }
1506
1507
1508 /** @endcond */
1509
1510
1511 bool
isSetActiveObjective() const1512 ListOfObjectives::isSetActiveObjective() const
1513 {
1514 return !mActiveObjective.empty();
1515 }
1516
1517 int
setActiveObjective(const std::string & activeObjective)1518 ListOfObjectives::setActiveObjective(const std::string &activeObjective)
1519 {
1520 if (!SyntaxChecker::isValidSBMLSId(activeObjective))
1521 {
1522 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
1523 }
1524 mActiveObjective = activeObjective;
1525 return LIBSBML_OPERATION_SUCCESS;
1526 }
1527
1528 const std::string &
getActiveObjective() const1529 ListOfObjectives::getActiveObjective() const
1530 {
1531 return mActiveObjective;
1532 }
1533
1534 int
unsetActiveObjective()1535 ListOfObjectives::unsetActiveObjective()
1536 {
1537 mActiveObjective.erase();
1538 if (mActiveObjective.empty())
1539 return LIBSBML_OPERATION_SUCCESS;
1540 else
1541 return LIBSBML_OPERATION_FAILED;
1542 }
1543
1544 /** @cond doxygenLibsbmlInternal */
1545 void
addExpectedAttributes(ExpectedAttributes & attributes)1546 ListOfObjectives::addExpectedAttributes(ExpectedAttributes& attributes)
1547 {
1548 SBase::addExpectedAttributes(attributes);
1549 //
1550 // required attribute is not defined for SBML Level 2 or lesser.
1551 //
1552 if (getLevel() > 2)
1553 {
1554 attributes.add("activeObjective");
1555 }
1556 }
1557 /** @endcond */
1558 /** @cond doxygenLibsbmlInternal */
1559 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)1560 ListOfObjectives::readAttributes(const XMLAttributes& attributes,
1561 const ExpectedAttributes& expectedAttributes)
1562 {
1563 SBase::readAttributes(attributes, expectedAttributes);
1564
1565 if (getLevel() > 2)
1566 {
1567 bool assigned = attributes.readInto("activeObjective", mActiveObjective,
1568 getErrorLog(), false, getLine(), getColumn());
1569 if (assigned && mActiveObjective.empty())
1570 {
1571 logEmptyString(mActiveObjective, getLevel(), getVersion(),
1572 "<listOfObjectives>");
1573 }
1574 if (!SyntaxChecker::isValidSBMLSId(mActiveObjective))
1575 {
1576 getErrorLog()->logPackageError("fbc", FbcActiveObjectiveSyntax,
1577 getPackageVersion(), getLevel(), getVersion(), "", getLine(), getColumn());
1578 }
1579
1580 }
1581 }
1582 /** @endcond */
1583
1584 /** @cond doxygenLibsbmlInternal */
1585 void
writeAttributes(XMLOutputStream & stream) const1586 ListOfObjectives::writeAttributes(XMLOutputStream& stream) const
1587 {
1588 //
1589 // required attribute is not defined for SBML Level 2 .
1590 //
1591 if (getLevel() < 3)
1592 return;
1593
1594 //cout << "[DEBUG] SBMLDocumentPlugin::writeAttributes() " << endl;
1595 if (isSetActiveObjective())
1596 {
1597 stream.writeAttribute("activeObjective", getPrefix(), mActiveObjective);
1598 }
1599 }
1600 /** @endcond */
1601
1602
1603 /** @cond doxygenLibsbmlInternal */
1604
1605 /*
1606 * Write the namespace for the Fbc package.
1607 */
1608 void
writeXMLNS(XMLOutputStream & stream) const1609 ListOfObjectives::writeXMLNS(XMLOutputStream& stream) const
1610 {
1611 XMLNamespaces xmlns;
1612
1613 std::string prefix = getPrefix();
1614
1615 if (prefix.empty())
1616 {
1617 XMLNamespaces* thisxmlns = getNamespaces();
1618 if (thisxmlns && thisxmlns->hasURI(FbcExtension::getXmlnsL3V1V1()))
1619 {
1620 xmlns.add(FbcExtension::getXmlnsL3V1V1(),prefix);
1621 }
1622 }
1623
1624 stream << xmlns;
1625 }
1626
1627
1628 /** @endcond */
1629
1630
1631 /** @cond doxygenLibsbmlInternal */
1632 bool
accept(SBMLVisitor & v) const1633 ListOfObjectives::accept(SBMLVisitor& v) const
1634 {
1635 return v.visit(*this);
1636 }
1637 /** @endcond */
1638
1639 #endif // __cplusplus
1640
1641
1642 LIBSBML_EXTERN
1643 Objective_t *
Objective_create(unsigned int level,unsigned int version,unsigned int pkgVersion)1644 Objective_create(unsigned int level, unsigned int version,
1645 unsigned int pkgVersion)
1646 {
1647 return new Objective(level, version, pkgVersion);
1648 }
1649
1650
1651 LIBSBML_EXTERN
1652 void
Objective_free(Objective_t * o)1653 Objective_free(Objective_t * o)
1654 {
1655 if (o != NULL)
1656 delete o;
1657 }
1658
1659
1660 LIBSBML_EXTERN
1661 Objective_t *
Objective_clone(Objective_t * o)1662 Objective_clone(Objective_t * o)
1663 {
1664 if (o != NULL)
1665 {
1666 return static_cast<Objective_t*>(o->clone());
1667 }
1668 else
1669 {
1670 return NULL;
1671 }
1672 }
1673
1674
1675 LIBSBML_EXTERN
1676 const char *
Objective_getId(const Objective_t * o)1677 Objective_getId(const Objective_t * o)
1678 {
1679 return (o != NULL && o->isSetId()) ? o->getId().c_str() : NULL;
1680 }
1681
1682
1683 LIBSBML_EXTERN
1684 const char *
Objective_getName(const Objective_t * o)1685 Objective_getName(const Objective_t * o)
1686 {
1687 return (o != NULL && o->isSetName()) ? o->getName().c_str() : NULL;
1688 }
1689
1690
1691 LIBSBML_EXTERN
1692 const char *
Objective_getType(Objective_t * obj)1693 Objective_getType(Objective_t * obj)
1694 {
1695 if (obj == NULL)
1696 return NULL;
1697
1698 return obj->getType().empty() ? "" : obj->getType().c_str();
1699 }
1700
1701
1702 LIBSBML_EXTERN
1703 int
Objective_isSetId(const Objective_t * o)1704 Objective_isSetId(const Objective_t * o)
1705 {
1706 return (o != NULL) ? static_cast<int>(o->isSetId()) : 0;
1707 }
1708
1709
1710 LIBSBML_EXTERN
1711 int
Objective_isSetName(const Objective_t * o)1712 Objective_isSetName(const Objective_t * o)
1713 {
1714 return (o != NULL) ? static_cast<int>(o->isSetName()) : 0;
1715 }
1716
1717
1718 LIBSBML_EXTERN
1719 int
Objective_isSetType(const Objective_t * o)1720 Objective_isSetType(const Objective_t * o)
1721 {
1722 return (o != NULL) ? static_cast<int>(o->isSetType()) : 0;
1723 }
1724
1725
1726 LIBSBML_EXTERN
1727 int
Objective_setId(Objective_t * o,const char * id)1728 Objective_setId(Objective_t * o, const char * id)
1729 {
1730 if (o != NULL)
1731 return (id == NULL) ? o->setId("") : o->setId(id);
1732 else
1733 return LIBSBML_INVALID_OBJECT;
1734 }
1735
1736
1737 LIBSBML_EXTERN
1738 int
Objective_setName(Objective_t * o,const char * name)1739 Objective_setName(Objective_t * o, const char * name)
1740 {
1741 if (o != NULL)
1742 return (name == NULL) ? o->setName("") : o->setName(name);
1743 else
1744 return LIBSBML_INVALID_OBJECT;
1745 }
1746
1747
1748 LIBSBML_EXTERN
1749 int
Objective_setType(Objective_t * o,const char * type)1750 Objective_setType(Objective_t * o, const char* type)
1751 {
1752 if (o != NULL)
1753 return o->setType(type);
1754 else
1755 return LIBSBML_INVALID_OBJECT;
1756 }
1757
1758
1759 LIBSBML_EXTERN
1760 int
Objective_unsetId(Objective_t * o)1761 Objective_unsetId(Objective_t * o)
1762 {
1763 return (o != NULL) ? o->unsetId() : LIBSBML_INVALID_OBJECT;
1764 }
1765
1766
1767 LIBSBML_EXTERN
1768 int
Objective_unsetName(Objective_t * o)1769 Objective_unsetName(Objective_t * o)
1770 {
1771 return (o != NULL) ? o->unsetName() : LIBSBML_INVALID_OBJECT;
1772 }
1773
1774
1775 LIBSBML_EXTERN
1776 int
Objective_unsetType(Objective_t * o)1777 Objective_unsetType(Objective_t * o)
1778 {
1779 return (o != NULL) ? o->unsetType() : LIBSBML_INVALID_OBJECT;
1780 }
1781
1782
1783 LIBSBML_EXTERN
1784 int
Objective_addFluxObjective(Objective_t * o,FluxObjective_t * fo)1785 Objective_addFluxObjective(Objective_t * o, FluxObjective_t * fo)
1786 {
1787 return (o != NULL) ? o->addFluxObjective(fo) : LIBSBML_INVALID_OBJECT;
1788 }
1789
1790 LIBSBML_EXTERN
1791 FluxObjective_t *
Objective_createFluxObjective(Objective_t * o)1792 Objective_createFluxObjective(Objective_t * o)
1793 {
1794 return (o != NULL) ? o->createFluxObjective() : NULL;
1795 }
1796
1797 LIBSBML_EXTERN
1798 ListOf_t *
Objective_getListOfFluxObjectives(Objective_t * o)1799 Objective_getListOfFluxObjectives(Objective_t * o)
1800 {
1801 return (o != NULL) ? (ListOf_t *)o->getListOfFluxObjectives() : NULL;
1802 }
1803
1804 LIBSBML_EXTERN
1805 FluxObjective_t *
Objective_getFluxObjective(Objective_t * o,unsigned int n)1806 Objective_getFluxObjective(Objective_t * o, unsigned int n)
1807 {
1808 return (o != NULL) ? o->getFluxObjective(n) : NULL;
1809 }
1810
1811 LIBSBML_EXTERN
1812 FluxObjective_t *
Objective_getFluxObjectiveById(Objective_t * o,const char * sid)1813 Objective_getFluxObjectiveById(Objective_t * o, const char * sid)
1814 {
1815 return (o != NULL) ? o->getFluxObjective(sid) : NULL;
1816 }
1817
1818 LIBSBML_EXTERN
1819 unsigned int
Objective_getNumFluxObjectives(Objective_t * o)1820 Objective_getNumFluxObjectives(Objective_t * o)
1821 {
1822 return (o != NULL) ? o->getNumFluxObjectives() : SBML_INT_MAX;
1823 }
1824
1825 LIBSBML_EXTERN
1826 FluxObjective_t *
Objective_removeFluxObjective(Objective_t * o,unsigned int n)1827 Objective_removeFluxObjective(Objective_t * o, unsigned int n)
1828 {
1829 return (o != NULL) ? o->removeFluxObjective(n) : NULL;
1830 }
1831
1832 LIBSBML_EXTERN
1833 FluxObjective_t *
Objective_removeFluxObjectiveById(Objective_t * o,const char * sid)1834 Objective_removeFluxObjectiveById(Objective_t * o, const char * sid)
1835 {
1836 return (o != NULL) ? o->removeFluxObjective(sid) : NULL;
1837 }
1838
1839 LIBSBML_EXTERN
1840 int
Objective_hasRequiredAttributes(const Objective_t * o)1841 Objective_hasRequiredAttributes(const Objective_t * o)
1842 {
1843 return (o != NULL) ? static_cast<int>(o->hasRequiredAttributes()) : 0;
1844 }
1845
1846
1847 LIBSBML_EXTERN
1848 int
Objective_hasRequiredElements(const Objective_t * o)1849 Objective_hasRequiredElements(const Objective_t * o)
1850 {
1851 return (o != NULL) ? static_cast<int>(o->hasRequiredElements()) : 0;
1852 }
1853
1854
1855 LIBSBML_EXTERN
1856 Objective_t *
ListOfObjectives_getById(ListOf_t * lo,const char * sid)1857 ListOfObjectives_getById(ListOf_t * lo, const char * sid)
1858 {
1859 if (lo == NULL)
1860 return NULL;
1861
1862 return (sid != NULL) ? static_cast <ListOfObjectives *>(lo)->get(sid) : NULL;
1863 }
1864
1865
1866 LIBSBML_EXTERN
1867 Objective_t *
ListOfObjectives_removeById(ListOf_t * lo,const char * sid)1868 ListOfObjectives_removeById(ListOf_t * lo, const char * sid)
1869 {
1870 if (lo == NULL)
1871 return NULL;
1872
1873 return (sid != NULL) ? static_cast <ListOfObjectives *>(lo)->remove(sid) : NULL;
1874 }
1875
1876
1877 static
1878 const char* OBJECTIVE_TYPE_STRINGS[] =
1879 {
1880 "maximize"
1881 , "minimize"
1882 , "unknown"
1883 };
1884
1885
1886 LIBSBML_EXTERN
1887 const char*
ObjectiveType_toString(ObjectiveType_t type)1888 ObjectiveType_toString(ObjectiveType_t type)
1889 {
1890 int max = OBJECTIVE_TYPE_UNKNOWN;
1891
1892 if (type < OBJECTIVE_TYPE_MAXIMIZE || type >= max)
1893 {
1894 return NULL;
1895 }
1896
1897 return OBJECTIVE_TYPE_STRINGS[type];
1898 }
1899
1900
1901 LIBSBML_EXTERN
1902 ObjectiveType_t
ObjectiveType_fromString(const char * s)1903 ObjectiveType_fromString(const char* s)
1904 {
1905 if (s == NULL)
1906 {
1907 return OBJECTIVE_TYPE_UNKNOWN;
1908 }
1909
1910 int max = OBJECTIVE_TYPE_UNKNOWN;
1911 for (int i = 0; i < max; i++)
1912 {
1913 if (strcmp(OBJECTIVE_TYPE_STRINGS[i], s) == 0)
1914 return (ObjectiveType_t)i;
1915 }
1916 return OBJECTIVE_TYPE_UNKNOWN;
1917 }
1918
1919
1920 LIBSBML_EXTERN
1921 int
ObjectiveType_isValidObjectiveType(ObjectiveType_t effect)1922 ObjectiveType_isValidObjectiveType(ObjectiveType_t effect)
1923 {
1924 int max = OBJECTIVE_TYPE_UNKNOWN;
1925
1926 if (effect < OBJECTIVE_TYPE_MAXIMIZE || effect >= max)
1927 {
1928 return 0;
1929 }
1930 else
1931 {
1932 return 1;
1933 }
1934 }
1935
1936
1937
1938
1939 LIBSBML_EXTERN
1940 int
ObjectiveType_isValidObjectiveTypeString(const char * s)1941 ObjectiveType_isValidObjectiveTypeString(const char* s)
1942 {
1943 return ObjectiveType_isValidObjectiveType
1944 (ObjectiveType_fromString(s));
1945 }
1946
1947 LIBSBML_CPP_NAMESPACE_END
1948
1949
1950