next up previous contents
Next: 2.4 Definition of Model Classes Up: 2.3 Structures of the Previous: 2.3.4 Interface Structure


2.3.5 MDL Functions

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):% latex2html id marker 29396
\setcounter{footnote}{2}\fnsymbol{footnote}

(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.


Table 2.4: Columns of the MDL function definition tables
Column Name Description
mdlExpr name of the function within MDL input decks
exprDescr$^1$ name of an automatically generated C++ class used for the communication of the Algorithm Library with the MDL parser.
cxxExpr$^1$ name of an automatically generated C++ template class implementing the MDL function expressions.
parFkt$^1$ 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.
$^1$ 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.


Table 2.5: Columns of the MDL function definition tables
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.

\includegraphics[width=0.6cm]{figures/exaLeft.eps}

(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


next up previous contents
Next: 2.4 Definition of Model Classes Up: 2.3 Structures of the Previous: 2.3.4 Interface Structure
Robert Mlekus
1999-11-14