11.3 Saving and Loading Specialized Objects

It can often be useful to define specializations of the predefined graphical objects, often with additional attributes. To be able to save these kind of objects you have to tell Bifrost three things:

  1. How to save the user-defined attributes
  2. How to load the user-defined attributes
  3. How to instantiate new objects

11.3.1 Writing user-data

A very crude method, far from the more sophisticated persistent store method, is used for storing user-defined attributes or user-data. Bifrost simply expects the user to encode the user-data in a one line text string (note: it is important that only one line is used). Furthermore the one line string should start with the PostScript comment character % if you want to be able to print the file as a regular PostScript file. Further bind the writeUserData virtual to write user-data. See squarelib.bet in ~beta/demo/bifrost for an example.

11.3.2 Reading user-data

Reading user-data is simply done by further binding the readUserData virtual. Reading user-data is the inverse of writing user-data.

11.3.3 Creating New Objects

To be able to instantiate objects of the proper type, Bifrost uses the name of the pattern as identification. This means that the user should keep the following in mind when defining specialized graphical objects:

Do not use anonymous patterns for your graphical objects. I.e. avoid

&Rect(# ... init::(# do ... #) ... #)[] -> draw

Use distinct names for all patterns you want to save in a given file.

Keep it simple: If you plan to save a very complex data structure along with your graphical objects, you should probably consider splitting your objects in to two parts: one for the graphics (some specialization of AbstractGraphicalObject) and one for your datastructure, which you then can save using a persistent store.


The Bifrost Graphics System - Reference Manual
© 1991-2002 Mjølner Informatics
[Modified: Monday October 16th 2000 at 13:43]