next up previous contents
Next: A.3. MDL Function Definition Up: A. A Tiny Algorithm Previous: A.1. VMAKE Project Definition


A.2. Application Body

The application body with the main function is defined within the C++ source file tinyapp.cc (Example A.3). In this example the tinyapp test application is linked with the Parameter and Model extension libraries described in Appendix A.4 and Appendixsec:tinyapp:modeldef, which allows for the usage of the therein defined Parameter and Interface structures within the application source code.

The main function of tinyapp can be divided into three sections as described in Section 2.6. The first section contains the initialization of tinyapp and is performed by

The main part of the application consists of a single evaluation of the TinyAppTest Model instance after setting the interface parameters min and max to their intended values. For shutting down the application it is sufficient to shut down the Algorithm Library by calling the function mdlShutDownModelServer. This will automatically delete all remaining Model instances and shut down all initialized MDL extension libraries, whether they are linked against the executable or dynamically loaded during runtime of the application.

The according VMAKE makefile vmfile.mk in the tinyapp project directory is presented in Example A.2.

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

(Module-Directory TinyAlibApplication-Dir)

(C++-Target TinyAlibApplication-Objects
            :source "tinyapp.cc")

(Program-Target TinyAlibApplication
                :progname  "tinyapp"
                :objects   TinyAlibApplication-Objects
                :libraries Vienna-Model-Library
                           TinyAlibParExtLib-Library
                           TinyAlibModelExtLib-Library  )

Example A.2: The VMAKE makefile vmfile.mk

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

#include <iostream.h>
#include "vmodel.hh"                // Algorithm Library Declarations

#include "TinyAlibParExtLib.ahh"    // MDL Parameter Types
#include "TinyAlibModelExtLib.ahh"  // MDL Model classes

void shutDown(MdlString message) {  // die verbosely
   cerr << message << endl;
   mdlShutDownModelServer();
   exit(1);
}

int main (int argc, const char  **argv) {
   /*  INITIALIZATION  */
   /* -------- */
   ModelPtr    testModel;
   Param<double> min("min"),max("max");
   PlotModelInterface testInterface;

   if (mdlInitModelServer() == false) shutDown ("Can't initialize!");

   TinyAlibParExtLib_addLocalParams();  // initialize Parameter ext. library
   TinyAlibModelExtLib_addLocalModels();// initialize Model extension library
   
   if ( !mdlParseMDLFile(argv[1])) shutDown("Parsing error!");

   // request the Model from the Model server
   min.link(testInterface.search("minX"));
   max.link(testInterface.search("maxX"));
   
   testModel = mdlRequestModel( "TinyAppTest",    // instance name
                                "PlotModel",      // required Model type
                                &testInterface    // Interface
                              );

   /* test if the Model is correctly instantiated */
   if (!testModel)
      shutDown("The Program teminated with a fatal error!");

   /*  Main Part  */
   /* ------ */
   min=0;max=10.0;
   if ( !testModel->evaluate() ) {
      cerr << "Evaluation of 'TinyAppTest' failed" << endl;
   }
   
   /*  Shutdown  */
   /* ----- */
   mdlShutDownModelServer();
   return 0;
}

Example A.3: C++ source code of a tiny Algorithm Library application


next up previous contents
Next: A.3. MDL Function Definition Up: A. A Tiny Algorithm Previous: A.1. VMAKE Project Definition
Robert Mlekus
1999-11-14