next up previous contents index
Next: Triang2d "xdr" Up: More Examples Previous: Rot2d "xdr"

TimeStep "xdr"

 

This is a very good example on how references and NULL pointers are handled. The pre_object and post_object of a TimeStep instance can be identical, the pre_step or post_step can be NULL, the steps even can be cyclic (first pointing to last and vice versa). Nevertheless the TimeStep "xdr" method is very simple:

TIMESTEP *timestep_xdr(XDR *xdrp)
{
  TIMESTEP *self;
  int ver = 1;

  self = (TIMESTEP *)START_METHOD(G_INSTANCE);
  ASSURE(self, "", END_METHOD(NULL));

  if(!g_xdr_version(xdrp, &ver) ||
     !  xdr_double(xdrp, &self->time) ||
     !g_xdr_instance(xdrp, (INSTANCE **)&self->pre_step) ||
     !g_xdr_instance(xdrp, (INSTANCE **)&self->post_step) ||
     !g_xdr_instance(xdrp, (INSTANCE **)&self->pre_object) ||
     !g_xdr_instance(xdrp, (INSTANCE **)&self->post_object))
    END_METHOD(NULL);

  END_METHOD(self);
}
Compare this to the 140 lines of code of the old "read"/"write" methods which had to do all these checks for NULL pointers and references. Still the old routines were not able to detect all references correctly, i.e. if some objects were referenced somewhere outside the TimeStep sequence these references couldn't be detected.



SFB 256 Universität Bonn and IAM Universität Freiburg

Copyright © by the Sonderforschungsbereich 256 at the Institut für Angewandte Mathematik, Universität Bonn.