next up previous contents
Next: Connecting to Files Up: No Title Previous: Data Access

An Example Class

As an example of the ADI system we shall define and construct a few useful routines for a class called "Array". The definition first,

   data      members/'SHAPE*','TYPE*','Data'/

   adi_defcls( 'Array', ' ', 3, members, status )
The first argument to the routine adi_defcls is the name of the new class, followed by the names of the classes whose behaviour the new class will inherit (in this case none). The number and definition of the class data members follows. The asterisk following the names of the first two members indicates that they are mandatory keywords. If a data member has a default then this may be inserted after the keyword name following an equals sign, eg.
   data      members/'SHAPE*','TYPE*=_REAL','Data'/

   adi_defcls( 'Array(SHAPE,TYPE=_REAL)', 1, 'Data', status )
Note that ADI primitive types have the same names as their HDS counterparts. The rest of this discussion will assume that we have used the first of the definitions above.

The instantiation of all but the most trivial class objects is a two stage process. This is because the information required to perform create a functional instance of a class is arbitrarily large. The first stage is to allocate an empty template for the class.

   adi_new( 'Array', aid, status )
The only purpose of this routine is to reserve ADI internal storage space and to supply the user with an ADI identifier aid which can be used to further manipulate the object. The next stage is to define the values of the mandatory keywords,

   adi_cput1i( aid, 'SHAPE', 1, 256, status )
   adi_cput0c( aid, 'TYPE', '_REAL', status )
All the information required to create an array has now been supplied. All that remains is to create and perform the binding to any external objects as required. To perform a null binding (ie. the array will reside in memory) just specify 0 as the second argument to adi_creat.
   adi_creat( aid, 0, status )
We now have a new class instance up and running which we can shove data into. Here are a few examples,
   adi_cput1d( aid, 'Data', 256, my_double_array, status )
   adi_get1i( aid, 256, ivals, status )
The first of these demonstrates that ADI performs on the fly type conversion just like HDS. It is rather annoying to have so specify 'Data' when we know that there's only one data member, so ADI lets you use the primitive routines in this circumstance -- this is the only occasion where these routines can be thus used.





next up previous contents
Next: Connecting to Files Up: No Title Previous: Data Access



Web Master
Wed Oct 8 09:22:23 BST 1997