Defining New Data Types

There is a limited form of user-defined type, the Message type.

The MLDesigner contains a heterogeneous message interface, which provides a mechanism for primitives to transmit arbitrary objects to other primitives. It’s design fulfills the following requirements:

The message type is interpreted by MLDesigner as a particle containing a message. There are three classes that implement the support for message types:

Class Particle contains two member functions for message support: getMessage, to receive a message, and the << operator with an Envelope as the right argument, to load a message into a particle. These functions return errors in the base class. They are overridden in the MessageParticle class with functions that perform the expected operation.

Defining a New Message Class

Every user-defined message is derived from class Message. Certain virtual functions defined in that class must be overridden, others may optionally be overridden. Here is an example of a user-defined message type:

Use of the Envelope Class

The Envelope class references objects of the Message class or derived classes. Once a message object is placed into an envelope object, the envelope takes over the responsibility for managing its memory: maintaining reference counts and deleting the message when it is no longer needed.

Use of the MessageParticle Class

If a porthole is of type message, its particles are objects of the class MessageParticle. A MessageParticle is simply a particle whose data field is an Envelope, which means that it can hold a Message in the same way that Envelope objects do.

Use of Messages in Primitives

Here are a couple of simple examples of primitives that produce and consume messages.