The resource manager

Up to now we have avoided resources as much as possible. But now we must take a peak at the Centaur resource manager in order to add resources to our Ppml specification.

Each Centaur tool -pretty printer, formalism, graphical object, editor, etc.- has certain parameters, called properties, that the system or user should be able to specify and modify without altering the component's code. A tool may have subtools which may have their own subtools and so on, and at each level we should be able to specify property values. A resource specification is a pattern that traces a tool's position in the resource hierarchy (which is known in advance), designates one property for the tool, and furnishes a value. For example, to specify the background color of the basic pretty printer for the Exp formalism, we write:


*formalism-Exp.pprinter-basic.Format.Background: Blue

A resource pattern may consist of resource class names, instance names, question marks, and asterisks. A class name, such as Format above, means that all objects of this class will be given this resource value. An instance name, such as Exp, means that only instances of the Formalism class named Exp will be given this resource value. Thus, this specification does not apply to the METAL formalism, for example.

The question mark replaces one level of a resource pattern. The asterisk replaces any number of levels in the path. Thus, the line:


*Pprinter.Format.Background: Blue

specifies the background color for all pretty printers of all formalisms (the asterisk covers the formalism part). The line:


*Background: Blue

means that everything will have a blue background (selections, text, windows, etc.).

Normally we create a database file that contains a list of such specifications which the resource manager loads automatically into the current database. When a tool requires a property value, it provides a query to the resource manager who consults the current database for a pattern that matches (or returns a cached value). However, the database may contain several patterns that apply for the same query. The most important thing to remember about resources is that when several patterns match, the most specific resource pattern is always chosen.

Precedence is defined in the following order, from most specific to least specific: instance name, class name, question mark, asterisk. Thus, if the current database contains these patterns:


*formalism-Exp*Background: Green
*formalism-Exp.Pprinter.Format.Background: Blue
*Pprinter.Format.Background: Yellow

and we request the background color for the basic pretty printer of the Exp formalism, the resource manager returns Blue. Note that between the two following resources:


Centaur*Background: Green
*formalism-Exp.Pprinter.Format.Background: Blue

the resource manager would return Green since at the first level, Centaur is more specific than the asterisk.


                  



Tutorial