Two of the major design goals of the Algorithm Library and particularly the MDL language (see also Section 3) are partially contradicting: First the Algorithm Library is designed to provide an orthogonal set of operations on Model and Parameter classes but second it is desired to keep a maximum of compatibility between MDL and the C++ language. These paradigms come into conflict in conjunction with the decision if and how the concept of ``function definitions'' should be integrated into MDL.
The natural way of accessing and changing the values of Parameters is by defining proper methods for the involved Model classes. On the other hand abandoning the usage of the C++ function concept would imply the necessity to write a huge set of basic MDL classes wrapping at least a minimal set of functions required for development.
Therefore the Algorithm Library offers the possibility to introduce C++ functions taking up to two Parameters of arbitrary types as arguments and resulting in a value described by another Parameter. Again the procedure is to provide the function implementation by using traditional C++ code, and adding some LISP tables to the ``tuple file'' describing the contents of the extension library (Section 2.8):
(tuple
'(MDL-FunctionExpressions
( mdlExpr exprDescr cxxExpr parFkt instTuple errorMsg )
( String String String String fktTupleName String )
; further functions
))
(tuple
'(fktTupleName
(resType op1Type op2Type valFkt resAlias op1Alias op2Alias ( header ))
(String String String String String String String ( String ))
))
The first table with the name MDL-FunctionExpressions contains a list of all MDL functions providing the column entries described in Table 2.4 to the automatic source code generation routines of the Algorithm Library CASE interface module.
Column Name | Description |
mdlExpr | name of the function within MDL input decks |
exprDescr | name of an automatically generated C++ class used for the communication of the Algorithm Library with the MDL parser. |
cxxExpr | name of an automatically generated C++ template class implementing the MDL function expressions. |
parFkt | name of an automatically generated C++ template function used within the cxxExpr templates. |
instTuple | name of the LISP table listing all Parameter for which the function will be implemented |
errorMsg | C compatible format string for the printf function, which will be used to generate an error message in case the MDL function is not implemented for the particular combination of Parameters found on the input deck. |
These entries are required to work around possible conflicts with other C++ names defined in applications utilizing the Algorithm Library. Future implementations will manage without these columns as soon as the major C++ compilers provide working implementations of name spaces. |
The C++ function overloading concept is continued by enabling the definition of an MDL function for an arbitrary number of different Parameter type configurations. Each of these configurations has to be listed in another LISP table given by the corresponding column instTuple of the MDL-FunctionExpressions table. The column entries required are described in Table 2.5.
Column Name | Description |
resType | C++ class name of the result Parameter |
op1Type | C++ class name of the first function argument Parameter; NIL for functions with no arguments |
op2Type | C++ class name of the second function argument Parameter; NIL for functions with less than two arguments |
valFkt | C++ function implementing the MDL function |
resAlias | original C++ class name of resType if resType is defined by typedef resAlias resType; |
op1Alias | original C++ class name of op1Type if op1Type is defined by typedef op1Alias op1Type; |
op2Alias | original C++ class name of op2Type if op2Type is defined by typedef op2Alias op2Type; |
header | header file containing the declaration of valFkt |
Example 2.1 shows the table entries which would be necessary to introduce the MDL function atoi converting an MdlString parameter into an int Parameter by using the C++ function atoi.
(tuple
'(MDL-FunctionExpressions
(mdlExpr exprDescr cxxExpr parFkt instTuple errorMsg)
("atoi" "AtoiExprDescr" "AtoiExpr" "parAtoi" MDL-Fkt::atoi
"The function type '<%s> = atoi(<%s>)' is not defined!" )
))
(tuple
'(MDL-Fkt::atoi
(resType op1Type valFkt resAlias op1Alias ( header ))
("int" "MdlString" "atoi" "int" "MdlString" ( "stdlib.h" ))
))
Example 2.1: Definition of new MDL functions