muparser - Fast Math Parser Library

Version 2.2.5

Defining parser functions

The parser allows the definition of a wide variety of different callback functions. Functions with a fixed number of up to ten numeric arguments, functions with a variable number of numeric arguments and functions taking a sinlge string argument plus up to two numeric values. In order to define a parser function you need to specify its name, a pointer to a static callback function and an optional flag indicating if the function is volatile. Volatile functions are functions that do not always return the same result for the same arguments. They can not be optimized.

The static callback functions must have of either one of the following types:

// For fixed number of arguments
value_type (*fun_type1)(value_type); 
value_type (*fun_type2)(value_type, value_type); 
value_type (*fun_type3)(value_type, value_type, value_type); 
value_type (*fun_type4)(value_type, value_type, value_type, value_type); 
value_type (*fun_type5)(value_type, value_type, value_type, value_type, value_type); 
// ... and so on to up to 10 parameters

// for a variable number of arguments
//   first arg:   pointer to the arguments
//   second arg:  number of arguments
value_type (*multfun_type)(const value_type*, int);

// for functions taking a single string plus up to two numeric values
value_type (*strfun_type1)(const char_type*);
value_type (*strfun_type2)(const char_type*, value_type);
value_type (*strfun_type3)(const char_type*, value_type, value_type);

[DLL interface]

When using the DLL version it is necessary to call a seperate function for each type of callback. The following is a list of possible choices.
// Add functions taking string parameters that cant be optimized
mupDefineStrFun1(hParser, "StrFun1", pStrCallback1, false); 
mupDefineStrFun2(hParser, "StrFun2", pStrCallback2, false); 
mupDefineStrFun3(hParser, "StrFun3", pStrCallback3, false); 

// Add an function with a fixed number of arguments
mupDefineFun1(hParser, "fun1", pCallback1, false);             
mupDefineFun2(hParser, "fun2", pCallback2, false);             
mupDefineFun3(hParser, "fun3", pCallback3, false);    
mupDefineFun4(hParser, "fun4", pCallback4, false);             
mupDefineFun5(hParser, "fun5", pCallback5, false);             

// Define a function with variable number of arguments
mupDefineMultFun(hParser, "MultFun", pMultCallback);  
See also: example2/example2.c.

[Parser class interface]

Defining callback functions by using the parser class directly is easier since there is only a single member function that is used for all kinds of callbacks. Since this member function is defined as a template internally it automatically associates the right code to any given type of callback. (As long as this type is listed above)
parser.DefineFun("FunName", pCallback, false)
See also: example1/example1.cpp; src/muParser.cpp; src/muParserInt.cpp.

You might also like: