problem.setcbformula
problem.setcbformula |
Purpose
Set a callback to be used in formula evaluation when an unknown token is found
Synopsis
problem.setcbformula (callback, object)
(retval = result) = callback (my_prob, my_object, value)
Arguments
callback
|
The function to be called during formula evaluation.
callback returns an integer value. At present the value is ignored.
|
my_prob
|
The problem passed to the callback function.
|
my_object
|
The user-defined object passed as
object to
setcbformula.
|
value
|
The
Value of the unknown token.
|
result
|
Address of a double precision value to hold the result of the calculation.
|
object
|
Address of a user-defined object, which can be used for any purpose by the function.
object is passed to
callback as
my_object.
|
Example
The following example sets a callback to process unknown tokens in formulae. It then creates a formula with an unknown token, and evaluates it.
def MyCB (MyProb, MyObject, MyValue): if (MyValue == None): Result = 1 else: Result = 0 return (0, Result) p.setcbformula (MyCB,None) nToken = 0 type = [xslp_op_con, xslp_op_unknown, xslp_op_op, xslp_op_eof] value = [10, z, xslp_op_plus, 0] answer = p.evaluateformula (1, type, value) printf ("Answer:", answer)
This demonstrates how the value of an unknown token can be set in any way, as long as the routine that sets the token up and the callback agree on how it is to be interpreted.
In this case, the value actually contains the address of a character string, which is converted by the callback into a real number.
Related topics