GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

Cloning Objects

A mentioned previously, each GAT class has a ``Clone'' function. This subsection's example program will detail the use of such a ``Clone'' function.

The ``Clone'' function, with which every GAT class is equipted allows an application programmer to make a deep clone of a GAT object. This is useful, for example, if one has an instance of a GAT class and wishes to make a copy, which is semantically equivalent to the original instance, to modify it in some way while keeping the original instance around un-modified. One could also conceive of a situation in which one would modify the original in some orthognal manner. The example of this section will show the use of such a ``Clone'' function.

The full example for this subsection is as follows

#include "GAT.h"
#include <stdio.h>

int main(void)
{
  GATBool isequal;
  GATTime timeOne;
  GATTime timeTwo;
  GATResult result;
  
  /* Create a GATTime corresponding to now */
  timeOne = GATTime_Create( 0 );
  
  /* Check timeOne is not NULL */
  if( NULL != timeOne )
  {
    /* Clone the GATTime timeOne */
    result =  GATTime_Clone( timeOne,  &timeTwo );
    
    /* Check success of call to GATTime_Clone */
    if( GAT_SUCCEEDED( result ) )
    {
      /* Determine if timeOne and timeTwo are semantically equivalent */
      result = GATTime_Equals( timeOne, timeTwo, &isequal );
      
      /* Check success of call to GATTime_Equals */
      if( GAT_SUCCEEDED( result ) )
      {
        /* Print result of call to GATTime_Equals */
        if( GATTrue == isequal )
        {
          printf( "timeOne and timeTwo are semantically equivalent\n" );
        }
        else
        {
          printf( "timeOne and timeTwo are not semantically equivalent\n" );
        }
      }
    }
  }
  
  /* Destroy the GATTime timeOne */
  GATTime_Destroy( &timeOne );
  
  /* Destroy the GATTime timeTwo */
  GATTime_Destroy( &timeTwo );
  
  return 0;
}

We have covered all the elements of this program previously, except one. The new element is the call to the function

GATResult GATTime_Clone(GATTime_const timeOne, GATTime * timeOneClone)

This function takes the passed GATTime_const instance timeOne and makes a deep clone of it. The deep clone is returned in the GATTime pointed to by the passed GATTime*. The completion status of this function is returned through the return value of this function, a GATResult.


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