The tiny function plotting application is completed with the definition of a Model extension library containing the basic Model types PlotModel and GnuplotModel. Example A.9 depicts the definition of the virtual Model class PlotModel which serves for the definition of the interface common to all Model classes. GnuplotModel inherits its interface from this base class and provides an gnuplot compatible implementation of the MDL method plot. The definition of these Model classes is divided into the definition of the Parameter list, the Interface definition and the actual definition of the Model classes as described in Section 2.4. The according C++ source code file is listed in Example A.10. In particular it shows the installation of the C++ plot method of the GnuplotModel as a new MDL method for its derived Model classes.
The UNFUG tuple file TinyAlibModelExtLib.tup required for the generation of the Model extension library is listed in Example A.11. Again listing the VMAKE makefile for this Parameter extension library is omitted, since its derivation from the according template given in Example 2.9 can be done analogously to the derivation of the makefile for the function extension library (Example A.5) described in Appendix A.3.
#include "vmodel.hh"
#include "mdldblmap.hh"
class PlotModelParameters {
protected:
Param<MdlDblmap> map;
Param<double> minX;
Param<double> maxX;
Param<double> ptNr;
void addParams2Interface(Interface&,bool);
};
class PlotModelInterface : public PlotModelParameters, public Interface {
public:
PlotModelInterface() {addParams2Interface((Interface&)*this,false);}
};
class PlotModel : public Model, public PlotModelParameters {
public:
bool plot();
ModelClassStdDeclarations(PlotModel);
};
class GnuplotModel : public PlotModel {
public:
bool plot();
ModelClassStdDeclarations(GnuplotModel);
};
Example A.9: C++ header file for the definition two MDL Models
void PlotModelParameters::addParams2Interface(Interface& i,bool wDef) {
map.setName("map");
map.setInfo("[IO] Associative list [x] -> y");
minX.setName("minX"); maxX.setName("maxX"); ptNr.setName("ptNr");
if (wDef) {
minX.setDefault(0.); maxX.setDefault(1.); ptNr.setDefault(20);
}
i.addParam( &map ); i.addParam( &minX );
i.addParam( &maxX ); i.addParam( &ptNr );
}
// ------------------------------
RTTI_CLASS_DEFINITION_EXTENSIONS (PlotModel)
MODEL_CLASS_DEFINITION_EXTENSIONS(PlotModel)
ModelClassStdConstructor(PlotModel)
ModelClassStdDestructor(PlotModel)
bool PlotModel::evaluate () { return false; }
bool PlotModel::init () {
addParams2Interface(getInterface(),true);
addMDL_Method("plot",(mdlMethodPtr) &PlotModel::plot);
return true;
}
bool PlotModel::plot () {
return false;
}
// ------------------------------
RTTI_CLASS_DEFINITION_EXTENSIONS1 (GnuplotModel,PlotModel)
MODEL_CLASS_DEFINITION_EXTENSIONS1(GnuplotModel,PlotModel)
ModelClassStdConstructor1(GnuplotModel,PlotModel)
ModelClassStdDestructor(GnuplotModel)
bool GnuplotModel::evaluate () {
return plot();
}
bool GnuplotModel::init () {
addMDL_Method("plot",(mdlMethodPtr) &GnuplotModel::plot);
return true;
}
bool GnuplotModel::plot () {
cout << "set xlabel "x "" << endl;
cout << "set ylabel "y "" << endl;
MdlDblmapIter iter = map().first();
while(iter) {
cout << iter.key() << "" << iter.value() << endl;
iter++;
}
return true;
}
Example A.10: C++ source file for the definition MDL Models
; Declaration of the Symbolic Library Name
(defun LocalModelLibraryName () "TinyAlibModelExtLib")
; Declaration of MDL classes
(tuple
'(LocModels
( modelDecl vClass primBase )
( "plotmodel.hh" "PlotModel" NIL )
( NIL "GnuplotModel" NIL )
))
Example A.11: UNFUG tuples for these MDL Models