previous chapter contents page top page next chapter

DataList

January 21, 1994

Defined in List.Def (version 133
Inherits from FixedList



Class Description

Class DataList is a small subclass of class FixedList that provides you with a convenient way to vary the size of the list's elements. Class FixedList assumes that the list stride is always four; class DataList looks at a stride field to determine what it should be.

Remember that if the documentation and the software (especially the definition files) disagree, always trust the software.

Programming Information

Instantiate: sometimes
Subclass: sometimes
Call its methods: sometimes

To obtain an object of class DataList, add an instance to an object definition file and edit its fields.

Here's an example of a data list used by an animation object. This list contains a set of speeds corresponding to various behaviors the animation can display:


Instance DataList 9321; // speeds
       length: 10;
       stride: 8;
        entry: <30.0,0.0>;   // walk
        entry: <100.0,0.0>;  // run
        entry: <0.0,0.0>;   // stop
        entry: <0.0,0.0>;   // sleep
        entry: <0.0,0.0>;   // sit down
        entry: <0.0,0.0>;   // pinch up
        entry: <0.0,0.0>;   // gesture
        entry: <0.0,0.0>;   // cry
        entry: <1.0,150.0>; // fall
        entry: <0.0,0.0>;   // wake up
End Instance;

The speeds are of type Dotpairs of long numbers for the vertical and horizontal speed componentsso this list's stride is 8. The following code fragment shows how you might extract data from the sample list shown above.

/* get the object ID of the data list */
ObjectID   behaviorSpeeds = Field(self, behaviorSpeeds);
Dot   speed;
/* get a speed from the data list, using ourBehavior
   as an index into the list */
ElementAt(behaviorSpeeds, ourBehavior, &speed);
SetHorizontalSpeed(self, speed.h);
SetVerticalSpeed(self, speed.v);

Methods you might call

The DataList class has one method you might Call:

Method Description
Stride Return the size of a list element

Methods you might override

Whenever you create a subclass of the DataList class, you might want to override the following method:

Method When to override
Init Initialize the data list

Description of fields

The DataList class defines the following fields:

Field Type Description
Inherited from AbstractList
length Unsigned The number of elements in the list
Defined by DataList
stride Unsigned The size in bytes of a list element

Method Descriptions

Init

operation Init(VAR newParams: NewDataListParameters)

Call: rarely
Override: sometimes

When a new object is created, the system calls Init to allow the new object to set up its fields. The params parameter points to a structure containing initial values for the object's fields. In the case of a data list, the structure looks like this:

typedef struct
   {
   Parameters   header;
   ulong        initialEntries;
   ulong        stride;
   } NewDataListParameters;

Init first sets the stride field to the value in newParams->stride. It then calls its inherited initialization method, passing along the header portion of the parameters.

You should override Init if your data list subclass defines any additional fields that should be initialized when a new instance is created, or if it needs to initialize its inherited fields to values other than the ones shown here. Be sure to include a call to InheritedInit so that the inherited fields are properly set up.

See the description of Object_Init for more information.

Stride

field stride: Unsigned, getter;
// operation Stride

Call: rarely
Override: never

This method is a getter for the stride field.