Let us define a module geo for the representation of various geometric objects. The geo_h.tpl master template header file might look as can be seen in Fig. C.3.
geohtplexa/geo_h.tplThe geo_h.tpl master template header file
Since the Circle class has no parent class, it is automatically recognized as a root class (in VOOPS, multiple root classes are possible). Its only member is the circle Radius of double precision type. The Cylinder class inherits this member through specifying the Circle class as its parent. Additionally, it defines the cylinder Height as a member. After running VOOPS over this master template header file, the master header file of Fig. C.4 is produced.
geohexa/geo.hThe VOOPSed geo.h master header file
Now we define methods on these classes in the master template source file of Fig. C.5.
geoctplexa/geo_c.tplThe geo_c.tpl master template source file
The argument-less DEFAULTMETHODS statement is needed for VOOPS to include the class table (also called method-versus-class matrix), and generic default methods (i.e. methods applicable to any object). Then, the AreaOf method is defined on the Circle class returning a double value and receiving one object argument. Note the reference of the Radius member of the given object through the automatically predefined geoCircleRadius() accessor macro, providing an effective way of data hiding. Afterwards the VolumeOf method is defined on the Cylinder class. The SENDSELF statement gets translated to a geoAreaOfCylinder() call, since the current class is Cylinder. However, since the Cylinder class inherits this method from the Circle class, it is actually just a macro aliased to the geoAreaOfCircle() function.
The two DEFAULTMETHODS statements at the end of the file define the default methods for these two classes, if not overridden previously (which is not the case, since there are no AreaOf or VolumeOf default methods). The resulting C code after running VOOPS on this master template source file can be seen in Fig. C.6.
geocexa/geo.cThe VOOPSed geo.c master source file