com.bc.jexp.impl
Class UserFunction

java.lang.Object
  extended by com.bc.jexp.impl.AbstractFunction
      extended by com.bc.jexp.impl.UserFunction
All Implemented Interfaces:
Function

public final class UserFunction
extends AbstractFunction

A utility class which represents a user-defined function to be used within an expression.

User functions are created from a list parameters of type Variable and the function body, which is an arbitrary instance of Term. The function's return type is derived from the return type of the body.

User function bodies can be recursive - they can contain a node of the type Term.Call, which calls the function itself. An EvalException is thrown if the maximum stack size is reached.

Version:
$Revision$ $Date$
Author:
Norman Fomferra (norman.fomferra@brockmann-consult.de)
See Also:
getStackSizeMax(), setStackSizeMax(int)

Nested Class Summary
 
Nested classes/interfaces inherited from class com.bc.jexp.impl.AbstractFunction
AbstractFunction.B, AbstractFunction.D, AbstractFunction.I
 
Constructor Summary
UserFunction(String name, Variable[] params, Term body)
          Construcs a new user function with the given name, parameter list and body.
 
Method Summary
 boolean evalB(EvalEnv env, Term[] args)
          Evaluates this function to a double value.
 double evalD(EvalEnv env, Term[] args)
          Evaluates this function to a double value.
 int evalI(EvalEnv env, Term[] args)
          Evaluates this function to an int value.
static int getStackSizeMax()
          Gets the maximum stack size.
static void setStackSizeMax(int stackSizeMax)
          Sets the maximum stack size.
 
Methods inherited from class com.bc.jexp.impl.AbstractFunction
getArgType, getName, getNumArgs, getRetType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserFunction

public UserFunction(String name,
                    Variable[] params,
                    Term body)
Construcs a new user function with the given name, parameter list and body.

Parameters:
name - the function's name, must not be null
params - the parameter list, must not be null
body - the function's body, must not be null
Method Detail

evalB

public boolean evalB(EvalEnv env,
                     Term[] args)
              throws EvalException
Description copied from interface: Function
Evaluates this function to a double value.

Parameters:
env - the application dependant environment.
args - the (un-evaluated) arguments passed to the function
Returns:
a double value
Throws:
EvalException - if the evaluation fails

evalI

public int evalI(EvalEnv env,
                 Term[] args)
          throws EvalException
Description copied from interface: Function
Evaluates this function to an int value.

Parameters:
env - the application dependant environment.
args - the (un-evaluated) arguments passed to the function
Returns:
an int value
Throws:
EvalException - if the evaluation fails

evalD

public double evalD(EvalEnv env,
                    Term[] args)
Description copied from interface: Function
Evaluates this function to a double value.

Parameters:
env - the application dependant environment.
args - the (un-evaluated) arguments passed to the function
Returns:
a double value

getStackSizeMax

public static int getStackSizeMax()
Gets the maximum stack size.

Returns:
the maximum stack size in element units.

setStackSizeMax

public static void setStackSizeMax(int stackSizeMax)
Sets the maximum stack size.

Parameters:
stackSizeMax - the maximum stack size in element units.


Copyright © 2002-2012 Brockmann Consult GmbH. All Rights Reserved.