O'Reilly logo

Advanced Perl Programming by Sriram Srinivasan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Jeeves Example

We will consider a very simple object model specification file consisting of a list of classes, each of which contains a list of typed attributes:

// File: emp.om (om stands for object model)
class Employee { 
    int         id;
    string      name;
    int         dept_id;
};
class Department { 
    int    id;
    string name;
};

From this specification, we wish to produce a C++ header file for each class. Assume, for example, that the file Employee.h is expected to look like this (and similarly for Department.h):

#ifndef _Employee_h_
#define _Employee_h_
#include <Object.h>
// File : 'Employee.h'
// User : "sriram"
class Employee : Object {
   int id;
   string name;
   int dept_id;
   Employee(); // private constructor. Use Create()
public:
   // Methods
   static Employee* Create();
    ~Employee();
   // Accessor Methods;
   int   get_id();
   void set_id(int);
   string   get_name();
   void set_name(string);
   int   get_dept_id();
   void set_dept_id(int);
}
#endif

Instead of succumbing to the temptation of writing a throwaway script to handle this specific job, we use Jeeves. This approach has three steps:

  1. Write a parser module for the object specification.

  2. Write a template to create the output required.

  3. Invoke Jeeves with the name of the specification parser, the template file, and the example specification file.

This approach forces you to separate the parsing and output stages into two different modules. You might think it is simpler to write a throwaway script, but that’s not quite true: you still have the problem of parsing the specification and producing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required