1 /**
2  * @file    Event.cpp
3  * @brief   Implementations of Event and ListOfEvents.
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 <sbml/xml/XMLNode.h>
43 #include <sbml/xml/XMLAttributes.h>
44 #include <sbml/xml/XMLInputStream.h>
45 #include <sbml/xml/XMLOutputStream.h>
46 
47 #include <sbml/math/FormulaParser.h>
48 #include <sbml/math/MathML.h>
49 #include <sbml/math/ASTNode.h>
50 
51 #include <sbml/SBO.h>
52 #include <sbml/SBMLVisitor.h>
53 #include <sbml/SBMLDocument.h>
54 #include <sbml/SBMLError.h>
55 #include <sbml/Model.h>
56 #include <sbml/EventAssignment.h>
57 #include <sbml/Event.h>
58 
59 #include <sbml/util/ElementFilter.h>
60 
61 /** @cond doxygenIgnored */
62 using namespace std;
63 /** @endcond */
64 
65 LIBSBML_CPP_NAMESPACE_BEGIN
66 #ifdef __cplusplus
67 
Event(unsigned int level,unsigned int version)68 Event::Event (unsigned int level, unsigned int version) :
69    SBase ( level, version )
70  , mTrigger                  ( NULL    )
71  , mDelay                    ( NULL    )
72  , mPriority                 ( NULL    )
73  , mUseValuesFromTriggerTime ( true )
74  , mIsSetUseValuesFromTriggerTime ( false )
75  , mExplicitlySetUVFTT (false )
76  , mEventAssignments(level, version)
77  , mInternalId      ("")
78 {
79   if (!hasValidLevelVersionNamespaceCombination())
80     throw SBMLConstructorException();
81   // before level 3 useValuesFromTriggerTime was set by default
82   if (level < 3)
83   {
84     mIsSetUseValuesFromTriggerTime = true;
85   }
86   connectToChild();
87 }
88 
89 
Event(SBMLNamespaces * sbmlns)90 Event::Event (SBMLNamespaces * sbmlns) :
91    SBase                     ( sbmlns )
92  , mTrigger                  ( NULL    )
93  , mDelay                    ( NULL    )
94  , mPriority                 ( NULL    )
95  , mUseValuesFromTriggerTime ( true )
96  , mIsSetUseValuesFromTriggerTime (false )
97  , mExplicitlySetUVFTT (false )
98  , mEventAssignments(sbmlns)
99  , mInternalId      ("")
100 {
101   if (!hasValidLevelVersionNamespaceCombination())
102   {
103     throw SBMLConstructorException(getElementName(), sbmlns);
104   }
105 
106   if (sbmlns->getLevel() < 3)
107   {
108     mIsSetUseValuesFromTriggerTime = true;
109   }
110   connectToChild();
111   loadPlugins(sbmlns);
112 }
113 
114 
115 /*
116  * Destroys this Event.
117  */
~Event()118 Event::~Event ()
119 {
120   delete mTrigger;
121   delete mDelay;
122   delete mPriority;
123 }
124 
125 
126 /*
127  * Copy constructor. Creates a copy of this Event.
128  */
Event(const Event & orig)129 Event::Event (const Event& orig) :
130    SBase                     ( orig            )
131  , mTrigger                  ( NULL            )
132  , mDelay                    ( NULL            )
133  , mPriority                 ( NULL            )
134  , mTimeUnits                ( orig.mTimeUnits )
135  , mUseValuesFromTriggerTime ( orig.mUseValuesFromTriggerTime )
136  , mIsSetUseValuesFromTriggerTime ( orig.mIsSetUseValuesFromTriggerTime )
137  , mExplicitlySetUVFTT       ( orig.mExplicitlySetUVFTT )
138  , mEventAssignments         ( orig.mEventAssignments   )
139  , mInternalId      ( orig.mInternalId      )
140 {
141 
142   if (orig.mTrigger != NULL)
143   {
144     mTrigger = new Trigger(*orig.getTrigger());
145   }
146 
147   if (orig.mDelay != NULL)
148   {
149     mDelay = new Delay(*orig.getDelay());
150   }
151 
152   if (orig.mPriority != NULL)
153   {
154     mPriority = new Priority(*orig.getPriority());
155   }
156 
157 
158   connectToChild();
159 }
160 
161 
162 /*
163  * Assignment operator
164  */
operator =(const Event & rhs)165 Event& Event::operator=(const Event& rhs)
166 {
167   if(&rhs!=this)
168   {
169     this->SBase::operator =(rhs);
170 
171     mTimeUnits        = rhs.mTimeUnits        ;
172     mUseValuesFromTriggerTime = rhs.mUseValuesFromTriggerTime;
173     mIsSetUseValuesFromTriggerTime = rhs.mIsSetUseValuesFromTriggerTime;
174     mExplicitlySetUVFTT = rhs.mExplicitlySetUVFTT;
175     mInternalId     = rhs.mInternalId     ;
176     mEventAssignments = rhs.mEventAssignments ;
177 
178     delete mTrigger;
179     if (rhs.mTrigger != NULL)
180     {
181       mTrigger = new Trigger(*rhs.getTrigger());
182     }
183     else
184     {
185       mTrigger = NULL;
186     }
187 
188     delete mDelay;
189     if (rhs.mDelay != NULL)
190     {
191       mDelay = new Delay(*rhs.getDelay());
192     }
193     else
194     {
195       mDelay = NULL;
196     }
197 
198     delete mPriority;
199     if (rhs.mPriority != NULL)
200     {
201       mPriority = new Priority(*rhs.getPriority());
202     }
203     else
204     {
205       mPriority = NULL;
206     }
207   }
208 
209   connectToChild();
210 
211   return *this;
212 }
213 
214 
215 /** @cond doxygenLibsbmlInternal */
216 bool
accept(SBMLVisitor & v) const217 Event::accept (SBMLVisitor& v) const
218 {
219   bool result = v.visit(*this);
220 
221   if (mTrigger != NULL) mTrigger->accept(v);
222 
223   if (mDelay != NULL) mDelay->accept(v);
224 
225   if (mPriority != NULL) mPriority->accept(v);
226 
227   mEventAssignments.accept(v);
228 
229   return result;
230 }
231 /** @endcond */
232 
233 
234 /*
235  * @return a (deep) copy of this Event.
236  */
237 Event*
clone() const238 Event::clone () const
239 {
240   return new Event(*this);
241 }
242 
243 
244 void
initDefaults()245 Event::initDefaults()
246 {
247   setUseValuesFromTriggerTime(true);
248   // not explicitly set
249   mExplicitlySetUVFTT = false;
250 }
251 
252 SBase*
getElementBySId(const std::string & id)253 Event::getElementBySId(const std::string& id)
254 {
255   if (id.empty()) return NULL;
256   SBase* obj = NULL;
257   if (mTrigger != NULL) {
258     if (mTrigger->getId() == id) return mTrigger;
259     obj = mTrigger->getElementBySId(id);
260     if (obj != NULL) return obj;
261   }
262   if (mDelay != NULL) {
263     if (mDelay->getId() == id) return mDelay;
264     obj = mDelay->getElementBySId(id);
265     if (obj != NULL) return obj;
266   }
267   if (mPriority != NULL) {
268     if (mPriority->getId() == id) return mPriority;
269     obj = mPriority->getElementBySId(id);
270     if (obj != NULL) return obj;
271   }
272   if (mEventAssignments.getId() == id) return &mEventAssignments;
273   obj = mEventAssignments.getElementBySId(id);
274   if (obj != NULL) return obj;
275   return getElementFromPluginsBySId(id);
276 }
277 
278 
279 SBase*
getElementByMetaId(const std::string & metaid)280 Event::getElementByMetaId(const std::string& metaid)
281 {
282   if (metaid.empty()) return NULL;
283   SBase* obj = NULL;
284   if (mTrigger != NULL) {
285     if (mTrigger->getMetaId() == metaid) return mTrigger;
286     obj = mTrigger->getElementByMetaId(metaid);
287     if (obj != NULL) return obj;
288   }
289   if (mDelay != NULL) {
290     if (mDelay->getMetaId() == metaid) return mDelay;
291     obj = mDelay->getElementByMetaId(metaid);
292     if (obj != NULL) return obj;
293   }
294   if (mPriority != NULL) {
295     if (mPriority->getMetaId() == metaid) return mPriority;
296     obj = mPriority->getElementByMetaId(metaid);
297     if (obj != NULL) return obj;
298   }
299   if (mEventAssignments.getMetaId() == metaid) return &mEventAssignments;
300   obj = mEventAssignments.getElementByMetaId(metaid);
301   if (obj != NULL) return obj;
302   return getElementFromPluginsByMetaId(metaid);
303 }
304 
305 List*
getAllElements(ElementFilter * filter)306 Event::getAllElements(ElementFilter *filter)
307 {
308   List* ret = new List();
309   List* sublist = NULL;
310 
311   ADD_FILTERED_POINTER(ret, sublist, mTrigger, filter);
312   ADD_FILTERED_POINTER(ret, sublist, mDelay, filter);
313   ADD_FILTERED_POINTER(ret, sublist, mPriority, filter);
314 
315   ADD_FILTERED_LIST(ret, sublist, mEventAssignments, filter);
316 
317   ADD_FILTERED_FROM_PLUGIN(ret, sublist, filter);
318 
319   return ret;
320 }
321 
322 /*
323  * @return the id of this SBML object.
324  */
325 const string&
getId() const326 Event::getId () const
327 {
328   return mId;
329 }
330 
331 
332 /*
333  * @return the name of this SBML object.
334  */
335 const string&
getName() const336 Event::getName () const
337 {
338   return (getLevel() == 1) ? mId : mName;
339 }
340 
341 
342 /*
343  * @return the trigger of this Event.
344  */
345 const Trigger*
getTrigger() const346 Event::getTrigger () const
347 {
348   return mTrigger;
349 }
350 
351 
352 /*
353  * @return the trigger of this Event.
354  */
355 Trigger*
getTrigger()356 Event::getTrigger ()
357 {
358   return mTrigger;
359 }
360 
361 
362 /*
363  * @return the delay of this Event.
364  */
365 const Delay*
getDelay() const366 Event::getDelay () const
367 {
368   return mDelay;
369 }
370 
371 
372 /*
373  * @return the delay of this Event.
374  */
375 Delay*
getDelay()376 Event::getDelay ()
377 {
378   return mDelay;
379 }
380 
381 
382 /*
383  * @return the delay of this Event.
384  */
385 const Priority*
getPriority() const386 Event::getPriority () const
387 {
388   return mPriority;
389 }
390 
391 
392 /*
393  * @return the delay of this Event.
394  */
395 Priority*
getPriority()396 Event::getPriority ()
397 {
398   return mPriority;
399 }
400 
401 
402 /*
403  * @return the timeUnits of this Event
404  *
405  * @warning Definitions of Event in SBML Level 2 Versions 1 and 2
406  * included the additional attribute called "timeUnits", but it was
407  * removed in SBML Level 2 Version 3.  LibSBML supports this attribute
408  * for compatibility with previous versions of SBML Level 2, but its use
409  * is discouraged since models in Level 2 Versions 3 cannot contain it.
410  */
411 const string&
getTimeUnits() const412 Event::getTimeUnits () const
413 {
414   return mTimeUnits;
415 }
416 
417 
418 /*
419  * Returns the value of the "useValuesFromTriggerTime" attribute of this Event.
420  */
421 bool
getUseValuesFromTriggerTime() const422 Event::getUseValuesFromTriggerTime () const
423 {
424   return mUseValuesFromTriggerTime;
425 }
426 
427 
428 /*
429  * @return @c true if the id of this SBML object is set, false
430  * otherwise.
431  */
432 bool
isSetId() const433 Event::isSetId () const
434 {
435   return (mId.empty() == false);
436 }
437 
438 
439 /*
440  * @return @c true if the name of this SBML object is set, false
441  * otherwise.
442  */
443 bool
isSetName() const444 Event::isSetName () const
445 {
446   return (getLevel() == 1) ? (mId.empty() == false) :
447                             (mName.empty() == false);
448 }
449 
450 
451 /*
452  * @return @c true if the trigger of this Event is set, false otherwise.
453  */
454 bool
isSetTrigger() const455 Event::isSetTrigger () const
456 {
457   return (mTrigger != NULL);
458 }
459 
460 
461 /*
462  * @return @c true if the delay of this Event is set, false otherwise.
463  */
464 bool
isSetDelay() const465 Event::isSetDelay () const
466 {
467   return (mDelay != NULL);
468 }
469 
470 
471 /*
472  * @return @c true if the priority of this Event is set, false otherwise.
473  */
474 bool
isSetPriority() const475 Event::isSetPriority () const
476 {
477   return (mPriority != NULL);
478 }
479 
480 
481 /*
482  * @return @c true if the timeUnits of this Event is set, false
483  * otherwise.
484  *
485  * @warning Definitions of Event in SBML Level 2 Versions 1 and 2
486  * included the additional attribute called "timeUnits", but it was
487  * removed in SBML Level 2 Version 3.  LibSBML supports this attribute
488  * for compatibility with previous versions of SBML Level 2, but its use
489  * is discouraged since models in Level 2 Version 3 cannot contain it.
490  */
491 bool
isSetTimeUnits() const492 Event::isSetTimeUnits () const
493 {
494   return (mTimeUnits.empty() == false);
495 }
496 
497 
498 /*
499  * @return @c true if the mUseValuesFromTriggerTime of this Event is set, false otherwise.
500  */
501 bool
isSetUseValuesFromTriggerTime() const502 Event::isSetUseValuesFromTriggerTime () const
503 {
504   return mIsSetUseValuesFromTriggerTime;
505 }
506 
507 
508 /*
509  * Sets the id of this SBML object to a copy of @p sid.
510  */
511 int
setId(const std::string & sid)512 Event::setId (const std::string& sid)
513 {
514   /* since the setId function has been used as an
515    * alias for setName we cant require it to only
516    * be used on a L2 model
517    */
518 /*  if (getLevel() == 1)
519   {
520     return LIBSBML_UNEXPECTED_ATTRIBUTE;
521   }
522 */
523   if (!(SyntaxChecker::isValidInternalSId(sid)))
524   {
525     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
526   }
527   else
528   {
529     mId = sid;
530     return LIBSBML_OPERATION_SUCCESS;
531   }
532 }
533 
534 
535 /*
536  * Sets the name of this SBML object to a copy of name.
537  */
538 int
setName(const std::string & name)539 Event::setName (const std::string& name)
540 {
541   /* if this is setting an L2 name the type is string
542    * whereas if it is setting an L1 name its type is SId
543    */
544   if (getLevel() == 1)
545   {
546     if (!(SyntaxChecker::isValidInternalSId(name)))
547     {
548       return LIBSBML_INVALID_ATTRIBUTE_VALUE;
549     }
550     else
551     {
552       mId = name;
553       return LIBSBML_OPERATION_SUCCESS;
554     }
555   }
556   else
557   {
558     mName = name;
559     return LIBSBML_OPERATION_SUCCESS;
560   }
561 }
562 
563 
564 /*
565  * Sets the trigger of this Event to a copy of the given Trigger.
566  */
567 int
setTrigger(const Trigger * trigger)568 Event::setTrigger (const Trigger* trigger)
569 {
570   int returnValue = checkCompatibility(static_cast<const SBase *>(trigger));
571 
572   if (returnValue == LIBSBML_OPERATION_FAILED && trigger == NULL)
573   {
574     delete mTrigger;
575     mTrigger = NULL;
576     return LIBSBML_OPERATION_SUCCESS;
577   }
578   else if (returnValue != LIBSBML_OPERATION_SUCCESS)
579   {
580     return returnValue;
581   }
582 
583   if (mTrigger == trigger)
584   {
585     return LIBSBML_OPERATION_SUCCESS;
586   }
587   else
588   {
589     delete mTrigger;
590     mTrigger = (trigger != NULL) ?
591                 static_cast<Trigger*>( trigger->clone() ) : NULL;
592 
593     if (mTrigger != NULL) mTrigger->connectToParent(this);
594 
595     return LIBSBML_OPERATION_SUCCESS;
596   }
597 }
598 
599 
600 /*
601  * Sets the delay of this Event to a copy of the given Delay.
602  */
603 int
setDelay(const Delay * delay)604 Event::setDelay (const Delay* delay)
605 {
606   int returnValue = checkCompatibility(static_cast<const SBase *>(delay));
607 
608   if (returnValue == LIBSBML_OPERATION_FAILED && delay == NULL)
609   {
610     delete mDelay;
611     mDelay = NULL;
612     return LIBSBML_OPERATION_SUCCESS;
613   }
614   else if (returnValue != LIBSBML_OPERATION_SUCCESS)
615   {
616     return returnValue;
617   }
618 
619   if (mDelay == delay)
620   {
621     return LIBSBML_OPERATION_SUCCESS;
622   }
623   else
624   {
625     delete mDelay;
626     mDelay = (delay != NULL) ? static_cast<Delay*>( delay->clone() ) : NULL;
627 
628     if (mDelay != NULL) mDelay->connectToParent(this);
629 
630     return LIBSBML_OPERATION_SUCCESS;
631   }
632 }
633 
634 
635 /*
636  * Sets the prioirty of this Event to a copy of the given Priority.
637  */
638 int
setPriority(const Priority * priority)639 Event::setPriority (const Priority* priority)
640 {
641   if (getLevel() < 3)
642   {
643     return LIBSBML_UNEXPECTED_ATTRIBUTE;
644   }
645 
646   int returnValue = checkCompatibility(static_cast<const SBase *>(priority));
647 
648   if (returnValue == LIBSBML_OPERATION_FAILED && priority == NULL)
649   {
650     delete mPriority;
651     mPriority = NULL;
652     return LIBSBML_OPERATION_SUCCESS;
653   }
654   else if (returnValue != LIBSBML_OPERATION_SUCCESS)
655   {
656     return returnValue;
657   }
658 
659   if (mPriority == priority)
660   {
661     return LIBSBML_OPERATION_SUCCESS;
662   }
663   else
664   {
665     delete mPriority;
666     mPriority = (priority != NULL) ?
667                  static_cast<Priority*>( priority->clone() ) : NULL;
668 
669     if (mPriority != NULL) mPriority->connectToParent(this);
670 
671     return LIBSBML_OPERATION_SUCCESS;
672   }
673 }
674 
675 
676 /*
677  * Sets the timeUnits of this Event to a copy of @p sid.
678  *
679  * @warning Definitions of Event in SBML Level 2 Versions 1 and 2
680  * included the additional attribute called "timeUnits", but it was
681  * removed in SBML Level 2 Version 3.  LibSBML supports this attribute
682  * for compatibility with previous versions of SBML Level 2, but its use
683  * is discouraged since models in Level 2 Version 3 cannot contain it.
684  */
685 int
setTimeUnits(const std::string & sid)686 Event::setTimeUnits (const std::string& sid)
687 {
688   if (getLevel() == 2 && getVersion() > 2)
689   {
690     return LIBSBML_UNEXPECTED_ATTRIBUTE;
691   }
692   else if (!(SyntaxChecker::isValidInternalSId(sid)))
693   {
694     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
695   }
696   else
697   {
698     mTimeUnits = sid;
699     return LIBSBML_OPERATION_SUCCESS;
700   }
701 }
702 
703 
704 /*
705  * Sets the "useValuesFromTriggerTime" attribute of this Event to a @p value.
706  */
707 int
setUseValuesFromTriggerTime(bool value)708 Event::setUseValuesFromTriggerTime (bool value)
709 {
710   if (getLevel() == 2 && getVersion() < 4)
711   {
712     return LIBSBML_UNEXPECTED_ATTRIBUTE;
713   }
714   else
715   {
716     mUseValuesFromTriggerTime = value;
717     mIsSetUseValuesFromTriggerTime = true;
718     mExplicitlySetUVFTT = true;
719     return LIBSBML_OPERATION_SUCCESS;
720   }
721 }
722 
723 
724 /*
725  * Unsets the id of this SBML object.
726  */
727 int
unsetId()728 Event::unsetId ()
729 {
730   mId.erase();
731 
732   if (mId.empty())
733   {
734     return LIBSBML_OPERATION_SUCCESS;
735   }
736   else
737   {
738     return LIBSBML_OPERATION_FAILED;
739   }
740 }
741 
742 
743 /*
744  * Unsets the name of this SBML object.
745  */
746 int
unsetName()747 Event::unsetName ()
748 {
749   if (getLevel() == 1)
750   {
751     mId.erase();
752   }
753   else
754   {
755     mName.erase();
756   }
757 
758   if (getLevel() == 1 && mId.empty())
759   {
760     return LIBSBML_OPERATION_SUCCESS;
761   }
762   else if (mName.empty())
763   {
764     return LIBSBML_OPERATION_SUCCESS;
765   }
766   else
767   {
768     return LIBSBML_OPERATION_FAILED;
769   }
770 }
771 
772 
773 int
unsetUseValuesFromTriggerTime()774 Event::unsetUseValuesFromTriggerTime ()
775 {
776   if (getLevel() == 2 && getVersion() < 4)
777   {
778     return LIBSBML_UNEXPECTED_ATTRIBUTE;
779   }
780   else if (getLevel() == 2)
781   {
782     // reset defaults
783     mUseValuesFromTriggerTime = true;
784     mIsSetUseValuesFromTriggerTime = true;
785     mExplicitlySetUVFTT = false;
786     return LIBSBML_UNEXPECTED_ATTRIBUTE;
787   }
788   else
789   {
790     mIsSetUseValuesFromTriggerTime = false;
791     mExplicitlySetUVFTT = false;
792     return LIBSBML_OPERATION_SUCCESS;
793   }
794 }
795 
796 
797 /*
798  * Unsets the delay of this Event.
799  */
800 int
unsetDelay()801 Event::unsetDelay ()
802 {
803   delete mDelay;
804   mDelay = NULL;
805 
806   if (mDelay == NULL)
807   {
808     return LIBSBML_OPERATION_SUCCESS;
809   }
810   else
811   {
812     return LIBSBML_OPERATION_FAILED;
813   }
814 }
815 
816 
817 /*
818  * Unsets the priority of this Event.
819  */
820 int
unsetPriority()821 Event::unsetPriority ()
822 {
823   delete mPriority;
824   mPriority = NULL;
825 
826   if (mPriority == NULL)
827   {
828     return LIBSBML_OPERATION_SUCCESS;
829   }
830   else
831   {
832     return LIBSBML_OPERATION_FAILED;
833   }
834 }
835 
836 
837 /*
838  * Unsets the trigger of this Event.
839  */
840 int
unsetTrigger()841 Event::unsetTrigger ()
842 {
843   delete mTrigger;
844   mTrigger = NULL;
845 
846   if (mTrigger == NULL)
847   {
848     return LIBSBML_OPERATION_SUCCESS;
849   }
850   else
851   {
852     return LIBSBML_OPERATION_FAILED;
853   }
854 }
855 
856 
857 /*
858  * Unsets the timeUnits of this Event.
859  *
860  * @warning Definitions of Event in SBML Level 2 Versions 1 and 2
861  * included the additional attribute called "timeUnits", but it was
862  * removed in SBML Level 2 Version 3.  LibSBML supports this attribute
863  * for compatibility with previous versions of SBML Level 2, but its use
864  * is discouraged since models in Level 2 Version 3 cannot contain it.
865  */
866 int
unsetTimeUnits()867 Event::unsetTimeUnits ()
868 {
869   if (getLevel() == 2 && getVersion() > 2)
870   {
871     return LIBSBML_UNEXPECTED_ATTRIBUTE;
872   }
873 
874   mTimeUnits.erase();
875 
876   if (mTimeUnits.empty())
877   {
878     return LIBSBML_OPERATION_SUCCESS;
879   }
880   else
881   {
882     return LIBSBML_OPERATION_FAILED;
883   }
884 }
885 
886 
887 /*
888  * Appends a copy of the given EventAssignment to this Event.
889  */
890 int
addEventAssignment(const EventAssignment * ea)891 Event::addEventAssignment (const EventAssignment* ea)
892 {
893   int returnValue = checkCompatibility(static_cast<const SBase *>(ea));
894   if (returnValue != LIBSBML_OPERATION_SUCCESS)
895   {
896     return returnValue;
897   }
898   else if (getEventAssignment(ea->getVariable()) != NULL)
899   {
900     // an eventAssignment for this variable already exists
901     return LIBSBML_DUPLICATE_OBJECT_ID;
902   }
903   else
904   {
905     mEventAssignments.append(ea);
906 
907     return LIBSBML_OPERATION_SUCCESS;
908   }
909 }
910 
911 
912 /*
913  * Creates a new EventAssignment, adds it to this Event's list of event
914  * assignments and returns it.
915  */
916 EventAssignment*
createEventAssignment()917 Event::createEventAssignment ()
918 {
919   EventAssignment* ea = NULL;
920 
921   try
922   {
923     ea = new EventAssignment(getSBMLNamespaces());
924   }
925   catch (...)
926   {
927     /* here we do not create a default object as the level/version must
928      * match the parent object
929      *
930      * so do nothing
931      */
932      return NULL;
933   }
934 
935   if (ea != NULL) mEventAssignments.appendAndOwn(ea);
936 
937   return ea;
938 }
939 
940 
941 /*
942  * Creates a new Trigger, adds it to this Event
943  * and returns it.
944  */
945 Trigger*
createTrigger()946 Event::createTrigger ()
947 {
948   delete mTrigger;
949   mTrigger = NULL;
950 
951   try
952   {
953     mTrigger = new Trigger(getSBMLNamespaces());
954   }
955   catch (...)
956   {
957     /* here we do not create a default object as the level/version must
958      * match the parent object
959      *
960      * so do nothing
961      */
962      return NULL;
963   }
964 
965   if (mTrigger != NULL)
966   {
967     mTrigger->connectToParent(this);
968   }
969 
970   return mTrigger;
971 }
972 
973 
974 /*
975  * Creates a new Delay, adds it to this Event
976  * and returns it.
977  */
978 Delay*
createDelay()979 Event::createDelay ()
980 {
981   delete mDelay;
982   mDelay = 0;
983 
984   try
985   {
986     mDelay = new Delay(getSBMLNamespaces());
987   }
988   catch (...)
989   {
990     /* here we do not create a default object as the level/version must
991      * match the parent object
992      *
993      * so do nothing
994      */
995      return NULL;
996   }
997 
998   if (mDelay)
999   {
1000     mDelay->connectToParent(this);
1001   }
1002 
1003   return mDelay;
1004 }
1005 
1006 
1007 /*
1008  * Creates a new Priority, adds it to this Event
1009  * and returns it.
1010  */
1011 Priority*
createPriority()1012 Event::createPriority ()
1013 {
1014   delete mPriority;
1015   mPriority = NULL;
1016 
1017   try
1018   {
1019     mPriority = new Priority(getSBMLNamespaces());
1020   }
1021   catch (...)
1022   {
1023     /* here we do not create a default object as the level/version must
1024      * match the parent object
1025      *
1026      * so do nothing
1027      */
1028      return NULL;
1029   }
1030 
1031   if (mPriority != NULL)
1032   {
1033     mPriority->connectToParent(this);
1034   }
1035 
1036   return mPriority;
1037 }
1038 
1039 
1040 /*
1041  * @return the list of EventAssignments for this Event.
1042  */
1043 const ListOfEventAssignments*
getListOfEventAssignments() const1044 Event::getListOfEventAssignments () const
1045 {
1046   return &mEventAssignments;
1047 }
1048 
1049 
1050 /*
1051  * @return the list of EventAssignments for this Event.
1052  */
1053 ListOfEventAssignments*
getListOfEventAssignments()1054 Event::getListOfEventAssignments ()
1055 {
1056   return &mEventAssignments;
1057 }
1058 
1059 
1060 /*
1061  * @return the nth EventAssignment of this Event.
1062  */
1063 const EventAssignment*
getEventAssignment(unsigned int n) const1064 Event::getEventAssignment (unsigned int n) const
1065 {
1066   return static_cast<const EventAssignment*>( mEventAssignments.get(n) );
1067 }
1068 
1069 
1070 /*
1071  * @return the nth EventAssignment of this Event.
1072  */
1073 EventAssignment*
getEventAssignment(unsigned int n)1074 Event::getEventAssignment (unsigned int n)
1075 {
1076   return static_cast<EventAssignment*>( mEventAssignments.get(n) );
1077 }
1078 
1079 
1080 /*
1081  * @return the EventAssignment for the given variable, or @c NULL if no such
1082  * EventAssignment exists.
1083  */
1084 const EventAssignment*
getEventAssignment(const std::string & variable) const1085 Event::getEventAssignment (const std::string& variable) const
1086 {
1087   return static_cast<const EventAssignment*>( mEventAssignments.get(variable) );
1088 }
1089 
1090 
1091 /*
1092  * @return the EventAssignment for the given variable, or @c NULL if no such
1093  * EventAssignment exists.
1094  */
1095 EventAssignment*
getEventAssignment(const std::string & variable)1096 Event::getEventAssignment (const std::string& variable)
1097 {
1098   return static_cast<EventAssignment*>( mEventAssignments.get(variable) );
1099 }
1100 
1101 
1102 /*
1103  * @return the number of EventAssignments in this Event.
1104  */
1105 unsigned int
getNumEventAssignments() const1106 Event::getNumEventAssignments () const
1107 {
1108   return mEventAssignments.size();
1109 }
1110 
1111 
1112 /**
1113  * Removes the nth EventAssignment object from this Event object and
1114  * returns a pointer to it.
1115  */
1116 EventAssignment*
removeEventAssignment(unsigned int n)1117 Event::removeEventAssignment (unsigned int n)
1118 {
1119   return mEventAssignments.remove(n);
1120 }
1121 
1122 
1123 /**
1124  * Removes the EventAssignment object with the given "variable" attribute
1125  * from this Event object and returns a pointer to it.
1126  */
1127 EventAssignment*
removeEventAssignment(const std::string & variable)1128 Event::removeEventAssignment (const std::string& variable)
1129 {
1130   return mEventAssignments.remove(variable);
1131 }
1132 
1133 
1134 /** @cond doxygenLibsbmlInternal */
1135 /*
1136  * Sets the parent SBMLDocument of this SBML object.
1137  */
1138 void
setSBMLDocument(SBMLDocument * d)1139 Event::setSBMLDocument (SBMLDocument* d)
1140 {
1141   SBase::setSBMLDocument(d);
1142 
1143   mEventAssignments.setSBMLDocument(d);
1144   if (mTrigger != NULL) mTrigger->setSBMLDocument(d);
1145   if (mDelay != NULL) mDelay->setSBMLDocument(d);
1146 }
1147 
1148 
1149 /*
1150  * Sets this SBML object to child SBML objects (if any).
1151  * (Creates a child-parent relationship by the parent)
1152   */
1153 void
connectToChild()1154 Event::connectToChild()
1155 {
1156   SBase::connectToChild();
1157   mEventAssignments.connectToParent(this);
1158   if (mTrigger != NULL) mTrigger->connectToParent(this);
1159   if (mDelay != NULL)   mDelay->connectToParent(this);
1160   if (mPriority != NULL)   mPriority->connectToParent(this);
1161 }
1162 
1163 
1164 /**
1165  * Enables/Disables the given package with this element and child
1166  * elements (if any).
1167  * (This is an internal implementation for enablePackage function)
1168  */
1169 void
enablePackageInternal(const std::string & pkgURI,const std::string & pkgPrefix,bool flag)1170 Event::enablePackageInternal(const std::string& pkgURI, const std::string& pkgPrefix, bool flag)
1171 {
1172   SBase::enablePackageInternal(pkgURI,pkgPrefix,flag);
1173 
1174   mEventAssignments.enablePackageInternal(pkgURI,pkgPrefix,flag);
1175   if (mTrigger) mTrigger->enablePackageInternal(pkgURI,pkgPrefix,flag);
1176   if (mDelay)   mDelay->enablePackageInternal(pkgURI,pkgPrefix,flag);
1177   if (mPriority)   mPriority->enablePackageInternal(pkgURI,pkgPrefix,flag);
1178 }
1179 
1180 void
updateSBMLNamespace(const std::string & pkg,unsigned int level,unsigned int version)1181 Event::updateSBMLNamespace(const std::string& pkg, unsigned int level,
1182   unsigned int version)
1183 {
1184   SBase::updateSBMLNamespace(pkg, level, version);
1185 
1186   mEventAssignments.updateSBMLNamespace(pkg, level, version);
1187   if (mTrigger) mTrigger->updateSBMLNamespace(pkg, level, version);
1188   if (mDelay)   mDelay->updateSBMLNamespace(pkg, level, version);
1189   if (mPriority)   mPriority->updateSBMLNamespace(pkg, level, version);
1190 
1191 }
1192 /** @endcond */
1193 
1194 
1195 /*
1196  * @return the typecode (int) of this SBML object or SBML_UNKNOWN
1197  * (default).
1198  *
1199  * @see getElementName()
1200  */
1201 int
getTypeCode() const1202 Event::getTypeCode () const
1203 {
1204   return SBML_EVENT;
1205 }
1206 
1207 
1208 /*
1209  * @return the name of this element ie "event".
1210  */
1211 const string&
getElementName() const1212 Event::getElementName () const
1213 {
1214   static const string name = "event";
1215   return name;
1216 }
1217 
1218 
1219 bool
hasRequiredAttributes() const1220 Event::hasRequiredAttributes() const
1221 {
1222   bool allPresent = true;
1223 
1224   /* required attributes for event: useValuesFromtriggerTime (L3 ->) */
1225   if (getLevel() > 2)
1226   {
1227     if(!isSetUseValuesFromTriggerTime())
1228       allPresent = false;
1229   }
1230 
1231   return allPresent;
1232 }
1233 
1234 
1235 bool
hasRequiredElements() const1236 Event::hasRequiredElements() const
1237 {
1238   bool allPresent = true;
1239 
1240   /* required attributes for event: trigger;
1241    * listOfEventAssignments (not L3)
1242   */
1243 
1244   if (!isSetTrigger())
1245     allPresent = false;
1246 
1247   if (getLevel() < 3 && getNumEventAssignments() == 0)
1248     allPresent = false;
1249 
1250   return allPresent;
1251 }
1252 
1253 
1254 /** @cond doxygenLibsbmlInternal */
1255 /*
1256  * @return the SBML object corresponding to next XMLToken in the
1257  * XMLInputStream or @c NULL if the token was not recognized.
1258  */
1259 SBase*
createObject(XMLInputStream & stream)1260 Event::createObject (XMLInputStream& stream)
1261 {
1262   SBase* object = NULL;
1263 
1264   const string& name = stream.peek().getName();
1265   if (name == "listOfEventAssignments")
1266   {
1267     if (mEventAssignments.size() != 0)
1268     {
1269       if (getLevel() < 3)
1270         logError(NotSchemaConformant, getLevel(), getVersion(),
1271          "Only one <listOfEventAssignments> elements is permitted "
1272          "in a single <event> element.");
1273       else
1274         logError(OneListOfEventAssignmentsPerEvent, getLevel(), getVersion());
1275     }
1276     mEventAssignments.setExplicitlyListed();
1277     object = &mEventAssignments;
1278   }
1279   else if (name == "trigger")
1280   {
1281     if (mTrigger != NULL)
1282     {
1283       if (getLevel() < 3)
1284         logError(NotSchemaConformant, getLevel(), getVersion(),
1285          "Only one <trigger> elements is permitted "
1286          "in a single <event> element.");
1287       else
1288         logError(MissingTriggerInEvent, getLevel(), getVersion());
1289     }
1290 
1291     delete mTrigger;
1292 
1293     try
1294     {
1295       mTrigger = new Trigger(getSBMLNamespaces());
1296     }
1297     catch (SBMLConstructorException*)
1298     {
1299       mTrigger = new Trigger(SBMLDocument::getDefaultLevel(),
1300         SBMLDocument::getDefaultVersion());
1301     }
1302     catch ( ... )
1303     {
1304       mTrigger = new Trigger(SBMLDocument::getDefaultLevel(),
1305         SBMLDocument::getDefaultVersion());
1306     }
1307     object = mTrigger;
1308   }
1309   else if (name == "delay")
1310   {
1311     if (mDelay != NULL)
1312     {
1313       if (getLevel() < 3)
1314         logError(NotSchemaConformant, getLevel(), getVersion(),
1315          "Only one <delay> element is permitted in a single "
1316          "<event> element.");
1317       else
1318         logError(OnlyOneDelayPerEvent, getLevel(), getVersion());
1319     }
1320     delete mDelay;
1321 
1322     try
1323     {
1324       mDelay = new Delay(getSBMLNamespaces());
1325     }
1326     catch (SBMLConstructorException*)
1327     {
1328       mDelay = new Delay(SBMLDocument::getDefaultLevel(),
1329         SBMLDocument::getDefaultVersion());
1330     }
1331     catch ( ... )
1332     {
1333       mDelay = new Delay(SBMLDocument::getDefaultLevel(),
1334         SBMLDocument::getDefaultVersion());
1335     }
1336     object = mDelay;
1337   }
1338   else if (name == "priority")
1339   {
1340     if (mPriority != NULL)
1341     {
1342       if (getLevel() < 3)
1343         logError(NotSchemaConformant, getLevel(), getVersion(),
1344          "Priority is not a valid component for this level/version.");
1345       else
1346       {
1347         logError(OnlyOnePriorityPerEvent, getLevel(), getVersion());
1348       }
1349 
1350     }
1351     delete mPriority;
1352 
1353     try
1354     {
1355       mPriority = new Priority(getSBMLNamespaces());
1356     }
1357     catch (SBMLConstructorException*)
1358     {
1359       mPriority = new Priority(SBMLDocument::getDefaultLevel(),
1360         SBMLDocument::getDefaultVersion());
1361     }
1362     catch ( ... )
1363     {
1364       mPriority = new Priority(SBMLDocument::getDefaultLevel(),
1365         SBMLDocument::getDefaultVersion());
1366     }
1367     object = mPriority;
1368   }
1369 
1370   return object;
1371 }
1372 /** @endcond */
1373 
1374 
1375 
1376 
1377 
1378 
1379 /** @cond doxygenLibsbmlInternal */
1380 
1381 /*
1382  * Returns the value of the "attributeName" attribute of this Event.
1383  */
1384 int
getAttribute(const std::string & attributeName,bool & value) const1385 Event::getAttribute(const std::string& attributeName, bool& value) const
1386 {
1387   int return_value = SBase::getAttribute(attributeName, value);
1388 
1389   if (return_value == LIBSBML_OPERATION_SUCCESS)
1390   {
1391     return return_value;
1392   }
1393 
1394   if (attributeName == "useValuesFromTriggerTime")
1395   {
1396     value = getUseValuesFromTriggerTime();
1397     return_value = LIBSBML_OPERATION_SUCCESS;
1398   }
1399 
1400   return return_value;
1401 }
1402 
1403 /** @endcond */
1404 
1405 
1406 
1407 /** @cond doxygenLibsbmlInternal */
1408 
1409 /*
1410  * Returns the value of the "attributeName" attribute of this Event.
1411  */
1412 int
getAttribute(const std::string & attributeName,int & value) const1413 Event::getAttribute(const std::string& attributeName, int& value) const
1414 {
1415   int return_value = SBase::getAttribute(attributeName, value);
1416 
1417   return return_value;
1418 }
1419 
1420 /** @endcond */
1421 
1422 
1423 
1424 /** @cond doxygenLibsbmlInternal */
1425 
1426 /*
1427  * Returns the value of the "attributeName" attribute of this Event.
1428  */
1429 int
getAttribute(const std::string & attributeName,double & value) const1430 Event::getAttribute(const std::string& attributeName, double& value) const
1431 {
1432   int return_value = SBase::getAttribute(attributeName, value);
1433 
1434   return return_value;
1435 }
1436 
1437 /** @endcond */
1438 
1439 
1440 
1441 /** @cond doxygenLibsbmlInternal */
1442 
1443 /*
1444  * Returns the value of the "attributeName" attribute of this Event.
1445  */
1446 int
getAttribute(const std::string & attributeName,unsigned int & value) const1447 Event::getAttribute(const std::string& attributeName,
1448                     unsigned int& value) const
1449 {
1450   int return_value = SBase::getAttribute(attributeName, value);
1451 
1452   return return_value;
1453 }
1454 
1455 /** @endcond */
1456 
1457 
1458 
1459 /** @cond doxygenLibsbmlInternal */
1460 
1461 /*
1462  * Returns the value of the "attributeName" attribute of this Event.
1463  */
1464 int
getAttribute(const std::string & attributeName,std::string & value) const1465 Event::getAttribute(const std::string& attributeName,
1466                     std::string& value) const
1467 {
1468   int return_value = SBase::getAttribute(attributeName, value);
1469 
1470   if (return_value == LIBSBML_OPERATION_SUCCESS)
1471   {
1472     return return_value;
1473   }
1474 
1475   if (attributeName == "timeUnits")
1476   {
1477     value = getTimeUnits();
1478     return_value = LIBSBML_OPERATION_SUCCESS;
1479   }
1480 
1481   return return_value;
1482 }
1483 
1484 /** @endcond */
1485 
1486 
1487 
1488 /** @cond doxygenLibsbmlInternal */
1489 
1490 /*
1491  * Returns the value of the "attributeName" attribute of this Event.
1492  */
1493 //int
1494 //Event::getAttribute(const std::string& attributeName, const char* value) const
1495 //{
1496 //  int return_value = SBase::getAttribute(attributeName, value);
1497 //
1498 //  if (return_value == LIBSBML_OPERATION_SUCCESS)
1499 //  {
1500 //    return return_value;
1501 //  }
1502 //
1503 //  if (attributeName == "timeUnits")
1504 //  {
1505 //    value = getTimeUnits().c_str();
1506 //    return_value = LIBSBML_OPERATION_SUCCESS;
1507 //  }
1508 //
1509 //  return return_value;
1510 //}
1511 
1512 /** @endcond */
1513 
1514 
1515 
1516 /** @cond doxygenLibsbmlInternal */
1517 
1518 /*
1519  * Predicate returning @c true if this Event's attribute "attributeName" is
1520  * set.
1521  */
1522 bool
isSetAttribute(const std::string & attributeName) const1523 Event::isSetAttribute(const std::string& attributeName) const
1524 {
1525   bool value = SBase::isSetAttribute(attributeName);
1526 
1527   if (attributeName == "useValuesFromTriggerTime")
1528   {
1529     value = isSetUseValuesFromTriggerTime();
1530   }
1531   else if (attributeName == "timeUnits")
1532   {
1533     value = isSetTimeUnits();
1534   }
1535 
1536   return value;
1537 }
1538 
1539 /** @endcond */
1540 
1541 
1542 
1543 /** @cond doxygenLibsbmlInternal */
1544 
1545 /*
1546  * Sets the value of the "attributeName" attribute of this Event.
1547  */
1548 int
setAttribute(const std::string & attributeName,bool value)1549 Event::setAttribute(const std::string& attributeName, bool value)
1550 {
1551   int return_value = SBase::setAttribute(attributeName, value);
1552 
1553   if (attributeName == "useValuesFromTriggerTime")
1554   {
1555     return_value = setUseValuesFromTriggerTime(value);
1556   }
1557 
1558   return return_value;
1559 }
1560 
1561 /** @endcond */
1562 
1563 
1564 
1565 /** @cond doxygenLibsbmlInternal */
1566 
1567 /*
1568  * Sets the value of the "attributeName" attribute of this Event.
1569  */
1570 int
setAttribute(const std::string & attributeName,int value)1571 Event::setAttribute(const std::string& attributeName, int value)
1572 {
1573   int return_value = SBase::setAttribute(attributeName, value);
1574 
1575   return return_value;
1576 }
1577 
1578 /** @endcond */
1579 
1580 
1581 
1582 /** @cond doxygenLibsbmlInternal */
1583 
1584 /*
1585  * Sets the value of the "attributeName" attribute of this Event.
1586  */
1587 int
setAttribute(const std::string & attributeName,double value)1588 Event::setAttribute(const std::string& attributeName, double value)
1589 {
1590   int return_value = SBase::setAttribute(attributeName, value);
1591 
1592   return return_value;
1593 }
1594 
1595 /** @endcond */
1596 
1597 
1598 
1599 /** @cond doxygenLibsbmlInternal */
1600 
1601 /*
1602  * Sets the value of the "attributeName" attribute of this Event.
1603  */
1604 int
setAttribute(const std::string & attributeName,unsigned int value)1605 Event::setAttribute(const std::string& attributeName, unsigned int value)
1606 {
1607   int return_value = SBase::setAttribute(attributeName, value);
1608 
1609   return return_value;
1610 }
1611 
1612 /** @endcond */
1613 
1614 
1615 
1616 /** @cond doxygenLibsbmlInternal */
1617 
1618 /*
1619  * Sets the value of the "attributeName" attribute of this Event.
1620  */
1621 int
setAttribute(const std::string & attributeName,const std::string & value)1622 Event::setAttribute(const std::string& attributeName,
1623                     const std::string& value)
1624 {
1625   int return_value = SBase::setAttribute(attributeName, value);
1626 
1627   if (attributeName == "timeUnits")
1628   {
1629     return_value = setTimeUnits(value);
1630   }
1631 
1632   return return_value;
1633 }
1634 
1635 /** @endcond */
1636 
1637 
1638 
1639 /** @cond doxygenLibsbmlInternal */
1640 
1641 /*
1642  * Sets the value of the "attributeName" attribute of this Event.
1643  */
1644 //int
1645 //Event::setAttribute(const std::string& attributeName, const char* value)
1646 //{
1647 //  int return_value = SBase::setAttribute(attributeName, value);
1648 //
1649 //  if (attributeName == "timeUnits")
1650 //  {
1651 //    return_value = setTimeUnits(value);
1652 //  }
1653 //
1654 //  return return_value;
1655 //}
1656 
1657 /** @endcond */
1658 
1659 
1660 
1661 /** @cond doxygenLibsbmlInternal */
1662 
1663 /*
1664  * Unsets the value of the "attributeName" attribute of this Event.
1665  */
1666 int
unsetAttribute(const std::string & attributeName)1667 Event::unsetAttribute(const std::string& attributeName)
1668 {
1669   int value = SBase::unsetAttribute(attributeName);
1670 
1671   if (attributeName == "useValuesFromTriggerTime")
1672   {
1673     value = unsetUseValuesFromTriggerTime();
1674   }
1675   else if (attributeName == "timeUnits")
1676   {
1677     value = unsetTimeUnits();
1678   }
1679 
1680   return value;
1681 }
1682 
1683 /** @endcond */
1684 
1685 
1686 
1687 /** @cond doxygenLibsbmlInternal */
1688 
1689 /*
1690  * Creates and returns an new "elementName" object in this Event.
1691  */
1692 SBase*
createChildObject(const std::string & elementName)1693 Event::createChildObject(const std::string& elementName)
1694 {
1695   SBase* obj = NULL;
1696 
1697   if (elementName == "trigger")
1698   {
1699     return createTrigger();
1700   }
1701   else if (elementName == "priority")
1702   {
1703     return createPriority();
1704   }
1705   else if (elementName == "delay")
1706   {
1707     return createDelay();
1708   }
1709   else if (elementName == "eventAssignment")
1710   {
1711     return createEventAssignment();
1712   }
1713 
1714   return obj;
1715 }
1716 
1717 /** @endcond */
1718 
1719 /** @cond doxygenLibsbmlInternal */
1720 
1721 /*
1722  * Adds an new "elementName" object in this Event.
1723  */
1724 int
addChildObject(const std::string & elementName,const SBase * element)1725 Event::addChildObject(const std::string& elementName, const SBase* element)
1726 {
1727   if (elementName == "trigger" && element->getTypeCode() == SBML_TRIGGER)
1728   {
1729     return setTrigger((const Trigger*)(element));
1730   }
1731   else if (elementName == "priority" && element->getTypeCode() == SBML_PRIORITY)
1732   {
1733     return setPriority((const Priority*)(element));
1734   }
1735   else if (elementName == "delay" && element->getTypeCode() == SBML_DELAY)
1736   {
1737     return setDelay((const Delay*)(element));
1738   }
1739   else if (elementName == "eventAssignment" && element->getTypeCode() == SBML_EVENT_ASSIGNMENT)
1740   {
1741     return addEventAssignment((const EventAssignment*)(element));
1742   }
1743 
1744   return LIBSBML_OPERATION_FAILED;
1745 }
1746 
1747 /** @endcond */
1748 
1749 
1750 /** @cond doxygenLibsbmlInternal */
1751 
1752 /*
1753  * Adds an new "elementName" object in this Event.
1754  */
1755 SBase*
removeChildObject(const std::string & elementName,const std::string & id)1756 Event::removeChildObject(const std::string& elementName, const std::string& id)
1757 {
1758 
1759   if (elementName == "trigger")
1760   {
1761     Trigger* t = getTrigger();
1762     mTrigger = NULL;
1763     return t;
1764   }
1765   else if (elementName == "priority")
1766   {
1767     Priority* t = getPriority();
1768     mPriority = NULL;
1769     return t;
1770   }
1771   else if (elementName == "delay")
1772   {
1773     Delay* t = getDelay();
1774     mDelay = NULL;
1775     return t;
1776   }
1777   else if (elementName == "eventAssignment")
1778   {
1779     return removeEventAssignment(id);
1780   }
1781 
1782   return NULL;
1783 }
1784 
1785 /** @endcond */
1786 
1787 
1788 
1789 /** @cond doxygenLibsbmlInternal */
1790 
1791 /*
1792  * Returns the number of "elementName" in this Event.
1793  */
1794 unsigned int
getNumObjects(const std::string & elementName)1795 Event::getNumObjects(const std::string& elementName)
1796 {
1797   unsigned int n = 0;
1798 
1799   if (elementName == "trigger")
1800   {
1801     if (isSetTrigger())
1802     {
1803       return 1;
1804     }
1805   }
1806   else if (elementName == "priority")
1807   {
1808     if (isSetPriority())
1809     {
1810       return 1;
1811     }
1812   }
1813   else if (elementName == "delay")
1814   {
1815     if (isSetDelay())
1816     {
1817       return 1;
1818     }
1819   }
1820   else if (elementName == "eventAssignment")
1821   {
1822     return getNumEventAssignments();
1823   }
1824 
1825   return n;
1826 }
1827 
1828 /** @endcond */
1829 
1830 
1831 
1832 /** @cond doxygenLibsbmlInternal */
1833 
1834 /*
1835  * Returns the nth object of "objectName" in this Event.
1836  */
1837 SBase*
getObject(const std::string & elementName,unsigned int index)1838 Event::getObject(const std::string& elementName, unsigned int index)
1839 {
1840   SBase* obj = NULL;
1841 
1842   if (elementName == "trigger")
1843   {
1844     return getTrigger();
1845   }
1846   else if (elementName == "priority")
1847   {
1848     return getPriority();
1849   }
1850   else if (elementName == "delay")
1851   {
1852     return getDelay();
1853   }
1854   else if (elementName == "eventAssignment")
1855   {
1856     return getEventAssignment(index);
1857   }
1858 
1859   return obj;
1860 }
1861 
1862 /** @endcond */
1863 
1864 
1865 /** @cond doxygenLibsbmlInternal */
isExplicitlySetUVFTT() const1866 bool Event::isExplicitlySetUVFTT() const
1867 {
1868   return mExplicitlySetUVFTT;
1869 }
1870 /** @endcond */
1871 
1872 
1873 /** @cond doxygenLibsbmlInternal */
1874 /**
1875  * Subclasses should override this method to get the list of
1876  * expected attributes.
1877  * This function is invoked from corresponding readAttributes()
1878  * function.
1879  */
1880 void
addExpectedAttributes(ExpectedAttributes & attributes)1881 Event::addExpectedAttributes(ExpectedAttributes& attributes)
1882 {
1883   SBase::addExpectedAttributes(attributes);
1884 
1885   const unsigned int level = getLevel();
1886   const unsigned int version = getVersion();
1887 
1888   switch (level)
1889   {
1890   case 2:
1891     attributes.add("name");
1892     attributes.add("id");
1893     if (version < 3)
1894     {
1895       attributes.add("timeUnits");
1896     }
1897     if (version == 2)
1898     {
1899       attributes.add("sboTerm");
1900     }
1901     if (version > 3)
1902     {
1903       attributes.add("useValuesFromTriggerTime");
1904     }
1905     break;
1906   case 3:
1907   default:
1908     attributes.add("name");
1909     attributes.add("id");
1910     attributes.add("useValuesFromTriggerTime");
1911     break;
1912   }
1913 }
1914 /** @endcond */
1915 
1916 /** @cond doxygenLibsbmlInternal */
1917 /*
1918  * Subclasses should override this method to read values from the given
1919  * XMLAttributes set into their specific fields.  Be sure to call your
1920  * parent's implementation of this method as well.
1921  */
1922 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)1923 Event::readAttributes (const XMLAttributes& attributes,
1924                        const ExpectedAttributes& expectedAttributes)
1925 {
1926   const unsigned int level   = getLevel  ();
1927   const unsigned int version = getVersion();
1928 
1929   SBase::readAttributes(attributes, expectedAttributes);
1930 
1931   switch (level)
1932   {
1933   case 1:
1934     logError(NotSchemaConformant, level, version,
1935         "Event is not a valid component for this level/version.");
1936     break;
1937   case 2:
1938     readL2Attributes(attributes);
1939     break;
1940   case 3:
1941   default:
1942     readL3Attributes(attributes);
1943     break;
1944   }
1945 }
1946 /** @endcond */
1947 
1948 /** @cond doxygenLibsbmlInternal */
1949 /*
1950  * Subclasses should override this method to read values from the given
1951  * XMLAttributes set into their specific fields.  Be sure to call your
1952  * parent's implementation of this method as well.
1953  */
1954 void
readL2Attributes(const XMLAttributes & attributes)1955 Event::readL2Attributes (const XMLAttributes& attributes)
1956 {
1957   const unsigned int level = getLevel();
1958   const unsigned int version = getVersion();
1959   //
1960   // id: SId  { use="optional" }  (L2v1 ->)
1961   //
1962   bool assigned = attributes.readInto("id", mId, getErrorLog(), false, getLine(), getColumn());
1963   if (assigned && mId.size() == 0)
1964   {
1965     logEmptyString("id", level, version, "<event>");
1966   }
1967   if (!SyntaxChecker::isValidInternalSId(mId))
1968     logError(InvalidIdSyntax, level, version, "The id '" + mId + "' does not conform to the syntax.");
1969 
1970   //
1971   // name: string  { use="optional" }  (L2v1 ->)
1972   //
1973   attributes.readInto("name", mName, getErrorLog(), false, getLine(), getColumn());
1974 
1975   //
1976   // timeUnits: SId  { use="optional" }  (L2v1, L2v2)
1977   // removed in l2v3
1978   //
1979   if (version < 3)
1980   {
1981     assigned = attributes.readInto("timeUnits", mTimeUnits, getErrorLog(), false, getLine(), getColumn());
1982     if (assigned && mTimeUnits.size() == 0)
1983     {
1984       logEmptyString("timeUnits", level, version, "<event>");
1985     }
1986     if (!SyntaxChecker::isValidInternalUnitSId(mTimeUnits))
1987     {
1988       logError(InvalidUnitIdSyntax, getLevel(), getVersion(), "The timeUnits attribute '" + mTimeUnits + "' does not conform to the syntax.");
1989     }
1990   }
1991 
1992   //
1993   // sboTerm: SBOTerm { use="optional" }  (L2v2 ->)
1994   //
1995   if (version == 2)
1996     mSBOTerm = SBO::readTerm(attributes, this->getErrorLog(), level, version,
1997         getLine(), getColumn());
1998 
1999   //
2000   // useValuesFromTriggerTime: bool {use="optional" default="true"} (L2V4 ->)
2001   // useValuesFromTriggerTime: bool {use="optional" } (L3 ->)
2002   //
2003   if (version  > 3)
2004   {
2005     mExplicitlySetUVFTT = attributes.readInto("useValuesFromTriggerTime",
2006                                                 mUseValuesFromTriggerTime, getErrorLog(), false, getLine(), getColumn());
2007   }
2008 }
2009 /** @endcond */
2010 
2011 
2012 /** @cond doxygenLibsbmlInternal */
2013 /*
2014  * Subclasses should override this method to read values from the given
2015  * XMLAttributes set into their specific fields.  Be sure to call your
2016  * parent's implementation of this method as well.
2017  */
2018 void
readL3Attributes(const XMLAttributes & attributes)2019 Event::readL3Attributes (const XMLAttributes& attributes)
2020 {
2021   const unsigned int level = getLevel();
2022   const unsigned int version = getVersion();
2023 
2024   //
2025   // id: SId  { use="optional" }  (L2v1 ->)
2026   //
2027   // for l3v2 sbase will read this as generically optional
2028   // we want to log errors relating to the specific object
2029   if (version == 1)
2030   {
2031     bool assigned = attributes.readInto("id", mId, getErrorLog(), false, getLine(), getColumn());
2032     if (assigned && mId.size() == 0)
2033     {
2034       logEmptyString("id", level, version, "<event>");
2035     }
2036     if (!SyntaxChecker::isValidInternalSId(mId))
2037       logError(InvalidIdSyntax, level, version, "The id '" + mId + "' does not conform to the syntax.");
2038   }
2039 
2040   //
2041   // name: string  { use="optional" }  (L2v1 ->)
2042   //
2043   // for l3v2 sbase will read this
2044   if (version == 1)
2045   {
2046     attributes.readInto("name", mName, getErrorLog(), false,
2047                                        getLine(), getColumn());
2048   }
2049 
2050   //
2051   //
2052   // useValuesFromTriggerTime: bool {use="required" } (L3 ->)
2053   //
2054   mIsSetUseValuesFromTriggerTime = attributes.readInto(
2055       "useValuesFromTriggerTime", mUseValuesFromTriggerTime,
2056        getErrorLog(),false, getLine(), getColumn());
2057   mExplicitlySetUVFTT = mIsSetUseValuesFromTriggerTime;
2058 
2059   if (!mIsSetUseValuesFromTriggerTime)
2060   {
2061     logError(AllowedAttributesOnEvent, level, version,
2062       "The required attribute 'useValuesfromTriggerTime' is missing.");
2063   }
2064 
2065 }
2066 /** @endcond */
2067 
2068 
2069 
2070 
2071 /** @cond doxygenLibsbmlInternal */
2072 /*
2073  * Subclasses should override this method to write their XML attributes
2074  * to the XMLOutputStream.  Be sure to call your parent's implementation
2075  * of this method as well.
2076  */
2077 void
writeAttributes(XMLOutputStream & stream) const2078 Event::writeAttributes (XMLOutputStream& stream) const
2079 {
2080   const unsigned int level = getLevel();
2081   const unsigned int version = getVersion();
2082 
2083   /* invalid level/version */
2084   if (level < 2)
2085   {
2086     return;
2087   }
2088 
2089   SBase::writeAttributes(stream);
2090 
2091   //
2092   // sboTerm: SBOTerm { use="optional" }  (L2v2 ->)
2093   //
2094   // sboTerm for L2V3 or later is written in SBase::writeAttributes()
2095   //
2096   if ( (level == 2) && (version == 2) )
2097   {
2098     SBO::writeTerm(stream, mSBOTerm);
2099   }
2100 
2101 
2102   // for L3V2 and above SBase will write this out
2103   if (level < 3 || (level == 3 && version == 1))
2104   {
2105     //
2106     //
2107     // id: SId  { use="optional" }  (L2v1 ->)
2108     //
2109     stream.writeAttribute("id", mId);
2110 
2111     //
2112     // name: string  { use="optional" }  (L2v1->)
2113     //
2114     stream.writeAttribute("name", mName);
2115   }
2116 
2117   if (level == 2 && version < 3)
2118   {
2119     //
2120     // timeUnits: SId  { use="optional" }  (L2v1, L2v2)
2121     // removed in l2v3
2122     //
2123     stream.writeAttribute("timeUnits", mTimeUnits);
2124   }
2125 
2126 
2127   // useValuesFromTriggerTime: bool {use="optional" default="true"} (L2V4 ->)
2128   // useValuesFromTriggerTime: bool {use="required"} (L3 ->)
2129   //
2130   if (level == 2 && version > 3)
2131   {
2132     if (isExplicitlySetUVFTT() || !mUseValuesFromTriggerTime)
2133       stream.writeAttribute("useValuesFromTriggerTime",
2134                             mUseValuesFromTriggerTime);
2135   }
2136   else if (level > 2)
2137   {
2138     // in L3 only write it out if it has been set
2139     if (isSetUseValuesFromTriggerTime())
2140       stream.writeAttribute("useValuesFromTriggerTime",
2141                           mUseValuesFromTriggerTime);
2142   }
2143 
2144   //
2145   // (EXTENSION)
2146   //
2147   SBase::writeExtensionAttributes(stream);
2148 }
2149 /** @endcond */
2150 
2151 
2152 /** @cond doxygenLibsbmlInternal */
2153 /*
2154  * Subclasses should override this method to write out their contained
2155  * SBML objects as XML elements.  Be sure to call your parent's
2156  * implementation of this method as well.
2157  */
2158 void
writeElements(XMLOutputStream & stream) const2159 Event::writeElements (XMLOutputStream& stream) const
2160 {
2161   SBase::writeElements(stream);
2162 
2163   if (mTrigger != NULL)
2164   {
2165     mTrigger->write(stream);
2166   }
2167 
2168   if (mDelay != NULL)
2169   {
2170     mDelay->write(stream);
2171   }
2172 
2173   if (getLevel() > 2 && mPriority != NULL)
2174   {
2175     mPriority->write(stream);
2176   }
2177 
2178   if (getLevel() == 3 && getVersion() > 1)
2179   {
2180     if (mEventAssignments.hasOptionalElements() == true ||
2181         mEventAssignments.hasOptionalAttributes() == true ||
2182         mEventAssignments.isExplicitlyListed())
2183     {
2184       mEventAssignments.write(stream);
2185     }
2186   }
2187   else
2188   {
2189     // use original code
2190     if ( getNumEventAssignments() > 0 ) mEventAssignments.write(stream);
2191   }
2192 
2193   //
2194   // (EXTENSION)
2195   //
2196   SBase::writeExtensionElements(stream);
2197 }
2198 /** @endcond */
2199 
2200 
2201 /*
2202  * Creates a new ListOfEvents items.
2203  */
ListOfEvents(unsigned int level,unsigned int version)2204 ListOfEvents::ListOfEvents (unsigned int level, unsigned int version)
2205   : ListOf(level,version)
2206 {
2207 }
2208 
2209 
2210 /*
2211  * Creates a new ListOfEvents items.
2212  */
ListOfEvents(SBMLNamespaces * sbmlns)2213 ListOfEvents::ListOfEvents (SBMLNamespaces* sbmlns)
2214   : ListOf(sbmlns)
2215 {
2216   loadPlugins(sbmlns);
2217 }
2218 
2219 
2220 /*
2221  * @return a (deep) copy of this ListOfEvents.
2222  */
2223 ListOfEvents*
clone() const2224 ListOfEvents::clone () const
2225 {
2226   return new ListOfEvents(*this);
2227 }
2228 
2229 
2230 /*
2231  * @return the typecode (int) of SBML objects contained in this ListOf or
2232  * SBML_UNKNOWN (default).
2233  */
2234 int
getItemTypeCode() const2235 ListOfEvents::getItemTypeCode () const
2236 {
2237   return SBML_EVENT;
2238 }
2239 
2240 
2241 /*
2242  * @return the name of this element ie "listOfEvents".
2243  */
2244 const string&
getElementName() const2245 ListOfEvents::getElementName () const
2246 {
2247   static const string name = "listOfEvents";
2248   return name;
2249 }
2250 
2251 
2252 /* return nth item in list */
2253 Event *
get(unsigned int n)2254 ListOfEvents::get(unsigned int n)
2255 {
2256   return static_cast<Event*>(ListOf::get(n));
2257 }
2258 
2259 
2260 /* return nth item in list */
2261 const Event *
get(unsigned int n) const2262 ListOfEvents::get(unsigned int n) const
2263 {
2264   return static_cast<const Event*>(ListOf::get(n));
2265 }
2266 
2267 
2268 /**
2269  * Used by ListOf::get() to lookup an SBase based by its id.
2270  */
2271 struct IdEqE : public unary_function<SBase*, bool>
2272 {
2273   const string& mId;
2274 
IdEqEIdEqE2275   IdEqE (const string& id) : mId(id) { }
operator ()IdEqE2276   bool operator() (SBase* sb)
2277        { return static_cast <Event *> (sb)->getId() == mId; }
2278 };
2279 
2280 
2281 /* return item by id */
2282 Event*
get(const std::string & sid)2283 ListOfEvents::get (const std::string& sid)
2284 {
2285   return const_cast<Event*>(
2286     static_cast<const ListOfEvents&>(*this).get(sid) );
2287 }
2288 
2289 
2290 /* return item by id */
2291 const Event*
get(const std::string & sid) const2292 ListOfEvents::get (const std::string& sid) const
2293 {
2294   vector<SBase*>::const_iterator result;
2295 
2296   result = find_if( mItems.begin(), mItems.end(), IdEqE(sid) );
2297   return (result == mItems.end()) ? NULL : static_cast <Event*> (*result);
2298 }
2299 
2300 
2301 /* Removes the nth item from this list */
2302 Event*
remove(unsigned int n)2303 ListOfEvents::remove (unsigned int n)
2304 {
2305    return static_cast<Event*>(ListOf::remove(n));
2306 }
2307 
2308 
2309 /* Removes item in this list by id */
2310 Event*
remove(const std::string & sid)2311 ListOfEvents::remove (const std::string& sid)
2312 {
2313   SBase* item = NULL;
2314   vector<SBase*>::iterator result;
2315 
2316   result = find_if( mItems.begin(), mItems.end(), IdEqE(sid) );
2317 
2318   if (result != mItems.end())
2319   {
2320     item = *result;
2321     mItems.erase(result);
2322   }
2323 
2324   return static_cast <Event*> (item);
2325 }
2326 
2327 
2328 /** @cond doxygenLibsbmlInternal */
2329 /*
2330  * @return the ordinal position of the element with respect to its siblings
2331  * or -1 (default) to indicate the position is not significant.
2332  */
2333 int
getElementPosition() const2334 ListOfEvents::getElementPosition () const
2335 {
2336   return 12;
2337 }
2338 /** @endcond */
2339 
2340 
2341 /** @cond doxygenLibsbmlInternal */
2342 /*
2343  * @return the SBML object corresponding to next XMLToken in the
2344  * XMLInputStream or @c NULL if the token was not recognized.
2345  */
2346 SBase*
createObject(XMLInputStream & stream)2347 ListOfEvents::createObject (XMLInputStream& stream)
2348 {
2349   const string& name   = stream.peek().getName();
2350   SBase*        object = NULL;
2351 
2352 
2353   if (name == "event")
2354   {
2355     try
2356     {
2357       object = new Event(getSBMLNamespaces());
2358     }
2359     catch (SBMLConstructorException*)
2360     {
2361       object = new Event(SBMLDocument::getDefaultLevel(),
2362         SBMLDocument::getDefaultVersion());
2363     }
2364     catch ( ... )
2365     {
2366       object = new Event(SBMLDocument::getDefaultLevel(),
2367         SBMLDocument::getDefaultVersion());
2368     }
2369 
2370     if (object != NULL) mItems.push_back(object);
2371   }
2372 
2373   return object;
2374 }
2375 /** @endcond */
2376 
2377 
2378 
2379 #endif /* __cplusplus */
2380 /** @cond doxygenIgnored */
2381 LIBSBML_EXTERN
2382 Event_t *
Event_create(unsigned int level,unsigned int version)2383 Event_create (unsigned int level, unsigned int version)
2384 {
2385   try
2386   {
2387     Event* obj = new Event(level,version);
2388     return obj;
2389   }
2390   catch (SBMLConstructorException)
2391   {
2392     return NULL;
2393   }
2394 }
2395 
2396 
2397 LIBSBML_EXTERN
2398 Event_t *
Event_createWithNS(SBMLNamespaces_t * sbmlns)2399 Event_createWithNS (SBMLNamespaces_t* sbmlns)
2400 {
2401   try
2402   {
2403     Event* obj = new Event(sbmlns);
2404     return obj;
2405   }
2406   catch (SBMLConstructorException)
2407   {
2408     return NULL;
2409   }
2410 }
2411 
2412 
2413 LIBSBML_EXTERN
2414 void
Event_free(Event_t * e)2415 Event_free (Event_t *e)
2416 {
2417   if (e != NULL)
2418   delete e;
2419 }
2420 
2421 
2422 LIBSBML_EXTERN
2423 Event_t *
Event_clone(const Event_t * e)2424 Event_clone (const Event_t *e)
2425 {
2426   return (e != NULL) ? static_cast<Event_t*>( e->clone() ) : NULL;
2427 }
2428 
2429 
2430 LIBSBML_EXTERN
2431 const XMLNamespaces_t *
Event_getNamespaces(Event_t * e)2432 Event_getNamespaces(Event_t *e)
2433 {
2434   return (e != NULL) ? e->getNamespaces() : NULL;
2435 }
2436 
2437 
2438 LIBSBML_EXTERN
2439 const char *
Event_getId(const Event_t * e)2440 Event_getId (const Event_t *e)
2441 {
2442   return (e != NULL && e->isSetId()) ? e->getId().c_str() : NULL;
2443 }
2444 
2445 
2446 LIBSBML_EXTERN
2447 const char *
Event_getName(const Event_t * e)2448 Event_getName (const Event_t *e)
2449 {
2450   return (e != NULL && e->isSetName()) ? e->getName().c_str() : NULL;
2451 }
2452 
2453 
2454 LIBSBML_EXTERN
2455 Trigger_t *
Event_getTrigger(Event_t * e)2456 Event_getTrigger (Event_t *e)
2457 {
2458   return (e != NULL) ? e->getTrigger() : NULL;
2459 }
2460 
2461 
2462 LIBSBML_EXTERN
2463 Delay_t *
Event_getDelay(Event_t * e)2464 Event_getDelay (Event_t *e)
2465 {
2466   return (e != NULL) ? e->getDelay() : NULL;
2467 }
2468 
2469 
2470 LIBSBML_EXTERN
2471 Priority_t *
Event_getPriority(Event_t * e)2472 Event_getPriority (Event_t *e)
2473 {
2474   return (e != NULL) ? e->getPriority() : NULL;
2475 }
2476 
2477 
2478 LIBSBML_EXTERN
2479 const char *
Event_getTimeUnits(const Event_t * e)2480 Event_getTimeUnits (const Event_t *e)
2481 {
2482   return (e != NULL && e->isSetTimeUnits()) ? e->getTimeUnits().c_str() : NULL;
2483 }
2484 
2485 
2486 LIBSBML_EXTERN
2487 int
Event_getUseValuesFromTriggerTime(const Event_t * e)2488 Event_getUseValuesFromTriggerTime (const Event_t *e)
2489 {
2490   return (e != NULL) ? static_cast<int> (e->getUseValuesFromTriggerTime()) : 0;
2491 }
2492 
2493 
2494 LIBSBML_EXTERN
2495 int
Event_isSetId(const Event_t * e)2496 Event_isSetId (const Event_t *e)
2497 {
2498   return (e != NULL) ? static_cast<int>( e->isSetId() ) : 0;
2499 }
2500 
2501 
2502 LIBSBML_EXTERN
2503 int
Event_isSetName(const Event_t * e)2504 Event_isSetName (const Event_t *e)
2505 {
2506   return (e != NULL) ? static_cast<int>( e->isSetName() ) : 0;
2507 }
2508 
2509 
2510 LIBSBML_EXTERN
2511 int
Event_isSetTrigger(const Event_t * e)2512 Event_isSetTrigger (const Event_t *e)
2513 {
2514   return (e != NULL) ? static_cast<int>( e->isSetTrigger() ) : 0;
2515 }
2516 
2517 
2518 LIBSBML_EXTERN
2519 int
Event_isSetDelay(const Event_t * e)2520 Event_isSetDelay (const Event_t *e)
2521 {
2522   return (e != NULL) ? static_cast<int>( e->isSetDelay() ) : 0;
2523 }
2524 
2525 
2526 LIBSBML_EXTERN
2527 int
Event_isSetPriority(const Event_t * e)2528 Event_isSetPriority (const Event_t *e)
2529 {
2530   return (e != NULL) ? static_cast<int>( e->isSetPriority() ) : 0;
2531 }
2532 
2533 
2534 LIBSBML_EXTERN
2535 int
Event_isSetTimeUnits(const Event_t * e)2536 Event_isSetTimeUnits (const Event_t *e)
2537 {
2538   return (e != NULL) ? static_cast<int>( e->isSetTimeUnits() ) : 0;
2539 }
2540 
2541 
2542 LIBSBML_EXTERN
2543 int
Event_isSetUseValuesFromTriggerTime(const Event_t * e)2544 Event_isSetUseValuesFromTriggerTime (const Event_t *e)
2545 {
2546   return (e != NULL) ?
2547     static_cast<int>( e->isSetUseValuesFromTriggerTime() ) : 0;
2548 }
2549 
2550 
2551 LIBSBML_EXTERN
2552 int
Event_setId(Event_t * e,const char * sid)2553 Event_setId (Event_t *e, const char *sid)
2554 {
2555   if (e != NULL)
2556     return (sid == NULL) ? e->unsetId() : e->setId(sid);
2557   else
2558     return LIBSBML_INVALID_OBJECT;
2559 }
2560 
2561 
2562 LIBSBML_EXTERN
2563 int
Event_setName(Event_t * e,const char * name)2564 Event_setName (Event_t *e, const char *name)
2565 {
2566   if (e != NULL)
2567     return (name == NULL) ? e->unsetName() : e->setName(name);
2568   else
2569     return LIBSBML_INVALID_OBJECT;
2570 }
2571 
2572 
2573 LIBSBML_EXTERN
2574 int
Event_setTrigger(Event_t * e,const Trigger_t * trigger)2575 Event_setTrigger (Event_t *e, const Trigger_t *trigger)
2576 {
2577   if (e != NULL)
2578     return e->setTrigger(trigger);
2579   else
2580     return LIBSBML_INVALID_OBJECT;
2581 }
2582 
2583 
2584 LIBSBML_EXTERN
2585 int
Event_setDelay(Event_t * e,const Delay_t * delay)2586 Event_setDelay (Event_t *e, const Delay_t *delay)
2587 {
2588   if (e != NULL)
2589     return e->setDelay(delay);
2590   else
2591     return LIBSBML_INVALID_OBJECT;
2592 }
2593 
2594 
2595 LIBSBML_EXTERN
2596 int
Event_setPriority(Event_t * e,const Priority_t * priority)2597 Event_setPriority (Event_t *e, const Priority_t *priority)
2598 {
2599   if (e != NULL)
2600     return e->setPriority(priority);
2601   else
2602     return LIBSBML_INVALID_OBJECT;
2603 }
2604 
2605 
2606 LIBSBML_EXTERN
2607 int
Event_setTimeUnits(Event_t * e,const char * sid)2608 Event_setTimeUnits (Event_t *e, const char *sid)
2609 {
2610   if (e != NULL)
2611     return (sid == NULL) ? e->unsetTimeUnits() : e->setTimeUnits(sid);
2612   else
2613     return LIBSBML_INVALID_OBJECT;
2614 }
2615 
2616 
2617 LIBSBML_EXTERN
2618 int
Event_setUseValuesFromTriggerTime(Event_t * e,int value)2619 Event_setUseValuesFromTriggerTime (Event_t *e, int value)
2620 {
2621   if (e != NULL)
2622     return e->setUseValuesFromTriggerTime( static_cast<bool>(value) );
2623   else
2624     return LIBSBML_INVALID_OBJECT;
2625 }
2626 
2627 
2628 LIBSBML_EXTERN
2629 int
Event_unsetId(Event_t * e)2630 Event_unsetId (Event_t *e)
2631 {
2632   if (e != NULL)
2633     return e->unsetId();
2634   else
2635     return LIBSBML_INVALID_OBJECT;
2636 }
2637 
2638 
2639 LIBSBML_EXTERN
2640 int
Event_unsetName(Event_t * e)2641 Event_unsetName (Event_t *e)
2642 {
2643   if (e != NULL)
2644     return e->unsetName();
2645   else
2646     return LIBSBML_INVALID_OBJECT;
2647 }
2648 
2649 
2650 LIBSBML_EXTERN
2651 int
Event_unsetUseValuesFromTriggerTime(Event_t * e)2652 Event_unsetUseValuesFromTriggerTime (Event_t *e)
2653 {
2654   if (e != NULL)
2655     return e->unsetUseValuesFromTriggerTime();
2656   else
2657     return LIBSBML_INVALID_OBJECT;
2658 }
2659 
2660 
2661 LIBSBML_EXTERN
2662 int
Event_unsetDelay(Event_t * e)2663 Event_unsetDelay (Event_t *e)
2664 {
2665   if (e != NULL)
2666     return e->unsetDelay();
2667   else
2668     return LIBSBML_INVALID_OBJECT;
2669 }
2670 
2671 
2672 LIBSBML_EXTERN
2673 int
Event_unsetPriority(Event_t * e)2674 Event_unsetPriority (Event_t *e)
2675 {
2676   if (e != NULL)
2677     return e->unsetPriority();
2678   else
2679     return LIBSBML_INVALID_OBJECT;
2680 }
2681 
2682 
2683 LIBSBML_EXTERN
2684 int
Event_unsetTimeUnits(Event_t * e)2685 Event_unsetTimeUnits (Event_t *e)
2686 {
2687   if (e != NULL)
2688     return e->unsetTimeUnits();
2689   else
2690     return LIBSBML_INVALID_OBJECT;
2691 }
2692 
2693 
2694 LIBSBML_EXTERN
2695 int
Event_hasRequiredAttributes(Event_t * e)2696 Event_hasRequiredAttributes (Event_t *e)
2697 {
2698   return (e != NULL) ? static_cast <int> (e->hasRequiredAttributes()) : 0;
2699 }
2700 
2701 
2702 
2703 LIBSBML_EXTERN
2704 int
Event_hasRequiredElements(Event_t * e)2705 Event_hasRequiredElements (Event_t *e)
2706 {
2707   return (e != NULL) ? static_cast <int> (e->hasRequiredElements() ) : 0;
2708 }
2709 
2710 
2711 
2712 LIBSBML_EXTERN
2713 int
Event_addEventAssignment(Event_t * e,const EventAssignment_t * ea)2714 Event_addEventAssignment (Event_t *e, const EventAssignment_t *ea)
2715 {
2716   if (e != NULL)
2717     return e->addEventAssignment(ea);
2718   else
2719     return LIBSBML_INVALID_OBJECT;
2720 }
2721 
2722 
2723 LIBSBML_EXTERN
2724 EventAssignment_t *
Event_createEventAssignment(Event_t * e)2725 Event_createEventAssignment (Event_t *e)
2726 {
2727   return (e != NULL) ? e->createEventAssignment() : NULL;
2728 }
2729 
2730 
2731 LIBSBML_EXTERN
2732 Trigger_t *
Event_createTrigger(Event_t * e)2733 Event_createTrigger (Event_t *e)
2734 {
2735   return (e != NULL) ? e->createTrigger() : NULL;
2736 }
2737 
2738 
2739 LIBSBML_EXTERN
2740 Delay_t *
Event_createDelay(Event_t * e)2741 Event_createDelay (Event_t *e)
2742 {
2743   return (e != NULL) ? e->createDelay() : NULL;
2744 }
2745 
2746 
2747 LIBSBML_EXTERN
2748 Priority_t *
Event_createPriority(Event_t * e)2749 Event_createPriority (Event_t *e)
2750 {
2751   return (e != NULL) ? e->createPriority() : NULL;
2752 }
2753 
2754 
2755 LIBSBML_EXTERN
2756 ListOf_t *
Event_getListOfEventAssignments(Event_t * e)2757 Event_getListOfEventAssignments (Event_t *e)
2758 {
2759   return (e != NULL) ? e->getListOfEventAssignments() : NULL;
2760 }
2761 
2762 
2763 LIBSBML_EXTERN
2764 EventAssignment_t *
Event_getEventAssignment(Event_t * e,unsigned int n)2765 Event_getEventAssignment (Event_t *e, unsigned int n)
2766 {
2767   return (e != NULL) ? e->getEventAssignment(n) : NULL;
2768 }
2769 
2770 
2771 LIBSBML_EXTERN
2772 EventAssignment_t *
Event_getEventAssignmentByVar(Event_t * e,const char * variable)2773 Event_getEventAssignmentByVar (Event_t *e, const char *variable)
2774 {
2775   return (e != NULL && variable != NULL) ?
2776            e->getEventAssignment(variable) : NULL;
2777 }
2778 
2779 
2780 LIBSBML_EXTERN
2781 unsigned int
Event_getNumEventAssignments(const Event_t * e)2782 Event_getNumEventAssignments (const Event_t *e)
2783 {
2784   return (e != NULL) ? e->getNumEventAssignments() : SBML_INT_MAX;
2785 }
2786 
2787 
2788 LIBSBML_EXTERN
2789 EventAssignment_t *
Event_removeEventAssignment(Event_t * e,unsigned int n)2790 Event_removeEventAssignment (Event_t *e, unsigned int n)
2791 {
2792   return (e != NULL) ? e->removeEventAssignment(n) : NULL;
2793 }
2794 
2795 
2796 LIBSBML_EXTERN
2797 EventAssignment_t *
Event_removeEventAssignmentByVar(Event_t * e,const char * variable)2798 Event_removeEventAssignmentByVar (Event_t *e, const char *variable)
2799 {
2800   if (e != NULL)
2801     return (variable != NULL) ? e->removeEventAssignment(variable) : NULL;
2802   else
2803     return NULL;
2804 }
2805 
2806 
2807 LIBSBML_EXTERN
2808 Event_t *
ListOfEvents_getById(ListOf_t * lo,const char * sid)2809 ListOfEvents_getById (ListOf_t *lo, const char *sid)
2810 {
2811   if (lo != NULL)
2812     return (sid != NULL) ?
2813       static_cast <ListOfEvents *> (lo)->get(sid) : NULL;
2814   else
2815     return NULL;
2816 }
2817 
2818 
2819 LIBSBML_EXTERN
2820 Event_t *
ListOfEvents_removeById(ListOf_t * lo,const char * sid)2821 ListOfEvents_removeById (ListOf_t *lo, const char *sid)
2822 {
2823   if (lo != NULL)
2824     return (sid != NULL) ?
2825                          static_cast <ListOfEvents *> (lo)->remove(sid) : NULL;
2826   else
2827     return NULL;
2828 }
2829 /** @endcond */
2830 
2831 LIBSBML_CPP_NAMESPACE_END
2832 
2833 
2834