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:
Write a parser module for the object specification.
Write a template to create the output required.
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 ...
Get Advanced Perl Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.