1 /**
2  * @file    ListOf.h
3  * @author  Wraps List and inherits from SBase
4  * @author  SBML Team <sbml-team@googlegroups.com>
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  * @class ListOf
43  * @sbmlbrief{core} Parent class for libSBML's "ListOfXYZ" classes.
44  *
45  * @htmlinclude not-sbml-warning.html
46  *
47  * The ListOf class in libSBML is a utility class that serves as the parent
48  * class for implementing the ListOf__ classes.  It provides methods for
49  * working generically with the various SBML lists of objects in a program.
50  * LibSBML uses this separate list class rather than ordinary
51  * @if conly C@endif@if cpp C++; @endif@if java Java@endif@if python Python@endif@~ lists,
52  * so that it can provide the methods and features associated with SBase.
53  *
54  * Whether a given ListOf element may be empty or not depends on the
55  * element in question, and on what level and version of SBML it
56  * is being used for.  For ListOf elements in SBML Level&nbsp;3
57  * Version&nbsp;1 and prior, no core list and few package lists could
58  * be empty.  As of SBML Level&nbsp;3 Version&nbsp;2, the rules
59  * were relaxed, and lists were allowed to be empty.  In libSBML,
60  * documents created for Level&nbsp;3 Version&nbsp;2 will be written
61  * with empty ListOf's if that ListOf contains some other 'extra'
62  * information: an attribute such as metaid or sboTerm, a child
63  * '&lt;notes&gt;' or '&lt;annotation&gt;', or information from a SBML
64  * Level&nbsp;3 package.
65  *
66  * @copydetails doc_what_is_listof
67  */
68 
69 /**
70  * <!-- ~ ~ ~ ~ ~ Start of common documentation strings ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
71  * The following text is used as common documentation blocks copied multiple
72  * times elsewhere in this file.  The use of @class is a hack needed because
73  * Doxygen's @copydetails command has limited functionality.  Symbols
74  * beginning with "doc_" are marked as ignored in our Doxygen configuration.
75  * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~  -->
76  *
77  * @class doc_note_bare_listof
78  *
79  * @note Bare ListOf @if conly structures @else objects@endif@~ are
80  * impossible to add to SBML models.  The ListOf
81  * @if conly structure type@else class@endif@~ is simply the base
82  * of <em>other</em> @if conly structure types @else classes@endif@~ in
83  * libSBML.  Calling programs are not intended to create bare ListOf
84  * @if conly structures @else objects@endif@~ themselves.
85  */
86 
87 #ifndef ListOf_h
88 #define ListOf_h
89 
90 
91 #include <sbml/common/extern.h>
92 #include <sbml/common/sbmlfwd.h>
93 #include <sbml/SBMLTypeCodes.h>
94 
95 
96 #ifdef __cplusplus
97 
98 
99 #include <vector>
100 #include <algorithm>
101 #include <functional>
102 
103 #include <sbml/SBase.h>
104 
105 LIBSBML_CPP_NAMESPACE_BEGIN
106 
107 class SBMLVisitor;
108 
109 
110 /** @cond doxygenLibsbmlInternal */
111 /**
112  * Used by ListOf::get() to lookup an SBase based by its id.
113  */
114 #ifndef SWIG
115 template<class CNAME>
116 struct IdEq : public std::unary_function<SBase*, bool>
117 {
118   const std::string& mId;
119 
IdEqIdEq120   IdEq (const std::string& id) : mId(id) { }
operatorIdEq121   bool operator() (SBase* sb)
122        { return static_cast <CNAME*> (sb)->getId() == mId; }
123 };
124 #endif /* SWIG */
125 /** @endcond */
126 
127 
128 class LIBSBML_EXTERN ListOf : public SBase
129 {
130 public:
131 
132   /**
133    * Creates a new ListOf object.
134    *
135    * @param level the SBML Level; if not assigned, defaults to the
136    * value of SBMLDocument::getDefaultLevel().
137    *
138    * @param version the Version within the SBML Level; if not assigned,
139    * defaults to the value of SBMLDocument::getDefaultVersion().
140    *
141    * @copydetails doc_note_bare_listof
142    *
143    * @copydetails doc_note_setting_lv
144    *
145    * @ifnot hasDefaultArgs @htmlinclude warn-default-args-in-docs.html @endif@~
146    */
147   ListOf (unsigned int level   = SBML_DEFAULT_LEVEL,
148           unsigned int version = SBML_DEFAULT_VERSION);
149 
150 
151   /**
152    * Creates a new ListOf with a given SBMLNamespaces object.
153    *
154    * @param sbmlns the set of SBML namespaces that this ListOf should
155    * contain.
156    *
157    * @copydetails doc_note_bare_listof
158    *
159    * @copydetails doc_note_setting_lv
160    */
161   ListOf (SBMLNamespaces* sbmlns);
162 
163 
164   /**
165    * Destroys this ListOf and the items inside it.
166    */
167   virtual ~ListOf ();
168 
169 
170   /**
171    * Copy constructor; creates a copy of this ListOf.
172    *
173    * @param orig the ListOf instance to copy.
174    */
175   ListOf (const ListOf& orig);
176 
177 
178   /**
179    * Assignment operator for ListOf.
180    *
181    * @param rhs the object whose values are used as the basis of the
182    * assignment.
183    */
184   ListOf& operator=(const ListOf& rhs);
185 
186 
187 
188   /** @cond doxygenLibsbmlInternal */
189   /**
190    * Accepts the given SBMLVisitor.
191    *
192    * @param v the SBMLVisitor instance to be used.
193    *
194    * @return the result of calling <code>v.visit()</code>, which indicates
195    * whether the Visitor would like to visit the next item in the
196    * list.
197    */
198   virtual bool accept (SBMLVisitor& v) const;
199   /** @endcond */
200 
201 
202   /**
203    * Creates and returns a deep copy of this ListOf object.
204    *
205    * @return the (deep) copy of this ListOf object.
206    */
207   virtual ListOf* clone () const;
208 
209 
210   /**
211    * Adds an item to the end of this ListOf's list of items.
212    *
213    * This method makes a clone of the @p item handed to it.  This means that
214    * when the ListOf object is destroyed, the original items will not be
215    * destroyed.  For a method with an alternative ownership behavior, see the
216    * ListOf::appendAndOwn(@if java SBase@endif) method.
217    *
218    * @param item the item to be added to the list.
219    *
220    * @copydetails doc_returns_success_code
221    * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
222    * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t}
223    *
224    * @see appendAndOwn(SBase* disownedItem)
225    * @see appendFrom(const ListOf* list)
226    */
227   int append (const SBase* item);
228 
229 
230   /**
231    * Adds an item to the end of this ListOf's list of items.
232    *
233    * This method does not clone the @p disownedItem handed to it; instead, it assumes
234    * ownership of it.  This means that when the ListOf is destroyed, the item
235    * will be destroyed along with it.  For a method with an alternative
236    * ownership behavior, see the ListOf::append(SBase* item) method.
237    *
238    * @param disownedItem the item to be added to the list.
239    * Will become a child of the parent list.
240    *
241    * @copydetails doc_returns_success_code
242    * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
243    * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t}
244    *
245    * @see append(const SBase* item)
246    * @see appendFrom(const ListOf* list)
247    */
248   int appendAndOwn (SBase* disownedItem);
249 
250 
251   /**
252    * Adds a clone of a list of items to this ListOf's list.
253    *
254    * Note that because this clones the objects handed to it, the original
255    * items will not be destroyed when this ListOf object is destroyed.
256    *
257    * @param list a list of items to be added.
258    *
259    * @copydetails doc_returns_success_code
260    * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
261    * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t}
262    *
263    * @see append(const SBase* item)
264    * @see appendAndOwn(SBase* disownedItem)
265    */
266   virtual int appendFrom (const ListOf* list);
267 
268 
269   /**
270    * Inserts an item at a given position in this ListOf's list of items.
271    *
272    * This variant of the method makes a clone of the @p item handed to it.
273    * This means that when the ListOf is destroyed, the original @p item will
274    * <em>not</em> be destroyed.
275    *
276    * @param location the location in the list where to insert the item.
277    * @param item the item to be inserted to the list.
278    *
279    * @copydetails doc_returns_success_code
280    * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
281    * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t}
282    *
283    * @see insertAndOwn(int location, SBase* item)
284    */
285   int insert (int location, const SBase* item);
286 
287 
288   /**
289    * Inserts an item at a given position in this ListOf's list of items.
290    *
291    * This variant of the method does not make a clone of the @p disownedItem handed to it.
292    * This means that when the ListOf is destroyed, the original @p item
293    * <em>will</em> be destroyed.
294    *
295    * @param location the location where to insert the item.
296    * @param disownedItem the item to be inserted to the list.
297    * Will become a child of the parent list.
298    *
299    * @copydetails doc_returns_success_code
300    * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
301    * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t}
302    *
303    * @see insert(int location, const SBase* item)
304    */
305   int insertAndOwn(int location, SBase* disownedItem);
306 
307 
308   /**
309    * Get an item from the list.
310    *
311    * @param n the index number of the item to get.
312    *
313    * @return the <em>n</em>th item in this ListOf items, or a null pointer if
314    * the index number @p n refers to a nonexistent position in this list.
315    *
316    * @see size()
317    */
318   virtual const SBase* get (unsigned int n) const;
319 
320 
321   /**
322    * Get an item from the list.
323    *
324    * @param n the index number of the item to get.
325    *
326    * @return the <em>n</em>th item in this ListOf items, or a null pointer if
327    * the index number @p n refers to a nonexistent position in this list.
328    *
329    * @see size()
330    */
331   virtual SBase* get (unsigned int n);
332 
333 
334   /**
335    * Returns the first child element found that has the given identifier.
336    *
337    * This method searches this ListOf's list of items for SBML objects based
338    * on their "id" attribute value in the model-wide <code>SId</code>
339    * identifier namespace.
340    *
341    * @param id string representing the id of the object to find.
342    *
343    * @return the first element found with the given @p id, or @c NULL if no
344    * such object is found.
345    */
346   virtual SBase* getElementBySId(const std::string& id);
347 
348 
349   /**
350    * Returns the first child element found with the given meta-identifier.
351    *
352    * @param metaid string representing the "metaid" attribute of the object
353    * to find.
354    *
355    * @return the first element found with the given @p metaid, or @c NULL if
356    * no such object is found.
357    */
358   virtual SBase* getElementByMetaId(const std::string& metaid);
359 
360 
361   /**
362    * Returns a List of all child SBase objects.
363    *
364    * The values returned include all children of the objects in this ListOf
365    * list, nested to an arbitrary depth.
366    *
367    * @param filter a pointer to an ElementFilter, which causes the function
368    * to return only elements that match a particular set of constraints.
369    * If NULL (the default), the function will return all child objects.
370    *
371    * @return a List of pointers to all child objects.
372    */
373   virtual List* getAllElements(ElementFilter* filter=NULL);
374 
375 
376 #if 0
377   /**
378    * Get an item from the list based on its identifier.
379    *
380    * @param sid a string representing the the identifier of the item to get.
381    *
382    * @return item in this ListOf items with the given @p sid or @c NULL if no such
383    * item exists.
384    *
385    * @see get(unsigned int n)
386    * @see size()
387    */
388   virtual const SBase* get (const std::string& sid) const;
389 #endif
390 
391 
392 #if 0
393   /**
394    * Get an item from the list based on its identifier.
395    *
396    * @param sid a string representing the the identifier of the item to get.
397    *
398    * @return item in this ListOf items with the given @p sid or @c NULL if no such
399    * item exists.
400    *
401    * @see get(unsigned int n)
402    * @see size()
403    */
404   virtual SBase* get (const std::string& sid);
405 #endif
406 
407 
408   /**
409    * Removes all items in this ListOf object.
410    *
411    * If parameter @p doDelete is @c true (default), all items in this ListOf
412    * object are deleted and cleared, and thus the caller doesn't have to
413    * delete those items.  Otherwise, all items are cleared only from this
414    * ListOf object; the caller is still responsible for deleting the actual
415    * items.  (In the latter case, callers are advised to store pointers to
416    * all items elsewhere before calling this function.)
417    *
418    * @param doDelete if @c true (default), all items are deleted and cleared.
419    * Otherwise, all items are just cleared and not deleted.
420    *
421    * @ifnot hasDefaultArgs @htmlinclude warn-default-args-in-docs.html @endif@~
422    */
423   void clear (bool doDelete = true);
424 
425 
426   /**
427    * Removes all items in this ListOf object and deletes its properties too.
428    *
429    * This performs a call to clear() with an argument of @c true (thus removing
430    * all the child objects in the list), followed by calls to various libSBML
431    * <code>unset<em>Foo</em></code> methods to delete everything else: CVTerm
432    * objects, model history objects, etc.
433    *
434    * @if cpp Implementations of subclasses of ListOf may need to override
435    * this method if different handling of child objects is needed.@endif@~
436    *
437    * @copydetails doc_returns_success_code
438    * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
439    */
440   virtual int removeFromParentAndDelete();
441 
442 
443   /**
444    * Removes the <em>n</em>th item from this ListOf list of items and returns
445    * it.
446    *
447    * The caller owns the returned item and is responsible for deleting it.
448    *
449    * @param n the index of the item to remove.
450    *
451    * @see size()
452    */
453   virtual SBase* remove (unsigned int n);
454 
455 
456 #if 0
457   /**
458    * Removes item in this ListOf items with the given identifier.
459    *
460    * The caller owns the returned item and is responsible for deleting it.
461    * If none of the items in this list have the identifier @p sid, then
462    * @c NULL is returned.
463    *
464    * @param sid the identifier of the item to remove.
465    *
466    * @return the item removed.  As mentioned above, the caller owns the
467    * returned item.
468    */
469   virtual SBase* remove (const std::string& sid);
470 #endif
471 
472 
473   /**
474    * Returns number of items in this ListOf list.
475    *
476    * @return the number of items in this ListOf items.
477    */
478   unsigned int size () const;
479 
480 
481   /** @cond doxygenLibsbmlInternal */
482   /**
483    * Sets the parent SBMLDocument of this SBML object.
484    *
485    * @param d the SBMLDocument that should become the parent of this
486    * ListOf.
487    */
488   virtual void setSBMLDocument (SBMLDocument* d);
489   /** @endcond */
490 
491 
492   /** @cond doxygenLibsbmlInternal */
493   /**
494    * Sets this SBML object to child SBML objects (if any).
495    * (Creates a child-parent relationship by the parent)
496    *
497    * Subclasses must override this function if they define
498    * one ore more child elements.
499    * Basically, this function needs to be called in
500    * constructor, copy constructor and assignment operator.
501    *
502    * @if cpp
503    * @see setSBMLDocument()
504    * @see enablePackageInternal()
505    * @endif
506    */
507   virtual void connectToChild ();
508   /** @endcond */
509 
510 
511   /**
512    * Returns the libSBML type code for this object, namely,
513    * @sbmlconstant{SBML_LIST_OF, SBMLTypeCode_t}.
514    *
515    * @copydetails doc_what_are_typecodes
516    *
517    * @return the SBML type code for this object:
518    * @sbmlconstant{SBML_LIST_OF, SBMLTypeCode_t} (default).
519    *
520    * @note The various ListOf classes mostly differ from each other in what they
521    * contain.  Hence, one must call getItemTypeCode() to fully determine the
522    * class of this SBML object.
523    *
524    * @copydetails doc_warning_typecodes_not_unique
525    *
526    * @see getItemTypeCode()
527    * @see getElementName()
528    * @see getPackageName()
529    */
530   virtual int getTypeCode () const;
531 
532 
533   /**
534    * Get the type code of the objects contained in this ListOf.
535    *
536    * @copydetails doc_what_are_typecodes
537    *
538    * Classes that inherit from the ListOf class should override this method
539    * to return the SBML type code for the objects contained in this ListOf.
540    * If they do not, this method will return
541    * @sbmlconstant{SBML_UNKNOWN, SBMLTypeCode_t}
542    *
543    * @return The ListOf base class contains no SBML objects, and therefore
544    * this method returns @sbmlconstant{SBML_UNKNOWN, SBMLTypeCode_t}.
545    *
546    * @see getElementName()
547    * @see getPackageName()
548    */
549   virtual int getItemTypeCode () const;
550 
551 
552   /**
553    * Returns the XML element name of this object, which for ListOf, is
554    * always @c "listOf".
555    *
556    * @return the XML name of this element.
557    */
558   virtual const std::string& getElementName () const;
559 
560 
561   /** @cond doxygenLibsbmlInternal */
562   /**
563    * Subclasses should override this method to write out their contained
564    * SBML objects as XML elements.  Be sure to call your parent's
565    * implementation of this method as well.
566    */
567   virtual void writeElements (XMLOutputStream& stream) const;
568   /** @endcond */
569 
570 
571   /** @cond doxygenLibsbmlInternal */
572   /**
573    * Enables/Disables the given package with this element and child
574    * elements (if any).
575    * (This is an internal implementation for enablePackage function)
576    *
577    * @note Subclasses of the SBML Core package in which one or more child
578    * elements are defined must override this function.
579    */
580   virtual void enablePackageInternal(const std::string& pkgURI, const std::string& pkgPrefix, bool flag);
581   /** @endcond */
582 
583   /** @cond doxygenLibsbmlInternal */
584 
585   virtual void updateSBMLNamespace(const std::string& package,
586     unsigned int level, unsigned int version);
587 
588   /** @endcond */
589 
590 
591   /** @cond doxygenLibsbmlInternal */
592 
593 
594   virtual bool hasOptionalElements() const;
595 
596 
597   /** @endcond */
598 
599   /** @cond doxygenLibsbmlInternal */
600 
601 
602   bool isExplicitlyListed() const;
603 
604     /** @endcond */
605 
606   /** @cond doxygenLibsbmlInternal */
607 
608   void setExplicitlyListed(bool value=true) ;
609 
610 
611   /** @endcond */
612 
613   /** @cond doxygenLibsbmlInternal */
614   /**
615    * Sort the ListOf by the element SId.
616    *
617    * If the SIds are not set (or equal), sort by the result of
618    * the 'getId' function (which is different from the 'id'
619    * attribute for some elements such as rules), then by the
620    * 'name' attribute, and finally by the metaids.  If none
621    * are set, the items are considered to be sorted.
622    */
623   void sort();
624   /** @endcond */
625 
626 protected:
627   /** @cond doxygenLibsbmlInternal */
628   typedef std::vector<SBase*>           ListItem;
629   typedef std::vector<SBase*>::iterator ListItemIter;
630 
631   /**
632    * Subclasses should override this method to get the list of
633    * expected attributes.
634    * This function is invoked from corresponding readAttributes()
635    * function.
636    */
637   virtual void addExpectedAttributes(ExpectedAttributes& attributes);
638 
639 
640   /**
641    * Subclasses should override this method to read values from the given
642    * XMLAttributes set into their specific fields.  Be sure to call your
643    * parent's implementation of this method as well.
644    */
645   virtual void readAttributes (const XMLAttributes& attributes,
646                                const ExpectedAttributes& expectedAttributes);
647 
648   /**
649    * Subclasses should override this method to write their XML attributes
650    * to the XMLOutputStream.  Be sure to call your parent's implementation
651    * of this method as well.  For example:
652    *
653    *   SBase::writeAttributes(stream);
654    *   stream.writeAttribute( "id"  , mId   );
655    *   stream.writeAttribute( "name", mName );
656    *   ...
657    */
658   virtual void writeAttributes (XMLOutputStream& stream) const;
659 
660   virtual bool isValidTypeForList(SBase * item);
661 
662 
663   ListItem mItems;
664 
665   bool mExplicitlyListed;
666 
667   /** @endcond */
668 };
669 
670 LIBSBML_CPP_NAMESPACE_END
671 
672 #endif  /* __cplusplus */
673 
674 
675 #ifndef SWIG
676 
677 LIBSBML_CPP_NAMESPACE_BEGIN
678 BEGIN_C_DECLS
679 
680 
681 /**
682  * Creates a new instance of a ListOf_t structure.
683  *
684  * @param level an unsigned int, the SBML Level to assign to this
685  * ListOf_t structure.
686  *
687  * @param version an unsigned int, the SBML Version to assign to this
688  * ListOf_t structure.
689  *
690  * @return a pointer to the newly-created ListOf_t structure.
691  *
692  * @copydetails doc_note_bare_listof
693  *
694  * @memberof ListOf_t
695  */
696 LIBSBML_EXTERN
697 ListOf_t *
698 ListOf_create (unsigned int level, unsigned int version);
699 
700 
701 /**
702  * Frees the given ListOf_t structure.
703  *
704  * This function assumes each item in the list is derived from SBase_t.
705  *
706  * @param lo the ListOf_t structure to be freed.
707  *
708  * @memberof ListOf_t
709  */
710 LIBSBML_EXTERN
711 void
712 ListOf_free (ListOf_t *lo);
713 
714 
715 /**
716  * Creates a deep copy of the given ListOf_t structure.
717  *
718  * @param lo the ListOf_t structure to be copied.
719  *
720  * @return a (deep) copy of the given ListOf_t structure, or a null
721  * pointer if a failure occurred.
722  *
723  * @memberof ListOf_t
724  */
725 LIBSBML_EXTERN
726 ListOf_t *
727 ListOf_clone (const ListOf_t *lo);
728 
729 
730 /**
731  * Adds a copy of a given item to the end of a ListOf_t list.
732  *
733  * @param lo the ListOf_t structure to which the @p item should be appended.
734  * @param item the item to append to the list.
735  *
736  * @copydetails doc_returns_success_code
737  * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
738  * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t}
739  *
740  * @see ListOf_appendAndOwn()
741  *
742  * @memberof ListOf_t
743  */
744 LIBSBML_EXTERN
745 int
746 ListOf_append (ListOf_t *lo, const SBase_t *item);
747 
748 
749 /**
750  * Adds the given item to the end of a ListOf_t list.
751  *
752  * @param lo the ListOf_t structure to which the @p disownedItem should be appended.
753  * @param disownedItem the item to append to the list.
754  * Will become a child of the parent list.
755  *
756  * Unlike ListOf_append(), this function does not copy the @p disownedItem.
757  * The given @p lo list will contain the original item, and becomes responsible
758  * for its deletion.
759  *
760  * @copydetails doc_returns_success_code
761  * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
762  * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t}
763  *
764  * @see ListOf_append()
765  *
766  * @memberof ListOf_t
767  */
768 LIBSBML_EXTERN
769 int
770 ListOf_appendAndOwn (ListOf_t *lo, SBase_t *disownedItem);
771 
772 
773 /**
774  * Adds clones of one list of items to another.
775  *
776  * @param lo the ListOf_t list to which @p list will be appended.
777  * @param list the list of items to append to @p lo.
778  *
779  * @copydetails doc_returns_success_code
780  * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
781  * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t}
782  *
783  * @memberof ListOf_t
784  */
785 LIBSBML_EXTERN
786 int
787 ListOf_appendFrom (ListOf_t *lo, ListOf_t *list);
788 
789 
790 /**
791  * Inserts a copy of an item into a ListOf_t list at a given position.
792  *
793  * @param lo the list into which @p item will be inserted.
794  * @param location the starting index for the @p item in the @p lo list.
795  * @param item the item to append to insert into @p lo.
796  *
797  * @copydetails doc_returns_success_code
798  * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
799  * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t}
800  *
801  * @memberof ListOf_t
802  */
803 LIBSBML_EXTERN
804 int
805 ListOf_insert (ListOf_t *lo, int location, const SBase_t *item);
806 
807 
808 /**
809  * Inserts an item into a ListOf_t list at a given position.
810  *
811  * Unlike ListOf_insert(), this function does not clone @p disownedItem before
812  * inserting it into @p lo, which means that @p lo becomes the owner.
813  *
814  * @param lo the list into which @p disownedItem will be inserted.
815  * @param location the starting index for the @p disownedItem in the @p lo list.
816  * @param disownedItem the item to append to insert into @p lo.
817  * Will become a child of the parent list.
818  *
819  * @copydetails doc_returns_success_code
820  * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
821  * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t}
822  *
823  * @memberof ListOf_t
824  */
825 LIBSBML_EXTERN
826 int
827 ListOf_insertAndOwn (ListOf_t *lo, int location, SBase_t *disownedItem);
828 
829 
830 /**
831  * Returns the <em>n</em>th item of a given list.
832  *
833  * @param lo the list from which to retrieve the item.
834  * @param n the index of the item to retrieve.
835  *
836  * @return the <em>n</em>th item in this ListOf items, or a null pointer if
837  * the index number @p n refers to a nonexistent position in @p lo.
838  *
839  * @see ListOf_size()
840  *
841  * @memberof ListOf_t
842  */
843 LIBSBML_EXTERN
844 SBase_t *
845 ListOf_get (ListOf_t *lo, unsigned int n);
846 
847 
848 #if (0)
849 /**
850  * @return item in this ListOf_t items with the given @p sid or @c NULL if no such
851  * item exists.
852  *
853  * @memberof ListOf_t
854  */
855 LIBSBML_EXTERN
856 SBase_t *
857 ListOf_getById (ListOf_t *lo, const char *sid);
858 #endif
859 
860 
861 /**
862  * Removes all items in this ListOf_t structure.
863  *
864  * If @p doDelete is @c nonzero (true), all items in this ListOf_t structure
865  * are both deleted and cleared, and thus the caller doesn't have to delete
866  * those items.  Otherwise, if @p doDelete is @c 0 (false), all items are
867  * only cleared from this ListOf_t structure and the caller is responsible
868  * for deleting all items.  (In the latter case, callers are advised to store
869  * pointers to all items elsewhere before calling this function.)
870  *
871  * @param lo the ListOf_t structure to clear.
872  * @param doDelete whether to delete the items.
873  *
874  * @memberof ListOf_t
875  */
876 LIBSBML_EXTERN
877 void
878 ListOf_clear (ListOf_t *lo, int doDelete);
879 
880 
881 /**
882  * Removes the <em>n</em>th item from this ListOf_t list and returns it.
883  *
884  * The caller owns the returned item and is responsible for deleting it.
885  *
886  * @param lo the list from which the item should be removed.
887  * @param n the index number of the item to remove.
888  *
889  * @return the item removed, or a null pointer if no item existed at the
890  * index @p n.
891  *
892  * @memberof ListOf_t
893  */
894 LIBSBML_EXTERN
895 SBase_t *
896 ListOf_remove (ListOf_t *lo, unsigned int n);
897 
898 
899 #if (0)
900 /**
901  * Removes item in this ListOf_t items with the given @p sid or @c NULL if no such
902  * item exists.  The caller owns the returned item and is repsonsible for
903  * deleting it.
904  *
905  * @memberof ListOf_t
906  */
907 LIBSBML_EXTERN
908 SBase_t *
909 ListOf_removeById (ListOf_t *lo, const char *sid);
910 #endif
911 
912 
913 /**
914  * Returns the number of items in this ListOf_t items.
915  *
916  * @param lo the ListOf_t structure to count.
917  *
918  * @return the number of items in @p lo.
919  *
920  * @memberof ListOf_t
921  */
922 LIBSBML_EXTERN
923 unsigned int
924 ListOf_size (const ListOf_t *lo);
925 
926 
927 /**
928  * Get the type code of the objects contained in the given ListOf_t
929  * structure.
930  *
931  * @copydetails doc_what_are_typecodes
932  *
933  * @param lo the ListOf_t whose item type codes are sought.
934  *
935  * @return the type code corresponding to the objects in @p lo,
936  * or @sbmlconstant{SBML_UNKNOWN, SBMLTypeCode_t}.
937  *
938  * @memberof ListOf_t
939  */
940 LIBSBML_EXTERN
941 int
942 ListOf_getItemTypeCode (const ListOf_t *lo);
943 
944 
945 END_C_DECLS
946 LIBSBML_CPP_NAMESPACE_END
947 
948 #endif  /* !SWIG */
949 #endif  /* ListOf_h */
950 
951