VistaIOtype(3)

VistaIOtype πŸ’…

okay bestie, so this is a page from the Library Functions Manual about VistaIOtype, and it's literally all about registering Vista object types. sit down, grab a strawberry, we're doing this πŸ“


✨ NAME ✨

VistaIOtype β€” registering Vista object types πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

πŸ’– Introduction πŸ’–

okay so. an object β€” like an image or an edge set β€” gets represented inside a Vista data file by an attribute. and that attribute's value is carrying around three things: a type name, an attribute list, and maybe some binary data. and honestly? that form is great for storing and communicating the object. but in memory you usually want a different representation. like, an image in memory is best represented by a structure with fixed fields to record the image properties you keep touching. it's giving practical. ✨

and here's the slay part: the Vista library lets you 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). no cap.

since Vista lets you invent your own types of objects and 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). bestie you should read it before reading this one. fr fr. πŸ“š

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.


🌸 Registering a Type 🌸

so this is the whole vibe:

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 you register a custom object type you will need to establish:

  • a unique name identifying the type. the name must match the regular expression [a-zA-Z0-9_.+-]+ (see grep(1)), and it must not be bit, ubyte, sbyte, short, long, float, double, attr-list, boolean, bundle, list, pointer, string, edges, image, or any type name already registered. the audacity of trying to steal a name bestie, don't. πŸ’€
  • a data structure for representing instances of the type in memory. a single pointer must suffice for referring to an instance, and the memory for each instance must be dynamically allocated. πŸ‘‘
  • a set of routines for copying, destroying, encoding, and decoding instances of the type. these routines are called methods. they're described in more detail below. ⬇️
  • any other routines or macros your programs will be using to access or manipulate instances of the type.

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)). iconic. ✨


πŸŽ€ Methods πŸŽ€

the type you register must be accompanied by these five methods:

typedef VistaIOPointer VistaIOCopyMethod (VistaIOPointer value);
  • the Copy method is passed an instance of your type; it returns a copy of that object made with newly-allocated storage. 🫢
typedef void VistaIODestroyMethod (VistaIOPointer value);
  • the Destroy method releases all storage occupied by the object value. bye bye storage πŸ‘‹
typedef VistaIOPointer VistaIODecodeMethod (VistaIOStringConst name,
          VistaIOBundle bundle);
  • the Decode method creates an instance of your type. data for the object is supplied via bundle in the form of an attribute list and an optional block of binary data, both of which may be modified by the method. an attribute name, name, is supplied for use in any error messages produced by decode (e.g., ``The name attribute has the wrong amount of binary data''). the method returns the newly-created object, or NULL if an error is encountered. 😭
  • storage for the new object can be freshly allocated, or it can be taken from bundle provided bundle itself is left in a state such that it can be destroyed without releasing storage used by the new object. for example, the new object can incorporate the attribute list bundle->list provided bundle->list is then set to a new, empty attribute list. it can incorporate the data block bundle->data provided bundle->length is then set to zero. lowkey genius tbh.
typedef VistaIOAttrList VistaIOEncodeAttrMethod (VistaIOPointer value,
          size_t *length);

typedef VistaIOPointer VistaIOEncodeDataMethod (VistaIOPointer value,
          VistaIOAttrList list, size_t length, VistaIOBoolean *free_it);
  • these two methods produce an attribute list value and a block of binary data from an instance of your type. for any particular object the two methods are always called in sequence. first the EncodeAttr method is called with value identifying the object. it returns the attribute list value while setting length to the number of bytes required for the block of binary data. later, the EncodeData method is called with value identifying the same object, and list and length supplying the values returned by the EncodeAttr method. it returns a pointer to memory containing the block of binary data while setting free_it to TRUE if the memory should be released once the binary data has been recorded. setting free_it to FALSE indicates that the memory may be part of the object, value, and the memory contents should be recorded before taking any action that might modify the object. ⚠️
  • the attribute list returned by the EncodeAttr method can be assumed to exist only until the subsequent call to the EncodeData method. if this list is created by the EncodeAttr method, then the EncodeData method is responsible for destroying it. a practice adopted for the image and edges types is for the EncodeAttr method to return a list that belongs to the object being encoded, but with some standard attributes prepended to it; the EncodeData method then removes the prepended attributes so that the object is left in the correct form. 🧚
  • if either method encounters an error, it signals the error by returning NULL. note that both methods are called even if the first indicates, by setting length to zero, that there is no binary data associated with value. when there is no binary data to return, the EncodeData method should return a non-NULL pointer and set free_it to FALSE to avoid signalling an error. don't be dramatic and throw an error for no reason bestie πŸ’…

⭐ Querying Registered Types ⭐

the following routine and macro provide information about registered types:

VistaIORepnKind VistaIOLookupType (VistaIOStringConst name)
  • VistaIOLookupType returns the representation code associated with the type named name. (this will be the same as that returned by VistaIORegisterObjectType when the type was registered.) if name is not the name of a known type, VistaIOLookupType returns VistaIOUnknownRepn. πŸ™ˆ
VistaIOTypeMethods *VistaIORepnMethods (VistaIORepnKind repn)
  • the macro VistaIORepnMethods provides a handle to the methods for the registered type identified by repn. ✨

🌈 Standard Object Types 🌈

the library implements some standard object types using the mechanism described by this manual page. currently, these standard object types are:

  • edges β€” set of edges. see VistaIOEdges(3). πŸ•ΈοΈ
  • image β€” multi-band two-dimensional array of pixels. see VistaIOImage(3). πŸ–ΌοΈ

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. go read the source bestie, iykyk πŸ“–


πŸ’œ SEE ALSO πŸ’œ

VistaIOBundle(3), VistaIOattribute(3),


πŸ‘‘ AUTHOR πŸ‘‘

Art Pope <pope@cs.ubc.ca>

Adaption to vistaio: Gert Wollny <gw.fossdev@gmail.com>


and that's the whole page bestie, no crumbs left 🫢 this was VistaIO Version 1.2.14, dated 26 January 1994 β€” yes she's vintage, yes she still ate πŸ’…βœ¨πŸŽ€