001/* ----------------------------------------------------------------------------
002 * This file was automatically generated by SWIG (http://www.swig.org).
003 * Version 2.0.12
004 *
005 * Do not make changes to this file unless you know what you are doing--modify
006 * the SWIG interface file instead.
007 * ----------------------------------------------------------------------------- */
008
009package org.sbml.libsbml;
010
011/** 
012 *  Implementation of SBML Level 2's ListOfCompartments
013 * construct.
014 <p>
015 * <p>
016 * The various ListOf___ classes in SBML
017 * are merely containers used for organizing the main components of an SBML
018 * model.  In libSBML's implementation, ListOf___
019 * classes are derived from the
020 * intermediate utility class {@link ListOf}, which
021 * is not defined by the SBML specifications but serves as a useful
022 * programmatic construct.  {@link ListOf} is itself is in turn derived from {@link SBase},
023 * which provides all of the various ListOf___
024 * classes with common features
025 * defined by the SBML specification, such as 'metaid' attributes and
026 * annotations.
027 <p>
028 * The relationship between the lists and the rest of an SBML model is
029 * illustrated by the following (for SBML Level&nbsp;2 Version&nbsp;4):
030 <p>
031 * <figure>
032  <object type="image/svg+xml" data="listof-illustration.svg" class="centered"></object>
033</figure>
034
035 <p>
036 * Readers may wonder about the motivations for using the ListOf___
037 * containers in SBML.  A simpler approach in XML might be to place the
038 * components all directly at the top level of the model definition.  The
039 * choice made in SBML is to group them within XML elements named after
040 * ListOf<em>Classname</em>, in part because it helps organize the
041 * components.  More importantly, the fact that the container classes are
042 * derived from {@link SBase} means that software tools can add information <em>about</em>
043 * the lists themselves into each list container's 'annotation'.
044 <p>
045 * @see ListOfFunctionDefinitions
046 * @see ListOfUnitDefinitions
047 * @see ListOfCompartmentTypes
048 * @see ListOfSpeciesTypes
049 * @see ListOfCompartments
050 * @see ListOfSpecies
051 * @see ListOfParameters
052 * @see ListOfInitialAssignments
053 * @see ListOfRules
054 * @see ListOfConstraints
055 * @see ListOfReactions
056 * @see ListOfEvents
057 */
058
059public class ListOfCompartments extends ListOf {
060   private long swigCPtr;
061
062   protected ListOfCompartments(long cPtr, boolean cMemoryOwn)
063   {
064     super(libsbmlJNI.ListOfCompartments_SWIGUpcast(cPtr), cMemoryOwn);
065     swigCPtr = cPtr;
066   }
067
068   protected static long getCPtr(ListOfCompartments obj)
069   {
070     return (obj == null) ? 0 : obj.swigCPtr;
071   }
072
073   protected static long getCPtrAndDisown (ListOfCompartments obj)
074   {
075     long ptr = 0;
076
077     if (obj != null)
078     {
079       ptr             = obj.swigCPtr;
080       obj.swigCMemOwn = false;
081     }
082
083     return ptr;
084   }
085
086  protected void finalize() {
087    delete();
088  }
089
090  public synchronized void delete() {
091    if (swigCPtr != 0) {
092      if (swigCMemOwn) {
093        swigCMemOwn = false;
094        libsbmlJNI.delete_ListOfCompartments(swigCPtr);
095      }
096      swigCPtr = 0;
097    }
098    super.delete();
099  }
100
101  
102/**
103   * Creates a new {@link ListOfCompartments} object.
104   <p>
105   * The object is constructed such that it is valid for the given SBML
106   * Level and Version combination.
107   <p>
108   * @param level the SBML Level
109   <p>
110   * @param version the Version within the SBML Level
111   */ public
112 ListOfCompartments(long level, long version) throws org.sbml.libsbml.SBMLConstructorException {
113    this(libsbmlJNI.new_ListOfCompartments__SWIG_0(level, version), true);
114  }
115
116  
117/**
118   * Creates a new {@link ListOfCompartments} object.
119   <p>
120   * The object is constructed such that it is valid for the SBML Level and
121   * Version combination determined by the {@link SBMLNamespaces} object in 
122   * <code>sbmlns</code>.
123   <p>
124   * @param sbmlns an {@link SBMLNamespaces} object that is used to determine the
125   * characteristics of the {@link ListOfCompartments} object to be created.
126   */ public
127 ListOfCompartments(SBMLNamespaces sbmlns) throws org.sbml.libsbml.SBMLConstructorException {
128    this(libsbmlJNI.new_ListOfCompartments__SWIG_1(SBMLNamespaces.getCPtr(sbmlns), sbmlns), true);
129  }
130
131  
132/**
133   * Creates and returns a deep copy of this {@link ListOfCompartments} instance.
134   <p>
135   * @return a (deep) copy of this {@link ListOfCompartments}.
136   */ public
137 ListOfCompartments cloneObject() {
138    long cPtr = libsbmlJNI.ListOfCompartments_cloneObject(swigCPtr, this);
139    return (cPtr == 0) ? null : new ListOfCompartments(cPtr, true);
140  }
141
142  
143/**
144   * Returns the libSBML type code for the objects contained in this {@link ListOf}
145   * (i.e., {@link Compartment} objects, if the list is non-empty).
146   <p>
147   * <p>
148 * LibSBML attaches an identifying code to every kind of SBML object.  These
149 * are integer constants known as <em>SBML type codes</em>.  The names of all
150 * the codes begin with the characters &ldquo;<code>SBML_</code>&rdquo;. 
151 * In the Java language interface for libSBML, the
152 * type codes are defined as static integer constants in the interface class
153 * {@link libsbmlConstants}.    Note that different Level&nbsp;3 
154 * package plug-ins may use overlapping type codes; to identify the package
155 * to which a given object belongs, call the <code>getPackageName()</code>
156 * method on the object.
157   <p>
158   * @return the SBML type code for the objects contained in this {@link ListOf}
159   * instance: {@link  libsbmlConstants#SBML_COMPARTMENT SBML_COMPARTMENT} (default).
160   <p>
161   * @see #getElementName()
162   * @see #getPackageName()
163   */ public
164 int getItemTypeCode() {
165    return libsbmlJNI.ListOfCompartments_getItemTypeCode(swigCPtr, this);
166  }
167
168  
169/**
170   * Returns the XML element name of this object.
171   <p>
172   * For {@link ListOfCompartments}, the XML element name is <code>'listOfCompartments'.</code>
173   <p>
174   * @return the name of this element, i.e., <code>'listOfCompartments'.</code>
175   */ public
176 String getElementName() {
177    return libsbmlJNI.ListOfCompartments_getElementName(swigCPtr, this);
178  }
179
180  
181/**
182   * Get a {@link Compartment} from the {@link ListOfCompartments}.
183   <p>
184   * @param n the index number of the {@link Compartment} to get.
185   <p>
186   * @return the nth {@link Compartment} in this {@link ListOfCompartments}.
187   <p>
188   * @see #size()
189   */ public
190 Compartment get(long n) {
191    long cPtr = libsbmlJNI.ListOfCompartments_get__SWIG_0(swigCPtr, this, n);
192    return (cPtr == 0) ? null : new Compartment(cPtr, false);
193  }
194
195  
196/**
197   * Get a {@link Compartment} from the {@link ListOfCompartments}
198   * based on its identifier.
199   <p>
200   * @param sid a string representing the identifier 
201   * of the {@link Compartment} to get.
202   <p>
203   * @return {@link Compartment} in this {@link ListOfCompartments}
204   * with the given <code>sid</code> or <code>null</code> if no such
205   * {@link Compartment} exists.
206   <p>
207   * @see #get(long n)
208   * @see #size()
209   */ public
210 Compartment get(String sid) {
211    long cPtr = libsbmlJNI.ListOfCompartments_get__SWIG_2(swigCPtr, this, sid);
212    return (cPtr == 0) ? null : new Compartment(cPtr, false);
213  }
214
215  
216/**
217   * Removes the nth item from this {@link ListOfCompartments} items and returns a pointer to
218   * it.
219   <p>
220   * The caller owns the returned item and is responsible for deleting it.
221   <p>
222   * @param n the index of the item to remove
223   <p>
224   * @see #size()
225   */ public
226 Compartment remove(long n) {
227    long cPtr = libsbmlJNI.ListOfCompartments_remove__SWIG_0(swigCPtr, this, n);
228    return (cPtr == 0) ? null : new Compartment(cPtr, true);
229  }
230
231  
232/**
233   * Removes item in this {@link ListOfCompartments} items with the given identifier.
234   <p>
235   * The caller owns the returned item and is responsible for deleting it.
236   * If none of the items in this list have the identifier <code>sid</code>, then
237   * <code>null</code> is returned.
238   <p>
239   * @param sid the identifier of the item to remove
240   <p>
241   * @return the item removed.  As mentioned above, the caller owns the
242   * returned item.
243   */ public
244 Compartment remove(String sid) {
245    long cPtr = libsbmlJNI.ListOfCompartments_remove__SWIG_1(swigCPtr, this, sid);
246    return (cPtr == 0) ? null : new Compartment(cPtr, true);
247  }
248
249}