VistaIOtype(3) | Library Functions Manual | VistaIOtype(3) |
VistaIOtype - registering Vista object types
An object such as an image or edge set is represented in a Vista data file by an attribute. That attribute's value includes a type name, an attribute list, and possibly some binary data. Although the object is easily stored and communicated in that form, some other representation is often more useful when working with the object in memory. An image, for example, is best represented in memory by a structure with fixed fields to record the properties of the image that are frequently accessed.
The Vista library allows you to define a type that has its own internal representation for objects. By registering your type with the library you can arrange to have objects of that type automatically translated to and from your internal representation whenever data files are read and written. And when you use attribute lists to organize your objects, the objects will be correctly copied and released by routines such as VistaIOCopyAttrList(3) and VistaIODestroyAttrList(3).
Since Vista allows you to invent your own types of objects and to store those objects in data files, it must provide some way for standard programs to gracefully handle objects that are unfamiliar to them. A program must at least be able to copy your custom objects intact, binary data and all, from input to output. Unfamiliar objects are represented internally by the Vista library using the VistaIOBundle data structure, which is described separately in VistaIOBundle(3). You should be read it before reading this.
This manual page explains how to register a type, what routines you must supply to support a type you are registering, and how to find out about a registered type.
typedef struct {
VistaIOCopyMethod *copy; /* copy object's value */ VistaIODestroyMethod *destroy; /* destroy object's value */ VistaIODecodeMethod *decode; /* decode object's binary data */ VistaIOEncodeAttrMethod *encode_attr; /* encode object's attr list */ VistaIOEncodeDataMethod *encode_data; /* encode object's binary data */
} VistaIOTypeMethods;
VistaIORepnKind VistaIORegisterType (VistaIOStringConst *name, VistaIOTypeMethods *methods)
Before registering a custom object type you will need to establish
The type is registered with a call to VistaIORegisterType prior to any use of the type within a program. Pass to VistaIORegisterType the type's name and a pointer to a VistaIOTypeMethods structure listing the type's methods. VistaIORegisterType will return a unique code from the VistaIORepnKind series, which can subsequently be used to refer to the type whenever a VistaIORepnKind value is called for (e.g., in a call to VistaIOSetAttr(3)).
The type you register must be accompanied by these five methods:
typedef VistaIOPointer VistaIOCopyMethod (VistaIOPointer value);
typedef void VistaIODestroyMethod (VistaIOPointer value);
typedef VistaIOPointer VistaIODecodeMethod (VistaIOStringConst name, VistaIOBundle bundle);
typedef VistaIOAttrList VistaIOEncodeAttrMethod (VistaIOPointer value, size_t *length);
typedef VistaIOPointer VistaIOEncodeDataMethod (VistaIOPointer value, VistaIOAttrList list, size_t length, VistaIOBoolean *free_it);
The following routine and macro provide information about registered types:
VistaIORepnKind VistaIOLookupType (VistaIOStringConst name)
VistaIOTypeMethods *VistaIORepnMethods (VistaIORepnKind repn)
The library implements some standard object types using the mechanism described by this manual page. Currently, these standard object types are:
If you are developing your own custom type, you're encouraged to first consult these as examples; their methods are implemented in the files /usr/src/vista/EdgesType.c and /usr/src/vista/ImageType.c.
Art Pope <pope@cs.ubc.ca>
Adaption to vistaio: Gert Wollny <gw.fossdev@gmail.com>
26 January 1994 | VistaIO Version 1.2.14 |