Beispiel #1
0
 L3ParserSettings(L3ParserSettings source) : this(libsbmlPINVOKE.new_L3ParserSettings__SWIG_4(L3ParserSettings.getCPtr(source)), true)
 {
     if (libsbmlPINVOKE.SWIGPendingException.Pending)
     {
         throw libsbmlPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #2
0
        internal static HandleRef getCPtrAndDisown(L3ParserSettings obj)
        {
            HandleRef ptr = new HandleRef(null, IntPtr.Zero);

            if (obj != null)
            {
                ptr             = obj.swigCPtr;
                obj.swigCMemOwn = false;
            }

            return(ptr);
        }
        internal static HandleRef getCPtrAndDisown(L3ParserSettings obj)
        {
            HandleRef ptr = new HandleRef(null, IntPtr.Zero);

            if (obj != null)
            {
            ptr             = obj.swigCPtr;
            obj.swigCMemOwn = false;
            }

            return ptr;
        }
 internal static HandleRef getCPtr(L3ParserSettings obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
Beispiel #5
0
 /**
  * Parses the given mathematical formula using specific parser settings and
  * returns an Abstract Syntax Tree (AST) representation of the result.
  *
  * This is identical to
  @if clike SBML_parseL3Formula()@endif@if csharp SBML_parseL3Formula()@endif@if python libsbml.parseL3Formula()@endif@if java <code><a href='libsbml.html#parseL3Formula(java.lang.String)'>libsbml.parseL3Formula(String formula)</a></code>@endif,
  * except that this function uses the parser settings given in the argument
  * @p settings.  The settings override the default parsing behavior.
  *
  * The parameter @p settings allows callers to change the following parsing
  * behaviors:
  *
  * @li Use a specific Model object against which identifiers to compare
  * identifiers.  This causes the parser to search the Model for identifiers
  * that the parser encounters in the formula.  If a given symbol in the
  * formula matches the identifier of a Species, Compartment, Parameter,
  * Reaction, SpeciesReference or FunctionDefinition in the Model, then the
  * symbol is assumed to refer to that model entity instead of any possible
  * mathematical terms with the same symbol.  For example, if the parser is
  * given a Model containing a Species with the identifier
  * &quot;<code>pi</code>&quot;, and the formula to be parsed is
  * &quot;<code>3*pi</code>&quot;, the MathML produced will contain the
  * construct <code>&lt;ci&gt; pi &lt;/ci&gt;</code> instead of the
  * construct <code>&lt;pi/&gt;</code>.
  * @li Whether to parse &quot;<code>log(x)</code>&quot; with a single
  * argument as the base 10
  * logarithm of x, the natural logarithm of x, or treat the case as an
  * error.
  * @li Whether to parse &quot;<code>number id</code>&quot; by interpreting
  * @c id as the identifier of a unit of measurement associated with the
  * number, or whether to treat the case as an error.
  * @li Whether to parse &quot;<code>avogadro</code>&quot; as an ASTNode of
  * type @link libsbmlcs.libsbml.AST_NAME_AVOGADRO AST_NAME_AVOGADRO@endlink or
  * as type @link libsbmlcs.libsbml.AST_NAME AST_NAME@endlink.
  * @li Whether to always create explicit ASTNodes of type @link
  * libsbmlcs.libsbml.AST_MINUS AST_MINUS@endlink for all unary minuses, or
  * collapse and remove minuses where possible.
  *
  * For more details about the parser, please see the definition of
  * L3ParserSettings and
  * @if clike SBML_parseL3Formula()@endif@if csharp SBML_parseL3Formula()@endif@if python libsbml.parseL3Formula()@endif@if java <code><a href='libsbml.html#parseL3Formula(java.lang.String)'>libsbml.parseL3Formula(String formula)</a></code>@endif.
  *
  * @param formula the mathematical formula expression to be parsed
  *
  * @param settings the settings to be used for this parser invocation
  *
  * @return the root node of an AST representing the mathematical formula,
  * or @c null if an error occurred while parsing the formula.  When @c null
  * is returned, an error is recorded internally; information about the
  * error can be retrieved using
  * @if clike SBML_getLastParseL3Error()@endif@if csharp SBML_getLastParseL3Error()@endif@if python libsbml.getLastParseL3Error()@endif@if java <code><a href='libsbml.html#getLastParseL3Error()'>libsbml.getLastParseL3Error()</a></code>@endif.
  *
  * @if clike @see libsbmlcs.libsbml.formulaToString()
  * @see SBML_parseL3Formula()
  * @see SBML_parseL3FormulaWithModel()
  * @see SBML_getLastParseL3Error()
  * @see SBML_getDefaultL3ParserSettings()
  * @endif
  * @if csharp @see libsbmlcs.libsbml.formulaToString()
  * @see SBML_parseL3Formula()
  * @see SBML_parseL3FormulaWithModel()
  * @see SBML_getLastParseL3Error()
  * @see SBML_getDefaultL3ParserSettings()
  * @endif
  * @if python @see libsbml.formulaToString()
  * @see libsbml.parseL3Formula()
  * @see libsbml.parseL3FormulaWithModel()
  * @see libsbml.getLastParseL3Error()
  * @see libsbml.getDefaultL3ParserSettings()
  * @endif
  * @if java @see <code><a href='libsbml.html#formulaToString(org.sbml.libsbml.ASTNode tree)'>libsbml.formulaToString(ASTNode tree)</a></code>
  * @see <code><a href='libsbml.html#parseL3Formula(java.lang.String)'>libsbml.parseL3Formula(String formula)</a></code>
  * @see <code><a href='libsbml.html#parseL3FormulaWithModel(java.lang.String, org.sbml.libsbml.Model)'>parseL3FormulaWithModel(String formula, Model model)</a></code>
  * @see <code><a href='libsbml.html#getLastParseL3Error()'>getLastParseL3Error()</a></code>
  * @see <code><a href='libsbml.html#getDefaultL3ParserSettings()'>getDefaultL3ParserSettings()</a></code>
  * @endif
  */
 public static ASTNode parseL3FormulaWithSettings(string formula, L3ParserSettings settings)
 {
     IntPtr cPtr = libsbmlPINVOKE.parseL3FormulaWithSettings(formula, L3ParserSettings.getCPtr(settings));
     ASTNode ret = (cPtr == IntPtr.Zero) ? null : new ASTNode(cPtr, true);
     return ret;
 }
 /**
    * Copy constructor.
    */
 public L3ParserSettings(L3ParserSettings source)
     : this(libsbmlPINVOKE.new_L3ParserSettings__SWIG_4(L3ParserSettings.getCPtr(source)), true)
 {
     if (libsbmlPINVOKE.SWIGPendingException.Pending) throw libsbmlPINVOKE.SWIGPendingException.Retrieve();
 }
Beispiel #7
0
 internal static HandleRef getCPtr(L3ParserSettings obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }
Beispiel #8
0
        /**
         * Converts an AST to a text string representation of a formula, using
         * specific formatter settings.
         *
         * This function behaves identically to @sbmlfunction{formulaToL3String,
         * ASTNode} but its behavior is controlled by two fields in the @p
         * settings object, namely:
         *
         * @li <em>parseunits</em> ('parse units'): If this field in the @p settings
         *     object is set to <code>true</code> (the default), the function will
         *     write out the units of any numerical ASTNodes that have them,
         *     producing (for example) &quot;<code>3 mL</code>&quot;,
         *     &quot;<code>(3/4) m</code>&quot;, or &quot;<code>5.5e-10
         *     M</code>&quot;.  If this is set to <code>false</code>, this function
         *     will only write out the number itself (&quot;<code>3</code>&quot;,
         *     &quot;<code>(3/4)</code>&quot;, and &quot;<code>5.5e-10</code>&quot;,
         *     in the previous examples).
         * @li <em>collapseminus</em> ('collapse minus'): If this field in the @p
         *     settings object is set to <code>false</code> (the default), the
         *     function will write out explicitly any doubly-nested unary minus
         *     ASTNodes, producing (for example) &quot;<code>- -x</code>&quot; or
         *     even &quot;<code>- - - - -3.1</code>&quot;.  If this is set to
         *     <code>true</code>, the function will collapse the nodes before
         *     producing the infix form, producing &quot;<code>x</code>&quot; and
         *     &quot;<code>-3.1</code>&quot; in the previous examples.
         *
         * All the other settings of the L3ParserSettings object passed in as @p
         * settings will be ignored for the purposes of this function: the
         * <em>parselog</em> ('parse log') setting is ignored so that
         * &quot;<code>log10(x)</code>&quot;, &quot;<code>ln(x)</code>&quot;, and
         * &quot;<code>log(x, y)</code>&quot; are always produced; the
         * <em>avocsymbol</em> ('Avogadro csymbol') is irrelevant to the behavior
         * of this function; and nothing in the Model object set via the
         * <em>model</em> setting is used.
         *
         * @param tree the AST to be converted.

         * @param settings the L3ParserSettings object used to modify the behavior of
         * this function.
         *
         * @return the formula from the given AST as text string, with a syntax
         * oriented towards the capabilities defined in SBML Level&nbsp;3.  The
         * caller owns the returned string and is responsible for freeing it when it
         * is no longer needed.  If @p tree is a null pointer, then a null pointer is
         * returned.
         *
         * @see @sbmlfunction{formulaToL3String, ASTNode}
         * @see @sbmlfunction{formulaToString, ASTNode}
         * @see @sbmlfunction{parseL3FormulaWithSettings, String\, L3ParserSettings}
         * @see @sbmlfunction{parseL3FormulaWithModel, String\, Model}
         * @see @sbmlfunction{parseFormula, String}
         * @see L3ParserSettings
         * @see @sbmlfunction{getDefaultL3ParserSettings,}
         * @see @sbmlfunction{getLastParseL3Error,}
         *
         * @if conly
         * @memberof ASTNode_t
         * @endif
         */
        public static string formulaToL3StringWithSettings(ASTNode tree, L3ParserSettings settings)
        {
            string ret = libsbmlPINVOKE.formulaToL3StringWithSettings(ASTNode.getCPtr(tree), L3ParserSettings.getCPtr(settings));
            return ret;
        }
 public void test_SBML_C_parseL3Formula_parselogsettings()
 {
     ASTNode r = libsbml.parseL3Formula("log(4.4)");
       ASTNode c;
       assertTrue( r.getType() == libsbml.AST_FUNCTION_LOG );
       assertTrue( r.getNumChildren() == 2 );
       c = r.getLeftChild();
       assertTrue( c.getType() == libsbml.AST_INTEGER );
       assertTrue( c.getInteger() == 10 );
       assertTrue( c.getNumChildren() == 0 );
       c = r.getRightChild();
       assertTrue( c.getType() == libsbml.AST_REAL );
       assertTrue( c.getReal() == 4.4 );
       assertTrue( c.getNumChildren() == 0 );
       r = null;
       L3ParserSettings settings = new  L3ParserSettings();
       settings.setParseLog(libsbml.L3P_PARSE_LOG_AS_LN);
       assertTrue( settings.getParseLog() == libsbml.L3P_PARSE_LOG_AS_LN );
       r = libsbml.parseL3FormulaWithSettings("log(4.4)", settings);
       assertTrue( r.getType() == libsbml.AST_FUNCTION_LN );
       assertTrue( r.getNumChildren() == 1 );
       c = r.getLeftChild();
       assertTrue( c.getType() == libsbml.AST_REAL );
       assertTrue( c.getReal() == 4.4 );
       assertTrue( c.getNumChildren() == 0 );
       r = null;
       settings.setParseLog(libsbml.L3P_PARSE_LOG_AS_LOG10);
       assertTrue( settings.getParseLog() == libsbml.L3P_PARSE_LOG_AS_LOG10 );
       r = libsbml.parseL3FormulaWithSettings("log(4.4)", settings);
       assertTrue( r.getType() == libsbml.AST_FUNCTION_LOG );
       assertTrue( r.getNumChildren() == 2 );
       c = r.getLeftChild();
       assertTrue( c.getType() == libsbml.AST_INTEGER );
       assertTrue( c.getInteger() == 10 );
       assertTrue( c.getNumChildren() == 0 );
       c = r.getRightChild();
       assertTrue( c.getType() == libsbml.AST_REAL );
       assertTrue( c.getReal() == 4.4 );
       assertTrue( c.getNumChildren() == 0 );
       r = null;
       settings.setParseLog(libsbml.L3P_PARSE_LOG_AS_ERROR);
       assertTrue( settings.getParseLog() == libsbml.L3P_PARSE_LOG_AS_ERROR );
       r = libsbml.parseL3FormulaWithSettings("log(4.4)", settings);
       assertTrue( r == null );
       assertTrue((  "Error when parsing input 'log(4.4)' at position 8:  Writing a function as 'log(x)' was legal in the L1 parser, but translated as the natural log, not the base-10 log.  This construct is disallowed entirely as being ambiguous, and you are encouraged instead to use 'ln(x)', 'log10(x)', or 'log(base, x)'." == libsbml.getLastParseL3Error() ));
       settings = null;
 }