GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



next up previous contents
Next: Determining Object Equality Up: Some Not So Useful Previous: Some Not So Useful   Contents

Getting an Object's Type

From the discussion earlier in this chapter, one can glean that each GAT class has a corresponding ``GetType'' function that returns a GATType, an enum whose values correspond to the various GAT types. (The full set of values which this enum may take on are detailed in Appendix [*].) As our first example we will examine a program which obtains the GATType corresponding to a given GAT object. The full program is as follows

#include "GAT.h"

int main(void)
{
  GATType type;
  GATTime time;
  
  /* Create a GATTime corresponding to now */
  time = GATTime_Create(0);
  
  /* Obtain the GATType of the GATTime time */
  if( NULL != time )
  {
    type = GATTime_GetType(time);
  }
  
  /* Destroy the GATTime time */
  GATTime_Destroy( &time );
  
  return 0;
}

Let's examine this program line by line.

The first line in the program

#include "GAT.h"

is required of all GAT programs. This line includes the header GAT.h in which all the various functions and struct's required by GAT are declared. Next the lines

int main(void)
{
  ...
}

are standard in any C program; thus, we won't belabor their details here. The next line

GATType type;

declares a variable type of type GATType which we will use to hold the GAT type of the GAT object we will study. The following line

GATTime time;

declares a variable time of type GATTime. As one can glean from figure [*], GATTime is a GATObject. Thus, as we mentioned previously, it has a ``GetType'' function. We will use this ``GetType'' function to assign the variable type the GAT type of time. The next lines in the program

/* Create a GATTime corresponding to now */
time = GATTime_Create(0);

create a GATTime instance. The function GATTime_Create has the following signature

GATTime GATTime_Create(GATdouble64 intime);

and is used to create instances of the class GATTime. In particular, it takes a GATdouble64, a GAT primitive type (The full set of GAT primitive types are detailed in the Appendix [*].), and returns a corresponding GATTime instance. The value passed to this function, when non-zero, is interpreted as the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC, and the function returns a GATTime corresponding to this passed value. If the value $0$ is passed to this function, then the returned GATTime corresponds to the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC at which the function was called. In our case we pass $0$ to the function; thus, the returned GATTime corresponds to the ``instant'' the function was called. Next the lines

/* Obtain the GATType of the GATTime time */
if( NULL != time )
{
  type = GATTime_GetType(time);
}

begin by first checking that the GATTime time is not NULL. A NULL instance may be returned from a ``Create'' statement if, for example, memory is running low and the program was unable to allocate sufficient memory to create a GATTime instance. Here we simple check this is not the case. After this check, we are guaranteed to have a valid GATTime instance time on which we may operate. The next line obtains the GATType corresponding to time and assigns this value to type. The full signature of the function GATTime_GetType which does this is as follows

GATType GATTime_GetType(GATTime_const time)

where, as one will recall, GATTime_const is a const version of GATTime. The next lines of the program

/* Destroy the GATTime time */
GATTime_Destroy( &time );

simply call the function

void GATTime_Destroy(GATTime *time)

This function deallocates any resources tied up by the GATTime instance time and should always be called when one is done with a GATTime instance. Similar ``Destroy'' functions exist for all GAT classes and should be called on the corresponding instances when one is done with such instances[*]. The final line of the program

return 0;

is part of standard C, and thus, we will not review it here.


next up previous contents
Next: Determining Object Equality Up: Some Not So Useful Previous: Some Not So Useful   Contents
Andre Merzky 2004-05-13