next up previous contents
Next: 2.5 Definition of Model Classes Up: 2. The Algorithm Library Previous: 2.3.5 MDL Functions


2.4 Definition of Model Classes in C++

The recommended procedure for the definition of a new MDL base class MDLClass with one interface parameter cxxParName in C++ is to separate the definitions into three parts as illustrated in the pseudo code given in Example 2.2 and Example 2.3:

A small example application illustrating the implementation of an MDL interpreter and a Model serving as parent class for further MDL classes is described in more detail in Appendix A.5.

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

#include "vmodel.hh"  // headers of the MDL Library

class ParameterList {
protected:
   Parameter<type> cxxParName;
   void addParams2Interface(Interface& i);
};

class InterfaceClass :
public Interface, public  ParameterList {
   InterfaceClass() { addParams2Interface(this); }
};

class MDLClass : public Model , public ParameterList {
public:
   ModelClassStdDeclarations(MDLClass);
};

Example 2.2: C++ header file template for an MDL Model class

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

void ParameterList::addParams2Interface(Interface& i) {
   // set the parameter names
   cxxParName.setName    ("MDLParName");
   cxxParName.setInfo    ("documentation");
   cxxParName.setDefault (value);
   i.addParam( &cxxParName );
}

// MDL Class Definition
MODEL_CLASS_DEFINITION_EXTENSIONS(MDLClass)
ModelClassStdConstructor(MDLClass)
ModelClassStdDestructor(MDLClass)

bool MDLClass::init() {
   MODEL_CLASS_INIT_EXTENSION;
   addParams2Interface(getInterface());
   return vTRUE;
}

bool MDLClass::evaluate () {
  // ....
  return true;
}

Example 2.3: C++ source file template for an MDL Model class

The therein contained C++ preprocessor macros MODEL_CLASS_DEFINITION_EXTENSIONS and MODEL_CLASS_INIT_EXTENSION are required by Algorithm Library internal modules for the runtime type management and dynamic creation of MDL classes within the MDL interpreter. The standard constructor and destructor methods ModelClassStdConstructor and ModelClassStdDestructor implemented by using C++ preprocessor macros can be replaced by own definitions on demand. The automation of the process of generating Algorithm Library compatible Model classes from ordinary C++ classes by adding all the extensions mentioned in this section is subject for future extensions of the Algorithm Library.

Similar to the introduction of new Parameter classes, new Model classes have to be declared to the Algorithm Library modules using a LISP table. The therein contained columns are described in Table 2.6. The automated process of the generation of dynamic Model extension libraries containing the described Model classes is discussed in Section 2.7.

(tuple
 '(LocModels
   ( modelDecl   vClass     primBase     )
   ( String      String     String       )
   ))


Table 2.6: Columns of the Model definition table
Column Name Description
modelDecl C++ header file containing the declaration of the Model class.
vClass C++ class name of the Model class.
primBase C++ class name of the ``primary'' parent Model class or 'NIL'. This column needs only non-'NIL' values for Model classes inheriting from multiple parent Model classes to compile with certain C++ compilers which do not fully support virtual base classes!


next up previous contents
Next: 2.5 Definition of Model Classes Up: 2. The Algorithm Library Previous: 2.3.5 MDL Functions
Robert Mlekus
1999-11-14